summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-14 09:20:20 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-14 09:20:20 +0200
commit31046b18bbf198c77ddeaddb1a99de0141f746ad (patch)
tree6c38dc30abb54a6e286beb0924750a224fef2bc9
parentc543ee5c5bcfbb7dd31ab70f3a64e91933485275 (diff)
downloadserenity-31046b18bbf198c77ddeaddb1a99de0141f746ad.zip
FileManager: Use a special clipboard data type for copied file lists
When copying a list of files to the clipboard, we now use the special data type "file-list". This allows us to have the paste action's enabled state reflect the actual ability to paste something. :^)
-rw-r--r--Applications/FileManager/main.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp
index b24a935423..cf3c8758be 100644
--- a/Applications/FileManager/main.cpp
+++ b/Applications/FileManager/main.cpp
@@ -136,23 +136,25 @@ int main(int argc, char** argv)
return;
}
StringBuilder copy_text;
- copy_text.append("copy\n");
for (String& path : selected_file_paths.value()) {
copy_text.appendf("%s\n", path.characters());
}
- GClipboard::the().set_data(copy_text.build());
+ GClipboard::the().set_data(copy_text.build(), "file-list");
});
copy_action->set_enabled(false);
auto paste_action = GAction::create("Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), [&](const GAction&) {
- dbgprintf("'Paste' action activated!\n");
- auto copied_lines = GClipboard::the().data().split('\n');
- if (copied_lines.is_empty() || copied_lines.first() != "copy") {
- GMessageBox::show("No files cut or copied.", "File Manager", GMessageBox::Type::Information);
+ auto data_and_type = GClipboard::the().data_and_type();
+ if (data_and_type.type != "file-list") {
+ dbg() << "Cannot paste clipboard type " << data_and_type.type;
return;
}
- for (int i = 1; i < copied_lines.size(); ++i) {
- auto current_path = copied_lines[i];
+ auto copied_lines = data_and_type.data.split('\n');
+ if (copied_lines.is_empty()) {
+ dbg() << "No files to paste";
+ return;
+ }
+ for (auto& current_path : copied_lines) {
if (current_path.is_empty())
continue;
auto current_directory = directory_view->path();
@@ -166,8 +168,14 @@ int main(int argc, char** argv)
}
}
});
+ paste_action->set_enabled(GClipboard::the().type() == "file-list");
+
+ GClipboard::the().on_content_change = [&](const String& data_type) {
+ paste_action->set_enabled(data_type == "file-list");
+ };
- auto properties_action = GAction::create("Properties...", { Mod_Alt, Key_Return }, GraphicsBitmap::load_from_file("/res/icons/16x16/properties.png"), [](auto&) {});
+ auto properties_action
+ = GAction::create("Properties...", { Mod_Alt, Key_Return }, GraphicsBitmap::load_from_file("/res/icons/16x16/properties.png"), [](auto&) {});
auto delete_action = GAction::create("Delete", { Mod_None, Key_Delete }, GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), [](const GAction&) {
dbgprintf("'Delete' action activated!\n");