diff --git a/src/notebook.cpp b/src/notebook.cpp index 24cef1d..32c3862 100644 --- a/src/notebook.cpp +++ b/src/notebook.cpp @@ -102,6 +102,18 @@ std::vector &Notebook::get_views() { return source_views; } +bool Notebook::open(Source::View *view) { + for(size_t c = 0; c < size(); c++) { + if(view == source_views[c]) { + auto notebook_page = get_notebook_page(c); + notebooks[notebook_page.first].set_current_page(notebook_page.second); + focus_view(source_views[c]); + return true; + } + } + return false; +} + bool Notebook::open(const boost::filesystem::path &file_path_, Position position) { boost::system::error_code ec; if(file_path_.empty() || (boost::filesystem::exists(file_path_, ec) && !boost::filesystem::is_regular_file(file_path_, ec))) { diff --git a/src/notebook.hpp b/src/notebook.hpp index 51f39df..733c26d 100644 --- a/src/notebook.hpp +++ b/src/notebook.hpp @@ -41,6 +41,7 @@ public: std::vector &get_views(); enum class Position { left, right, infer, split }; + bool open(Source::View *view); bool open(const boost::filesystem::path &file_path, Position position = Position::infer); void open_uri(const std::string &uri); void configure(size_t index); diff --git a/src/window.cpp b/src/window.cpp index 676b21f..1765ead 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -784,7 +784,7 @@ void Window::set_menu_actions() { if(current_cursor_location->view != Notebook::get().get_current_view()) { // Move to current position if current position's view is not current view // (for instance, in case one is looking at a new file but has not yet placed the cursor within the file) - if(!Notebook::get().open(current_cursor_location->view->file_path)) + if(!Notebook::get().open(current_cursor_location->view)) return; } else { @@ -793,7 +793,7 @@ void Window::set_menu_actions() { --current_cursor_location; if(current_cursor_location->view != Notebook::get().get_current_view()) { - if(!Notebook::get().open(current_cursor_location->view->file_path)) + if(!Notebook::get().open(current_cursor_location->view)) return; } } @@ -809,7 +809,7 @@ void Window::set_menu_actions() { if(current_cursor_location->view != Notebook::get().get_current_view()) { // Move to current position if current position's view is not current view // (for instance, in case one is looking at a new file but has not yet placed the cursor within the file) - if(!Notebook::get().open(current_cursor_location->view->file_path)) + if(!Notebook::get().open(current_cursor_location->view)) return; } else { @@ -818,7 +818,7 @@ void Window::set_menu_actions() { ++current_cursor_location; if(current_cursor_location->view != Notebook::get().get_current_view()) { - if(!Notebook::get().open(current_cursor_location->view->file_path)) + if(!Notebook::get().open(current_cursor_location->view)) return; } } @@ -1307,7 +1307,7 @@ void Window::set_menu_actions() { Info::get().print("Saved Fix-Its to header file: " + filesystem::get_short_path(view->file_path).string()); } if(current_view != Notebook::get().get_current_view()) - Notebook::get().open(current_view->file_path); + Notebook::get().open(current_view); } } });