Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public JFXStageRepresentation(final Stage stage)
public Parent configureStage(final DisplayModel model, final Consumer<DisplayModel> close_request_handler)
{
final String name = model.getDisplayName();
stage.setTitle(name);

// The following trick is necessary because keys cannot be longer than 80 characters.
final String hexName = Integer.toHexString(name.hashCode()).toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public class Messages
public static String WebBrowser;
public static String Welcome;
public static String Window;
public static String WindowTitleFormat;

static
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.dialog.ListPickerDialog;
import org.phoebus.ui.dialog.OpenFileDialog;
import org.phoebus.ui.docking.DockItem;
import org.phoebus.ui.docking.DockItemWithInput;
import org.phoebus.ui.docking.DockPane;
import org.phoebus.ui.docking.DockPaneListener;
import org.phoebus.ui.docking.DockStage;
import org.phoebus.ui.docking.*;
import org.phoebus.ui.help.OpenAbout;
import org.phoebus.ui.help.OpenHelp;
import org.phoebus.ui.internal.MementoHelper;
Expand Down Expand Up @@ -547,6 +543,8 @@ private void startUI(final MementoTree memento, final JobMonitor monitor) throws
closeMainStage();
});

StageTitleManager.bindStageTitlesToActiveTabs(main_stage);

DockPane.addListener(dock_pane_listener);
DockPane.setActiveDockPane(DockStage.getDockPanes(main_stage).get(0));
monitor.done();
Expand Down
7 changes: 2 additions & 5 deletions core/ui/src/main/java/org/phoebus/ui/docking/DockPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,6 @@ private void doAutoHideTabs(final Scene scene)
throw new IllegalStateException("Expected DockItem, got " + tab);
stage.titleProperty().bind(((DockItem)tab).labelTextProperty());
}
else
{ // Fixed title
stage.titleProperty().unbind();
stage.setTitle(Messages.FixedTitle);
}
}

/** @param tabs One or more tabs to add */
Expand All @@ -533,6 +528,8 @@ public void addTab(final DockItem... tabs)
getTabs().addAll(tabs);
// Select the newly added tab
getSelectionModel().select(getTabs().size()-1);
// Set this as the active dock pane
setActiveDockPane(this);
}

/** @return All {@link DockItem}s in this pane (safe copy) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ else if(layout.getChildren().get(0) instanceof SplitPane){

final Scene scene = new Scene(layout, geometry.width, geometry.height);
stage.setScene(scene);
stage.setTitle(Messages.FixedTitle);
// Set position
stage.setX(geometry.x);
stage.setY(geometry.y);
Expand Down
22 changes: 22 additions & 0 deletions core/ui/src/main/java/org/phoebus/ui/docking/SplitDock.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ else if (dock_parent instanceof SplitPane) { // "dock_parent instanceof SplitPan
return;
}

// If the dock pane that has just been merged is active,
// switch the active dock pane to the first pane found in the other child
if (empty_dock == DockPane.getActiveDockPane()) {
if (child instanceof DockPane dockPane) {
DockPane.setActiveDockPane(dockPane);
} else if (child instanceof SplitDock splitDock) {
splitDock.findAndActivateDockPane();
}
}

// Tell child about its new dock_parent
if (child instanceof DockPane)
((DockPane)child).setDockParent(dock_parent);
Expand Down Expand Up @@ -261,6 +271,18 @@ private boolean isEmptyDock(final Node item)
return false;
}

private void findAndActivateDockPane() {
// switch the active dock pane to the first pane found in this split or in any nested split
for (Node child : getItems()) {
if (child instanceof DockPane dockPane) {
DockPane.setActiveDockPane(dockPane);
return;
} else if (child instanceof SplitDock splitDock) {
splitDock.findAndActivateDockPane();
}
}
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.phoebus.ui.docking;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringExpression;
import javafx.stage.Stage;
import org.phoebus.ui.application.Messages;

import java.util.List;
import java.util.logging.Logger;

/**
* Helper class to manage the window title.
*/
public class StageTitleManager {

private static final DockPaneListener listener = StageTitleManager::setStageTitleToTabTitle;

// This class is only a static utility, so it should not be instantiated.
private StageTitleManager() {}

public static void bindStageTitlesToActiveTabs(Stage mainStage) {
// this will listen to all tab focus events and set the stage title
// of the stage in which the tab is located to the formatted title.
DockPane.addListener(listener);

// This listener is passed down to all child panes when a split occurs,
// so it fires when any pane in the main stage becomes empty.
// Therefore, we have to check if all panes are empty.
DockStage.getDockPanes(mainStage).get(0).addDockPaneEmptyListener(() -> {
List<DockPane> panes = DockStage.getDockPanes(mainStage);
for (DockPane pane : panes) {
if (!pane.getDockItems().isEmpty()) {
// If any pane has items, we don't need to set the title to default
return;
}
}
// If all panes are empty, set the stage title to the default
mainStage.titleProperty().unbind();
setStageTitleToDefault(mainStage);
});
}

private static void setStageTitleToTabTitle(DockItem dockItem) {
if (dockItem == null) {
return;
}
DockPane pane = dockItem.getDockPane();
// I don't think this is ever true,
// but better to have it and not need it than the other way around
if (pane == null) {
return;
}
pane.deferUntilInScene(scene -> {
if (scene.getWindow() instanceof Stage stage) {
if (DockPane.getActiveDockPane() != pane) {
// If the dock pane is not active, don't do anything
return;
}
StringExpression exp = Bindings.format(Messages.WindowTitleFormat, dockItem.labelTextProperty());
stage.titleProperty().bind(exp);
}
});
}

private static void setStageTitleToDefault(Stage stage) {
stage.setTitle(Messages.FixedTitle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ UnsavedChanges_wouldYouLikeToSaveAnyChangesBeforeReplacingTheLayout=Would you li
WebBrowser=Web Browser
Welcome=Welcome
Window=Window
WindowTitleFormat=CS-Studio: %s
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ UnsavedChanges_wouldYouLikeToSaveAnyChangesBeforeReplacingTheLayout=Voulez-vous
WebBrowser=Navigateur Web
Welcome=Bienvenue
Window=Fen\u00EAtre
WindowTitleFormat=CS-Studio: %s