Skip to content

Commit

Permalink
CSSTUDIO-2648 Add "Add Layout" button to the toolbar when org.phoebus…
Browse files Browse the repository at this point in the history
….ui/toolbar_entries=Add Layouts is set.
  • Loading branch information
abrahamwolk committed Jan 9, 2025
1 parent d051c56 commit 3b65cd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -759,6 +764,7 @@ void createLoadLayoutsMenu() {
final List<MenuItem> menuItemList = new ArrayList<>();
final List<MenuItem> toolbarMenuItemList = new ArrayList<>();
final List<MenuItem> addLayoutMenuItemList = new ArrayList<>();
final List<MenuItem> toolbarAddLayoutMenuItemList = new ArrayList<>();

final Map<String, File> layoutFiles = new HashMap<String, File>();

Expand Down Expand Up @@ -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);
}
});
}
Expand All @@ -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());
});
});
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3b65cd8

Please sign in to comment.