From ef963dae7e900e09aa1a8c3f3374de73d8d86bc0 Mon Sep 17 00:00:00 2001 From: Andres Vieira Date: Mon, 27 Apr 2020 00:09:53 +0200 Subject: [PATCH] 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. --- Applications/FileManager/main.cpp | 13 ++++++++++--- 1 file 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 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 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.",