Example #1
0
  private File getSelectedDirectory() {
    File directory = getSelectedFile();

    if (directory != null && !directory.isDirectory()) directory = directory.getParentFile();

    return directory;
  }
Example #2
0
  @FXML
  private void renameButtonClicked(final ActionEvent event) {
    final File selectedFile = getSelectedFile();
    final File parent = selectedFile.getParentFile();

    final String newName =
        showCreateOrRenameDialog(
            "Rename",
            "What should be the new name?",
            parent,
            selectedFile.getName(),
            (name) -> !selectedFile.getName().equals(name) && !createFile(parent, name).exists());

    if (newName != null) {
      final File newFile = createFile(parent, newName);
      if (!selectedFile.renameTo(newFile))
        showErrorDialog(
            "Failed to rename file!",
            "The file could not be renamed! Maybe you're missing the required permissions?!");
      else {
        refresh();
        getSelectedFiles().clear();
        getSelectedFiles().add(newFile);
      }
    }
  }