Skip to content

Commit

Permalink
feat: implement initial solution to incorporating DefaultFileMonitor …
Browse files Browse the repository at this point in the history
…to LatexCitation (JabRef#10585)

Known Issues:

Sometimes throws ConcurrentModificationException from DefaultFileUpdateMonitor whenever a change occurs in the tracked directory

Does not have any kind of shutdown

Is not able to track changes in nested directories

Does not handle whenever a directory is changed from the initial one properly

Makes use of a Deprecated Class
  • Loading branch information
VinterSallad committed Feb 27, 2024
1 parent d811923 commit 426b0bf
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.TaskExecutor;
Expand All @@ -28,6 +29,7 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.texparser.Citation;
import org.jabref.model.texparser.LatexParserResult;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

import org.slf4j.Logger;
Expand Down Expand Up @@ -55,6 +57,7 @@ enum Status {
private Future<?> searchTask;
private LatexParserResult latexParserResult;
private BibEntry currentEntry;
private final FileUpdateMonitor fileUpdateMonitor;

public LatexCitationsTabViewModel(BibDatabaseContext databaseContext,
PreferencesService preferencesService,
Expand All @@ -69,6 +72,8 @@ public LatexCitationsTabViewModel(BibDatabaseContext databaseContext,
this.citationList = FXCollections.observableArrayList();
this.status = new SimpleObjectProperty<>(Status.IN_PROGRESS);
this.searchError = new SimpleStringProperty("");

this.fileUpdateMonitor = Globals.getFileUpdateMonitor();
}

public void init(BibEntry entry) {
Expand Down Expand Up @@ -130,6 +135,7 @@ private Collection<Citation> searchAndParse(String citeKey) throws IOException {
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory()));

if (latexParserResult == null || !newDirectory.equals(directory.get())) {
fileUpdateMonitor.addListenerForFile(newDirectory, this::refreshLatexDirectory);
directory.set(newDirectory);

if (!newDirectory.toFile().exists()) {
Expand Down

0 comments on commit 426b0bf

Please sign in to comment.