From 478185319a0cfd378d2db1f638adad1680069a5e Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 4 Jun 2017 15:24:16 +0200 Subject: [PATCH] Finalised Find File (PR #336): various cleanups/fixes and added keybinding. Resolves #312. --- CMakeLists.txt | 2 +- src/config.cc | 19 ++++++++++-- src/config.h | 4 +++ src/files.h | 3 +- src/window.cc | 78 ++++++++++++++++++++++++++------------------------ 5 files changed, 64 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06f5f49..0591ba4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.2.4") +set(JUCI_VERSION "1.2.4-1") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/src/config.cc b/src/config.cc index 2c88474..afe484d 100644 --- a/src/config.cc +++ b/src/config.cc @@ -43,7 +43,9 @@ void Config::load() { read(cfg); } catch(const std::exception &e) { - ::Terminal::get().print("Error: could not parse "+config_json+": "+e.what()+"\n", true); + dispatcher.post([config_json, e_what=std::string(e.what())] { + ::Terminal::get().print("Error: could not parse "+config_json+": "+e_what+"\n", true); + }); std::stringstream ss; ss << default_config_file; boost::property_tree::read_json(ss, cfg); @@ -104,10 +106,21 @@ void Config::update(boost::property_tree::ptree &cfg) { } void Config::make_version_dependent_corrections(boost::property_tree::ptree &cfg, const boost::property_tree::ptree &default_cfg, const std::string &version) { + auto &keybindings_cfg=cfg.get_child("keybindings"); try { - + if(version<="1.2.4") { + auto it_file_print=keybindings_cfg.find("print"); + if(it_file_print!=keybindings_cfg.not_found() && it_file_print->second.data()=="p") { + dispatcher.post([] { + ::Terminal::get().print("Preference change: keybindings.print set to \"\"\n"); + }); + it_file_print->second.data()=""; + } + } + } + catch(const std::exception &e) { + std::cerr << "Error correcting preferences: " << e.what() << std::endl; } - catch(...) {} } bool Config::add_missing_nodes(boost::property_tree::ptree &cfg, const boost::property_tree::ptree &default_cfg, std::string parent_path) { diff --git a/src/config.h b/src/config.h index de64884..20aa05e 100644 --- a/src/config.h +++ b/src/config.h @@ -6,6 +6,7 @@ #include #include #include +#include "dispatcher.h" class Config { public: @@ -113,6 +114,9 @@ public: boost::filesystem::path home_juci_path; private: + /// Used to dispatch Terminal outputs after juCi++ GUI setup and configuration + Dispatcher dispatcher; + void find_or_create_config_files(); void update(boost::property_tree::ptree &cfg); void make_version_dependent_corrections(boost::property_tree::ptree &cfg, const boost::property_tree::ptree &default_cfg, const std::string &version); diff --git a/src/files.h b/src/files.h index 60fded5..bb66c7b 100644 --- a/src/files.h +++ b/src/files.h @@ -92,7 +92,7 @@ R"RAW( "reload_file": "", "save": "s", "save_as": "s", - "print": "p", + "print": "", "edit_undo": "z", "edit_redo": "z", "edit_cut": "x", @@ -113,6 +113,7 @@ R"RAW( "source_cursor_history_forward": "Right", "source_show_completion_comment" : "Add completion keybinding to disable interactive autocompletion", "source_show_completion" : "", + "source_find_file": "p", "source_find_symbol_ctags": "f", "source_comments_toggle": "slash", "source_comments_add_documentation": "slash", diff --git a/src/window.cc b/src/window.cc index 4092d1f..259203c 100644 --- a/src/window.cc +++ b/src/window.cc @@ -659,63 +659,67 @@ void Window::set_menu_actions() { menu.add_action("source_find_file", [this]() { auto view = Notebook::get().get_current_view(); - boost::filesystem::path project_path; - if(!Directories::get().path.empty()) - project_path=Directories::get().path; + boost::filesystem::path search_path; + if(view) + search_path=view->file_path.parent_path(); + else if(!Directories::get().path.empty()) + search_path=Directories::get().path; else { boost::system::error_code ec; - project_path=boost::filesystem::current_path(ec); + search_path=boost::filesystem::current_path(ec); if(ec) { Terminal::get().print("Error: could not find current path\n", true); return; } } + auto build=Project::Build::create(search_path); + auto project_path=build->project_path; + boost::filesystem::path default_path, debug_path; + if(!project_path.empty()) { + search_path=project_path; + default_path = build->get_default_path(); + debug_path = build->get_debug_path(); + } + else if (!Directories::get().path.empty()) + search_path=Directories::get().path; if(view) { auto dialog_iter=view->get_iter_for_dialog(); SelectionDialog::create(view, view->get_buffer()->create_mark(dialog_iter), true, true); } - else { + else SelectionDialog::create(true, true); - } - boost::filesystem::path build_default_path, build_debug_path; - auto build = Project::Build::create(project_path); - if(!project_path.empty()) { - if (is_directory(build->get_default_path())) { - build_default_path = build->get_default_path(); - } - if (is_directory(build->get_debug_path())) { - build_debug_path = build->get_debug_path(); - } - } - - // populate with all files in project - for (boost::filesystem::recursive_directory_iterator iter(project_path), end; iter != end; iter++) { + std::unordered_set buffer_paths; + for(auto view: Notebook::get().get_views()) + buffer_paths.emplace(view->file_path.string()); + + auto paths=std::make_shared>(); + // populate with all files in search_path + for (boost::filesystem::recursive_directory_iterator iter(search_path), end; iter != end; iter++) { auto path = iter->path(); - // ignore folders, but not everything in them + // ignore folders if (!boost::filesystem::is_regular_file(path)) { + if(path==default_path || path==debug_path || path.filename()==".git") + iter.no_push(); continue; } - - // ignore build directory, and everything in it - if ((filesystem::file_in_path(path, build_default_path) && build_default_path != "") || - (filesystem::file_in_path(path, build_debug_path) && build_debug_path != "")) { - iter.pop(); - continue; - } - - // remove project base path (and separating slash) - auto path_str = filesystem::get_relative_path(path, project_path).string(); - // SelectionDialog::get()->add_row(path_str.substr(project_path.string().length()+1)); - SelectionDialog::get()->add_row(path_str); + + // remove project base path + auto row_str = filesystem::get_relative_path(path, search_path).string(); + if(buffer_paths.count(path.string())) + row_str=""+row_str+""; + paths->emplace(row_str, path); + SelectionDialog::get()->add_row(row_str); } - SelectionDialog::get()->on_select=[this, project_path](const std::string &selected, bool hide_window) { - auto full_path = boost::filesystem::canonical(selected); - Notebook::get().open(full_path); - if (auto view=Notebook::get().get_current_view()) - view->hide_tooltips(); + SelectionDialog::get()->on_select=[this, paths](const std::string &selected, bool hide_window) { + auto it=paths->find(selected); + if(it!=paths->end()) { + Notebook::get().open(it->second); + if (auto view=Notebook::get().get_current_view()) + view->hide_tooltips(); + } }; if(view)