修复设置后导航与顶部栏契约

This commit is contained in:
张家训
2026-08-01 15:16:10 +08:00
parent 145b6559b8
commit 7044d5ec14
4 changed files with 122 additions and 40 deletions
@@ -43,8 +43,7 @@ public class MainWindow {
private String activePluginId;
private EmbeddedEntry currentEmbedded;
private HBox pluginToolbar;
private FontIcon toolbarIcon;
private FontIcon toolbarChevron;
private Label toolbarTitle;
public MainWindow(List<NavItem> navItems, WorkUtilsProperties properties, Runnable openSettings) {
@@ -54,12 +53,6 @@ public class MainWindow {
buildUI(Objects.requireNonNull(openSettings, "openSettings must not be null"));
}
/** Compatibility constructor for callers that do not expose settings. */
public MainWindow(List<NavItem> navItems, WorkUtilsProperties properties) {
this(navItems, properties, () -> {
});
}
public void refreshNavItems(List<NavItem> newItems) {
navItems = new ArrayList<>(newItems);
navigationRail.setItems(navItems);
@@ -129,17 +122,14 @@ public class MainWindow {
brand.setContentDisplay(ContentDisplay.LEFT);
brand.setFont(Theme.sectionTitle());
pluginToolbar = new HBox(Theme.S2);
pluginToolbar.setAlignment(Pos.CENTER_LEFT);
pluginToolbar.setVisible(false);
pluginToolbar.setManaged(false);
FontIcon chevron = IconFactory.create(AppIcon.CHEVRON_RIGHT, 14);
toolbarIcon = IconFactory.create(AppIcon.APP, 18);
toolbarChevron = IconFactory.create(AppIcon.CHEVRON_RIGHT, 14);
toolbarChevron.setVisible(false);
toolbarChevron.setManaged(false);
toolbarTitle = new Label();
toolbarTitle.setFont(Theme.pageTitle());
toolbarTitle.getStyleClass().add(Theme.CSS_PAGE_TITLE);
pluginToolbar.getChildren().addAll(chevron, toolbarIcon, toolbarTitle);
toolbarTitle.setVisible(false);
toolbarTitle.setManaged(false);
Region spacerRight = new Region();
HBox.setHgrow(spacerRight, Priority.ALWAYS);
@@ -151,7 +141,7 @@ public class MainWindow {
settingsButton.setOnAction(event -> openSettings.run());
bar.getChildren().addAll(
menuButton, brand, pluginToolbar, spacerRight, settingsButton);
menuButton, brand, toolbarChevron, toolbarTitle, spacerRight, settingsButton);
return bar;
}
@@ -163,16 +153,19 @@ public class MainWindow {
showEmbeddedFor(item);
}
private void showPluginToolbar(AppIcon icon, String title) {
toolbarIcon.setIconCode(icon.glyph());
private void showPluginToolbar(String title) {
toolbarTitle.setText(title);
pluginToolbar.setVisible(true);
pluginToolbar.setManaged(true);
toolbarChevron.setVisible(true);
toolbarChevron.setManaged(true);
toolbarTitle.setVisible(true);
toolbarTitle.setManaged(true);
}
private void hidePluginToolbar() {
pluginToolbar.setVisible(false);
pluginToolbar.setManaged(false);
toolbarChevron.setVisible(false);
toolbarChevron.setManaged(false);
toolbarTitle.setVisible(false);
toolbarTitle.setManaged(false);
}
private void showWelcomePage() {
@@ -215,12 +208,15 @@ public class MainWindow {
public void embedPlugin(String pluginId, String ignoredIcon, String name, Parent content) {
embeddedCache.remove(pluginId);
EmbeddedEntry entry = new EmbeddedEntry(content, NavItem.iconForPlugin(pluginId), name);
EmbeddedEntry entry = new EmbeddedEntry(content, name);
embeddedCache.put(pluginId, entry);
switchToEmbedded(pluginId, entry);
}
private void switchToEmbedded(String pluginId, EmbeddedEntry entry) {
if ("__settings__".equals(pluginId)) {
navigationRail.clearSelection();
}
if (currentEmbedded != null && currentEmbedded != entry) {
contentArea.getChildren().remove(currentEmbedded.wrapper);
}
@@ -235,7 +231,7 @@ public class MainWindow {
if (!contentArea.getChildren().contains(entry.wrapper)) {
contentArea.getChildren().setAll(entry.wrapper);
}
showPluginToolbar(entry.icon, entry.title);
showPluginToolbar(entry.title);
}
public void closePlugin(String pluginId) {
@@ -264,7 +260,7 @@ public class MainWindow {
wrapper.getStyleClass().add(Theme.CSS_CONTENT_AREA);
wrapper.setCenter(content);
contentArea.getChildren().setAll(wrapper);
showPluginToolbar(AppIcon.APP, title);
showPluginToolbar(title);
}
public void refreshTheme() {
@@ -273,13 +269,11 @@ public class MainWindow {
private static final class EmbeddedEntry {
private final Parent content;
private final AppIcon icon;
private final String title;
private BorderPane wrapper;
private EmbeddedEntry(Parent content, AppIcon icon, String title) {
private EmbeddedEntry(Parent content, String title) {
this.content = content;
this.icon = icon;
this.title = title;
}
}
@@ -96,6 +96,14 @@ public final class NavigationRail extends VBox {
return selectedPluginId;
}
public void clearSelection() {
requireFxThread();
selection.selectToggle(null);
itemViews.forEach(view -> view.button().getStyleClass().remove(Theme.CSS_NAV_CELL_ACTIVE));
selectedItem = null;
selectedPluginId = null;
}
public void setItems(List<MainWindow.NavItem> items) {
requireFxThread();
Objects.requireNonNull(items, "items must not be null");