Change context menu behavior

This commit is contained in:
crschnick 2023-05-20 18:13:21 +00:00
parent 48d155400c
commit f48b1fa212
8 changed files with 12 additions and 11 deletions

View file

@ -221,7 +221,7 @@ final class BrowserFileListComp extends SimpleComp {
table.setRowFactory(param -> {
TableRow<BrowserEntry> row = new TableRow<>();
new ContextMenuAugment<>(false, () -> {
new ContextMenuAugment<>(true, true, () -> {
if (row.getItem() != null && row.getItem().isSynthetic()) {
return null;
}

View file

@ -2,7 +2,6 @@ package io.xpipe.app.browser;
import io.xpipe.app.fxcomps.util.BindingsHelper;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.util.FileOpener;
import io.xpipe.core.impl.FileNames;
import io.xpipe.core.store.FileSystem;
import javafx.beans.property.ObjectProperty;
@ -121,7 +120,7 @@ public final class BrowserFileListModel {
fileSystemModel.cd(dir.get());
}
} else {
FileOpener.openInTextEditor(entry.getRawFileEntry());
// FileOpener.openInTextEditor(entry.getRawFileEntry());
}
}

View file

@ -60,7 +60,7 @@ public class BrowserStatusBarComp extends SimpleComp {
AppFont.small(bar);
// Use status bar as an extension of file list
new ContextMenuAugment<>(false, () -> new BrowserContextMenu(model, null)).augment(new SimpleCompStructure<>(bar));
new ContextMenuAugment<>(false, true, () -> new BrowserContextMenu(model, null)).augment(new SimpleCompStructure<>(bar));
return bar;
}

View file

@ -57,7 +57,7 @@ public class OpenFileSystemComp extends SimpleComp {
terminalBtn.disableProperty().bind(PlatformThread.sync(model.getNoDirectory()));
var menuButton = new MenuButton(null, new FontIcon("mdral-folder_open"));
new ContextMenuAugment<>(true, () -> new BrowserContextMenu(model, null)).augment(new SimpleCompStructure<>(menuButton));
new ContextMenuAugment<>(true, false, () -> new BrowserContextMenu(model, null)).augment(new SimpleCompStructure<>(menuButton));
var filter = new BrowserFilterComp(model.getFilter()).createStructure();
Shortcuts.addShortcut(filter.toggleButton(), new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN));

View file

@ -17,7 +17,7 @@ public class SourceCollectionContextMenu<S extends CompStructure<?>> extends Con
public SourceCollectionContextMenu(
boolean showOnPrimaryButton, SourceCollectionWrapper group, Region renameTextField) {
super(showOnPrimaryButton, () -> createContextMenu(group, renameTextField));
super(showOnPrimaryButton, true, () -> createContextMenu(group, renameTextField));
}
private static void onDelete(SourceCollectionWrapper group) {

View file

@ -20,7 +20,7 @@ public class SourceEntryContextMenu<S extends CompStructure<?>> extends ContextM
public SourceEntryContextMenu(boolean showOnPrimaryButton, SourceEntryWrapper entry, Region renameTextField) {
super(showOnPrimaryButton, () -> createContextMenu(entry, renameTextField));
super(showOnPrimaryButton, true, () -> createContextMenu(entry, renameTextField));
}
protected static ContextMenu createContextMenu(SourceEntryWrapper entry, Region renameTextField) {

View file

@ -164,7 +164,7 @@ public class StoreEntryComp extends SimpleComp {
});
});
new ContextMenuAugment<>(false, () -> StoreEntryComp.this.createContextMenu()).augment(new SimpleCompStructure<>(button));
new ContextMenuAugment<>(false, true, () -> StoreEntryComp.this.createContextMenu()).augment(new SimpleCompStructure<>(button));
return button;
}
@ -213,7 +213,7 @@ public class StoreEntryComp extends SimpleComp {
private Comp<?> createSettingsButton() {
var settingsButton = new IconButtonComp("mdomz-settings");
settingsButton.styleClass("settings");
settingsButton.apply(new ContextMenuAugment<>(true, () -> StoreEntryComp.this.createContextMenu()));
settingsButton.apply(new ContextMenuAugment<>(true, false, () -> StoreEntryComp.this.createContextMenu()));
settingsButton.apply(GrowAugment.create(false, true));
settingsButton.apply(s -> {
s.get().prefWidthProperty().bind(Bindings.divide(s.get().heightProperty(), 1.35));

View file

@ -9,10 +9,12 @@ import java.util.function.Supplier;
public class ContextMenuAugment<S extends CompStructure<?>> implements Augment<S> {
private final boolean showOnPrimaryButton;
private final boolean showOnSecondaryButton;
private final Supplier<ContextMenu> contextMenu;
public ContextMenuAugment(boolean showOnPrimaryButton, Supplier<ContextMenu> contextMenu) {
public ContextMenuAugment(boolean showOnPrimaryButton, boolean showOnSecondaryButton, Supplier<ContextMenu> contextMenu) {
this.showOnPrimaryButton = showOnPrimaryButton;
this.showOnSecondaryButton = showOnSecondaryButton;
this.contextMenu = contextMenu;
}
@ -28,7 +30,7 @@ public class ContextMenuAugment<S extends CompStructure<?>> implements Augment<S
}
if ((showOnPrimaryButton && event.getButton() == MouseButton.PRIMARY)
|| (!showOnPrimaryButton && event.getButton() == MouseButton.SECONDARY)) {
|| (showOnSecondaryButton && event.getButton() == MouseButton.SECONDARY)) {
var cm = contextMenu.get();
if (cm != null) {
cm.setAutoHide(true);