added f9 terminal
This commit is contained in:
parent
69afa0c738
commit
ac13e6504f
@ -240,7 +240,7 @@ public class MainWindow extends JFrame {
|
||||
* Create button panel (like Total Commander)
|
||||
*/
|
||||
private void createButtonPanel() {
|
||||
buttonPanel = new JPanel(new GridLayout(1, 8, 5, 5));
|
||||
buttonPanel = new JPanel(new GridLayout(1, 9, 5, 5));
|
||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
|
||||
JButton btnView = new JButton("F3 View");
|
||||
@ -261,6 +261,9 @@ public class MainWindow extends JFrame {
|
||||
JButton btnDelete = new JButton("F8 Delete");
|
||||
btnDelete.addActionListener(e -> deleteFiles());
|
||||
|
||||
JButton btnTerminal = new JButton("F9 Terminal");
|
||||
btnTerminal.addActionListener(e -> openTerminal());
|
||||
|
||||
JButton btnRename = new JButton("Shift+F6 Rename");
|
||||
btnRename.addActionListener(e -> renameFile());
|
||||
|
||||
@ -273,6 +276,7 @@ public class MainWindow extends JFrame {
|
||||
buttonPanel.add(btnMove);
|
||||
buttonPanel.add(btnNewDir);
|
||||
buttonPanel.add(btnDelete);
|
||||
buttonPanel.add(btnTerminal);
|
||||
buttonPanel.add(btnRename);
|
||||
buttonPanel.add(btnExit);
|
||||
}
|
||||
@ -482,6 +486,11 @@ public class MainWindow extends JFrame {
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0),
|
||||
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
|
||||
// F9 - Open terminal
|
||||
rootPane.registerKeyboardAction(e -> openTerminal(),
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0),
|
||||
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
|
||||
// Delete key - global delete binding (also added per-table)
|
||||
rootPane.registerKeyboardAction(e -> deleteFiles(),
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
|
||||
@ -1038,6 +1047,60 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open terminal in the current directory
|
||||
*/
|
||||
private void openTerminal() {
|
||||
File currentDir = activePanel.getCurrentDirectory();
|
||||
if (currentDir == null) {
|
||||
currentDir = new File(System.getProperty("user.home"));
|
||||
}
|
||||
|
||||
try {
|
||||
String osName = System.getProperty("os.name").toLowerCase();
|
||||
ProcessBuilder pb;
|
||||
|
||||
if (osName.contains("win")) {
|
||||
// Windows
|
||||
pb = new ProcessBuilder("cmd.exe", "/c", "start", "cmd.exe");
|
||||
} else if (osName.contains("mac")) {
|
||||
// macOS
|
||||
pb = new ProcessBuilder("open", "-a", "Terminal", currentDir.getAbsolutePath());
|
||||
} else {
|
||||
// Linux and other Unix-like systems
|
||||
// Try common terminal emulators
|
||||
String[] terminals = {"gnome-terminal", "xterm", "konsole", "xfce4-terminal", "mate-terminal"};
|
||||
pb = null;
|
||||
|
||||
for (String terminal : terminals) {
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(new String[]{"which", terminal});
|
||||
if (p.waitFor() == 0) {
|
||||
pb = new ProcessBuilder(terminal);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Try next terminal
|
||||
}
|
||||
}
|
||||
|
||||
if (pb == null) {
|
||||
// Fallback to xterm if nothing else works
|
||||
pb = new ProcessBuilder("xterm");
|
||||
}
|
||||
}
|
||||
|
||||
pb.directory(currentDir);
|
||||
pb.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Chyba při otevírání terminálu: " + e.getMessage(),
|
||||
"Chyba",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show About dialog
|
||||
*/
|
||||
@ -1053,7 +1116,8 @@ public class MainWindow extends JFrame {
|
||||
"F6 - Move\n" +
|
||||
"F7 - New directory\n" +
|
||||
"F8 - Delete\n" +
|
||||
"F9 / Shift+F6 - Rename\n" +
|
||||
"F9 - Open terminal\n" +
|
||||
"Shift+F6 - Rename\n" +
|
||||
"TAB - Switch panel\n" +
|
||||
"Ctrl+F - Search\n" +
|
||||
"Alt+O - Settings\n" +
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user