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