Skip to content

Commit 2a7c6ac

Browse files
committed
CommandFinder: Disambiguate duplicated entries
1 parent 2e642bf commit 2a7c6ac

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/main/java/sc/fiji/snt/gui/SNTCommandFinder.java‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,14 +1292,22 @@ private void register(final TreeMap<String, CmdAction> map, final AbstractButton
12921292
final boolean isMenuItem = button instanceof JMenuItem;
12931293
final CmdAction registeredAction = map.get(label);
12941294
final KeyStroke accelerator = (isMenuItem) ? ((JMenuItem) button).getAccelerator() : null;
1295-
if (registeredAction != null && accelerator != null) {
1295+
if (registeredAction != null && accelerator != null && registeredAction.path.equals(path)) {
1296+
// Same command registered again (e.g., in multiple menus): merge accelerator
12961297
registeredAction.setKeyString(accelerator);
12971298
} else {
12981299
final CmdAction ca = new CmdAction(label, button);
12991300
ca.path = path;
13001301
if (accelerator != null)
13011302
ca.setKeyString(accelerator);
1302-
map.put(ca.id, ca);
1303+
String key = ca.id;
1304+
if (map.containsKey(key)) {
1305+
// Disambiguate: qualify with last path element to avoid collision
1306+
final String qualifier = path.isEmpty() ? "" : path.get(path.size() - 1);
1307+
if (!qualifier.isEmpty())
1308+
key = ca.id + " (" + qualifier + ")";
1309+
}
1310+
map.put(key, ca);
13031311
}
13041312
}
13051313
}

0 commit comments

Comments
 (0)