diff options
author | Jonathan Archer <jon@jonnyarcher.com> | 2020-04-22 13:27:35 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-23 11:22:32 +0200 |
commit | d02c02cebeab0b145c1077084078b2dd9bc14550 (patch) | |
tree | 0019a7e6899bfb59b262d47d1954f4fbdda3cadd /Applications/FileManager/main.cpp | |
parent | 6d308113b8ab15b9ffe97534480c9e85cc461f77 (diff) | |
download | serenity-d02c02cebeab0b145c1077084078b2dd9bc14550.zip |
Desktop: Add context menu for directory view
Only has the option to create a folder, but hey ;^)
Diffstat (limited to 'Applications/FileManager/main.cpp')
-rw-r--r-- | Applications/FileManager/main.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 0fa3dfd584..0939b3a3a8 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -157,6 +157,29 @@ int run_in_desktop_mode(RefPtr<Core::ConfigFile> config, String initial_location Core::DesktopServices::open(URL::create_with_file_protocol(path)); }; + auto desktop_view_context_menu = GUI::Menu::construct("Directory View"); + + auto mkdir_action = GUI::Action::create("New directory...", {}, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) { + auto input_box = GUI::InputBox::construct("Enter name:", "New directory", window); + if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { + auto new_dir_path = canonicalized_path( + String::format("%s/%s", + model->root_path().characters(), + input_box->text_value().characters())); + int rc = mkdir(new_dir_path.characters(), 0777); + if (rc < 0) { + GUI::MessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window); + } + } + }); + + desktop_view_context_menu->add_action(mkdir_action); + + item_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) { + if (!index.is_valid()) + desktop_view_context_menu->popup(event.screen_position()); + }; + window->show(); return GUI::Application::the().exec(); } |