From 3da8569bfdac56f0d123779104cee872bee975ef Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Thu, 1 Jun 2017 21:36:48 -0500 Subject: [PATCH 1/4] add find file option --- src/menu.cc | 8 +++++-- src/window.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/menu.cc b/src/menu.cc index 87dad11..fbe4ddc 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -262,6 +262,10 @@ const Glib::ustring menu_xml= R"RAW(
+ + G_oto File + app.source_find_file + _Find _Symbol (Ctags) app.source_find_symbol_ctags @@ -469,7 +473,7 @@ void Menu::add_action(const std::string &name, std::function action) { auto g_application=g_application_get_default(); auto gio_application=Glib::wrap(g_application, true); auto application=Glib::RefPtr::cast_static(gio_application); - + actions[name]=application->add_action(name, action); } @@ -477,7 +481,7 @@ void Menu::set_keys() { auto g_application=g_application_get_default(); auto gio_application=Glib::wrap(g_application, true); auto application=Glib::RefPtr::cast_static(gio_application); - + for(auto &key: Config::get().menu.keys) { if(key.second.size()>0 && actions.find(key.first)!=actions.end()) application->set_accel_for_action("app."+key.first, key.second); diff --git a/src/window.cc b/src/window.cc index 544932b..a89926c 100644 --- a/src/window.cc +++ b/src/window.cc @@ -656,6 +656,66 @@ void Window::set_menu_actions() { SelectionDialog::get()->show(); }); + menu.add_action("source_find_file", [this]() { + using namespace boost::filesystem; + auto view = Notebook::get().get_current_view(); + auto project_path = canonical(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 { + SelectionDialog::create(true, true); + } + + // std::vector excludes; + 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 = canonical(build->get_default_path()); + } + if (is_directory(build->get_debug_path())) { + build_debug_path = canonical(build->get_debug_path()); + } + } + + // populate with all files in project + for (recursive_directory_iterator iter(project_path), end; iter != end; iter++) { + auto path = canonical(iter->path()); + // ignore folders, but not everything in them + if (!is_regular_file(path)) { + 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 != "")) { + std::cout << path << std::endl; + 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); + } + + SelectionDialog::get()->on_select=[this, project_path](const std::string &selected, bool hide_window) { + auto full_path = canonical(selected); + Notebook::get().open(full_path); + auto view=Notebook::get().get_current_view(); + view->hide_tooltips(); + }; + + if(view) + view->hide_tooltips(); + SelectionDialog::get()->show(); + + }); + menu.add_action("source_comments_toggle", [this]() { if(auto view=Notebook::get().get_current_view()) { if(view->toggle_comments) { From e37df9f0e8cb40e836ac3dd68cf40be14bc3a51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 2 Jun 2017 13:53:10 +0200 Subject: [PATCH 2/4] remove usage of using namespace --- src/window.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/window.cc b/src/window.cc index a89926c..1b904c9 100644 --- a/src/window.cc +++ b/src/window.cc @@ -657,9 +657,8 @@ void Window::set_menu_actions() { }); menu.add_action("source_find_file", [this]() { - using namespace boost::filesystem; auto view = Notebook::get().get_current_view(); - auto project_path = canonical(Directories::get().path); + auto project_path = boost::filesystem::canonical(Directories::get().path); if(view) { auto dialog_iter=view->get_iter_for_dialog(); @@ -670,22 +669,22 @@ void Window::set_menu_actions() { } // std::vector excludes; - path build_default_path, build_debug_path; + 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 = canonical(build->get_default_path()); + build_default_path = boost::filesystem::canonical(build->get_default_path()); } if (is_directory(build->get_debug_path())) { - build_debug_path = canonical(build->get_debug_path()); + build_debug_path = boost::filesystem::canonical(build->get_debug_path()); } } // populate with all files in project - for (recursive_directory_iterator iter(project_path), end; iter != end; iter++) { - auto path = canonical(iter->path()); + for (boost::filesystem::recursive_directory_iterator iter(project_path), end; iter != end; iter++) { + auto path = boost::filesystem::canonical(iter->path()); // ignore folders, but not everything in them - if (!is_regular_file(path)) { + if (!boost::filesystem::is_regular_file(path)) { continue; } @@ -704,7 +703,7 @@ void Window::set_menu_actions() { } SelectionDialog::get()->on_select=[this, project_path](const std::string &selected, bool hide_window) { - auto full_path = canonical(selected); + auto full_path = boost::filesystem::canonical(selected); Notebook::get().open(full_path); auto view=Notebook::get().get_current_view(); view->hide_tooltips(); From edba5a5561f4626f3aba57862ef1bfd9dcd0e866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 2 Jun 2017 13:53:22 +0200 Subject: [PATCH 3/4] remove debug print --- src/window.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/window.cc b/src/window.cc index 1b904c9..215ab5e 100644 --- a/src/window.cc +++ b/src/window.cc @@ -691,7 +691,6 @@ void Window::set_menu_actions() { // 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 != "")) { - std::cout << path << std::endl; iter.pop(); continue; } From e4fe99fa8097fb09c98279faeb1beda023ef264f Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Sat, 3 Jun 2017 15:38:48 -0500 Subject: [PATCH 4/4] address review comments --- src/menu.cc | 2 +- src/window.cc | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/menu.cc b/src/menu.cc index fbe4ddc..61b39b6 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -263,7 +263,7 @@ const Glib::ustring menu_xml= R"RAW(
- G_oto File + _Find _File app.source_find_file diff --git a/src/window.cc b/src/window.cc index 215ab5e..4092d1f 100644 --- a/src/window.cc +++ b/src/window.cc @@ -658,7 +658,18 @@ void Window::set_menu_actions() { menu.add_action("source_find_file", [this]() { auto view = Notebook::get().get_current_view(); - auto project_path = boost::filesystem::canonical(Directories::get().path); + + boost::filesystem::path project_path; + if(!Directories::get().path.empty()) + project_path=Directories::get().path; + else { + boost::system::error_code ec; + project_path=boost::filesystem::current_path(ec); + if(ec) { + Terminal::get().print("Error: could not find current path\n", true); + return; + } + } if(view) { auto dialog_iter=view->get_iter_for_dialog(); @@ -668,21 +679,20 @@ void Window::set_menu_actions() { SelectionDialog::create(true, true); } - // std::vector excludes; 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 = boost::filesystem::canonical(build->get_default_path()); + build_default_path = build->get_default_path(); } if (is_directory(build->get_debug_path())) { - build_debug_path = boost::filesystem::canonical(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++) { - auto path = boost::filesystem::canonical(iter->path()); + auto path = iter->path(); // ignore folders, but not everything in them if (!boost::filesystem::is_regular_file(path)) { continue; @@ -704,8 +714,8 @@ void Window::set_menu_actions() { 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); - auto view=Notebook::get().get_current_view(); - view->hide_tooltips(); + if (auto view=Notebook::get().get_current_view()) + view->hide_tooltips(); }; if(view)