Browse Source

added new directory tree feature: create new file here

merge-requests/365/head
milleniumbug 10 years ago
parent
commit
47f9f4599c
No known key found for this signature in database
GPG Key ID: E069867FCF5D84EA
  1. 26
      src/directories.cc
  2. 1
      src/directories.h

26
src/directories.cc

@ -299,6 +299,32 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
}); });
menu.append(menu_item_delete); 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<boost::filesystem::path>(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.show_all();
menu.accelerate(*this); menu.accelerate(*this);
} }

1
src/directories.h

@ -69,6 +69,7 @@ private:
Dispatcher dispatcher; Dispatcher dispatcher;
Gtk::Menu menu; Gtk::Menu menu;
Gtk::MenuItem menu_item_create;
Gtk::MenuItem menu_item_rename; Gtk::MenuItem menu_item_rename;
Gtk::MenuItem menu_item_delete; Gtk::MenuItem menu_item_delete;
boost::filesystem::path menu_popup_row_path; boost::filesystem::path menu_popup_row_path;

Loading…
Cancel
Save