search dialog improvements

This commit is contained in:
rdavidek 2026-01-21 18:42:11 +01:00
parent 6854693492
commit 4f15bac6ff
5 changed files with 137 additions and 27 deletions

View File

@ -52,6 +52,10 @@ public class FileEditor extends JDialog {
private JLabel searchStatusLabel; private JLabel searchStatusLabel;
private static String lastSearchValue = ""; private static String lastSearchValue = "";
public static void setLastSearchValue(String value) {
lastSearchValue = value;
}
public FileEditor(Window parent, File file, AppConfig config, boolean readOnly) { public FileEditor(Window parent, File file, AppConfig config, boolean readOnly) {
this(parent, file, null, config, readOnly); this(parent, file, null, config, readOnly);
} }
@ -566,15 +570,35 @@ public class FileEditor extends JDialog {
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW); JComponent.WHEN_IN_FOCUSED_WINDOW);
// F3/F4 - Pokud není aktivní hledání // F3 behavior: Search in all modes, shows panel if hidden
rootPane.registerKeyboardAction(e -> { rootPane.registerKeyboardAction(e -> {
if (!searchPanel.isVisible()) { if (isImageFile(file)) {
closeEditor(); if (readOnly) closeEditor();
return;
} }
if (!searchPanel.isVisible()) {
showSearchPanel();
}
findNext();
}, },
KeyStroke.getKeyStroke(readOnly ? KeyEvent.VK_F3 : KeyEvent.VK_F4, 0), KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW); JComponent.WHEN_IN_FOCUSED_WINDOW);
// F4 behavior: In editor closes editor
if (!readOnly) {
rootPane.registerKeyboardAction(e -> {
if (isImageFile(file)) {
closeEditor();
return;
}
if (!searchPanel.isVisible()) {
closeEditor();
}
},
KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
}
// Ctrl+S - Save (common shortcut) but show confirmation dialog when there are unsaved changes // Ctrl+S - Save (common shortcut) but show confirmation dialog when there are unsaved changes
if (!readOnly) { if (!readOnly) {
rootPane.registerKeyboardAction(e -> handleCtrlS(), rootPane.registerKeyboardAction(e -> handleCtrlS(),
@ -628,10 +652,6 @@ public class FileEditor extends JDialog {
KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK), KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW); JComponent.WHEN_IN_FOCUSED_WINDOW);
rootPane.registerKeyboardAction(e -> findNext(),
KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
rootPane.registerKeyboardAction(e -> findPrevious(), rootPane.registerKeyboardAction(e -> findPrevious(),
KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_DOWN_MASK), KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_DOWN_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW); JComponent.WHEN_IN_FOCUSED_WINDOW);

View File

@ -737,6 +737,14 @@ public class FilePanel extends JPanel {
} }
} }
public void showArchiveFile(File archive, String entryName) {
FilePanelTab tab = getCurrentTab();
if (tab != null) {
tab.showArchiveFile(archive, entryName);
updatePathField();
}
}
public void refresh(boolean requestFocus) { public void refresh(boolean requestFocus) {
FilePanelTab tab = getCurrentTab(); FilePanelTab tab = getCurrentTab();
if (tab != null) { if (tab != null) {

View File

@ -1109,6 +1109,33 @@ public class FilePanelTab extends JPanel {
} }
} }
public void showArchiveFile(File archive, String entryName) {
Path temp = extractArchiveToTemp(archive);
if (temp != null) {
// Delete any previous temp dir if different
try {
if (currentArchiveTempDir != null && !currentArchiveTempDir.equals(temp)) {
deleteTempDirRecursively(currentArchiveTempDir);
}
} catch (Exception ignore) {}
currentArchiveTempDir = temp;
currentArchiveSourceFile = archive;
File targetFile = new File(temp.toFile(), entryName);
File targetDir = targetFile.isDirectory() ? targetFile : targetFile.getParentFile();
if (targetDir != null && targetDir.exists()) {
loadDirectory(targetDir, false, true, () -> {
if (!targetFile.isDirectory()) {
selectItem(targetFile.getName());
}
});
} else {
loadDirectory(temp.toFile(), true, true);
}
}
}
private boolean isArchiveFile(File f) { private boolean isArchiveFile(File f) {
if (f == null) return false; if (f == null) return false;
String n = f.getName().toLowerCase(); String n = f.getName().toLowerCase();

View File

@ -1742,24 +1742,7 @@ public class MainWindow extends JFrame {
*/ */
public void showFileInFocusedPanel(File file) { public void showFileInFocusedPanel(File file) {
if (file == null) return; if (file == null) return;
// Determine which panel currently has focus FilePanel target = getFocusedFilePanel();
java.awt.Component owner = java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
FilePanel target = null;
if (owner != null) {
Component p = owner;
while (p != null) {
if (p == leftPanel) {
target = leftPanel;
break;
}
if (p == rightPanel) {
target = rightPanel;
break;
}
p = p.getParent();
}
}
if (target == null) target = activePanel != null ? activePanel : leftPanel;
final FilePanel chosen = target; final FilePanel chosen = target;
final File parentDir = file.getParentFile(); final File parentDir = file.getParentFile();
@ -1782,6 +1765,42 @@ public class MainWindow extends JFrame {
}); });
} }
/**
* Show a file that is inside an archive in the focused panel.
*/
public void showArchiveFileInFocusedPanel(File archive, String entryName) {
if (archive == null || entryName == null) return;
FilePanel target = getFocusedFilePanel();
final FilePanel chosen = target;
SwingUtilities.invokeLater(() -> {
chosen.showArchiveFile(archive, entryName);
activePanel = chosen;
updateActivePanelBorder();
});
}
private FilePanel getFocusedFilePanel() {
java.awt.Component owner = java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
FilePanel target = null;
if (owner != null) {
Component p = owner;
while (p != null) {
if (p == leftPanel) {
target = leftPanel;
break;
}
if (p == rightPanel) {
target = rightPanel;
break;
}
p = p.getParent();
}
}
if (target == null) target = activePanel != null ? activePanel : leftPanel;
return target;
}
/** /**
* Show file in internal viewer * Show file in internal viewer
*/ */

View File

@ -598,7 +598,21 @@ public class SearchDialog extends JDialog {
java.awt.Window w = SwingUtilities.getWindowAncestor(this); java.awt.Window w = SwingUtilities.getWindowAncestor(this);
if (w instanceof MainWindow) { if (w instanceof MainWindow) {
MainWindow mw = (MainWindow) w; MainWindow mw = (MainWindow) w;
mw.showFileInFocusedPanel(item.getFile());
String fullPath = item.getPath();
File file = item.getFile();
String archivePath = file.getAbsolutePath();
if (fullPath != null && fullPath.startsWith(archivePath) && fullPath.length() > archivePath.length()) {
String entryName = fullPath.substring(archivePath.length());
// Normalize separators and leading slash
if (entryName.startsWith("/") || entryName.startsWith("\\")) {
entryName = entryName.substring(1);
}
mw.showArchiveFileInFocusedPanel(file, entryName);
} else {
mw.showFileInFocusedPanel(file);
}
dispose(); dispose();
return; return;
} }
@ -627,6 +641,17 @@ public class SearchDialog extends JDialog {
if (item.getPath() != null && !item.getPath().equals(item.getFile().getAbsolutePath())) { if (item.getPath() != null && !item.getPath().equals(item.getFile().getAbsolutePath())) {
vPath = item.getPath(); vPath = item.getPath();
} }
// Set search text from search dialog to editor
String contentPat = "";
try {
Object cit = contentPatternCombo.getEditor().getItem();
contentPat = cit != null ? cit.toString().trim() : "";
} catch (Exception ex) {}
if (!contentPat.isEmpty()) {
FileEditor.setLastSearchValue(contentPat);
}
FileEditor viewer = new FileEditor(owner, item.getFile(), vPath, config, true); FileEditor viewer = new FileEditor(owner, item.getFile(), vPath, config, true);
viewer.addWindowListener(new java.awt.event.WindowAdapter() { viewer.addWindowListener(new java.awt.event.WindowAdapter() {
@Override @Override
@ -660,6 +685,17 @@ public class SearchDialog extends JDialog {
} }
try { try {
Frame owner = (Frame) SwingUtilities.getWindowAncestor(this); Frame owner = (Frame) SwingUtilities.getWindowAncestor(this);
// Set search text from search dialog to editor
String contentPat = "";
try {
Object cit = contentPatternCombo.getEditor().getItem();
contentPat = cit != null ? cit.toString().trim() : "";
} catch (Exception ex) {}
if (!contentPat.isEmpty()) {
FileEditor.setLastSearchValue(contentPat);
}
FileEditor editor = new FileEditor(owner, item.getFile(), config, false); FileEditor editor = new FileEditor(owner, item.getFile(), config, false);
editor.addWindowListener(new java.awt.event.WindowAdapter() { editor.addWindowListener(new java.awt.event.WindowAdapter() {
@Override @Override