From 3b65cd82dd21324d117500efd0058159dbffeb24 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Thu, 9 Jan 2025 10:08:11 +0100 Subject: [PATCH] CSSTUDIO-2648 Add "Add Layout" button to the toolbar when org.phoebus.ui/toolbar_entries=Add Layouts is set. --- .../ui/application/PhoebusApplication.java | 19 +++++++++++++++++++ .../ui/application/ToolbarEntryService.java | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 092f40dca6..3a3851fe4c 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -229,6 +229,11 @@ public class PhoebusApplication extends Application { */ private MenuButton layout_menu_button; + /** + * Toolbar button for adding past layouts + */ + private MenuButton add_layout_menu_button; + /** * Last file used by 'File, Open' menu * (the _directory_ is actually used by the file-open dialog) @@ -759,6 +764,7 @@ void createLoadLayoutsMenu() { final List menuItemList = new ArrayList<>(); final List toolbarMenuItemList = new ArrayList<>(); final List addLayoutMenuItemList = new ArrayList<>(); + final List toolbarAddLayoutMenuItemList = new ArrayList<>(); final Map layoutFiles = new HashMap(); @@ -822,6 +828,12 @@ void createLoadLayoutsMenu() { addLayoutMenuItem.setMnemonicParsing(false); addLayoutMenuItem.setOnAction(event -> startAddingLayout(file)); addLayoutMenuItemList.add(addLayoutMenuItem); + + // Repeat for the same menu in the toolbar. They can't share menu items. + final MenuItem toolbarAddLayoutMenuItem = new MenuItem(filename); + toolbarAddLayoutMenuItem.setMnemonicParsing(false); + toolbarAddLayoutMenuItem.setOnAction(event -> startAddingLayout(file)); + toolbarAddLayoutMenuItemList.add(toolbarAddLayoutMenuItem); } }); } @@ -832,6 +844,7 @@ void createLoadLayoutsMenu() { load_layout.getItems().setAll(menuItemList); add_layout.getItems().setAll(addLayoutMenuItemList); layout_menu_button.getItems().setAll(toolbarMenuItemList); + add_layout_menu_button.getItems().setAll(toolbarAddLayoutMenuItemList); delete_layouts.setDisable(memento_files.isEmpty()); }); }); @@ -965,6 +978,12 @@ private ToolBar createToolbar() { if (! Preferences.toolbar_entries.contains("!Layouts")) toolBar.getItems().add(layout_menu_button); + add_layout_menu_button = new MenuButton(null, ImageCache.getImageView(getClass(), "/icons/add_layout.png")); + add_layout_menu_button.setTooltip(new Tooltip(Messages.AddLayout)); + if (Preferences.toolbar_entries.contains("Add Layouts") && !Preferences.toolbar_entries.contains("!Add Layouts")) { + toolBar.getItems().add(add_layout_menu_button); + } + // Contributed Entries ToolbarEntryService.getInstance().listToolbarEntries().forEach((entry) -> { final AtomicBoolean open_new = new AtomicBoolean(); diff --git a/core/ui/src/main/java/org/phoebus/ui/application/ToolbarEntryService.java b/core/ui/src/main/java/org/phoebus/ui/application/ToolbarEntryService.java index 9872637359..d46e54193d 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/ToolbarEntryService.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/ToolbarEntryService.java @@ -29,7 +29,7 @@ private ToolbarEntryService() { if (suppress) desired = desired.substring(1); // Skip entries handled in PhoebusApplication - if (desired.equals("Home") || desired.equals("Top Resources") || desired.equals("Layouts")) + if (desired.equals("Home") || desired.equals("Top Resources") || desired.equals("Layouts") || desired.equals("Add Layouts")) continue; // Add specific 'desired' entry ToolbarEntry found = null;