Browse Source

Cleanup of directory view right click menus. Also now checks if target path exists on rename

merge-requests/365/head
eidheim 10 years ago
parent
commit
7d10fa491b
  1. 24
      src/directories.cc

24
src/directories.cc

@ -216,12 +216,19 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
EntryBox::get().entries.emplace_back(menu_popup_row_path.filename().string(), [this, source_path](const std::string &content){ EntryBox::get().entries.emplace_back(menu_popup_row_path.filename().string(), [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);
boost::system::error_code ec;
auto target_path=source_path->parent_path()/content; auto target_path=source_path->parent_path()/content;
if(boost::filesystem::exists(target_path)) {
Terminal::get().print("Error: could not rename to "+target_path.string()+": already exists\n", true);
return;
}
boost::system::error_code ec;
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', true); Terminal::get().print("Error: could not rename "+source_path->string()+": "+ec.message()+'\n', true);
else { return;
}
update(); update();
select(target_path); select(target_path);
@ -252,7 +259,6 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
if(new_language_id!=old_language_id) if(new_language_id!=old_language_id)
Terminal::get().print("Warning: language for "+target_path.string()+" has changed. Please reopen the file\n"); Terminal::get().print("Warning: language for "+target_path.string()+" has changed. Please reopen the file\n");
} }
}
EntryBox::get().hide(); EntryBox::get().hide();
} }
@ -305,7 +311,7 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
return; return;
EntryBox::get().clear(); EntryBox::get().clear();
auto source_path=std::make_shared<boost::filesystem::path>(menu_popup_row_path); 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){ 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)) {
@ -313,11 +319,15 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
update(); update();
Notebook::get().open(target_path); Notebook::get().open(target_path);
} }
else else {
Terminal::get().print("Error: could not create "+target_path.string()+'\n', true); Terminal::get().print("Error: could not create "+target_path.string()+'\n', true);
return;
} }
else }
else {
Terminal::get().print("Error: could not create "+target_path.string()+": file already exists\n", true); Terminal::get().print("Error: could not create "+target_path.string()+": file already exists\n", true);
return;
}
EntryBox::get().hide(); EntryBox::get().hide();
}); });

Loading…
Cancel
Save