From bc71859699eaa968ef9dc152d17267c213030545 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 6 Nov 2019 13:45:22 +0100 Subject: [PATCH] Added Window->Split Source Buffer --- CMakeLists.txt | 2 +- src/files.h | 3 ++- src/menu.cc | 4 ++++ src/notebook.cc | 41 +++++++++++++++++++++++++++++------------ src/notebook.h | 2 +- src/window.cc | 14 ++++++++++++++ tests/stubs/notebook.cc | 2 +- 7 files changed, 52 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d67c97c..0b5f47d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.5.0.2") +set(JUCI_VERSION "1.5.0.3") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/src/files.h b/src/files.h index 83af234..48b1fd1 100644 --- a/src/files.h +++ b/src/files.h @@ -153,7 +153,8 @@ const std::string default_config_file = R"RAW({ #endif R"RAW( "window_close_tab": "w", - "window_toggle_split": "",)RAW" + "window_toggle_split": "", + "window_split_source_buffer": "",)RAW" #ifdef __APPLE__ R"RAW( "window_toggle_full_screen": "f",)RAW" diff --git a/src/menu.cc b/src/menu.cc index 497337e..8005bb2 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -489,6 +489,10 @@ const Glib::ustring menu_xml = R"RAW( _Toggle _Split app.window_toggle_split + + _Split _Source _Buffer + app.window_split_source_buffer +
diff --git a/src/notebook.cc b/src/notebook.cc index b23c3c2..55f3318 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -103,7 +103,7 @@ std::vector &Notebook::get_views() { return source_views; } -void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_index) { +void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_index, bool copy) { auto file_path = filesystem::get_normal_path(file_path_); if(notebook_index == 1 && !split) @@ -114,17 +114,19 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i auto canonical_file_path = boost::filesystem::canonical(file_path, ec); if(ec) canonical_file_path = file_path; - for(size_t c = 0; c < size(); c++) { - bool equal; - { - LockGuard lock(source_views[c]->canonical_file_path_mutex); - equal = canonical_file_path == source_views[c]->canonical_file_path; - } - if(equal) { - auto notebook_page = get_notebook_page(c); - notebooks[notebook_page.first].set_current_page(notebook_page.second); - focus_view(source_views[c]); - return; + if(!copy) { + for(size_t c = 0; c < size(); c++) { + bool equal; + { + LockGuard lock(source_views[c]->canonical_file_path_mutex); + equal = canonical_file_path == source_views[c]->canonical_file_path; + } + if(equal) { + auto notebook_page = get_notebook_page(c); + notebooks[notebook_page.first].set_current_page(notebook_page.second); + focus_view(source_views[c]); + return; + } } } @@ -162,6 +164,21 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i source_views.emplace_back(new Source::GenericView(file_path, language)); auto view = source_views.back(); + + if(copy) { + auto previous_view = get_current_view(); + if(previous_view) { + view->replace_text(previous_view->get_buffer()->get_text()); + if(!split) + toggle_split(); + else { + auto pair = get_notebook_page(get_index(previous_view)); + if(pair.second != -1) + notebook_index = pair.first == 0 ? 1 : 0; + } + } + } + view->configure(); view->scroll_to_cursor_delayed = [this](Source::BaseView *view, bool center, bool show_tooltips) { diff --git a/src/notebook.h b/src/notebook.h index 2577ca0..e730a03 100644 --- a/src/notebook.h +++ b/src/notebook.h @@ -34,7 +34,7 @@ public: Source::View *get_current_view(); std::vector &get_views(); - void open(const boost::filesystem::path &file_path, size_t notebook_index = -1); + void open(const boost::filesystem::path &file_path, size_t notebook_index = -1, bool copy = false); void open_uri(const std::string &uri); void configure(size_t index); bool save(size_t index); diff --git a/src/window.cc b/src/window.cc index 70a3860..4c5ca00 100644 --- a/src/window.cc +++ b/src/window.cc @@ -1426,6 +1426,20 @@ void Window::set_menu_actions() { menu.add_action("window_toggle_split", [] { Notebook::get().toggle_split(); }); + menu.add_action("window_split_source_buffer", [] { + auto view = Notebook::get().get_current_view(); + if(!view) { + Info::get().print("No source buffers found"); + return; + } + + auto iter = view->get_buffer()->get_insert()->get_iter(); + + Notebook::get().open(view->file_path, -1, true); + auto new_view = Notebook::get().get_current_view(); + new_view->place_cursor_at_line_offset(iter.get_line(), iter.get_line_offset()); + new_view->scroll_to_cursor_delayed(new_view, true, false); + }); menu.add_action("window_toggle_full_screen", [this] { if(this->get_window()->get_state() & Gdk::WindowState::WINDOW_STATE_FULLSCREEN) unfullscreen(); diff --git a/tests/stubs/notebook.cc b/tests/stubs/notebook.cc index a4681b4..53b682f 100644 --- a/tests/stubs/notebook.cc +++ b/tests/stubs/notebook.cc @@ -6,4 +6,4 @@ Source::View *Notebook::get_current_view() { return nullptr; } -void Notebook::open(const boost::filesystem::path &file_path, size_t notebook_index) {} +void Notebook::open(const boost::filesystem::path &file_path, size_t notebook_index, bool copy) {}