From 29fc8c0a2c5469d9a3b40eea36fc4b807b7252a0 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 11 May 2020 11:04:04 +0200 Subject: [PATCH] Fixes #426: added Close Folder and Close Project to File menu. Also moved Close Tab to File Menu as Close File --- CMakeLists.txt | 2 +- src/directories.cc | 12 ++++++++++++ src/directories.h | 1 + src/files.h | 4 +++- src/menu.cc | 18 ++++++++++++++---- src/window.cc | 34 +++++++++++++++++++++++++++++----- 6 files changed, 60 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dde5c9a..145d3bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.6.0") +set(JUCI_VERSION "1.6.0.1") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/src/directories.cc b/src/directories.cc index 86577be..1102695 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -521,6 +521,18 @@ void Directories::open(const boost::filesystem::path &dir_path) { add_or_update_path(path, Gtk::TreeModel::Row(), true); } +void Directories::close(const boost::filesystem::path &dir_path) { + if(path.empty() || dir_path.empty()) + return; + if(filesystem::file_in_path(path, dir_path)) { + tree_store->clear(); + path.clear(); + get_column(0)->set_title(""); + } + else + remove_path(dir_path); +} + void Directories::update() { std::vector> saved_directories; for(auto &directory : directories) diff --git a/src/directories.h b/src/directories.h index 9f1bdee..d7b004c 100644 --- a/src/directories.h +++ b/src/directories.h @@ -59,6 +59,7 @@ public: ~Directories() override; void open(const boost::filesystem::path &dir_path = ""); + void close(const boost::filesystem::path &dir_path); void update(); void on_save_file(const boost::filesystem::path &file_path); void select(const boost::filesystem::path &path); diff --git a/src/files.h b/src/files.h index dba4935..ad092a3 100644 --- a/src/files.h +++ b/src/files.h @@ -85,6 +85,9 @@ const std::string default_config_file = R"RAW({ "file_reload_file": "", "file_save": "s", "file_save_as": "s", + "file_close_file": "w", + "file_close_folder": "", + "file_close_project": "", "file_print": "", "edit_undo": "z", "edit_redo": "z", @@ -154,7 +157,6 @@ const std::string default_config_file = R"RAW({ "window_previous_tab": "Left",)RAW" #endif R"RAW( - "window_close_tab": "w", "window_toggle_split": "", "window_split_source_buffer": "",)RAW" #ifdef __APPLE__ diff --git a/src/menu.cc b/src/menu.cc index f58d5b7..91851fb 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -163,6 +163,20 @@ const Glib::ustring menu_xml = R"RAW( app.file_save_as +
+ + _Close _File + app.file_close_file + + + _Close _Folder + app.file_close_folder + + + _Close _Project + app.file_close_project + +
_Print @@ -483,10 +497,6 @@ const Glib::ustring menu_xml = R"RAW( _Previous _Tab app.window_previous_tab - - _Close _Tab - app.window_close_tab -
diff --git a/src/window.cc b/src/window.cc index b1ce09f..82920cb 100644 --- a/src/window.cc +++ b/src/window.cc @@ -304,6 +304,8 @@ void Window::set_menu_actions() { if(!ec && last_write_time >= time_now) { if(!Directories::get().path.empty()) Directories::get().update(); + else + Directories::get().open(path); Terminal::get().print("New folder " + path.string() + " created.\n"); } else @@ -419,8 +421,11 @@ void Window::set_menu_actions() { }); menu.add_action("file_open_folder", []() { auto path = Dialog::open_folder(Project::get_preferably_directory_folder()); - if(!path.empty()) + if(!path.empty()) { Directories::get().open(path); + if(auto view = Notebook::get().get_current_view()) + Directories::get().select(view->file_path); + } }); menu.add_action("file_reload_file", []() { @@ -476,6 +481,29 @@ void Window::set_menu_actions() { } }); + menu.add_action("file_close_file", []() { + if(Notebook::get().get_current_view()) + Notebook::get().close_current(); + }); + menu.add_action("file_close_folder", []() { + Directories::get().close(Directories::get().path); + }); + menu.add_action("file_close_project", []() { + if(!Notebook::get().get_current_view() && Directories::get().path.empty()) + return; + auto project_path = Project::get_preferably_view_folder(); + auto build = Project::Build::create(project_path); + if(!build->project_path.empty()) + project_path = build->project_path; + for(size_t c = Notebook::get().size() - 1; c != static_cast(-1); --c) { + if(filesystem::file_in_path(Notebook::get().get_view(c)->file_path, project_path)) { + if(!Notebook::get().close(c)) + return; + } + } + Directories::get().close(project_path); + }); + menu.add_action("file_print", [this]() { if(auto view = Notebook::get().get_current_view()) { auto print_operation = Gtk::PrintOperation::create(); @@ -1531,10 +1559,6 @@ void Window::set_menu_actions() { menu.add_action("window_previous_tab", []() { Notebook::get().previous(); }); - menu.add_action("window_close_tab", []() { - if(Notebook::get().get_current_view()) - Notebook::get().close_current(); - }); menu.add_action("window_toggle_split", [] { Notebook::get().toggle_split(); });