Shortcut fixes

This commit is contained in:
crschnick 2024-06-23 22:39:23 +00:00
parent 65fbe13113
commit d1b506415c
3 changed files with 28 additions and 14 deletions

View file

@ -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<CompStructure<Pane>> {
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);

View file

@ -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<CompStructure<VBox>> {
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<CompStructure<VBox>> {
};
{
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<CompStructure<VBox>> {
}
{
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 -> {

View file

@ -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<String> name, String icon, Comp<?> comp) {}
public record Entry(ObservableValue<String> name, String icon, Comp<?> comp, KeyCombination combination) {}
}