diff --git a/src/main/java/cz/kamma/kfmanager/ui/FileEditor.java b/src/main/java/cz/kamma/kfmanager/ui/FileEditor.java index 15fbf59..4ad3cfd 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FileEditor.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FileEditor.java @@ -51,6 +51,10 @@ public class FileEditor extends JDialog { private JTextField searchField; private JLabel searchStatusLabel; private static String lastSearchValue = ""; + + public static void setLastSearchValue(String value) { + lastSearchValue = value; + } public FileEditor(Window parent, File file, AppConfig config, boolean readOnly) { this(parent, file, null, config, readOnly); @@ -566,15 +570,35 @@ public class FileEditor extends JDialog { KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), 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 -> { - if (!searchPanel.isVisible()) { - closeEditor(); + if (isImageFile(file)) { + 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); + // 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 if (!readOnly) { rootPane.registerKeyboardAction(e -> handleCtrlS(), @@ -628,10 +652,6 @@ public class FileEditor extends JDialog { KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); - rootPane.registerKeyboardAction(e -> findNext(), - KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), - JComponent.WHEN_IN_FOCUSED_WINDOW); - rootPane.registerKeyboardAction(e -> findPrevious(), KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); diff --git a/src/main/java/cz/kamma/kfmanager/ui/FilePanel.java b/src/main/java/cz/kamma/kfmanager/ui/FilePanel.java index e295db3..96172f2 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FilePanel.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FilePanel.java @@ -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) { FilePanelTab tab = getCurrentTab(); if (tab != null) { diff --git a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java index 2fd6759..e6457ac 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java @@ -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) { if (f == null) return false; String n = f.getName().toLowerCase(); diff --git a/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java b/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java index fc5b5f9..868eeaf 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java +++ b/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java @@ -1742,24 +1742,7 @@ public class MainWindow extends JFrame { */ public void showFileInFocusedPanel(File file) { if (file == null) return; - // Determine which panel currently has focus - 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; + FilePanel target = getFocusedFilePanel(); final FilePanel chosen = target; final File parentDir = file.getParentFile(); @@ -1781,6 +1764,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 diff --git a/src/main/java/cz/kamma/kfmanager/ui/SearchDialog.java b/src/main/java/cz/kamma/kfmanager/ui/SearchDialog.java index 419982d..68fa571 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/SearchDialog.java +++ b/src/main/java/cz/kamma/kfmanager/ui/SearchDialog.java @@ -598,7 +598,21 @@ public class SearchDialog extends JDialog { java.awt.Window w = SwingUtilities.getWindowAncestor(this); if (w instanceof MainWindow) { 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(); return; } @@ -627,6 +641,17 @@ public class SearchDialog extends JDialog { if (item.getPath() != null && !item.getPath().equals(item.getFile().getAbsolutePath())) { 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); viewer.addWindowListener(new java.awt.event.WindowAdapter() { @Override @@ -660,6 +685,17 @@ public class SearchDialog extends JDialog { } try { 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); editor.addWindowListener(new java.awt.event.WindowAdapter() { @Override