fixed search dialog
This commit is contained in:
parent
197e367ca4
commit
fac3a35984
@ -766,6 +766,11 @@ public class FileEditor extends JFrame {
|
||||
return name.endsWith(".md") || name.endsWith(".markdown") || name.endsWith(".mdown") || name.endsWith(".mkd");
|
||||
}
|
||||
|
||||
private boolean isNfoFile() {
|
||||
String name = virtualPath != null ? virtualPath : file.getName();
|
||||
return name.toLowerCase().endsWith(".nfo");
|
||||
}
|
||||
|
||||
private void setMarkdownMode(boolean on) {
|
||||
if (on && (!readOnly || !isMarkdownFile() || hexMode || isImageFile(file))) {
|
||||
on = false;
|
||||
@ -1500,7 +1505,13 @@ public class FileEditor extends JFrame {
|
||||
} else if (hexMode) {
|
||||
buildHexViewText(0L);
|
||||
} else {
|
||||
String content = new String(fileBytes, "UTF-8");
|
||||
String encoding = isNfoFile() ? "Cp437" : "UTF-8";
|
||||
String content;
|
||||
try {
|
||||
content = new String(fileBytes, encoding);
|
||||
} catch (java.io.UnsupportedEncodingException e) {
|
||||
content = new String(fileBytes, "UTF-8");
|
||||
}
|
||||
textArea.setText(content);
|
||||
textArea.setCaretPosition(0);
|
||||
}
|
||||
@ -1569,7 +1580,13 @@ public class FileEditor extends JFrame {
|
||||
} else if (hexMode) {
|
||||
buildHexViewText(0L);
|
||||
} else {
|
||||
String content = new String(fileBytes, "UTF-8");
|
||||
String encoding = isNfoFile() ? "Cp437" : "UTF-8";
|
||||
String content;
|
||||
try {
|
||||
content = new String(fileBytes, encoding);
|
||||
} catch (java.io.UnsupportedEncodingException e) {
|
||||
content = new String(fileBytes, "UTF-8");
|
||||
}
|
||||
textArea.setText(content);
|
||||
textArea.setCaretPosition(0);
|
||||
}
|
||||
@ -1590,7 +1607,7 @@ public class FileEditor extends JFrame {
|
||||
}
|
||||
|
||||
private boolean isBinaryForCurrentFile(byte[] bytes) {
|
||||
if (isMarkdownFile()) {
|
||||
if (isMarkdownFile() || isNfoFile()) {
|
||||
return containsNulByte(bytes);
|
||||
}
|
||||
return isBinary(bytes);
|
||||
|
||||
@ -3359,7 +3359,9 @@ public class FilePanelTab extends JPanel {
|
||||
briefCurrentColumn = column;
|
||||
fileTable.setRowSelectionInterval(row, row);
|
||||
if (scrollToItem) {
|
||||
scrollBriefCellToColumnStart(row, column);
|
||||
final int r = row;
|
||||
final int c = column;
|
||||
SwingUtilities.invokeLater(() -> scrollBriefCellToColumnStart(r, c));
|
||||
}
|
||||
fileTable.repaint();
|
||||
if (requestFocus) {
|
||||
@ -3376,7 +3378,10 @@ public class FilePanelTab extends JPanel {
|
||||
if (item != null && item.getName().equalsIgnoreCase(name)) {
|
||||
fileTable.setRowSelectionInterval(i, i);
|
||||
if (scrollToItem) {
|
||||
fileTable.scrollRectToVisible(fileTable.getCellRect(i, 0, true));
|
||||
final int row = i;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
fileTable.scrollRectToVisible(fileTable.getCellRect(row, 0, true));
|
||||
});
|
||||
}
|
||||
if (requestFocus) {
|
||||
fileTable.requestFocusInWindow();
|
||||
@ -3594,11 +3599,14 @@ public class FilePanelTab extends JPanel {
|
||||
int row = index % tableModel.briefRowsPerColumn;
|
||||
if (briefCurrentColumn < fileTable.getColumnCount()) {
|
||||
fileTable.setRowSelectionInterval(row, row);
|
||||
scrollBriefCellToColumnStart(row, briefCurrentColumn);
|
||||
final int r = row;
|
||||
final int c = briefCurrentColumn;
|
||||
SwingUtilities.invokeLater(() -> scrollBriefCellToColumnStart(r, c));
|
||||
}
|
||||
} else {
|
||||
fileTable.setRowSelectionInterval(index, index);
|
||||
fileTable.scrollRectToVisible(fileTable.getCellRect(index, 0, true));
|
||||
final int r = index;
|
||||
SwingUtilities.invokeLater(() -> fileTable.scrollRectToVisible(fileTable.getCellRect(r, 0, true)));
|
||||
}
|
||||
fileTable.repaint();
|
||||
fileTable.requestFocusInWindow();
|
||||
|
||||
@ -2702,18 +2702,16 @@ public class MainWindow extends JFrame {
|
||||
|
||||
// Load directory and then select item by name on the EDT
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
chosen.loadDirectory(parentDir);
|
||||
FilePanelTab tab = chosen.getCurrentTab();
|
||||
if (tab != null) {
|
||||
tab.loadDirectory(parentDir, false, true, () -> {
|
||||
tab.selectItem(file.getName());
|
||||
tab.getFileTable().requestFocusInWindow();
|
||||
});
|
||||
}
|
||||
// mark this panel active and refresh borders
|
||||
activePanel = chosen;
|
||||
updateActivePanelBorder();
|
||||
// After loading, select the file name
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
FilePanelTab tab = chosen.getCurrentTab();
|
||||
if (tab != null) {
|
||||
tab.selectItem(file.getName());
|
||||
tab.getFileTable().requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -332,9 +332,12 @@ public class SearchDialog extends JDialog {
|
||||
stopButton.setMaximumSize(new Dimension(120, 30));
|
||||
stopButton.setEnabled(false);
|
||||
stopButton.addActionListener(e -> {
|
||||
if (currentWorker != null) {
|
||||
currentWorker.cancel(true);
|
||||
}
|
||||
searching = false;
|
||||
stopButton.setEnabled(false);
|
||||
statusLabel.setText("Cancelling...");
|
||||
statusLabel.setText("Canceled — found " + foundCount + " files");
|
||||
});
|
||||
|
||||
eastPanel.add(searchButton);
|
||||
@ -490,10 +493,21 @@ public class SearchDialog extends JDialog {
|
||||
}
|
||||
});
|
||||
|
||||
// Escape closes the dialog (and cancels ongoing search)
|
||||
// Escape cancels ongoing search or closes the dialog
|
||||
getRootPane().registerKeyboardAction(e -> {
|
||||
if (searching) {
|
||||
if (currentWorker != null) {
|
||||
currentWorker.cancel(true);
|
||||
}
|
||||
searching = false;
|
||||
statusLabel.setText("Canceled — found " + foundCount + " files");
|
||||
statusProgressBar.setIndeterminate(false);
|
||||
statusProgressBar.setValue(0);
|
||||
searchButton.setEnabled(true);
|
||||
stopButton.setEnabled(false);
|
||||
} else {
|
||||
dispose();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
|
||||
// F3 = view, F4 = edit when dialog is active
|
||||
@ -556,7 +570,12 @@ public class SearchDialog extends JDialog {
|
||||
/**
|
||||
* Provede vyhledávání
|
||||
*/
|
||||
private SwingWorker<?, ?> currentWorker;
|
||||
|
||||
private void performSearch() {
|
||||
if (currentWorker != null && !currentWorker.isDone()) {
|
||||
currentWorker.cancel(true);
|
||||
}
|
||||
String namePat = "";
|
||||
try {
|
||||
Object it = patternCombo.getEditor().getItem();
|
||||
@ -669,7 +688,7 @@ public class SearchDialog extends JDialog {
|
||||
statusProgressBar.setIndeterminate(true);
|
||||
|
||||
// Spustit vyhledávání v samostatném vlákně
|
||||
SwingWorker<Void, Object[]> worker = new SwingWorker<Void, Object[]>() {
|
||||
currentWorker = new SwingWorker<Void, Object[]>() {
|
||||
private String currentSearchPath = "";
|
||||
|
||||
@Override
|
||||
@ -745,6 +764,10 @@ public class SearchDialog extends JDialog {
|
||||
statusProgressBar.setIndeterminate(false);
|
||||
statusProgressBar.setVisible(false);
|
||||
try {
|
||||
if (isCancelled()) {
|
||||
statusLabel.setText("Canceled — found " + foundCount + " files");
|
||||
return;
|
||||
}
|
||||
get();
|
||||
statusLabel.setText("Done — found " + foundCount + " files");
|
||||
if (tableModel.getRowCount() == 0) {
|
||||
@ -753,6 +776,8 @@ public class SearchDialog extends JDialog {
|
||||
"Result",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
} catch (java.util.concurrent.CancellationException e) {
|
||||
statusLabel.setText("Canceled — found " + foundCount + " files");
|
||||
} catch (Exception e) {
|
||||
statusLabel.setText("Error");
|
||||
JOptionPane.showMessageDialog(SearchDialog.this,
|
||||
@ -763,7 +788,7 @@ public class SearchDialog extends JDialog {
|
||||
}
|
||||
};
|
||||
|
||||
worker.execute();
|
||||
currentWorker.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user