From 875ab0cf107894cf7311ea6d779cdae980e88627 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Sun, 8 Dec 2019 00:39:45 -0500 Subject: [PATCH] FileManager: Add separate context menus for entries Ref: #826 Right-clicking a directory no longer has the "Open in TextEditor" entry. Right-clicking the directory view now allows you to create a new directory. --- Applications/FileManager/main.cpp | 40 +++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index d4380cf5c28..ff84f6a7be1 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -412,17 +412,37 @@ int main(int argc, char** argv) } }); - auto context_menu = make(); - context_menu->add_action(copy_action); - context_menu->add_action(paste_action); - context_menu->add_action(delete_action); - context_menu->add_separator(); - context_menu->add_action(open_in_text_editor_action); - context_menu->add_separator(); - context_menu->add_action(properties_action); + auto directory_context_menu = make(); + directory_context_menu->add_action(copy_action); + directory_context_menu->add_action(paste_action); + directory_context_menu->add_action(delete_action); + directory_context_menu->add_separator(); + directory_context_menu->add_action(properties_action); - directory_view->on_context_menu_request = [&](const GAbstractView&, const GModelIndex&, const GContextMenuEvent& event) { - context_menu->popup(event.screen_position()); + auto file_context_menu = make(); + file_context_menu->add_action(copy_action); + file_context_menu->add_action(paste_action); + file_context_menu->add_action(delete_action); + file_context_menu->add_separator(); + file_context_menu->add_action(open_in_text_editor_action); + file_context_menu->add_separator(); + file_context_menu->add_action(properties_action); + + auto directory_view_context_menu = make(); + directory_view_context_menu->add_action(mkdir_action); + + directory_view->on_context_menu_request = [&](const GAbstractView&, const GModelIndex& index, const GContextMenuEvent& event) { + if (index.is_valid()) { + auto& entry = directory_view->model().entry(index.row()); + + if (entry.is_directory()) { + directory_context_menu->popup(event.screen_position()); + } else { + file_context_menu->popup(event.screen_position()); + } + } else { + directory_view_context_menu->popup(event.screen_position()); + } }; // our initial location is defined as, in order of precedence: