From a3a5d2b27d54d6872a1c55d7e252a7b5cd88c816 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 7 Dec 2022 21:25:49 +0100 Subject: [PATCH] SpaceAnalyzer: Consolidate the node context menus Instead of having two separate context menus and popping up either the "file" or "directory" one depending on the selected node, we now have a single context menu and update it (before popping it up) to show the context-appropriate actions. This is achieved by simply updating the visibility of the actions. This takes care of one TODO! :^) --- Userland/Applications/SpaceAnalyzer/main.cpp | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Userland/Applications/SpaceAnalyzer/main.cpp b/Userland/Applications/SpaceAnalyzer/main.cpp index 8ce4b31a2c..e66e2b88f4 100644 --- a/Userland/Applications/SpaceAnalyzer/main.cpp +++ b/Userland/Applications/SpaceAnalyzer/main.cpp @@ -391,15 +391,12 @@ ErrorOr serenity_main(Main::Arguments arguments) GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error())); } }); - // TODO: Both these menus could've been implemented as one, but it's impossible to change action text after it's shown once. - auto folder_node_context_menu = GUI::Menu::construct(); - folder_node_context_menu->add_action(*open_folder_action); - folder_node_context_menu->add_action(*copy_path_action); - folder_node_context_menu->add_action(*delete_action); - auto file_node_context_menu = GUI::Menu::construct(); - file_node_context_menu->add_action(*open_containing_folder_action); - file_node_context_menu->add_action(*copy_path_action); - file_node_context_menu->add_action(*delete_action); + + auto context_menu = GUI::Menu::construct(); + context_menu->add_action(*open_folder_action); + context_menu->add_action(*open_containing_folder_action); + context_menu->add_action(*copy_path_action); + context_menu->add_action(*delete_action); // Configure event handlers. breadcrumbbar.on_segment_click = [&](size_t index) { @@ -438,10 +435,13 @@ ErrorOr serenity_main(Main::Arguments arguments) return; delete_action->set_enabled(is_removable(selected_node_path)); if (Core::File::is_directory(selected_node_path)) { - folder_node_context_menu->popup(event.screen_position()); + open_folder_action->set_visible(true); + open_containing_folder_action->set_visible(false); } else { - file_node_context_menu->popup(event.screen_position()); + open_folder_action->set_visible(false); + open_containing_folder_action->set_visible(true); } + context_menu->popup(event.screen_position()); }; // At startup automatically do an analysis of root.