From 47f9f4599c6e683c2dae5ec0f726fb3ce5c3f30b Mon Sep 17 00:00:00 2001 From: milleniumbug Date: Wed, 6 Apr 2016 19:58:18 +0200 Subject: [PATCH] added new directory tree feature: create new file here --- src/directories.cc | 26 ++++++++++++++++++++++++++ src/directories.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/directories.cc b/src/directories.cc index 5898c4c..0b019a6 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -299,6 +299,32 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) { }); menu.append(menu_item_delete); + menu_item_create.set_label("Create new file here"); + menu_item_create.signal_activate().connect([this] { + if(menu_popup_row_path.empty()) + return; + EntryBox::get().clear(); + auto source_path=std::make_shared(menu_popup_row_path); + EntryBox::get().entries.emplace_back("", [this, source_path](const std::string &content){ + bool is_directory=boost::filesystem::is_directory(*source_path); + auto target_path = (is_directory ? *source_path : source_path->parent_path())/content; + if(!boost::filesystem::exists(target_path)) + filesystem::write(target_path, ""); + else + Terminal::get().print("Cannot create "+target_path.string()+": file already exists.\n", true); + update(); + + EntryBox::get().hide(); + }); + auto entry_it=EntryBox::get().entries.begin(); + entry_it->set_placeholder_text("Filename"); + EntryBox::get().buttons.emplace_back("Create file", [this, entry_it](){ + entry_it->activate(); + }); + EntryBox::get().show(); + }); + menu.append(menu_item_create); + menu.show_all(); menu.accelerate(*this); } diff --git a/src/directories.h b/src/directories.h index 61daccc..a458ef0 100644 --- a/src/directories.h +++ b/src/directories.h @@ -69,6 +69,7 @@ private: Dispatcher dispatcher; Gtk::Menu menu; + Gtk::MenuItem menu_item_create; Gtk::MenuItem menu_item_rename; Gtk::MenuItem menu_item_delete; boost::filesystem::path menu_popup_row_path;