Fix menu not interactable
This commit is contained in:
parent
c52f1f3350
commit
36f462597a
|
@ -25,5 +25,6 @@ tasks.compileJava {
|
|||
|
||||
tasks.runShadow {
|
||||
workingDir = rootProject.projectDir
|
||||
environment("GTK_DEBUG", "interactive:actions")
|
||||
jvmArgs!!.addAll(listOf("--enable-preview", "--enable-native-access=ALL-UNNAMED"))
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import io.gitlab.jfronny.inceptum.gtk.menu.MenuBuilder;
|
|||
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
|
||||
import io.gitlab.jfronny.inceptum.gtk.util.ListIndexItem;
|
||||
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.instance.*;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.instance.InstanceNameTool;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.launch.LaunchType;
|
||||
import org.gnome.adw.ActionRow;
|
||||
import org.gtk.gio.ActionMap;
|
||||
|
@ -19,7 +20,6 @@ import org.gtk.gtk.Stack;
|
|||
import org.gtk.gtk.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class InstanceListEntryFactory extends SignalListItemFactory {
|
|||
var menu = new MenuButton();
|
||||
menu.addCssClass("flat");
|
||||
menu.iconName = "view-more-symbolic";
|
||||
menu.menuModel = new Menu();
|
||||
menu.popover = PopoverMenu.newFromModel(new Menu());
|
||||
|
||||
var row = new ActionRow();
|
||||
row.margin = 8;
|
||||
|
@ -73,8 +73,7 @@ public class InstanceListEntryFactory extends SignalListItemFactory {
|
|||
|
||||
li.thumbnail.bind(li.instance);
|
||||
|
||||
//TODO fix menu not interactable
|
||||
var menuBuilder = new MenuBuilder(actionMap, li.menu, li.instance.id);
|
||||
var menuBuilder = new MenuBuilder(li.popoverMenu, li.instance.id);
|
||||
var launchSection = menuBuilder.literalSection("launch", null);
|
||||
launchSection.literalButton("launch.client", I18n.get("instance.launch.client"),
|
||||
() -> GtkMenubar.launch(li.instance, LaunchType.Client))
|
||||
|
@ -116,12 +115,12 @@ public class InstanceListEntryFactory extends SignalListItemFactory {
|
|||
});
|
||||
onUnbind(item -> {
|
||||
Decomposed li = Decomposed.of((ListItem) item, instanceList);
|
||||
li.menu.removeAll();
|
||||
li.popoverMenu.insertActionGroup(li.instance.id, null);
|
||||
toDisconnect.get(li.instance.id).forEach(Signal::disconnect);
|
||||
});
|
||||
}
|
||||
|
||||
private record Decomposed(Instance instance, ActionRow row, InstanceThumbnail thumbnail, Button launch, Menu menu) {
|
||||
private record Decomposed(Instance instance, ActionRow row, InstanceThumbnail thumbnail, Button launch, PopoverMenu popoverMenu) {
|
||||
public static Decomposed of(ListItem item, List<Instance> instanceList) {
|
||||
Instance instance = instanceList.get(((ListIndexItem) item.getItem()).getIntValue());
|
||||
ActionRow row = (ActionRow) item.child;
|
||||
|
@ -130,7 +129,8 @@ public class InstanceListEntryFactory extends SignalListItemFactory {
|
|||
InstanceThumbnail thumbnail = InstanceThumbnail.castFrom((Stack) prefixes.firstChild);
|
||||
Button launch = (Button) suffixes.firstChild;
|
||||
MenuButton menuButton = (MenuButton) launch.nextSibling;
|
||||
return new Decomposed(instance, row, thumbnail, launch, (Menu) menuButton.menuModel);
|
||||
PopoverMenu popoverMenu = (PopoverMenu) menuButton.popover;
|
||||
return new Decomposed(instance, row, thumbnail, launch, popoverMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,6 @@ public abstract class BuiltMenuItem {
|
|||
}
|
||||
|
||||
public void setIconName(String iconName) {
|
||||
Objects.requireNonNull(menuItem).icon = new ThemedIcon(iconName);
|
||||
// Objects.requireNonNull(menuItem).icon = new ThemedIcon(iconName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,16 +38,33 @@ public class MenuBuilder {
|
|||
private final Map<String, Action> refs = new LinkedHashMap<>();
|
||||
private final Menu menu;
|
||||
private final String prefix;
|
||||
private final String groupName;
|
||||
|
||||
public MenuBuilder(Application app) {
|
||||
this(app, getRootMenu(app), "");
|
||||
}
|
||||
|
||||
public MenuBuilder(ActionMap map, Menu menu, String prefix) {
|
||||
if (!prefix.isEmpty() && !prefix.endsWith(".")) prefix += ".";
|
||||
public MenuBuilder(PopoverMenu menu, String groupName) {
|
||||
this(insertMap(menu, groupName), (Menu) menu.menuModel, "", groupName);
|
||||
}
|
||||
|
||||
private static ActionMap insertMap(PopoverMenu menu, String groupName) {
|
||||
SimpleActionGroup ag = new SimpleActionGroup();
|
||||
menu.insertActionGroup(groupName, ag);
|
||||
return ag;
|
||||
}
|
||||
|
||||
public MenuBuilder(Application app, Menu menu, String prefix) {
|
||||
this(app, menu, prefix, "app.");
|
||||
}
|
||||
|
||||
private MenuBuilder(ActionMap map, Menu menu, String prefix, String groupName) {
|
||||
if (!Objects.requireNonNull(prefix).isEmpty && !prefix.endsWith(".")) prefix += ".";
|
||||
if (!Objects.requireNonNull(groupName).isEmpty && !groupName.endsWith(".")) groupName += ".";
|
||||
this.map = Objects.requireNonNull(map);
|
||||
this.menu = Objects.requireNonNull(menu);
|
||||
this.prefix = Objects.requireNonNull(prefix);
|
||||
this.prefix = prefix;
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
public BuiltButtonItem button(String name, ThrowingRunnable<?> onClick) {
|
||||
|
@ -65,7 +82,7 @@ public class MenuBuilder {
|
|||
Utils.LOGGER.error("Could not execute action", e);
|
||||
}
|
||||
});
|
||||
MenuItem menuItem = new MenuItem(label, "app." + internalName);
|
||||
MenuItem menuItem = new MenuItem(label, groupName + internalName);
|
||||
menu.appendItem(menuItem);
|
||||
action.enabled = true;
|
||||
return new BuiltButtonItem(action, menuItem);
|
||||
|
@ -80,7 +97,7 @@ public class MenuBuilder {
|
|||
action.state = Variant.newBoolean(state);
|
||||
onToggle.accept(state);
|
||||
});
|
||||
MenuItem menuItem = new MenuItem(I18n.get("menu." + name), "app." + name);
|
||||
MenuItem menuItem = new MenuItem(I18n.get("menu." + name), groupName + name);
|
||||
menu.appendItem(menuItem);
|
||||
return new BuiltToggleItem(action, menuItem);
|
||||
}
|
||||
|
@ -100,7 +117,7 @@ public class MenuBuilder {
|
|||
});
|
||||
int i = 0;
|
||||
for (T option : options) {
|
||||
menu.appendItem(new MenuItem(stringifier.apply(i, option), "app." + name + "(" + i + ")"));
|
||||
menu.appendItem(new MenuItem(stringifier.apply(i, option), groupName + name + "(" + i + ")"));
|
||||
i++;
|
||||
}
|
||||
return new BuiltRadioItem<>(action, options);
|
||||
|
@ -114,7 +131,7 @@ public class MenuBuilder {
|
|||
name = prefix + name;
|
||||
Menu submenu = new Menu();
|
||||
menu.appendSubmenu(label, submenu);
|
||||
return new MenuBuilder(map, submenu, name);
|
||||
return new MenuBuilder(map, submenu, name, groupName);
|
||||
}
|
||||
|
||||
public MenuBuilder section(String name) {
|
||||
|
@ -125,7 +142,7 @@ public class MenuBuilder {
|
|||
name = prefix + name;
|
||||
Menu section = new Menu();
|
||||
menu.appendSection(label, section);
|
||||
return new MenuBuilder(map, section, name);
|
||||
return new MenuBuilder(map, section, name, groupName);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
|
Loading…
Reference in New Issue