Browse Source

Finalised Find File (PR #336): various cleanups/fixes and added keybinding. Resolves #312.

merge-requests/365/head
eidheim 9 years ago
parent
commit
478185319a
  1. 2
      CMakeLists.txt
  2. 19
      src/config.cc
  3. 4
      src/config.h
  4. 3
      src/files.h
  5. 70
      src/window.cc

2
CMakeLists.txt

@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 2.8.8) cmake_minimum_required (VERSION 2.8.8)
project(juci) project(juci)
set(JUCI_VERSION "1.2.4") set(JUCI_VERSION "1.2.4-1")
set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_NAME "jucipp")
set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>")

19
src/config.cc

@ -43,7 +43,9 @@ void Config::load() {
read(cfg); read(cfg);
} }
catch(const std::exception &e) { 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; std::stringstream ss;
ss << default_config_file; ss << default_config_file;
boost::property_tree::read_json(ss, cfg); 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) { 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 { 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()=="<primary>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) { bool Config::add_missing_nodes(boost::property_tree::ptree &cfg, const boost::property_tree::ptree &default_cfg, std::string parent_path) {

4
src/config.h

@ -6,6 +6,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "dispatcher.h"
class Config { class Config {
public: public:
@ -113,6 +114,9 @@ public:
boost::filesystem::path home_juci_path; boost::filesystem::path home_juci_path;
private: private:
/// Used to dispatch Terminal outputs after juCi++ GUI setup and configuration
Dispatcher dispatcher;
void find_or_create_config_files(); void find_or_create_config_files();
void update(boost::property_tree::ptree &cfg); 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); void make_version_dependent_corrections(boost::property_tree::ptree &cfg, const boost::property_tree::ptree &default_cfg, const std::string &version);

3
src/files.h

@ -92,7 +92,7 @@ R"RAW(
"reload_file": "", "reload_file": "",
"save": "<primary>s", "save": "<primary>s",
"save_as": "<primary><shift>s", "save_as": "<primary><shift>s",
"print": "<primary>p", "print": "",
"edit_undo": "<primary>z", "edit_undo": "<primary>z",
"edit_redo": "<primary><shift>z", "edit_redo": "<primary><shift>z",
"edit_cut": "<primary>x", "edit_cut": "<primary>x",
@ -113,6 +113,7 @@ R"RAW(
"source_cursor_history_forward": "<alt>Right", "source_cursor_history_forward": "<alt>Right",
"source_show_completion_comment" : "Add completion keybinding to disable interactive autocompletion", "source_show_completion_comment" : "Add completion keybinding to disable interactive autocompletion",
"source_show_completion" : "", "source_show_completion" : "",
"source_find_file": "<primary>p",
"source_find_symbol_ctags": "<primary><shift>f", "source_find_symbol_ctags": "<primary><shift>f",
"source_comments_toggle": "<primary>slash", "source_comments_toggle": "<primary>slash",
"source_comments_add_documentation": "<primary><alt>slash", "source_comments_add_documentation": "<primary><alt>slash",

70
src/window.cc

@ -659,63 +659,67 @@ void Window::set_menu_actions() {
menu.add_action("source_find_file", [this]() { menu.add_action("source_find_file", [this]() {
auto view = Notebook::get().get_current_view(); auto view = Notebook::get().get_current_view();
boost::filesystem::path project_path; boost::filesystem::path search_path;
if(!Directories::get().path.empty()) if(view)
project_path=Directories::get().path; search_path=view->file_path.parent_path();
else if(!Directories::get().path.empty())
search_path=Directories::get().path;
else { else {
boost::system::error_code ec; boost::system::error_code ec;
project_path=boost::filesystem::current_path(ec); search_path=boost::filesystem::current_path(ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not find current path\n", true); Terminal::get().print("Error: could not find current path\n", true);
return; 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) { if(view) {
auto dialog_iter=view->get_iter_for_dialog(); auto dialog_iter=view->get_iter_for_dialog();
SelectionDialog::create(view, view->get_buffer()->create_mark(dialog_iter), true, true); SelectionDialog::create(view, view->get_buffer()->create_mark(dialog_iter), true, true);
} }
else { else
SelectionDialog::create(true, true); SelectionDialog::create(true, true);
}
boost::filesystem::path build_default_path, build_debug_path; std::unordered_set<std::string> buffer_paths;
auto build = Project::Build::create(project_path); for(auto view: Notebook::get().get_views())
if(!project_path.empty()) { buffer_paths.emplace(view->file_path.string());
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 auto paths=std::make_shared<std::unordered_map<std::string, boost::filesystem::path>>();
for (boost::filesystem::recursive_directory_iterator iter(project_path), end; iter != end; iter++) { // populate with all files in search_path
for (boost::filesystem::recursive_directory_iterator iter(search_path), end; iter != end; iter++) {
auto path = iter->path(); auto path = iter->path();
// ignore folders, but not everything in them // ignore folders
if (!boost::filesystem::is_regular_file(path)) { if (!boost::filesystem::is_regular_file(path)) {
if(path==default_path || path==debug_path || path.filename()==".git")
iter.no_push();
continue; continue;
} }
// ignore build directory, and everything in it // remove project base path
if ((filesystem::file_in_path(path, build_default_path) && build_default_path != "") || auto row_str = filesystem::get_relative_path(path, search_path).string();
(filesystem::file_in_path(path, build_debug_path) && build_debug_path != "")) { if(buffer_paths.count(path.string()))
iter.pop(); row_str="<b>"+row_str+"</b>";
continue; paths->emplace(row_str, path);
SelectionDialog::get()->add_row(row_str);
} }
// remove project base path (and separating slash) SelectionDialog::get()->on_select=[this, paths](const std::string &selected, bool hide_window) {
auto path_str = filesystem::get_relative_path(path, project_path).string(); auto it=paths->find(selected);
// SelectionDialog::get()->add_row(path_str.substr(project_path.string().length()+1)); if(it!=paths->end()) {
SelectionDialog::get()->add_row(path_str); Notebook::get().open(it->second);
}
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()) if (auto view=Notebook::get().get_current_view())
view->hide_tooltips(); view->hide_tooltips();
}
}; };
if(view) if(view)

Loading…
Cancel
Save