Feed to panel partially works

This commit is contained in:
Radek Davidek 2026-04-22 17:31:40 +02:00
parent d30944ebec
commit d5df5d7042
4 changed files with 83 additions and 3 deletions

View File

@ -1028,6 +1028,14 @@ public class FilePanel extends JPanel {
} }
} }
public void showFeedToPanel(List<FileItem> items) {
FilePanelTab tab = getCurrentTab();
if (tab != null) {
tab.showFeedToPanel(items);
updatePathField();
}
}
public void navigateUp() { public void navigateUp() {
FilePanelTab tab = getCurrentTab(); FilePanelTab tab = getCurrentTab();
if (tab != null) { if (tab != null) {

View File

@ -351,6 +351,42 @@ public class FilePanelTab extends JPanel {
} }
} }
/**
* Display a custom list of items (e.g. search results).
* This puts the tab in "search mode".
*/
public void showFeedToPanel(List<FileItem> items) {
searchModeActive = true;
this.currentDirectory = new File("Search results"); // Or something indicative
allItems.clear();
allItems.addAll(items);
tableModel.setItems(new ArrayList<>(items));
if (sortColumn >= 0) {
sortItemsByColumn(sortColumn, sortAscending);
}
if (viewMode == ViewMode.BRIEF) {
tableModel.calculateBriefLayout();
tableModel.fireTableStructureChanged();
} else {
tableModel.fireTableDataChanged();
}
updateColumnRenderers();
updateColumnWidths();
fileTable.revalidate();
fileTable.repaint();
if (tableModel.getRowCount() > 0) {
fileTable.setRowSelectionInterval(0, 0);
}
fileTable.requestFocusInWindow();
updateStatus();
}
private void updateContentBorder() { private void updateContentBorder() {
if (tableScrollPane == null) { if (tableScrollPane == null) {
return; return;
@ -1174,7 +1210,7 @@ public class FilePanelTab extends JPanel {
filterTextField.requestFocusInWindow(); filterTextField.requestFocusInWindow();
} }
private void enterSearchMode() { public void enterSearchMode() {
searchModeActive = true; searchModeActive = true;
filterTextField.setText(""); filterTextField.setText("");
filterPanel.setVisible(true); filterPanel.setVisible(true);
@ -1182,7 +1218,7 @@ public class FilePanelTab extends JPanel {
repaint(); repaint();
} }
private void exitSearchMode() { public void exitSearchMode() {
searchModeActive = false; searchModeActive = false;
filterPanel.setVisible(false); filterPanel.setVisible(false);
filterTextField.setText(""); filterTextField.setText("");
@ -1638,6 +1674,8 @@ public class FilePanelTab extends JPanel {
* Refresh the current directory while attempting to preserve selection and focus. * Refresh the current directory while attempting to preserve selection and focus.
*/ */
public void refresh(boolean requestFocus) { public void refresh(boolean requestFocus) {
if (searchModeActive) return;
if (isFtpTab) { if (isFtpTab) {
loadFtpDirectory(ftpCurrentPath, false, requestFocus); loadFtpDirectory(ftpCurrentPath, false, requestFocus);
return; return;
@ -4133,6 +4171,9 @@ public class FilePanelTab extends JPanel {
java.util.List<FileItem> items = tableModel.items; java.util.List<FileItem> items = tableModel.items;
if (items.isEmpty()) return; if (items.isEmpty()) return;
// In search mode (no real directory), ".." might not be present or shouldn't be special
boolean hasParentDir = !items.isEmpty() && items.get(0).getName().equals("..");
// Remember currently selected item name to restore selection after sort // Remember currently selected item name to restore selection after sort
final String selectedItemName; final String selectedItemName;
FileItem focused = getFocusedItem(); FileItem focused = getFocusedItem();
@ -4140,7 +4181,7 @@ public class FilePanelTab extends JPanel {
// Extract and remember the ".." (parent directory) entry if present // Extract and remember the ".." (parent directory) entry if present
FileItem parentDir = null; FileItem parentDir = null;
if (!items.isEmpty() && items.get(0).getName().equals("..")) { if (hasParentDir) {
parentDir = items.remove(0); parentDir = items.remove(0);
} }

View File

@ -1500,6 +1500,10 @@ public class MainWindow extends JFrame {
switchPanels(); switchPanels();
} }
public FilePanel getActivePanel() {
return activePanel;
}
private void updateCommandLinePrompt() { private void updateCommandLinePrompt() {
if (cmdLabel == null) return; if (cmdLabel == null) return;

View File

@ -373,9 +373,13 @@ public class SearchDialog extends JDialog {
JButton openButton = new JButton("Open location"); JButton openButton = new JButton("Open location");
openButton.addActionListener(e -> openSelectedFile()); openButton.addActionListener(e -> openSelectedFile());
JButton feedToPanelButton = new JButton("Feed to panel");
feedToPanelButton.addActionListener(e -> feedToActivePanel());
bottomButtonPanel.add(viewButton); bottomButtonPanel.add(viewButton);
bottomButtonPanel.add(editButton); bottomButtonPanel.add(editButton);
bottomButtonPanel.add(openButton); bottomButtonPanel.add(openButton);
bottomButtonPanel.add(feedToPanelButton);
bottomButtonPanel.add(cancelButton); bottomButtonPanel.add(cancelButton);
JPanel bottomPanel = new JPanel(new BorderLayout()); JPanel bottomPanel = new JPanel(new BorderLayout());
@ -802,6 +806,25 @@ public class SearchDialog extends JDialog {
} }
} }
/**
* Feed all search results to the active panel in MainWindow.
*/
private void feedToActivePanel() {
if (tableModel.getRowCount() == 0) {
JOptionPane.showMessageDialog(this, "No search results to feed to panel.", "Information", JOptionPane.INFORMATION_MESSAGE);
return;
}
java.awt.Window w = SwingUtilities.getWindowAncestor(this);
if (w instanceof MainWindow mw) {
FilePanel active = mw.getActivePanel();
if (active != null) {
active.showFeedToPanel(tableModel.getResults());
dispose();
}
}
}
/** /**
* Open the selected file in the internal viewer (read-only) * Open the selected file in the internal viewer (read-only)
*/ */
@ -916,6 +939,10 @@ public class SearchDialog extends JDialog {
public FileItem getResult(int row) { public FileItem getResult(int row) {
return results.get(row); return results.get(row);
} }
public List<FileItem> getResults() {
return new ArrayList<>(results);
}
@Override @Override
public int getRowCount() { public int getRowCount() {