Browse Source

Fixes #426: added Close Folder and Close Project to File menu. Also moved Close Tab to File Menu as Close File

pipelines/235045657
eidheim 6 years ago
parent
commit
29fc8c0a2c
  1. 2
      CMakeLists.txt
  2. 12
      src/directories.cc
  3. 1
      src/directories.h
  4. 4
      src/files.h
  5. 18
      src/menu.cc
  6. 34
      src/window.cc

2
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 <eidheim@gmail.com>")

12
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<std::pair<std::string, Gtk::TreeModel::Row>> saved_directories;
for(auto &directory : directories)

1
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);

4
src/files.h

@ -85,6 +85,9 @@ const std::string default_config_file = R"RAW({
"file_reload_file": "",
"file_save": "<primary>s",
"file_save_as": "<primary><shift>s",
"file_close_file": "<primary>w",
"file_close_folder": "",
"file_close_project": "",
"file_print": "",
"edit_undo": "<primary>z",
"edit_redo": "<primary><shift>z",
@ -154,7 +157,6 @@ const std::string default_config_file = R"RAW({
"window_previous_tab": "<primary><alt>Left",)RAW"
#endif
R"RAW(
"window_close_tab": "<primary>w",
"window_toggle_split": "",
"window_split_source_buffer": "",)RAW"
#ifdef __APPLE__

18
src/menu.cc

@ -163,6 +163,20 @@ const Glib::ustring menu_xml = R"RAW(<interface>
<attribute name='action'>app.file_save_as</attribute>
</item>
</section>
<section>
<item>
<attribute name='label' translatable='yes'>_Close _File</attribute>
<attribute name='action'>app.file_close_file</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Close _Folder</attribute>
<attribute name='action'>app.file_close_folder</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Close _Project</attribute>
<attribute name='action'>app.file_close_project</attribute>
</item>
</section>
<section>
<item>
<attribute name='label' translatable='yes'>_Print</attribute>
@ -483,10 +497,6 @@ const Glib::ustring menu_xml = R"RAW(<interface>
<attribute name='label' translatable='yes'>_Previous _Tab</attribute>
<attribute name='action'>app.window_previous_tab</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Close _Tab</attribute>
<attribute name='action'>app.window_close_tab</attribute>
</item>
</section>
<section>
<item>

34
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<size_t>(-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();
});

Loading…
Cancel
Save