Browse Source

Now selects the current tab file in directories, and stores the directories' expanded rows between open directory (if same directory).

merge-requests/365/head
eidheim 11 years ago
parent
commit
11a54f7baa
  1. 23
      src/directories.cc
  2. 4
      src/directories.h
  3. 28
      src/window.cc

23
src/directories.cc

@ -39,12 +39,35 @@ Directories::Directories() {
void Directories::open_folder(const boost::filesystem::path& dir_path) { void Directories::open_folder(const boost::filesystem::path& dir_path) {
INFO("Open folder"); INFO("Open folder");
std::vector<Gtk::TreeModel::Path> 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_store->clear();
tree_view.get_column(0)->set_title(get_cmakelists_variable(dir_path, "project")); tree_view.get_column(0)->set_title(get_cmakelists_variable(dir_path, "project"));
add_paths(dir_path, Gtk::TreeModel::Row(), 0); 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"); 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) { bool Directories::ignored(std::string path) {
DEBUG("Checking if file-/directory is filtered"); DEBUG("Checking if file-/directory is filtered");
std::transform(path.begin(), path.end(), path.begin(), ::tolower); std::transform(path.begin(), path.end(), path.begin(), ::tolower);

4
src/directories.h

@ -28,16 +28,18 @@ public:
Directories(); Directories();
void open_folder(const boost::filesystem::path& dir_path); 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::string get_cmakelists_variable(const boost::filesystem::path& dir_path, std::string command_name);
std::function<void(const std::string &file)> on_row_activated; std::function<void(const std::string &file)> on_row_activated;
private: private:
void add_paths(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &row, unsigned depth); 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; Gtk::TreeView tree_view;
Glib::RefPtr<Gtk::TreeStore> tree_store; Glib::RefPtr<Gtk::TreeStore> tree_store;
ColumnRecord column_record; ColumnRecord column_record;
bool ignored(std::string path); boost::filesystem::path last_dir_path;
}; };
#endif // JUCI_DIRECTORIES_H_ #endif // JUCI_DIRECTORIES_H_

28
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) { 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(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<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceGotoDeclaration"))) if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceGotoDeclaration")))
menu_item->set_sensitive((bool)notebook.get_current_view()->get_declaration_location); 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<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceRename"))) if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceRename")))
menu_item->set_sensitive((bool)notebook.get_current_view()->rename_similar_tokens); menu_item->set_sensitive((bool)notebook.get_current_view()->rename_similar_tokens);
directories.select_path(notebook.get_current_view()->file_path);
} }
}); });
INFO("Window created"); INFO("Window created");
@ -280,10 +282,10 @@ void Window::new_file_entry() {
} }
else { else {
if(juci::filesystem::write(p)) { 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!="") 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 else
Singleton::terminal()->print("Error: could not create new file "+p.string()+".\n"); 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(); std::string project_path=dialog.get_filename();
notebook.project_path=project_path; notebook.project_path=project_path;
directories.open_folder(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) { if(file) {
file << notebook.get_current_view()->get_buffer()->get_text(); file << notebook.get_current_view()->get_buffer()->get_text();
file.close(); file.close();
if(notebook.project_path!="")
directories.open_folder(notebook.project_path);
notebook.open(path); notebook.open(path);
Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path+"\n"); 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 else
Singleton::terminal()->print("Error saving file\n"); Singleton::terminal()->print("Error saving file\n");

Loading…
Cancel
Save