diff options
author | Andres Vieira <anvieiravazquez@gmail.com> | 2020-04-27 00:09:53 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-27 11:21:24 +0200 |
commit | ef963dae7e900e09aa1a8c3f3374de73d8d86bc0 (patch) | |
tree | ae213874bd991d52e1486a6df85a94bd17aab4de /Applications | |
parent | 91b70d34e7ae5a489e142cd47e05cb30f679cdbf (diff) | |
download | serenity-ef963dae7e900e09aa1a8c3f3374de73d8d86bc0.zip |
FileManager: Paste inside folder if done through its context menu
Now FileManager will paste the clipboard contents inside a folder if the
paste action was clicked through a folder context menu, being the target
directory the selected folder.
This mimicks most of the behaviours that the different file managers
have.
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/FileManager/main.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 55f2282f90..d7f6746974 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -425,7 +425,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio copy_action->set_enabled(false); auto paste_action = GUI::CommonActions::make_paste_action( - [&](const GUI::Action&) { + [&](const GUI::Action& action) { auto data_and_type = GUI::Clipboard::the().data_and_type(); if (data_and_type.type != "file-list") { dbg() << "Cannot paste clipboard type " << data_and_type.type; @@ -436,12 +436,19 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio dbg() << "No files to paste"; return; } + + AK::String target_directory; + if (action.activator() == directory_context_menu) + target_directory = selected_file_paths()[0]; + else + target_directory = directory_view.path(); + for (auto& current_path : copied_lines) { if (current_path.is_empty()) continue; - auto current_directory = directory_view.path(); + auto new_path = String::format("%s/%s", - current_directory.characters(), + target_directory.characters(), FileSystemPath(current_path).basename().characters()); if (!FileUtils::copy_file_or_directory(current_path, new_path)) { auto error_message = String::format("Could not paste %s.", |