Skip to content

Commit

Permalink
fix bug using wrong parameter
Browse files Browse the repository at this point in the history
remove l10n keys
  • Loading branch information
Siedlerchr committed Jan 10, 2021
1 parent aebd602 commit 0e8cfbb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean, List<Path>> fileListPartition;

try (Stream<Path> filesStream = StreamSupport.stream(Files.newDirectoryStream(file, ff).spliterator(), false)) {
try (Stream<Path> 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()));
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> isDirectory = path -> Files.isDirectory(Path.of(path));
scanDirectoryValidator = new FunctionBasedValidator<>(directoryPath, isDirectory,
ValidationMessage.error(Localization.lang("Please enter a valid file path.")));

Predicate<String> 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() {
Expand All @@ -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);
}

Expand All @@ -169,7 +168,7 @@ public void startExport() {
applyButtonDisabled.setValue(true);

FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withInitialDirectory(preferences.getWorkingDir()).build();
.withInitialDirectory(preferences.getWorkingDir()).build();
Optional<Path> exportPath = dialogService.showFileSaveDialog(fileDialogConfiguration);

if (exportPath.isEmpty()) {
Expand All @@ -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");
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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<FileNodeViewModel> treeRoot() {
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0e8cfbb

Please sign in to comment.