added toolbar icon moving
This commit is contained in:
parent
eec2973b0a
commit
61d6d7ed3c
@ -566,6 +566,13 @@ public class MainWindow extends JFrame {
|
||||
});
|
||||
shortcutPopup.add(editItem);
|
||||
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() {
|
||||
@Override
|
||||
@ -772,6 +779,48 @@ public class MainWindow extends JFrame {
|
||||
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)
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user