mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 13:17:43 +00:00
FileManager: Add folder-specific paste action
This action is a bit different to the regular paste action because it takes into account the folder in which the context menu was opened, so it can be enabled/disabled whether that folder is writable or not for the current user. Both paste action use the same logic, now moved to the function do_action(const GUI::Action&), but in the case of the folder being right clicked, it pastes inside of it.
This commit is contained in:
parent
1f007181be
commit
42f493ec9d
1 changed files with 58 additions and 45 deletions
|
@ -424,8 +424,37 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
window);
|
window);
|
||||||
copy_action->set_enabled(false);
|
copy_action->set_enabled(false);
|
||||||
|
|
||||||
auto paste_action = GUI::CommonActions::make_paste_action(
|
auto properties_action
|
||||||
[&](const GUI::Action& action) {
|
= GUI::Action::create(
|
||||||
|
"Properties...", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), [&](const GUI::Action& action) {
|
||||||
|
auto& model = directory_view.model();
|
||||||
|
String path;
|
||||||
|
Vector<String> selected;
|
||||||
|
if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) {
|
||||||
|
path = directory_view.path();
|
||||||
|
selected = selected_file_paths();
|
||||||
|
} else {
|
||||||
|
path = directories_model->full_path(tree_view.selection().first());
|
||||||
|
selected = tree_view_selected_file_paths();
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<PropertiesDialog> properties;
|
||||||
|
if (selected.is_empty()) {
|
||||||
|
properties = window->add<PropertiesDialog>(model, path, true);
|
||||||
|
} else {
|
||||||
|
properties = window->add<PropertiesDialog>(model, selected.first(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
properties->exec();
|
||||||
|
},
|
||||||
|
window);
|
||||||
|
|
||||||
|
enum class ConfirmBeforeDelete {
|
||||||
|
No,
|
||||||
|
Yes
|
||||||
|
};
|
||||||
|
|
||||||
|
auto do_paste = [&](const GUI::Action& action) {
|
||||||
auto data_and_type = GUI::Clipboard::the().data_and_type();
|
auto data_and_type = GUI::Clipboard::the().data_and_type();
|
||||||
if (data_and_type.type != "file-list") {
|
if (data_and_type.type != "file-list") {
|
||||||
dbg() << "Cannot paste clipboard type " << data_and_type.type;
|
dbg() << "Cannot paste clipboard type " << data_and_type.type;
|
||||||
|
@ -458,42 +487,6 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
refresh_tree_view();
|
refresh_tree_view();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
window);
|
|
||||||
|
|
||||||
GUI::Clipboard::the().on_content_change = [&](const String& data_type) {
|
|
||||||
auto current_location = directory_view.path();
|
|
||||||
paste_action->set_enabled(data_type == "file-list" && access(current_location.characters(), W_OK) == 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto properties_action
|
|
||||||
= GUI::Action::create(
|
|
||||||
"Properties...", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), [&](const GUI::Action& action) {
|
|
||||||
auto& model = directory_view.model();
|
|
||||||
String path;
|
|
||||||
Vector<String> selected;
|
|
||||||
if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) {
|
|
||||||
path = directory_view.path();
|
|
||||||
selected = selected_file_paths();
|
|
||||||
} else {
|
|
||||||
path = directories_model->full_path(tree_view.selection().first());
|
|
||||||
selected = tree_view_selected_file_paths();
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<PropertiesDialog> properties;
|
|
||||||
if (selected.is_empty()) {
|
|
||||||
properties = window->add<PropertiesDialog>(model, path, true);
|
|
||||||
} else {
|
|
||||||
properties = window->add<PropertiesDialog>(model, selected.first(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
properties->exec();
|
|
||||||
},
|
|
||||||
window);
|
|
||||||
|
|
||||||
enum class ConfirmBeforeDelete {
|
|
||||||
No,
|
|
||||||
Yes
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_delete = [&](ConfirmBeforeDelete confirm, const GUI::Action&) {
|
auto do_delete = [&](ConfirmBeforeDelete confirm, const GUI::Action&) {
|
||||||
|
@ -565,6 +558,18 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto paste_action = GUI::CommonActions::make_paste_action(
|
||||||
|
[&](const GUI::Action& action) {
|
||||||
|
do_paste(action);
|
||||||
|
},
|
||||||
|
window);
|
||||||
|
|
||||||
|
auto folder_specific_paste_action = GUI::CommonActions::make_paste_action(
|
||||||
|
[&](const GUI::Action& action) {
|
||||||
|
do_paste(action);
|
||||||
|
},
|
||||||
|
window);
|
||||||
|
|
||||||
auto force_delete_action = GUI::Action::create(
|
auto force_delete_action = GUI::Action::create(
|
||||||
"Delete without confirmation", { Mod_Shift, Key_Delete }, [&](const GUI::Action& action) {
|
"Delete without confirmation", { Mod_Shift, Key_Delete }, [&](const GUI::Action& action) {
|
||||||
do_delete(ConfirmBeforeDelete::No, action);
|
do_delete(ConfirmBeforeDelete::No, action);
|
||||||
|
@ -596,6 +601,11 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
},
|
},
|
||||||
window);
|
window);
|
||||||
|
|
||||||
|
GUI::Clipboard::the().on_content_change = [&](const String& data_type) {
|
||||||
|
auto current_location = directory_view.path();
|
||||||
|
paste_action->set_enabled(data_type == "file-list" && access(current_location.characters(), W_OK) == 0);
|
||||||
|
};
|
||||||
|
|
||||||
auto menubar = GUI::MenuBar::construct();
|
auto menubar = GUI::MenuBar::construct();
|
||||||
|
|
||||||
auto& app_menu = menubar->add_menu("File Manager");
|
auto& app_menu = menubar->add_menu("File Manager");
|
||||||
|
@ -708,7 +718,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
});
|
});
|
||||||
|
|
||||||
directory_context_menu->add_action(copy_action);
|
directory_context_menu->add_action(copy_action);
|
||||||
directory_context_menu->add_action(paste_action);
|
directory_context_menu->add_action(folder_specific_paste_action);
|
||||||
directory_context_menu->add_action(delete_action);
|
directory_context_menu->add_action(delete_action);
|
||||||
directory_context_menu->add_separator();
|
directory_context_menu->add_separator();
|
||||||
directory_context_menu->add_action(properties_action);
|
directory_context_menu->add_action(properties_action);
|
||||||
|
@ -739,10 +749,13 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
if (index.is_valid()) {
|
if (index.is_valid()) {
|
||||||
auto& node = directory_view.model().node(index);
|
auto& node = directory_view.model().node(index);
|
||||||
|
|
||||||
if (node.is_directory())
|
if (node.is_directory()) {
|
||||||
|
auto should_get_enabled = access(node.full_path(directory_view.model()).characters(), W_OK) == 0 && GUI::Clipboard::the().type() == "file-list";
|
||||||
|
folder_specific_paste_action->set_enabled(should_get_enabled);
|
||||||
directory_context_menu->popup(event.screen_position());
|
directory_context_menu->popup(event.screen_position());
|
||||||
else
|
} else {
|
||||||
file_context_menu->popup(event.screen_position());
|
file_context_menu->popup(event.screen_position());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
directory_view_context_menu->popup(event.screen_position());
|
directory_view_context_menu->popup(event.screen_position());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue