From 11a54f7baa88a1504b1539ce69aae50be5f4ee26 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 1 Aug 2015 09:16:47 +0200 Subject: [PATCH] Now selects the current tab file in directories, and stores the directories' expanded rows between open directory (if same directory). --- src/directories.cc | 23 +++++++++++++++++++++++ src/directories.h | 4 +++- src/window.cc | 28 ++++++++++++++++------------ 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/directories.cc b/src/directories.cc index be6df8b..edac27b 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -39,12 +39,35 @@ Directories::Directories() { void Directories::open_folder(const boost::filesystem::path& dir_path) { INFO("Open folder"); + std::vector expanded_paths; + if(last_dir_path==dir_path) { + tree_view.map_expanded_rows([&expanded_paths](Gtk::TreeView* tree_view, const Gtk::TreeModel::Path& path){ + expanded_paths.emplace_back(path); + }); + } + tree_store->clear(); tree_view.get_column(0)->set_title(get_cmakelists_variable(dir_path, "project")); add_paths(dir_path, Gtk::TreeModel::Row(), 0); + + for(auto &path: expanded_paths) + tree_view.expand_row(path, false); + last_dir_path=dir_path; DEBUG("Folder opened"); } +void Directories::select_path(const std::string &path) { + tree_store->foreach_iter([this, &path](const Gtk::TreeModel::iterator& iter){ + if(iter->get_value(column_record.path)==path) { + auto tree_path=Gtk::TreePath(iter); + tree_view.expand_to_path(tree_path); + tree_view.set_cursor(tree_path); + return true; + } + return false; + }); +} + bool Directories::ignored(std::string path) { DEBUG("Checking if file-/directory is filtered"); std::transform(path.begin(), path.end(), path.begin(), ::tolower); diff --git a/src/directories.h b/src/directories.h index 3391998..ba545ec 100644 --- a/src/directories.h +++ b/src/directories.h @@ -28,16 +28,18 @@ public: Directories(); void open_folder(const boost::filesystem::path& dir_path); + void select_path(const std::string &path); std::string get_cmakelists_variable(const boost::filesystem::path& dir_path, std::string command_name); std::function on_row_activated; private: void add_paths(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &row, unsigned depth); + bool ignored(std::string path); Gtk::TreeView tree_view; Glib::RefPtr tree_store; ColumnRecord column_record; - bool ignored(std::string path); + boost::filesystem::path last_dir_path; }; #endif // JUCI_DIRECTORIES_H_ diff --git a/src/window.cc b/src/window.cc index 7462788..784a0be 100644 --- a/src/window.cc +++ b/src/window.cc @@ -52,14 +52,14 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL) { }); notebook.signal_switch_page().connect([this](Gtk::Widget* page, guint page_num) { - if(search_entry_shown && entry_box.labels.size()>0 && notebook.get_current_page()!=-1) { - notebook.get_current_view()->update_search_occurrences=[this](int number){ - entry_box.labels.begin()->update(0, std::to_string(number)); - }; - notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search); - } - if(notebook.get_current_page()!=-1) { + if(search_entry_shown && entry_box.labels.size()>0) { + notebook.get_current_view()->update_search_occurrences=[this](int number){ + entry_box.labels.begin()->update(0, std::to_string(number)); + }; + notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search); + } + if(auto menu_item=dynamic_cast(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceGotoDeclaration"))) menu_item->set_sensitive((bool)notebook.get_current_view()->get_declaration_location); @@ -68,6 +68,8 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL) { if(auto menu_item=dynamic_cast(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceRename"))) menu_item->set_sensitive((bool)notebook.get_current_view()->rename_similar_tokens); + + directories.select_path(notebook.get_current_view()->file_path); } }); INFO("Window created"); @@ -280,10 +282,10 @@ void Window::new_file_entry() { } else { if(juci::filesystem::write(p)) { - notebook.open(boost::filesystem::canonical(p).string()); - Singleton::terminal()->print("New file "+p.string()+" created.\n"); if(notebook.project_path!="") - directories.open_folder(notebook.project_path); //TODO: Do refresh instead + directories.open_folder(notebook.project_path); + notebook.open(boost::filesystem::canonical(p).string()); + Singleton::terminal()->print("New file "+p.string()+" created.\n"); } else Singleton::terminal()->print("Error: could not create new file "+p.string()+".\n"); @@ -315,6 +317,8 @@ void Window::open_folder_dialog() { std::string project_path=dialog.get_filename(); notebook.project_path=project_path; directories.open_folder(project_path); + if(notebook.get_current_page()!=-1) + directories.select_path(notebook.get_current_view()->file_path); } } @@ -375,10 +379,10 @@ void Window::save_file_dialog() { if(file) { file << notebook.get_current_view()->get_buffer()->get_text(); file.close(); + if(notebook.project_path!="") + directories.open_folder(notebook.project_path); notebook.open(path); Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path+"\n"); - if(notebook.project_path!="") - directories.open_folder(notebook.project_path); //TODO: Do refresh instead } else Singleton::terminal()->print("Error saving file\n");