Skip to content

Commit

Permalink
CSSTUDIO-1997 Add configuration option.
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamwolk committed Aug 8, 2023
1 parent 4c9233a commit 74efed4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
1 change: 1 addition & 0 deletions core/ui/src/main/java/org/phoebus/ui/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Preferences
@Preference public static int[] alarm_area_panel_invalid_severity_background_color;
@Preference public static int[] alarm_area_panel_undefined_severity_background_color;
@Preference public static String cache_hint_for_picture_and_symbol_widgets;
@Preference public static boolean open_previous_tab_when_closing_tab;

static
{
Expand Down
27 changes: 15 additions & 12 deletions core/ui/src/main/java/org/phoebus/ui/docking/DockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.phoebus.framework.spi.AppDescriptor;
import org.phoebus.framework.spi.AppInstance;
import org.phoebus.security.authorization.AuthorizationService;
import org.phoebus.ui.Preferences;
import org.phoebus.ui.application.Messages;
import org.phoebus.ui.application.SaveLayoutHelper;
import org.phoebus.ui.dialog.DialogHelper;
Expand Down Expand Up @@ -176,18 +177,20 @@ public DockItem(final String label)
createContextMenu();

setOnClosed(event -> handleClosed());
setOnCloseRequest(event -> {
// Select the previously selected tab:
var dockPane = getDockPane();
var recentlyOpenedTabs = dockPane.tabsInOrderOfFocus;
recentlyOpenedTabs.remove(this);

if (recentlyOpenedTabs.size() > 0) {
var tab = recentlyOpenedTabs.getFirst();
var selectionModel = dockPane.getSelectionModel();
selectionModel.select(tab);
}
});
if (Preferences.open_previous_tab_when_closing_tab) {
setOnCloseRequest(event -> {
// Select the previously selected tab:
var dockPane = getDockPane();
var recentlyOpenedTabs = dockPane.tabsInOrderOfFocus;
recentlyOpenedTabs.remove(this);

if (recentlyOpenedTabs.size() > 0) {
var tab = recentlyOpenedTabs.getFirst();
var selectionModel = dockPane.getSelectionModel();
selectionModel.select(tab);
}
});
}
}

/** This tab should be in a DockPane, not a plain TabPane
Expand Down
17 changes: 10 additions & 7 deletions core/ui/src/main/java/org/phoebus/ui/docking/DockPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import org.phoebus.framework.jobs.JobManager;
import org.phoebus.ui.Preferences;
import org.phoebus.ui.application.Messages;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.javafx.ImageCache;
Expand Down Expand Up @@ -224,13 +225,15 @@ public static void alwaysShowTabs(final boolean do_show_single_tabs)

setOnContextMenuRequested(this::showContextMenu);

getSelectionModel().selectedItemProperty().addListener((observable, previous_item, new_item) -> {
// Keep track of the order of focus of tabs:
if (new_item != null) {
tabsInOrderOfFocus.remove(new_item);
tabsInOrderOfFocus.push((DockItem) new_item);
}
});
if (Preferences.open_previous_tab_when_closing_tab) {
getSelectionModel().selectedItemProperty().addListener((observable, previous_item, new_item) -> {
// Keep track of the order of focus of tabs:
if (new_item != null) {
tabsInOrderOfFocus.remove(new_item);
tabsInOrderOfFocus.push((DockItem) new_item);
}
});
}
}

protected LinkedList<DockItem> tabsInOrderOfFocus = new LinkedList<>();
Expand Down
5 changes: 5 additions & 0 deletions core/ui/src/main/resources/phoebus_ui_preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,8 @@ alarm_area_panel_undefined_severity_background_color=200,0,200,200
# default caching behavior is used (i.e., caching is DISABLED,
# and the cache hint is set to "CacheHint.DEFAULT").
cache_hint_for_picture_and_symbol_widgets=

# When 'open_previous_tab_when_closing_tab' is set to 'false', the tab to the left
# receives the focus when the active tab is closed (e.g., by clicking the 'X'-icon
# on the tab). When set to 'true', the most recently opened tab receives the focus.
open_previous_tab_when_closing_tab=false

0 comments on commit 74efed4

Please sign in to comment.