diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessButtonComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessButtonComp.java index 9a27aae6a..fe992ced5 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessButtonComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessButtonComp.java @@ -2,6 +2,7 @@ package io.xpipe.app.browser; import io.xpipe.app.fxcomps.SimpleComp; import io.xpipe.app.fxcomps.impl.IconButtonComp; +import io.xpipe.app.util.InputHelper; import javafx.application.Platform; import javafx.scene.control.Menu; import javafx.scene.layout.Region; @@ -36,7 +37,7 @@ public class BrowserQuickAccessButtonComp extends SimpleComp { struc.get().requestFocus(); }); }); - BrowserQuickAccessContextMenu.onRight(struc.get(), false, keyEvent -> { + InputHelper.onRight(struc.get(), false, keyEvent -> { cm.showMenu(struc.get()); keyEvent.consume(); }); diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessContextMenu.java b/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessContextMenu.java index 0937c36e3..5d9e1ec63 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessContextMenu.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserQuickAccessContextMenu.java @@ -3,12 +3,11 @@ package io.xpipe.app.browser; import io.xpipe.app.browser.icon.FileIconManager; import io.xpipe.app.fxcomps.impl.PrettyImageHelper; import io.xpipe.app.util.BooleanAnimationTimer; +import io.xpipe.app.util.InputHelper; import io.xpipe.app.util.ThreadHelper; import io.xpipe.core.store.FileKind; import javafx.application.Platform; import javafx.beans.property.SimpleBooleanProperty; -import javafx.event.EventHandler; -import javafx.event.EventTarget; import javafx.geometry.Side; import javafx.scene.Node; import javafx.scene.control.ContextMenu; @@ -24,38 +23,11 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; public class BrowserQuickAccessContextMenu extends ContextMenu { - static void onLeft(EventTarget target, boolean filter, Consumer r) { - EventHandler keyEventEventHandler = event -> { - if (event.getCode() == KeyCode.LEFT || event.getCode() == KeyCode.NUMPAD4) { - r.accept(event); - } - }; - if (filter) { - target.addEventFilter(KeyEvent.KEY_PRESSED, keyEventEventHandler); - } else { - target.addEventHandler(KeyEvent.KEY_PRESSED, keyEventEventHandler); - } - } - - static void onRight(EventTarget target, boolean filter, Consumer r) { - EventHandler keyEventEventHandler = event -> { - if (event.getCode() == KeyCode.RIGHT || event.getCode() == KeyCode.NUMPAD6) { - r.accept(event); - } - }; - if (filter) { - target.addEventFilter(KeyEvent.KEY_PRESSED, keyEventEventHandler); - } else { - target.addEventHandler(KeyEvent.KEY_PRESSED, keyEventEventHandler); - } - } - @Getter class QuickAccessMenu { private final BrowserEntry browserEntry; @@ -107,7 +79,7 @@ public class BrowserQuickAccessContextMenu extends ContextMenu { var empty = new MenuItem("..."); empty.setDisable(true); menu.getItems().add(empty); - onRight(empty, true, keyEvent -> { + InputHelper.onRight(empty, true, keyEvent -> { keyEvent.consume(); }); } @@ -233,7 +205,7 @@ public class BrowserQuickAccessContextMenu extends ContextMenu { this.browserActionMenu.setOnAction(e -> { hide(); }); - onLeft(this.browserActionMenu, true, keyEvent -> { + InputHelper.onLeft(this.browserActionMenu, true, keyEvent -> { this.browserActionMenu.hide(); keyEvent.consume(); }); @@ -271,7 +243,7 @@ public class BrowserQuickAccessContextMenu extends ContextMenu { getItems().getFirst().getStyleableNode().requestFocus(); }); }); - onLeft(this, false, e -> { + InputHelper.onLeft(this, false, e -> { hide(); e.consume(); }); 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 831398246..3dcea999e 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 @@ -20,6 +20,8 @@ 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; @@ -67,8 +69,11 @@ public class SideMenuBarComp extends Comp> { Platform.getPreferences().accentColorProperty()); var selected = PseudoClass.getPseudoClass("selected"); - entries.forEach(e -> { - var b = new IconButtonComp(e.icon(), () -> value.setValue(e)).apply(new FancyTooltipAugment<>(e.name())); + for (int i = 0; i < entries.size(); i++) { + var e = entries.get(i); + var b = new IconButtonComp(e.icon(), () -> value.setValue(e)); + b.shortcut(new KeyCodeCombination(KeyCode.values()[KeyCode.DIGIT1.ordinal() + i])); + b.apply(new FancyTooltipAugment<>(e.name())); b.apply(struc -> { AppFont.setSize(struc.get(), 2); struc.get().pseudoClassStateChanged(selected, value.getValue().equals(e)); @@ -99,7 +104,7 @@ public class SideMenuBarComp extends Comp> { }); b.accessibleText(e.name()); vbox.getChildren().add(b.createRegion()); - }); + } Augment> simpleBorders = struc -> { struc.get() @@ -127,6 +132,7 @@ public class SideMenuBarComp extends Comp> { } UserReportComp.show(event.build()); }) + .shortcut(new KeyCodeCombination(KeyCode.values()[KeyCode.DIGIT1.ordinal() + entries.size()])) .apply(new FancyTooltipAugment<>("reportIssue")) .apply(simpleBorders) .accessibleTextKey("reportIssue"); @@ -138,6 +144,7 @@ public class SideMenuBarComp extends Comp> { { var b = new IconButtonComp("mdi2g-github", () -> Hyperlinks.open(Hyperlinks.GITHUB)) + .shortcut(new KeyCodeCombination(KeyCode.values()[KeyCode.DIGIT1.ordinal() + entries.size() + 1])) .apply(new FancyTooltipAugment<>("visitGithubRepository")) .apply(simpleBorders) .accessibleTextKey("visitGithubRepository"); @@ -149,6 +156,7 @@ public class SideMenuBarComp extends Comp> { { var b = new IconButtonComp("mdi2d-discord", () -> Hyperlinks.open(Hyperlinks.DISCORD)) + .shortcut(new KeyCodeCombination(KeyCode.values()[KeyCode.DIGIT1.ordinal() + entries.size() + 2])) .apply(new FancyTooltipAugment<>("discord")) .apply(simpleBorders) .accessibleTextKey("discord"); @@ -160,6 +168,7 @@ public class SideMenuBarComp extends Comp> { { var b = new IconButtonComp("mdi2u-update", () -> UpdateAvailableAlert.showIfNeeded()) + .shortcut(new KeyCodeCombination(KeyCode.values()[KeyCode.DIGIT1.ordinal() + entries.size() + 3])) .apply(new FancyTooltipAugment<>("updateAvailableTooltip")) .accessibleTextKey("updateAvailableTooltip"); b.apply(struc -> { diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreQuickAccessButtonComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreQuickAccessButtonComp.java index 5bcf921b9..4a937f5cb 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreQuickAccessButtonComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreQuickAccessButtonComp.java @@ -1,19 +1,20 @@ package io.xpipe.app.comp.store; -import io.xpipe.app.fxcomps.SimpleComp; +import io.xpipe.app.fxcomps.Comp; +import io.xpipe.app.fxcomps.CompStructure; import io.xpipe.app.fxcomps.impl.IconButtonComp; import io.xpipe.app.fxcomps.impl.PrettyImageHelper; import javafx.geometry.Side; import javafx.scene.Node; +import javafx.scene.control.Button; import javafx.scene.control.ContextMenu; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; -import javafx.scene.layout.Region; import java.util.ArrayList; import java.util.function.Consumer; -public class StoreQuickAccessButtonComp extends SimpleComp { +public class StoreQuickAccessButtonComp extends Comp> { private final StoreSection section; private final Consumer action; @@ -23,17 +24,6 @@ public class StoreQuickAccessButtonComp extends SimpleComp { this.action = action; } - @Override - protected Region createSimple() { - var button = new IconButtonComp("mdi2c-chevron-double-right"); - button.apply(struc -> { - struc.get().setOnAction(event -> { - showMenu(struc.get()); - }); - }); - return button.createRegion(); - } - private void showMenu(Node anchor) { var cm = createMenu(); if (cm == null) { @@ -94,4 +84,15 @@ public class StoreQuickAccessButtonComp extends SimpleComp { }); return m; } + + @Override + public CompStructure