fixed select by mask dialog
This commit is contained in:
parent
177f63f485
commit
93f73cc084
@ -35,6 +35,7 @@ public class MainWindow extends JFrame {
|
||||
private AppConfig config;
|
||||
private Timer autoRefreshTimer;
|
||||
private boolean isWindowResizing = false;
|
||||
private boolean wildcardDialogOpen = false;
|
||||
|
||||
public MainWindow() {
|
||||
super("KF Manager v" + MainApp.APP_VERSION + " (" + MainApp.CURRENT_OS + ")");
|
||||
@ -2097,16 +2098,20 @@ public class MainWindow extends JFrame {
|
||||
*/
|
||||
public void showWildcardSelectDialog() {
|
||||
if (activePanel == null) return;
|
||||
if (wildcardDialogOpen) return;
|
||||
wildcardDialogOpen = true;
|
||||
|
||||
WildcardSelectDialog dialog = new WildcardSelectDialog(this);
|
||||
dialog.setVisible(true);
|
||||
|
||||
String pattern = dialog.getPattern();
|
||||
if (pattern != null && !pattern.isEmpty()) {
|
||||
activePanel.selectByWildcard(pattern);
|
||||
} else {
|
||||
// If cancelled, return focus to the active panel
|
||||
if (activePanel.getFileTable() != null) {
|
||||
try {
|
||||
WildcardSelectDialog dialog = new WildcardSelectDialog(this, pattern -> {
|
||||
if (activePanel != null) {
|
||||
activePanel.selectByWildcard(pattern);
|
||||
}
|
||||
});
|
||||
dialog.setVisible(true);
|
||||
} finally {
|
||||
wildcardDialogOpen = false;
|
||||
// Return focus to the active panel after dialog is closed
|
||||
if (activePanel != null && activePanel.getFileTable() != null) {
|
||||
activePanel.getFileTable().requestFocusInWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import cz.kamma.kfmanager.MainApp;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Dialog for entering a wildcard pattern to select matching files
|
||||
@ -11,10 +12,11 @@ import java.awt.event.KeyEvent;
|
||||
public class WildcardSelectDialog extends JDialog {
|
||||
|
||||
private JTextField patternField;
|
||||
private boolean confirmed = false;
|
||||
private final Consumer<String> applyHandler;
|
||||
|
||||
public WildcardSelectDialog(Frame parent) {
|
||||
public WildcardSelectDialog(Frame parent, Consumer<String> applyHandler) {
|
||||
super(parent, "Select by pattern", true);
|
||||
this.applyHandler = applyHandler;
|
||||
initComponents();
|
||||
|
||||
MainApp.applyReflectiveCaretColor(getContentPane());
|
||||
@ -45,39 +47,41 @@ public class WildcardSelectDialog extends JDialog {
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.addActionListener(e -> {
|
||||
confirmed = true;
|
||||
dispose();
|
||||
});
|
||||
okButton.addActionListener(e -> applyAndMaybeClose(true));
|
||||
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.addActionListener(e -> {
|
||||
confirmed = false;
|
||||
dispose();
|
||||
});
|
||||
cancelButton.addActionListener(e -> dispose());
|
||||
|
||||
buttonPanel.add(okButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
|
||||
add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Enter confirms
|
||||
patternField.addActionListener(e -> {
|
||||
confirmed = true;
|
||||
dispose();
|
||||
});
|
||||
// Enter applies pattern and closes dialog
|
||||
patternField.addActionListener(e -> applyAndMaybeClose(true));
|
||||
|
||||
// ESC cancels
|
||||
getRootPane().registerKeyboardAction(e -> {
|
||||
confirmed = false;
|
||||
dispose();
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
|
||||
public String getPattern() {
|
||||
return confirmed ? patternField.getText().trim() : null;
|
||||
private void applyAndMaybeClose(boolean closeDialog) {
|
||||
String pattern = patternField.getText();
|
||||
if (pattern != null) {
|
||||
pattern = pattern.trim();
|
||||
}
|
||||
if (pattern != null && !pattern.isEmpty() && applyHandler != null) {
|
||||
applyHandler.accept(pattern);
|
||||
}
|
||||
if (closeDialog) {
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
patternField.requestFocusInWindow();
|
||||
patternField.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user