focus while copying

This commit is contained in:
rdavidek 2026-01-18 11:34:59 +01:00
parent b05a6fa3b7
commit bf735d99f7
5 changed files with 81 additions and 24 deletions

View File

@ -136,6 +136,10 @@ public class AppConfig {
return properties.getProperty("leftPanel.tab." + index + ".path", null); return properties.getProperty("leftPanel.tab." + index + ".path", null);
} }
public String getLeftPanelTabFocusedItem(int index) {
return properties.getProperty("leftPanel.tab." + index + ".focusedItem", null);
}
public String getLeftPanelTabViewMode(int index) { public String getLeftPanelTabViewMode(int index) {
return properties.getProperty("leftPanel.tab." + index + ".viewMode", "FULL"); return properties.getProperty("leftPanel.tab." + index + ".viewMode", "FULL");
} }
@ -144,11 +148,16 @@ public class AppConfig {
return Integer.parseInt(properties.getProperty("leftPanel.selectedIndex", "0")); return Integer.parseInt(properties.getProperty("leftPanel.selectedIndex", "0"));
} }
public void saveLeftPanelTabs(java.util.List<String> paths, java.util.List<String> viewModes, int selectedIndex) { public void saveLeftPanelTabs(java.util.List<String> paths, java.util.List<String> viewModes, java.util.List<String> focusedItems, int selectedIndex) {
properties.setProperty("leftPanel.tabs.count", String.valueOf(paths.size())); properties.setProperty("leftPanel.tabs.count", String.valueOf(paths.size()));
for (int i = 0; i < paths.size(); i++) { for (int i = 0; i < paths.size(); i++) {
properties.setProperty("leftPanel.tab." + i + ".path", paths.get(i)); properties.setProperty("leftPanel.tab." + i + ".path", paths.get(i));
properties.setProperty("leftPanel.tab." + i + ".viewMode", viewModes.get(i)); properties.setProperty("leftPanel.tab." + i + ".viewMode", viewModes.get(i));
if (focusedItems != null && i < focusedItems.size() && focusedItems.get(i) != null) {
properties.setProperty("leftPanel.tab." + i + ".focusedItem", focusedItems.get(i));
} else {
properties.remove("leftPanel.tab." + i + ".focusedItem");
}
} }
properties.setProperty("leftPanel.selectedIndex", String.valueOf(selectedIndex)); properties.setProperty("leftPanel.selectedIndex", String.valueOf(selectedIndex));
} }
@ -157,6 +166,10 @@ public class AppConfig {
return Integer.parseInt(properties.getProperty("rightPanel.tabs.count", "0")); return Integer.parseInt(properties.getProperty("rightPanel.tabs.count", "0"));
} }
public String getRightPanelTabFocusedItem(int index) {
return properties.getProperty("rightPanel.tab." + index + ".focusedItem", null);
}
public String getRightPanelTabPath(int index) { public String getRightPanelTabPath(int index) {
return properties.getProperty("rightPanel.tab." + index + ".path", null); return properties.getProperty("rightPanel.tab." + index + ".path", null);
} }
@ -169,11 +182,16 @@ public class AppConfig {
return Integer.parseInt(properties.getProperty("rightPanel.selectedIndex", "0")); return Integer.parseInt(properties.getProperty("rightPanel.selectedIndex", "0"));
} }
public void saveRightPanelTabs(java.util.List<String> paths, java.util.List<String> viewModes, int selectedIndex) { public void saveRightPanelTabs(java.util.List<String> paths, java.util.List<String> viewModes, java.util.List<String> focusedItems, int selectedIndex) {
properties.setProperty("rightPanel.tabs.count", String.valueOf(paths.size())); properties.setProperty("rightPanel.tabs.count", String.valueOf(paths.size()));
for (int i = 0; i < paths.size(); i++) { for (int i = 0; i < paths.size(); i++) {
properties.setProperty("rightPanel.tab." + i + ".path", paths.get(i)); properties.setProperty("rightPanel.tab." + i + ".path", paths.get(i));
properties.setProperty("rightPanel.tab." + i + ".viewMode", viewModes.get(i)); properties.setProperty("rightPanel.tab." + i + ".viewMode", viewModes.get(i));
if (focusedItems != null && i < focusedItems.size() && focusedItems.get(i) != null) {
properties.setProperty("rightPanel.tab." + i + ".focusedItem", focusedItems.get(i));
} else {
properties.remove("rightPanel.tab." + i + ".focusedItem");
}
} }
properties.setProperty("rightPanel.selectedIndex", String.valueOf(selectedIndex)); properties.setProperty("rightPanel.selectedIndex", String.valueOf(selectedIndex));
} }

View File

@ -326,6 +326,18 @@ public class FilePanel extends JPanel {
return modes; return modes;
} }
public java.util.List<String> getTabFocusedItems() {
java.util.List<String> items = new java.util.ArrayList<>();
for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Component c = tabbedPane.getComponentAt(i);
if (c instanceof FilePanelTab) {
cz.kamma.kfmanager.model.FileItem focused = ((FilePanelTab) c).getFocusedItem();
items.add(focused != null ? focused.getName() : null);
}
}
return items;
}
public int getSelectedTabIndex() { public int getSelectedTabIndex() {
return tabbedPane.getSelectedIndex(); return tabbedPane.getSelectedIndex();
} }
@ -333,7 +345,7 @@ public class FilePanel extends JPanel {
/** /**
* Restore the set of tabs according to specified paths and view modes. If the list is empty, nothing happens. * Restore the set of tabs according to specified paths and view modes. If the list is empty, nothing happens.
*/ */
public void restoreTabs(java.util.List<String> paths, java.util.List<String> viewModes, int selectedIndex) { public void restoreTabs(java.util.List<String> paths, java.util.List<String> viewModes, java.util.List<String> focusedItems, int selectedIndex) {
if (paths == null || paths.isEmpty()) return; if (paths == null || paths.isEmpty()) return;
tabbedPane.removeAll(); tabbedPane.removeAll();
@ -349,6 +361,13 @@ public class FilePanel extends JPanel {
} }
} }
addNewTabWithMode(p, mode); addNewTabWithMode(p, mode);
// Restore focus to the specific item if provided
if (focusedItems != null && i < focusedItems.size() && focusedItems.get(i) != null) {
final String focusName = focusedItems.get(i);
final FilePanelTab currentTab = (FilePanelTab) tabbedPane.getComponentAt(i);
SwingUtilities.invokeLater(() -> currentTab.selectItem(focusName));
}
} }
if (selectedIndex >= 0 && selectedIndex < tabbedPane.getTabCount()) { if (selectedIndex >= 0 && selectedIndex < tabbedPane.getTabCount()) {
@ -632,9 +651,13 @@ public class FilePanel extends JPanel {
} }
public void loadDirectory(File directory) { public void loadDirectory(File directory) {
loadDirectory(directory, true);
}
public void loadDirectory(File directory, boolean requestFocus) {
FilePanelTab tab = getCurrentTab(); FilePanelTab tab = getCurrentTab();
if (tab != null) { if (tab != null) {
tab.loadDirectory(directory); tab.loadDirectory(directory, true, requestFocus);
updatePathField(); updatePathField();
} }
} }

View File

@ -790,10 +790,14 @@ public class FilePanelTab extends JPanel {
} }
public void loadDirectory(File directory) { public void loadDirectory(File directory) {
loadDirectory(directory, true); loadDirectory(directory, true, true);
} }
private void loadDirectory(File directory, boolean autoSelectFirst) { public void loadDirectory(File directory, boolean autoSelectFirst) {
loadDirectory(directory, autoSelectFirst, true);
}
public void loadDirectory(File directory, boolean autoSelectFirst, boolean requestFocus) {
// If we are switching directories, cleanup any previously extracted archive temp dirs // If we are switching directories, cleanup any previously extracted archive temp dirs
cleanupArchiveTempDirIfNeeded(directory); cleanupArchiveTempDirIfNeeded(directory);
if (directory == null || !directory.isDirectory()) { if (directory == null || !directory.isDirectory()) {
@ -848,17 +852,21 @@ public class FilePanelTab extends JPanel {
fileTable.setRowSelectionInterval(selRow, selRow); fileTable.setRowSelectionInterval(selRow, selRow);
fileTable.scrollRectToVisible(fileTable.getCellRect(selRow, selCol, true)); fileTable.scrollRectToVisible(fileTable.getCellRect(selRow, selCol, true));
} }
if (requestFocus) {
fileTable.requestFocusInWindow(); fileTable.requestFocusInWindow();
}
}); });
} else { } else {
if (autoSelectFirst && fileTable.getRowCount() > 0) { if (autoSelectFirst && fileTable.getRowCount() > 0) {
int startIndex = 0; int startIndex = 0;
fileTable.setRowSelectionInterval(startIndex, startIndex); fileTable.setRowSelectionInterval(startIndex, startIndex);
if (requestFocus) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
try { fileTable.requestFocusInWindow(); } catch (Exception ignore) {} try { fileTable.requestFocusInWindow(); } catch (Exception ignore) {}
}); });
} }
} }
}
updateStatus(); updateStatus();

View File

@ -132,14 +132,16 @@ public class MainWindow extends JFrame {
if (leftCount > 0) { if (leftCount > 0) {
java.util.List<String> paths = new java.util.ArrayList<>(); java.util.List<String> paths = new java.util.ArrayList<>();
java.util.List<String> modes = new java.util.ArrayList<>(); java.util.List<String> modes = new java.util.ArrayList<>();
java.util.List<String> focusedItems = new java.util.ArrayList<>();
for (int i = 0; i < leftCount; i++) { for (int i = 0; i < leftCount; i++) {
String p = config.getLeftPanelTabPath(i); String p = config.getLeftPanelTabPath(i);
if (p == null) p = System.getProperty("user.home"); if (p == null) p = System.getProperty("user.home");
paths.add(p); paths.add(p);
modes.add(config.getLeftPanelTabViewMode(i)); modes.add(config.getLeftPanelTabViewMode(i));
focusedItems.add(config.getLeftPanelTabFocusedItem(i));
} }
int sel = config.getLeftPanelSelectedIndex(); int sel = config.getLeftPanelSelectedIndex();
leftPanel.restoreTabs(paths, modes, sel); leftPanel.restoreTabs(paths, modes, focusedItems, sel);
} }
} catch (Exception ex) { } catch (Exception ex) {
// ignore and keep default // ignore and keep default
@ -150,14 +152,16 @@ public class MainWindow extends JFrame {
if (rightCount > 0) { if (rightCount > 0) {
java.util.List<String> paths = new java.util.ArrayList<>(); java.util.List<String> paths = new java.util.ArrayList<>();
java.util.List<String> modes = new java.util.ArrayList<>(); java.util.List<String> modes = new java.util.ArrayList<>();
java.util.List<String> focusedItems = new java.util.ArrayList<>();
for (int i = 0; i < rightCount; i++) { for (int i = 0; i < rightCount; i++) {
String p = config.getRightPanelTabPath(i); String p = config.getRightPanelTabPath(i);
if (p == null) p = System.getProperty("user.home"); if (p == null) p = System.getProperty("user.home");
paths.add(p); paths.add(p);
modes.add(config.getRightPanelTabViewMode(i)); modes.add(config.getRightPanelTabViewMode(i));
focusedItems.add(config.getRightPanelTabFocusedItem(i));
} }
int sel = config.getRightPanelSelectedIndex(); int sel = config.getRightPanelSelectedIndex();
rightPanel.restoreTabs(paths, modes, sel); rightPanel.restoreTabs(paths, modes, focusedItems, sel);
} }
} catch (Exception ex) { } catch (Exception ex) {
// ignore and keep default // ignore and keep default
@ -1288,7 +1292,7 @@ public class MainWindow extends JFrame {
final File finalTargetZip = targetZip; final File finalTargetZip = targetZip;
performFileOperation((callback) -> { performFileOperation((callback) -> {
FileOperations.zip(selectedItems, finalTargetZip, callback); FileOperations.zip(selectedItems, finalTargetZip, callback);
}, "Zipped into " + zipName, false, targetPanel); }, "Zipped into " + zipName, false, targetPanel, targetPanel);
} }
/** /**
@ -1824,12 +1828,14 @@ public class MainWindow extends JFrame {
progressDialog.dispose(); progressDialog.dispose();
for (FilePanel panel : panelsToRefresh) { for (FilePanel panel : panelsToRefresh) {
if (panel.getCurrentDirectory() != null) { if (panel.getCurrentDirectory() != null) {
panel.loadDirectory(panel.getCurrentDirectory()); panel.loadDirectory(panel.getCurrentDirectory(), false);
} }
} }
if (activePanel != null && activePanel.getFileTable() != null) { if (activePanel != null && activePanel.getFileTable() != null) {
activePanel.getFileTable().requestFocusInWindow(); activePanel.getFileTable().requestFocusInWindow();
} }
if (callback.isCancelled()) { if (callback.isCancelled()) {
JOptionPane.showMessageDialog(MainWindow.this, "Operation was cancelled by user."); JOptionPane.showMessageDialog(MainWindow.this, "Operation was cancelled by user.");
if (activePanel != null && activePanel.getFileTable() != null) { if (activePanel != null && activePanel.getFileTable() != null) {
@ -1889,8 +1895,9 @@ public class MainWindow extends JFrame {
try { try {
java.util.List<String> leftPaths = leftPanel.getTabPaths(); java.util.List<String> leftPaths = leftPanel.getTabPaths();
java.util.List<String> leftModes = leftPanel.getTabViewModes(); java.util.List<String> leftModes = leftPanel.getTabViewModes();
java.util.List<String> leftFocused = leftPanel.getTabFocusedItems();
int leftSelected = leftPanel.getSelectedTabIndex(); int leftSelected = leftPanel.getSelectedTabIndex();
config.saveLeftPanelTabs(leftPaths, leftModes, leftSelected); config.saveLeftPanelTabs(leftPaths, leftModes, leftFocused, leftSelected);
} catch (Exception ex) { } catch (Exception ex) {
// ignore // ignore
} }
@ -1898,8 +1905,9 @@ public class MainWindow extends JFrame {
try { try {
java.util.List<String> rightPaths = rightPanel.getTabPaths(); java.util.List<String> rightPaths = rightPanel.getTabPaths();
java.util.List<String> rightModes = rightPanel.getTabViewModes(); java.util.List<String> rightModes = rightPanel.getTabViewModes();
java.util.List<String> rightFocused = rightPanel.getTabFocusedItems();
int rightSelected = rightPanel.getSelectedTabIndex(); int rightSelected = rightPanel.getSelectedTabIndex();
config.saveRightPanelTabs(rightPaths, rightModes, rightSelected); config.saveRightPanelTabs(rightPaths, rightModes, rightFocused, rightSelected);
} catch (Exception ex) { } catch (Exception ex) {
// ignore // ignore
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB