focus after dir creation
This commit is contained in:
parent
28e3e1bdad
commit
803e1e707b
@ -680,9 +680,13 @@ public class FilePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadDirectory(File directory, boolean requestFocus) {
|
public void loadDirectory(File directory, boolean requestFocus) {
|
||||||
|
loadDirectory(directory, true, requestFocus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadDirectory(File directory, boolean autoSelectFirst, boolean requestFocus) {
|
||||||
FilePanelTab tab = getCurrentTab();
|
FilePanelTab tab = getCurrentTab();
|
||||||
if (tab != null) {
|
if (tab != null) {
|
||||||
tab.loadDirectory(directory, true, requestFocus);
|
tab.loadDirectory(directory, autoSelectFirst, requestFocus);
|
||||||
updatePathField();
|
updatePathField();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1420,13 +1420,18 @@ public class FilePanelTab extends JPanel {
|
|||||||
|
|
||||||
private void selectItemByName(String name, boolean requestFocus) {
|
private void selectItemByName(String name, boolean requestFocus) {
|
||||||
if (viewMode == ViewMode.BRIEF) {
|
if (viewMode == ViewMode.BRIEF) {
|
||||||
|
// Re-calculate layout if needed before searching to ensure current mapping
|
||||||
|
if (tableModel.items.size() > 0 && (tableModel.briefColumns == 0 || tableModel.briefRowsPerColumn == 0)) {
|
||||||
|
tableModel.calculateBriefLayout();
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < tableModel.items.size(); i++) {
|
for (int i = 0; i < tableModel.items.size(); i++) {
|
||||||
FileItem item = tableModel.items.get(i);
|
FileItem item = tableModel.items.get(i);
|
||||||
if (item.getName().equals(name)) {
|
if (item != null && item.getName().equalsIgnoreCase(name)) {
|
||||||
int column = i / tableModel.briefRowsPerColumn;
|
int column = i / tableModel.briefRowsPerColumn;
|
||||||
int row = i % tableModel.briefRowsPerColumn;
|
int row = i % tableModel.briefRowsPerColumn;
|
||||||
|
|
||||||
if (column < tableModel.getColumnCount()) {
|
if (column < fileTable.getColumnCount()) {
|
||||||
briefCurrentColumn = column;
|
briefCurrentColumn = column;
|
||||||
fileTable.setRowSelectionInterval(row, row);
|
fileTable.setRowSelectionInterval(row, row);
|
||||||
fileTable.scrollRectToVisible(fileTable.getCellRect(row, column, true));
|
fileTable.scrollRectToVisible(fileTable.getCellRect(row, column, true));
|
||||||
@ -1442,7 +1447,7 @@ public class FilePanelTab extends JPanel {
|
|||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < tableModel.getRowCount(); i++) {
|
for (int i = 0; i < tableModel.getRowCount(); i++) {
|
||||||
FileItem item = tableModel.getItem(i);
|
FileItem item = tableModel.getItem(i);
|
||||||
if (item != null && item.getName().equals(name)) {
|
if (item != null && item.getName().equalsIgnoreCase(name)) {
|
||||||
fileTable.setRowSelectionInterval(i, i);
|
fileTable.setRowSelectionInterval(i, i);
|
||||||
fileTable.scrollRectToVisible(fileTable.getCellRect(i, 0, true));
|
fileTable.scrollRectToVisible(fileTable.getCellRect(i, 0, true));
|
||||||
if (requestFocus) {
|
if (requestFocus) {
|
||||||
|
|||||||
@ -1430,14 +1430,19 @@ public class MainWindow extends JFrame {
|
|||||||
* Create a new directory
|
* Create a new directory
|
||||||
*/
|
*/
|
||||||
private void createNewDirectory() {
|
private void createNewDirectory() {
|
||||||
String dirName = JOptionPane.showInputDialog(this,
|
String dirNameInput = JOptionPane.showInputDialog(this,
|
||||||
"New directory name:",
|
"New directory name:",
|
||||||
"New directory");
|
"New directory");
|
||||||
|
|
||||||
if (dirName != null && !dirName.trim().isEmpty()) {
|
if (dirNameInput != null && !dirNameInput.trim().isEmpty()) {
|
||||||
|
final String dirName = dirNameInput.trim();
|
||||||
performFileOperation((callback) -> {
|
performFileOperation((callback) -> {
|
||||||
FileOperations.createDirectory(activePanel.getCurrentDirectory(), dirName.trim());
|
FileOperations.createDirectory(activePanel.getCurrentDirectory(), dirName);
|
||||||
}, "Directory created", false, activePanel);
|
}, "Directory created", false, () -> {
|
||||||
|
if (activePanel != null && activePanel.getCurrentTab() != null) {
|
||||||
|
activePanel.getCurrentTab().selectItem(dirName);
|
||||||
|
}
|
||||||
|
}, activePanel);
|
||||||
} else {
|
} else {
|
||||||
if (activePanel != null && activePanel.getFileTable() != null) {
|
if (activePanel != null && activePanel.getFileTable() != null) {
|
||||||
activePanel.getFileTable().requestFocusInWindow();
|
activePanel.getFileTable().requestFocusInWindow();
|
||||||
@ -1847,6 +1852,13 @@ public class MainWindow extends JFrame {
|
|||||||
* Execute file operation with error handling
|
* Execute file operation with error handling
|
||||||
*/
|
*/
|
||||||
private void performFileOperation(FileOperation operation, String successMessage, boolean showBytes, FilePanel... panelsToRefresh) {
|
private void performFileOperation(FileOperation operation, String successMessage, boolean showBytes, FilePanel... panelsToRefresh) {
|
||||||
|
performFileOperation(operation, successMessage, showBytes, null, panelsToRefresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute file operation with error handling and a task to run after completion and refresh.
|
||||||
|
*/
|
||||||
|
private void performFileOperation(FileOperation operation, String successMessage, boolean showBytes, Runnable postTask, FilePanel... panelsToRefresh) {
|
||||||
ProgressDialog progressDialog = new ProgressDialog(this, "File Operation");
|
ProgressDialog progressDialog = new ProgressDialog(this, "File Operation");
|
||||||
progressDialog.setDisplayAsBytes(showBytes);
|
progressDialog.setDisplayAsBytes(showBytes);
|
||||||
|
|
||||||
@ -1903,10 +1915,14 @@ public class MainWindow extends JFrame {
|
|||||||
progressDialog.dispose();
|
progressDialog.dispose();
|
||||||
for (FilePanel panel : panelsToRefresh) {
|
for (FilePanel panel : panelsToRefresh) {
|
||||||
if (panel.getCurrentDirectory() != null) {
|
if (panel.getCurrentDirectory() != null) {
|
||||||
panel.loadDirectory(panel.getCurrentDirectory(), false);
|
panel.loadDirectory(panel.getCurrentDirectory(), false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (postTask != null) {
|
||||||
|
SwingUtilities.invokeLater(postTask);
|
||||||
|
}
|
||||||
|
|
||||||
if (activePanel != null && activePanel.getFileTable() != null) {
|
if (activePanel != null && activePanel.getFileTable() != null) {
|
||||||
activePanel.getFileTable().requestFocusInWindow();
|
activePanel.getFileTable().requestFocusInWindow();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user