added new file function, fixed new directory
This commit is contained in:
parent
2035ca4fa5
commit
7962d8defc
@ -550,6 +550,16 @@ public class FileOperations {
|
|||||||
throw new IOException("Failed to create directory");
|
throw new IOException("Failed to create directory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new empty file
|
||||||
|
*/
|
||||||
|
public static void createFile(File parentDirectory, String name) throws IOException {
|
||||||
|
File newFile = new File(parentDirectory, name);
|
||||||
|
if (!newFile.createNewFile()) {
|
||||||
|
throw new IOException("Failed to create file (maybe it already exists?)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete directory recursively
|
* Delete directory recursively
|
||||||
|
|||||||
@ -779,9 +779,6 @@ public class MainWindow extends JFrame {
|
|||||||
JButton btnTerminal = new JButton("F9 Terminal");
|
JButton btnTerminal = new JButton("F9 Terminal");
|
||||||
btnTerminal.addActionListener(e -> openTerminal());
|
btnTerminal.addActionListener(e -> openTerminal());
|
||||||
|
|
||||||
JButton btnRename = new JButton("Shift+F6 Rename");
|
|
||||||
btnRename.addActionListener(e -> renameFile());
|
|
||||||
|
|
||||||
JButton btnExit = new JButton("F10 Exit");
|
JButton btnExit = new JButton("F10 Exit");
|
||||||
btnExit.addActionListener(e -> saveConfigAndExit());
|
btnExit.addActionListener(e -> saveConfigAndExit());
|
||||||
|
|
||||||
@ -792,7 +789,6 @@ public class MainWindow extends JFrame {
|
|||||||
buttonPanel.add(btnNewDir);
|
buttonPanel.add(btnNewDir);
|
||||||
buttonPanel.add(btnDelete);
|
buttonPanel.add(btnDelete);
|
||||||
buttonPanel.add(btnTerminal);
|
buttonPanel.add(btnTerminal);
|
||||||
buttonPanel.add(btnRename);
|
|
||||||
buttonPanel.add(btnExit);
|
buttonPanel.add(btnExit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1076,6 +1072,11 @@ public class MainWindow extends JFrame {
|
|||||||
rootPane.registerKeyboardAction(e -> createNewDirectory(),
|
rootPane.registerKeyboardAction(e -> createNewDirectory(),
|
||||||
KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0),
|
KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0),
|
||||||
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
|
|
||||||
|
// Shift+F4 - New file
|
||||||
|
rootPane.registerKeyboardAction(e -> createNewFile(),
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.SHIFT_DOWN_MASK),
|
||||||
|
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
|
|
||||||
// F8 - Delete
|
// F8 - Delete
|
||||||
rootPane.registerKeyboardAction(e -> deleteFiles(),
|
rootPane.registerKeyboardAction(e -> deleteFiles(),
|
||||||
@ -1792,9 +1793,14 @@ public class MainWindow extends JFrame {
|
|||||||
* Create a new directory
|
* Create a new directory
|
||||||
*/
|
*/
|
||||||
private void createNewDirectory() {
|
private void createNewDirectory() {
|
||||||
|
String initialValue = "New directory";
|
||||||
|
FileItem focusedItem = activePanel.getFocusedItem();
|
||||||
|
if (focusedItem != null && !focusedItem.getName().equals("..")) {
|
||||||
|
initialValue = focusedItem.getName();
|
||||||
|
}
|
||||||
String dirNameInput = JOptionPane.showInputDialog(this,
|
String dirNameInput = JOptionPane.showInputDialog(this,
|
||||||
"New directory name:",
|
"New directory name:",
|
||||||
"New directory");
|
initialValue);
|
||||||
|
|
||||||
if (dirNameInput != null && !dirNameInput.trim().isEmpty()) {
|
if (dirNameInput != null && !dirNameInput.trim().isEmpty()) {
|
||||||
final String dirName = dirNameInput.trim();
|
final String dirName = dirNameInput.trim();
|
||||||
@ -1811,6 +1817,32 @@ public class MainWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createNewFile() {
|
||||||
|
String initialValue = "New file.txt";
|
||||||
|
FileItem focusedItem = activePanel.getFocusedItem();
|
||||||
|
if (focusedItem != null && !focusedItem.getName().equals("..")) {
|
||||||
|
initialValue = focusedItem.getName();
|
||||||
|
}
|
||||||
|
String fileNameInput = JOptionPane.showInputDialog(this,
|
||||||
|
"New file name:",
|
||||||
|
initialValue);
|
||||||
|
|
||||||
|
if (fileNameInput != null && !fileNameInput.trim().isEmpty()) {
|
||||||
|
final String fileName = fileNameInput.trim();
|
||||||
|
performFileOperation((callback) -> {
|
||||||
|
FileOperations.createFile(activePanel.getCurrentDirectory(), fileName);
|
||||||
|
}, "File created", false, () -> {
|
||||||
|
if (activePanel != null && activePanel.getCurrentTab() != null) {
|
||||||
|
activePanel.getCurrentTab().selectItem(fileName);
|
||||||
|
}
|
||||||
|
}, activePanel);
|
||||||
|
} else {
|
||||||
|
if (activePanel != null && activePanel.getFileTable() != null) {
|
||||||
|
activePanel.getFileTable().requestFocusInWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show search dialog
|
* Show search dialog
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user