Browse Source

Cleanup and improvements related to #187: right click menu operations in directory view

merge-requests/365/head
eidheim 10 years ago
parent
commit
45b86c4816
  1. 36
      src/directories.cc

36
src/directories.cc

@ -63,8 +63,10 @@ bool Directories::TreeStore::drag_data_received_vfunc(const TreeModel::Path &pat
auto it=directories.get_selection()->get_selected(); auto it=directories.get_selection()->get_selected();
if(it) { if(it) {
auto source_path=it->get_value(directories.column_record.path); auto source_path=it->get_value(directories.column_record.path);
auto target_path=get_target_folder(path); if(source_path.empty())
return false;
auto target_path=get_target_folder(path);
target_path/=source_path.filename(); target_path/=source_path.filename();
if(source_path==target_path) if(source_path==target_path)
@ -218,7 +220,7 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
auto target_path=source_path->parent_path()/content; auto target_path=source_path->parent_path()/content;
boost::filesystem::rename(*source_path, target_path, ec); boost::filesystem::rename(*source_path, target_path, ec);
if(ec) if(ec)
Terminal::get().print("Error: could not rename "+source_path->string()+": "+ec.message()+'\n'); Terminal::get().print("Error: could not rename "+source_path->string()+": "+ec.message()+'\n', true);
else { else {
update(); update();
select(target_path); select(target_path);
@ -297,7 +299,7 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
}); });
menu.append(menu_item_delete); menu.append(menu_item_delete);
auto create_file_label = "Create file"; auto create_file_label = "Create File";
auto create_file_signal = [this] { auto create_file_signal = [this] {
if(menu_popup_row_path.empty()) if(menu_popup_row_path.empty())
return; return;
@ -306,14 +308,16 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
EntryBox::get().entries.emplace_back("", [this, source_path](const std::string &content){ EntryBox::get().entries.emplace_back("", [this, source_path](const std::string &content){
bool is_directory=boost::filesystem::is_directory(*source_path); bool is_directory=boost::filesystem::is_directory(*source_path);
auto target_path = (is_directory ? *source_path : source_path->parent_path())/content; auto target_path = (is_directory ? *source_path : source_path->parent_path())/content;
if(!boost::filesystem::exists(target_path)) if(!boost::filesystem::exists(target_path)) {
{ if(filesystem::write(target_path, "")) {
filesystem::write(target_path, ""); update();
Notebook::get().open(target_path); Notebook::get().open(target_path);
}
else
Terminal::get().print("Error: could not create "+target_path.string()+'\n', true);
} }
else else
Terminal::get().print("Cannot create "+target_path.string()+": file already exists.\n", true); Terminal::get().print("Error: could not create "+target_path.string()+": file already exists\n", true);
update();
EntryBox::get().hide(); EntryBox::get().hide();
}); });
@ -446,15 +450,27 @@ void Directories::select(const boost::filesystem::path &select_path) {
bool Directories::on_button_press_event(GdkEventButton* event) { bool Directories::on_button_press_event(GdkEventButton* event) {
if(event->type==GDK_BUTTON_PRESS && event->button==GDK_BUTTON_SECONDARY) { if(event->type==GDK_BUTTON_PRESS && event->button==GDK_BUTTON_SECONDARY) {
EntryBox::get().hide();
Gtk::TreeModel::Path path; Gtk::TreeModel::Path path;
if(get_path_at_pos(static_cast<int>(event->x), static_cast<int>(event->y), path)) { if(get_path_at_pos(static_cast<int>(event->x), static_cast<int>(event->y), path)) {
menu_popup_row_path=get_model()->get_iter(path)->get_value(column_record.path); menu_popup_row_path=get_model()->get_iter(path)->get_value(column_record.path);
if(menu_popup_row_path.empty()) {
auto parent=get_model()->get_iter(path)->parent();
if(parent)
menu_popup_row_path=parent->get_value(column_record.path);
else {
menu_popup_row_path=this->path;
menu_root.popup(event->button, event->time);
return true;
}
}
menu.popup(event->button, event->time); menu.popup(event->button, event->time);
return true; return true;
} }
else { else if(!this->path.empty()) {
menu_popup_row_path=this->path; menu_popup_row_path=this->path;
menu_root.popup(event->button, event->time); menu_root.popup(event->button, event->time);
return true;
} }
} }

Loading…
Cancel
Save