Skip to content

Commit 9893fdf

Browse files
authored
Merge branch 'master' into custom_disabled_widget_style
2 parents 7105d82 + bf6fa78 commit 9893fdf

File tree

19 files changed

+998
-104
lines changed

19 files changed

+998
-104
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,5 @@ phoebus-product/settings_template.ini
123123

124124
# doc files generated by docs/source/conf.py
125125
docs/source/applications.rst
126-
docs/source/preference_properties.rst
127126
docs/source/services.rst
128127

app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/JFXStageRepresentation.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public JFXStageRepresentation(final Stage stage)
4949
public Parent configureStage(final DisplayModel model, final Consumer<DisplayModel> close_request_handler)
5050
{
5151
final String name = model.getDisplayName();
52-
stage.setTitle(name);
5352

5453
// The following trick is necessary because keys cannot be longer than 80 characters.
5554
final String hexName = Integer.toHexString(name.hashCode()).toLowerCase();

core/ui/src/main/java/org/phoebus/ui/Preferences.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public class Preferences
101101
@Preference public static boolean save_credentials;
102102
/** documentation_location */
103103
@Preference public static String documentation_location;
104+
/** window_title_format **/
105+
@Preference public static String window_title_format;
106+
/** default_window_title **/
107+
@Preference public static String default_window_title;
104108
/** Custom stylings file */
105109
@Preference public static String custom_css_styling;
106110

core/ui/src/main/java/org/phoebus/ui/application/Messages.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class Messages
5050
public static String File;
5151
public static String FileDoesNotExist;
5252
public static String FileExists;
53-
public static String FixedTitle;
5453
public static String Help;
5554
public static String HelpAbout;
5655
public static String HelpAboutAppFea;

core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import org.phoebus.ui.docking.DockPane;
8686
import org.phoebus.ui.docking.DockPaneListener;
8787
import org.phoebus.ui.docking.DockStage;
88+
import org.phoebus.ui.docking.StageTitleManager;
8889
import org.phoebus.ui.help.OpenAbout;
8990
import org.phoebus.ui.help.OpenHelp;
9091
import org.phoebus.ui.internal.MementoHelper;
@@ -547,6 +548,8 @@ private void startUI(final MementoTree memento, final JobMonitor monitor) throws
547548
closeMainStage();
548549
});
549550

551+
StageTitleManager.bindStageTitlesToActiveTabs(main_stage);
552+
550553
DockPane.addListener(dock_pane_listener);
551554
DockPane.setActiveDockPane(DockStage.getDockPanes(main_stage).get(0));
552555
monitor.done();

core/ui/src/main/java/org/phoebus/ui/docking/DockPane.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,6 @@ private void doAutoHideTabs(final Scene scene)
520520
throw new IllegalStateException("Expected DockItem, got " + tab);
521521
stage.titleProperty().bind(((DockItem)tab).labelTextProperty());
522522
}
523-
else
524-
{ // Fixed title
525-
stage.titleProperty().unbind();
526-
stage.setTitle(Messages.FixedTitle);
527-
}
528523
}
529524

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

538535
/** @return All {@link DockItem}s in this pane (safe copy) */

core/ui/src/main/java/org/phoebus/ui/docking/DockStage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ else if(layout.getChildren().get(0) instanceof SplitPane){
164164

165165
final Scene scene = new Scene(layout, geometry.width, geometry.height);
166166
stage.setScene(scene);
167-
stage.setTitle(Messages.FixedTitle);
168167
// Set position
169168
stage.setX(geometry.x);
170169
stage.setY(geometry.y);

core/ui/src/main/java/org/phoebus/ui/docking/SplitDock.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ else if (dock_parent instanceof SplitPane) { // "dock_parent instanceof SplitPan
184184
return;
185185
}
186186

187+
// If the dock pane that has just been merged is active,
188+
// switch the active dock pane to the first pane found in the other child
189+
if (empty_dock == DockPane.getActiveDockPane()) {
190+
if (child instanceof DockPane dockPane) {
191+
DockPane.setActiveDockPane(dockPane);
192+
} else if (child instanceof SplitDock splitDock) {
193+
splitDock.findAndActivateDockPane();
194+
}
195+
}
196+
187197
// Tell child about its new dock_parent
188198
if (child instanceof DockPane)
189199
((DockPane)child).setDockParent(dock_parent);
@@ -261,6 +271,18 @@ private boolean isEmptyDock(final Node item)
261271
return false;
262272
}
263273

274+
private void findAndActivateDockPane() {
275+
// switch the active dock pane to the first pane found in this split or in any nested split
276+
for (Node child : getItems()) {
277+
if (child instanceof DockPane dockPane) {
278+
DockPane.setActiveDockPane(dockPane);
279+
return;
280+
} else if (child instanceof SplitDock splitDock) {
281+
splitDock.findAndActivateDockPane();
282+
}
283+
}
284+
}
285+
264286
@Override
265287
public String toString()
266288
{
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.phoebus.ui.docking;
2+
3+
import javafx.beans.binding.Bindings;
4+
import javafx.beans.binding.StringExpression;
5+
import javafx.stage.Stage;
6+
import org.phoebus.ui.Preferences;
7+
8+
import java.util.List;
9+
10+
/**
11+
* Helper class to manage the window title.
12+
*/
13+
public class StageTitleManager {
14+
15+
private static final DockPaneListener listener = StageTitleManager::setStageTitleToTabTitle;
16+
17+
// This class is only a static utility, so it should not be instantiated.
18+
private StageTitleManager() {}
19+
20+
public static void bindStageTitlesToActiveTabs(Stage mainStage) {
21+
// this will listen to all tab focus events and set the stage title
22+
// of the stage in which the tab is located to the formatted title.
23+
DockPane.addListener(listener);
24+
25+
// This listener is passed down to all child panes when a split occurs,
26+
// so it fires when any pane in the main stage becomes empty.
27+
// Therefore, we have to check if all panes are empty.
28+
DockStage.getDockPanes(mainStage).get(0).addDockPaneEmptyListener(() -> {
29+
List<DockPane> panes = DockStage.getDockPanes(mainStage);
30+
for (DockPane pane : panes) {
31+
if (!pane.getDockItems().isEmpty()) {
32+
// If any pane has items, we don't need to set the title to default
33+
return;
34+
}
35+
}
36+
// If all panes are empty, set the stage title to the default
37+
mainStage.titleProperty().unbind();
38+
setStageTitleToDefault(mainStage);
39+
});
40+
}
41+
42+
private static void setStageTitleToTabTitle(DockItem dockItem) {
43+
if (dockItem == null) {
44+
return;
45+
}
46+
DockPane pane = dockItem.getDockPane();
47+
// I don't think this is ever true,
48+
// but better to have it and not need it than the other way around
49+
if (pane == null) {
50+
return;
51+
}
52+
pane.deferUntilInScene(scene -> {
53+
if (scene.getWindow() instanceof Stage stage) {
54+
if (DockPane.getActiveDockPane() != pane) {
55+
// If the dock pane is not active, don't do anything
56+
return;
57+
}
58+
StringExpression exp = Bindings.format(Preferences.window_title_format, dockItem.labelTextProperty());
59+
stage.titleProperty().bind(exp);
60+
}
61+
});
62+
}
63+
64+
private static void setStageTitleToDefault(Stage stage) {
65+
stage.setTitle(Preferences.default_window_title);
66+
}
67+
}

core/ui/src/main/resources/org/phoebus/ui/application/messages.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ ExitTitle=Exit
3636
File=File
3737
FileDoesNotExist=File does not exist!
3838
FileExists=File \"{0}\" already exists. Do you want to overwrite it?
39-
FixedTitle=CS-Studio
4039
Help=Help
4140
HelpAbout=About
4241
HelpAboutAppFea=Application Features

0 commit comments

Comments
 (0)