added toolbar icon moving

This commit is contained in:
Radek Davidek 2026-01-26 11:21:47 +01:00
parent eec2973b0a
commit 61d6d7ed3c

View File

@ -566,6 +566,13 @@ public class MainWindow extends JFrame {
}); });
shortcutPopup.add(editItem); shortcutPopup.add(editItem);
shortcutPopup.add(deleteItem); shortcutPopup.add(deleteItem);
shortcutPopup.addSeparator();
JMenuItem moveLeftItem = new JMenuItem("Move <");
moveLeftItem.addActionListener(ae -> moveToolbarShortcut(s, -1));
JMenuItem moveRightItem = new JMenuItem("Move >");
moveRightItem.addActionListener(ae -> moveToolbarShortcut(s, 1));
shortcutPopup.add(moveLeftItem);
shortcutPopup.add(moveRightItem);
btn.addMouseListener(new MouseAdapter() { btn.addMouseListener(new MouseAdapter() {
@Override @Override
@ -772,6 +779,48 @@ public class MainWindow extends JFrame {
createToolBar(); createToolBar();
} }
private void moveToolbarShortcut(AppConfig.ToolbarShortcut shortcut, int direction) {
List<AppConfig.ToolbarShortcut> shortcuts = config.getToolbarShortcuts();
int index = -1;
for (int i = 0; i < shortcuts.size(); i++) {
AppConfig.ToolbarShortcut s = shortcuts.get(i);
if (s.command.equals(shortcut.command) && s.label.equals(shortcut.label)) {
index = i;
break;
}
}
if (index != -1) {
boolean isDir = new File(shortcut.command).isDirectory() && new File(shortcut.command).exists();
int targetIndex = -1;
if (direction < 0) { // move left
for (int i = index - 1; i >= 0; i--) {
File f = new File(shortcuts.get(i).command);
if ((f.exists() && f.isDirectory()) == isDir) {
targetIndex = i;
break;
}
}
} else { // move right
for (int i = index + 1; i < shortcuts.size(); i++) {
File f = new File(shortcuts.get(i).command);
if ((f.exists() && f.isDirectory()) == isDir) {
targetIndex = i;
break;
}
}
}
if (targetIndex != -1) {
AppConfig.ToolbarShortcut s = shortcuts.remove(index);
shortcuts.add(targetIndex, s);
config.saveToolbarShortcuts(shortcuts);
createToolBar();
}
}
}
/** /**
* Create button panel (like Total Commander) * Create button panel (like Total Commander)
*/ */