diff --git a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesCrawler.java b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesCrawler.java index 0cd7f19587c..8400eb80851 100644 --- a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesCrawler.java +++ b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesCrawler.java @@ -64,16 +64,16 @@ protected FileNodeViewModel call() throws IOException { * resolve its recursion and return what it has saved so far. * @throws IOException */ - private FileNodeViewModel searchDirectory(Path file, UnlinkedPDFFileFilter ff) throws IOException { + private FileNodeViewModel searchDirectory(Path directory, UnlinkedPDFFileFilter fileFilter) throws IOException { // Return null if the directory is not valid. - if ((directory == null) || !directory.toFile().isDirectory()) { + if ((directory == null) || ! Files.isDirectory(directory)) { throw new IOException(String.format("Invalid directory for searching: %s", directory)); } FileNodeViewModel parent = new FileNodeViewModel(directory); Map> fileListPartition; - try (Stream filesStream = StreamSupport.stream(Files.newDirectoryStream(file, ff).spliterator(), false)) { + try (Stream filesStream = StreamSupport.stream(Files.newDirectoryStream(directory, fileFilter).spliterator(), false)) { fileListPartition = filesStream.collect(Collectors.partitioningBy(path -> path.toFile().isDirectory())); } catch (IOException e) { LOGGER.error(String.format("%s while searching files: %s", e.getClass().getName(), e.getMessage())); @@ -88,7 +88,7 @@ private FileNodeViewModel searchDirectory(Path file, UnlinkedPDFFileFilter ff) t int fileCount = 0; for (Path subDirectory : subDirectories) { - FileNodeViewModel subRoot = searchDirectory(subDirectory, ff); + FileNodeViewModel subRoot = searchDirectory(subDirectory, fileFilter); if (!subRoot.getChildren().isEmpty()) { fileCount += subRoot.getFileCount(); diff --git a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java index 6f92af19626..a18e5d60657 100644 --- a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java @@ -96,17 +96,16 @@ public UnlinkedFilesDialogViewModel(DialogService dialogService, ExternalFileTyp undoManager, stateManager); - this.fileFilterList = FXCollections.observableArrayList( - new FileExtensionViewModel(StandardFileType.ANY_FILE,externalFileTypes), - new FileExtensionViewModel(StandardFileType.BIBTEX_DB, externalFileTypes), - new FileExtensionViewModel(StandardFileType.PDF, externalFileTypes)); + this.fileFilterList = FXCollections.observableArrayList( + new FileExtensionViewModel(StandardFileType.ANY_FILE, externalFileTypes), + new FileExtensionViewModel(StandardFileType.BIBTEX_DB, externalFileTypes), + new FileExtensionViewModel(StandardFileType.PDF, externalFileTypes)); + Predicate isDirectory = path -> Files.isDirectory(Path.of(path)); + scanDirectoryValidator = new FunctionBasedValidator<>(directoryPath, isDirectory, + ValidationMessage.error(Localization.lang("Please enter a valid file path."))); - Predicate isDirectory = path -> Files.isDirectory(Path.of(path)); - scanDirectoryValidator = new FunctionBasedValidator<>(directoryPath, isDirectory, - ValidationMessage.error(Localization.lang("Please enter a valid file path."))); - - treeRoot.setValue(null); + treeRoot.setValue(null); } public void startImport() { @@ -121,34 +120,34 @@ public void startImport() { resultList.clear(); importFilesBackgroundTask = importHandler.importFilesInBackground(fileList) - .onRunning(() -> { - - progress.bind(importFilesBackgroundTask.workDonePercentageProperty()); - progressText.bind(importFilesBackgroundTask.messageProperty()); - - searchProgressVisible.setValue(true); - scanButtonDisabled.setValue(true); - applyButtonDisabled.setValue(true); - }) - .onFinished(() -> { - progress.unbind(); - progressText.unbind(); - searchProgressVisible.setValue(false); - scanButtonDisabled.setValue(false); - }) - .onSuccess(results -> { - applyButtonDisabled.setValue(false); - exportButtonDisabled.setValue(false); - scanButtonDefaultButton.setValue(false); - - progress.unbind(); - progressText.unbind(); - searchProgressVisible.setValue(false); - - filePaneExpanded.setValue(false); - resultPaneExpanded.setValue(true); - resultList.addAll(results); - }); + .onRunning(() -> { + + progress.bind(importFilesBackgroundTask.workDonePercentageProperty()); + progressText.bind(importFilesBackgroundTask.messageProperty()); + + searchProgressVisible.setValue(true); + scanButtonDisabled.setValue(true); + applyButtonDisabled.setValue(true); + }) + .onFinished(() -> { + progress.unbind(); + progressText.unbind(); + searchProgressVisible.setValue(false); + scanButtonDisabled.setValue(false); + }) + .onSuccess(results -> { + applyButtonDisabled.setValue(false); + exportButtonDisabled.setValue(false); + scanButtonDefaultButton.setValue(false); + + progress.unbind(); + progressText.unbind(); + searchProgressVisible.setValue(false); + + filePaneExpanded.setValue(false); + resultPaneExpanded.setValue(true); + resultList.addAll(results); + }); importFilesBackgroundTask.executeWith(taskExecutor); } @@ -169,7 +168,7 @@ public void startExport() { applyButtonDisabled.setValue(true); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withInitialDirectory(preferences.getWorkingDir()).build(); + .withInitialDirectory(preferences.getWorkingDir()).build(); Optional exportPath = dialogService.showFileSaveDialog(fileDialogConfiguration); if (exportPath.isEmpty()) { @@ -178,9 +177,8 @@ public void startExport() { return; } - try (BufferedWriter writer = - Files.newBufferedWriter(exportPath.get(), StandardCharsets.UTF_8, - StandardOpenOption.CREATE)) { + try (BufferedWriter writer = Files.newBufferedWriter(exportPath.get(), StandardCharsets.UTF_8, + StandardOpenOption.CREATE)) { for (Path file : fileList) { writer.write(file.toString() + "\n"); } @@ -203,35 +201,35 @@ public void startSearch() { progressText.unbind(); findUnlinkedFilesTask = new UnlinkedFilesCrawler(directory, selectedFileFilter, bibDatabase, preferences.getFilePreferences()) - .onRunning(() -> { - - progress.set(ProgressIndicator.INDETERMINATE_PROGRESS); - progressText.setValue(Localization.lang("Searching file system...")); - progressText.bind(findUnlinkedFilesTask.messageProperty()); - - searchProgressVisible.setValue(true); - scanButtonDisabled.setValue(true); - applyButtonDisabled.set(true); - treeRoot.setValue(null); - }) - .onFinished(() -> { - scanButtonDisabled.setValue(false); - applyButtonDisabled.setValue(false); - searchProgressVisible.set(false); - progress.set(0); - searchProgressVisible.set(false); - - }) - .onSuccess(root -> { - treeRoot.setValue(root); - progress.set(0); - - applyButtonDisabled.setValue(false); - exportButtonDisabled.setValue(false); - scanButtonDefaultButton.setValue(false); - searchProgressVisible.set(false); - }); - findUnlinkedFilesTask.executeWith(taskExecutor); + .onRunning(() -> { + + progress.set(ProgressIndicator.INDETERMINATE_PROGRESS); + progressText.setValue(Localization.lang("Searching file system...")); + progressText.bind(findUnlinkedFilesTask.messageProperty()); + + searchProgressVisible.setValue(true); + scanButtonDisabled.setValue(true); + applyButtonDisabled.set(true); + treeRoot.setValue(null); + }) + .onFinished(() -> { + scanButtonDisabled.setValue(false); + applyButtonDisabled.setValue(false); + searchProgressVisible.set(false); + progress.set(0); + searchProgressVisible.set(false); + + }) + .onSuccess(root -> { + treeRoot.setValue(root); + progress.set(0); + + applyButtonDisabled.setValue(false); + exportButtonDisabled.setValue(false); + scanButtonDefaultButton.setValue(false); + searchProgressVisible.set(false); + }); + findUnlinkedFilesTask.executeWith(taskExecutor); } public StringProperty directoryPath() { @@ -264,14 +262,14 @@ public BooleanProperty exportButtonDisabled() { public void browseFileDirectory() { DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(preferences.getWorkingDir()).build(); + .withInitialDirectory(preferences.getWorkingDir()).build(); dialogService.showDirectorySelectionDialog(directoryDialogConfiguration) - .ifPresent(selectedDirectory -> { - directoryPath.setValue(selectedDirectory.toAbsolutePath().toString()); - preferences.setWorkingDirectory(selectedDirectory.toAbsolutePath()); - this.scanButtonDisabled.setValue(false); - }); + .ifPresent(selectedDirectory -> { + directoryPath.setValue(selectedDirectory.toAbsolutePath().toString()); + preferences.setWorkingDirectory(selectedDirectory.toAbsolutePath()); + this.scanButtonDisabled.setValue(false); + }); } public ObjectProperty treeRoot() { diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 44d34c01a53..c5ecbe3de66 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2299,6 +2299,3 @@ Export\ selected=Export selected Unprotect\ terms=Unprotect terms Error\ connecting\ to\ Writer\ document=Error connecting to Writer document You\ need\ to\ open\ Writer\ with\ a\ document\ before\ connecting=You need to open Writer with a document before connecting - -%0\ (%1)\ files=%0 (%1) files -%0\ (%1)\ file=%0 (%1) file