Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSSTUDIO-1761 (Part 2/2) Functionality to save the layout of an individual window #2551

Merged
merged 11 commits into from
Feb 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CSSTUDIO-1761 Add the menu item "Save Layout of Containing Window" to…
… the menu that appears when one right-clicks on a tab.
  • Loading branch information
abrahamwolk committed Feb 15, 2023
commit 0a1724a54e55e1d0bc664faeb0e9e91a00110284
25 changes: 23 additions & 2 deletions core/ui/src/main/java/org/phoebus/ui/docking/DockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*******************************************************************************/
package org.phoebus.ui.docking;

import static org.phoebus.ui.docking.DockPane.getActiveDockPane;
import static org.phoebus.ui.docking.DockPane.logger;
import static org.phoebus.ui.docking.DockStage.getDockPanes;

import java.awt.MouseInfo;
import java.awt.Point;
Expand All @@ -20,12 +22,14 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.stream.Collectors;

import org.phoebus.framework.jobs.JobManager;
import org.phoebus.framework.spi.AppDescriptor;
import org.phoebus.framework.spi.AppInstance;
import org.phoebus.security.authorization.AuthorizationService;
import org.phoebus.ui.application.Messages;
import org.phoebus.ui.application.SaveLayoutMenuItem;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.javafx.ImageCache;
import org.phoebus.ui.javafx.Styles;
Expand Down Expand Up @@ -93,6 +97,7 @@ public class DockItem extends Tab
detach_icon = ImageCache.getImage(DockItem.class, "/icons/detach.png"),
split_horiz_icon = ImageCache.getImage(DockItem.class, "/icons/split_horiz.png"),
split_vert_icon = ImageCache.getImage(DockItem.class, "/icons/split_vert.png"),
save_window_layout_icon = ImageCache.getImage(DockItem.class, "/icons/new_layout.png"),
close_many_icon = ImageCache.getImage(DockItem.class, "/icons/remove_multiple.png");


Expand Down Expand Up @@ -198,6 +203,21 @@ private void createContextMenu()
final MenuItem split_vert = new MenuItem(Messages.DockSplitV, new ImageView(split_vert_icon));
split_vert.setOnAction(event -> split(false));

final SaveLayoutMenuItem save_window = new SaveLayoutMenuItem("Save Layout of Containing Window");
save_window.setOnAction(event -> {
DockPane activeDockPane = getActiveDockPane();
List<Stage> stagesContainingActiveDockPane = DockStage.getDockStages().stream().filter(stage -> getDockPanes(stage).contains(activeDockPane)).collect(Collectors.toList());
if (stagesContainingActiveDockPane.size() == 1) {
save_window.saveLayout(stagesContainingActiveDockPane);
}
else if (stagesContainingActiveDockPane.size() == 1) {
logger.log(Level.SEVERE, "No stage contains the active dock pane!");
}
else {
logger.log(Level.SEVERE, "More than one stage contains the active dock pane!");
}
});

final MenuItem close = new MenuItem(Messages.DockClose, new ImageView(DockPane.close_icon));
close.setOnAction(event -> close(List.of(this)));

Expand All @@ -207,7 +227,7 @@ private void createContextMenu()
// Close all other tabs in non-fixed panes of this window
final Stage stage = (Stage) getDockPane().getScene().getWindow();
final List<DockItem> tabs = new ArrayList<>();
for (DockPane pane : DockStage.getDockPanes(stage))
for (DockPane pane : getDockPanes(stage))
if (! pane.isFixed())
for (Tab tab : new ArrayList<>(pane.getTabs()))
if ((tab instanceof DockItem) && tab != DockItem.this)
Expand All @@ -221,7 +241,7 @@ private void createContextMenu()
// Close all tabs in non-fixed panes of this window
final Stage stage = (Stage) getDockPane().getScene().getWindow();
final List<DockItem> tabs = new ArrayList<>();
for (DockPane pane : DockStage.getDockPanes(stage))
for (DockPane pane : getDockPanes(stage))
if (! pane.isFixed())
for (Tab tab : new ArrayList<>(pane.getTabs()))
if ((tab instanceof DockItem))
Expand All @@ -234,6 +254,7 @@ private void createContextMenu()
menu.setOnShowing(event ->
{
menu.getItems().setAll(info);
menu.getItems().setAll(save_window);

final boolean may_lock = AuthorizationService.hasAuthorization("lock_ui");
final DockPane pane = getDockPane();
Expand Down