From d1b506415c9a21fe000a0f0408e305f113034987 Mon Sep 17 00:00:00 2001 From: crschnick Date: Sun, 23 Jun 2024 22:39:23 +0000 Subject: [PATCH] Shortcut fixes --- .../java/io/xpipe/app/comp/AppLayoutComp.java | 16 ++++++++++++++-- .../io/xpipe/app/comp/base/SideMenuBarComp.java | 13 ++++++------- .../java/io/xpipe/app/core/AppLayoutModel.java | 13 ++++++++----- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/AppLayoutComp.java b/app/src/main/java/io/xpipe/app/comp/AppLayoutComp.java index 884f7cb9..b227d170 100644 --- a/app/src/main/java/io/xpipe/app/comp/AppLayoutComp.java +++ b/app/src/main/java/io/xpipe/app/comp/AppLayoutComp.java @@ -9,9 +9,11 @@ import io.xpipe.app.fxcomps.CompStructure; import io.xpipe.app.fxcomps.SimpleCompStructure; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.storage.DataStorage; - import javafx.beans.binding.Bindings; import javafx.beans.value.ObservableValue; +import javafx.scene.control.ButtonBase; +import javafx.scene.input.KeyCodeCombination; +import javafx.scene.input.KeyEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; @@ -40,13 +42,23 @@ public class AppLayoutComp extends Comp> { var sidebar = new SideMenuBarComp(model.getSelected(), model.getEntries()); StackPane multiR = (StackPane) multi.createRegion(); pane.setCenter(multiR); - pane.setRight(sidebar.createRegion()); + var sidebarR = sidebar.createRegion(); + pane.setRight(sidebarR); model.getSelected().addListener((c, o, n) -> { if (o != null && o.equals(model.getEntries().get(2))) { AppPrefs.get().save(); DataStorage.get().saveAsync(); } }); + pane.addEventHandler(KeyEvent.KEY_PRESSED, event -> { + sidebarR.getChildrenUnmodifiable().forEach(node -> { + var shortcut = (KeyCodeCombination) node.getProperties().get("shortcut"); + if (shortcut != null && shortcut.match(event)) { + ((ButtonBase) node).fire(); + event.consume(); + } + }); + }); AppFont.normal(pane); pane.getStyleClass().add("layout"); return new SimpleCompStructure<>(pane); diff --git a/app/src/main/java/io/xpipe/app/comp/base/SideMenuBarComp.java b/app/src/main/java/io/xpipe/app/comp/base/SideMenuBarComp.java index d862a9d4..6da9967a 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/SideMenuBarComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/SideMenuBarComp.java @@ -18,8 +18,6 @@ import javafx.beans.binding.Bindings; import javafx.beans.property.Property; import javafx.css.PseudoClass; import javafx.scene.control.Button; -import javafx.scene.input.KeyCode; -import javafx.scene.input.KeyCodeCombination; import javafx.scene.layout.*; import javafx.scene.paint.Color; @@ -70,7 +68,10 @@ public class SideMenuBarComp extends Comp> { for (int i = 0; i < entries.size(); i++) { var e = entries.get(i); var b = new IconButtonComp(e.icon(), () -> value.setValue(e)); - var shortcut = new KeyCodeCombination(KeyCode.values()[KeyCode.DIGIT1.ordinal() + i]); + var shortcut = e.combination(); + if (shortcut != null) { + b.apply(struc -> struc.get().getProperties().put("shortcut", shortcut)); + } b.apply(new TooltipAugment<>(e.name(), shortcut)); b.apply(struc -> { AppFont.setSize(struc.get(), 2); @@ -123,9 +124,8 @@ public class SideMenuBarComp extends Comp> { }; { - var shortcut = new KeyCodeCombination(KeyCode.values()[KeyCode.DIGIT1.ordinal() + entries.size()]); var b = new IconButtonComp("mdi2g-github", () -> Hyperlinks.open(Hyperlinks.GITHUB)) - .tooltipKey("visitGithubRepository", shortcut) + .tooltipKey("visitGithubRepository") .apply(simpleBorders) .accessibleTextKey("visitGithubRepository"); b.apply(struc -> { @@ -135,9 +135,8 @@ public class SideMenuBarComp extends Comp> { } { - var shortcut = new KeyCodeCombination(KeyCode.values()[KeyCode.DIGIT1.ordinal() + entries.size() + 1]); var b = new IconButtonComp("mdi2d-discord", () -> Hyperlinks.open(Hyperlinks.DISCORD)) - .tooltipKey("discord", shortcut) + .tooltipKey("discord") .apply(simpleBorders) .accessibleTextKey("discord"); b.apply(struc -> { diff --git a/app/src/main/java/io/xpipe/app/core/AppLayoutModel.java b/app/src/main/java/io/xpipe/app/core/AppLayoutModel.java index 0ab96014..af806338 100644 --- a/app/src/main/java/io/xpipe/app/core/AppLayoutModel.java +++ b/app/src/main/java/io/xpipe/app/core/AppLayoutModel.java @@ -11,6 +11,9 @@ import javafx.beans.property.Property; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableValue; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyCodeCombination; +import javafx.scene.input.KeyCombination; import lombok.Builder; import lombok.Data; import lombok.Getter; @@ -71,13 +74,13 @@ public class AppLayoutModel { new Entry( AppI18n.observable("browser"), "mdi2f-file-cabinet", - new BrowserSessionComp(BrowserSessionModel.DEFAULT)), - new Entry(AppI18n.observable("connections"), "mdi2c-connection", new StoreLayoutComp()), - new Entry(AppI18n.observable("settings"), "mdsmz-miscellaneous_services", new AppPrefsComp()), + new BrowserSessionComp(BrowserSessionModel.DEFAULT), new KeyCodeCombination(KeyCode.DIGIT1, KeyCombination.CONTROL_DOWN)), + new Entry(AppI18n.observable("connections"), "mdi2c-connection", new StoreLayoutComp(), new KeyCodeCombination(KeyCode.DIGIT2, KeyCombination.CONTROL_DOWN)), + new Entry(AppI18n.observable("settings"), "mdsmz-miscellaneous_services", new AppPrefsComp(), new KeyCodeCombination(KeyCode.DIGIT3, KeyCombination.CONTROL_DOWN)), new Entry( AppI18n.observable("explorePlans"), "mdi2p-professional-hexagon", - LicenseProvider.get().overviewPage()))); + LicenseProvider.get().overviewPage(), null))); return l; } @@ -90,5 +93,5 @@ public class AppLayoutModel { double browserConnectionsWidth; } - public record Entry(ObservableValue name, String icon, Comp comp) {} + public record Entry(ObservableValue name, String icon, Comp comp, KeyCombination combination) {} }