windows shif+delete

This commit is contained in:
rdavidek 2026-01-25 22:53:00 +01:00
parent bd94fc6dc3
commit 3225f17050
2 changed files with 28 additions and 2 deletions

View File

@ -19,6 +19,7 @@ public class FilePanel extends JPanel {
private JLabel driveInfoLabel; private JLabel driveInfoLabel;
private cz.kamma.kfmanager.config.AppConfig appConfig; private cz.kamma.kfmanager.config.AppConfig appConfig;
private Runnable onDirectoryChangedAll; private Runnable onDirectoryChangedAll;
private java.util.function.Consumer<JTable> onTableCreated;
private boolean ignoreComboActions = false; private boolean ignoreComboActions = false;
private boolean active = false; private boolean active = false;
@ -31,6 +32,10 @@ public class FilePanel extends JPanel {
this.onDirectoryChangedAll = callback; this.onDirectoryChangedAll = callback;
} }
public void setOnTableCreated(java.util.function.Consumer<JTable> callback) {
this.onTableCreated = callback;
}
/** Start inline rename on the currently selected tab/table. */ /** Start inline rename on the currently selected tab/table. */
public void startInlineRename() { public void startInlineRename() {
FilePanelTab tab = getCurrentTab(); FilePanelTab tab = getCurrentTab();
@ -290,6 +295,10 @@ public class FilePanel extends JPanel {
// Update path field // Update path field
updateTabStyles(); updateTabStyles();
if (onTableCreated != null) {
onTableCreated.accept(tab.getFileTable());
}
// Set focus to the table in the new tab // Set focus to the table in the new tab
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
@ -332,6 +341,10 @@ public class FilePanel extends JPanel {
updatePathField(); updatePathField();
updateTabStyles(); updateTabStyles();
if (onTableCreated != null) {
onTableCreated.accept(tab.getFileTable());
}
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (requestFocus) { if (requestFocus) {
tab.getFileTable().requestFocusInWindow(); tab.getFileTable().requestFocusInWindow();

View File

@ -113,6 +113,10 @@ public class MainWindow extends JFrame {
// Provide a callback so tabs inside the panel can request switching panels with TAB // Provide a callback so tabs inside the panel can request switching panels with TAB
leftPanel.setSwitchPanelCallback(() -> switchPanelsFromChild()); leftPanel.setSwitchPanelCallback(() -> switchPanelsFromChild());
leftPanel.setOnDirectoryChangedAll(() -> updateCommandLinePrompt()); leftPanel.setOnDirectoryChangedAll(() -> updateCommandLinePrompt());
leftPanel.setOnTableCreated(table -> {
addTabKeyHandler(table);
addCommandLineRedirect(table);
});
// Load and set ViewMode for left panel // Load and set ViewMode for left panel
try { try {
@ -129,6 +133,10 @@ public class MainWindow extends JFrame {
// Provide a callback so tabs inside the panel can request switching panels with TAB // Provide a callback so tabs inside the panel can request switching panels with TAB
rightPanel.setSwitchPanelCallback(() -> switchPanelsFromChild()); rightPanel.setSwitchPanelCallback(() -> switchPanelsFromChild());
rightPanel.setOnDirectoryChangedAll(() -> updateCommandLinePrompt()); rightPanel.setOnDirectoryChangedAll(() -> updateCommandLinePrompt());
rightPanel.setOnTableCreated(table -> {
addTabKeyHandler(table);
addCommandLineRedirect(table);
});
// Load and set ViewMode for right panel // Load and set ViewMode for right panel
try { try {
@ -1138,6 +1146,9 @@ public class MainWindow extends JFrame {
rootPane.registerKeyboardAction(e -> deleteFiles(), rootPane.registerKeyboardAction(e -> deleteFiles(),
KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK), KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW); JComponent.WHEN_IN_FOCUSED_WINDOW);
rootPane.registerKeyboardAction(e -> deleteFiles(),
KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW);
// No direct F9 keyboard binding: inline rename should only be triggered by Shift+F6 // No direct F9 keyboard binding: inline rename should only be triggered by Shift+F6
@ -1324,7 +1335,7 @@ public class MainWindow extends JFrame {
/** /**
* Attach TAB handling to switch panels * Attach TAB handling to switch panels
*/ */
private void addTabKeyHandler(JTable table) { public void addTabKeyHandler(JTable table) {
if (table == null) return; if (table == null) return;
// Remove standard Swing TAB behavior // Remove standard Swing TAB behavior
@ -1364,6 +1375,8 @@ public class MainWindow extends JFrame {
// Also map Shift+Delete on table level // Also map Shift+Delete on table level
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK), "deleteFiles"); .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK), "deleteFiles");
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_MASK), "deleteFiles");
// Clipboard support (Ctrl+C, Ctrl+X, Ctrl+V) // Clipboard support (Ctrl+C, Ctrl+X, Ctrl+V)
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
@ -1437,7 +1450,7 @@ public class MainWindow extends JFrame {
/** /**
* Automatically focus command line when user starts typing on a table * Automatically focus command line when user starts typing on a table
*/ */
private void addCommandLineRedirect(JTable table) { public void addCommandLineRedirect(JTable table) {
// Use InputMap/ActionMap for Ctrl+Enter and Ctrl+Shift+Enter as KeyListener might be bypassed by JTable // Use InputMap/ActionMap for Ctrl+Enter and Ctrl+Shift+Enter as KeyListener might be bypassed by JTable
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK), "copyNameToCmd"); .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK), "copyNameToCmd");