Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileMonitor for LaTeX citations #10937

Closed
Closed
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
426b0bf
feat: implement initial solution to incorporating DefaultFileMonitor …
VinterSallad Feb 27, 2024
c2370b8
fix: address issues with concurrency in DefaultFileUpdateMonitor (Jab…
VinterSallad Feb 28, 2024
4eaf252
feat: improve logic for when filemonitor is added (JabRef#10585)
VinterSallad Feb 28, 2024
b4fa3a9
fix: revert the changes to DefaultFileUpdateMonitor and implement alt…
VinterSallad Feb 28, 2024
3e0f7a5
fix: refactor listener handling into methods (JabRef#10585)
VinterSallad Feb 29, 2024
3e7fb9e
feat: implement initial to listen a directory recursively (JabRef#10585)
roxannecvl Feb 29, 2024
14880ac
fix : refactor of listenerOnDirectory (JabRef#10585)
roxannecvl Feb 29, 2024
6c1bb03
Fix : If a change happens in an old directory, reload is no longer tr…
roxannecvl Feb 29, 2024
ce93345
fix: setListener started later and update to refreshLatexDirectory
MercuriaL01 Mar 1, 2024
71ea781
feat : implement proper shutdown (#10585)
rachedkko Mar 2, 2024
59797e5
fix : add one more test to improve the branch coverage (#10585)
rachedkko Mar 2, 2024
ba8adec
fix : add a remove listener method (#10585)
rachedkko Mar 3, 2024
fdd6750
fix : update the close method (#10585)
rachedkko Mar 3, 2024
dc161ca
fix : update the close method (#10585)
rachedkko Mar 3, 2024
ad19f5a
fix : add a shutdown method (#10585)
rachedkko Mar 3, 2024
8ff512e
fix : no override for the close method (#10585)
rachedkko Mar 3, 2024
afb4c09
fix : checkstyle (#10585)
rachedkko Mar 3, 2024
7f3b5f2
fix : checkstyle (#10585)
rachedkko Mar 3, 2024
653660e
fix : checkstyle (#10585)
rachedkko Mar 3, 2024
6f2982d
fix : checkstyle (#10585)
rachedkko Mar 3, 2024
2fd55bb
fix : checkstyle (#10585)
rachedkko Mar 3, 2024
2ea59b5
Update src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabView…
VinterSallad Mar 3, 2024
07423e8
fix : delete wrong testcase
rachedkko Mar 3, 2024
f3d3b90
Merge branch 'latexcitation-filemonitor-issue-10585' of github.com:ra…
rachedkko Mar 3, 2024
51848ad
fix: Added addListenerForDirectory method to interface
Emiesce Mar 3, 2024
7d1aa43
fix: Changed @param comment to match method parameter
Emiesce Mar 3, 2024
0eff465
fix : add a close method
rachedkko Mar 3, 2024
c3e9b13
fix : add a closeAllTabs method
rachedkko Mar 3, 2024
ac4950e
fix : make close an override method
rachedkko Mar 3, 2024
9318193
fix : call closeAllTabs for proper shutdown
rachedkko Mar 3, 2024
271e62c
Merge branch 'latexcitation-filemonitor-issue-10585' of github.com:ra…
rachedkko Mar 3, 2024
632f250
fix : delete incorrect method
rachedkko Mar 3, 2024
d0c1e0c
fix : make closeAllTabs public
rachedkko Mar 3, 2024
794291c
fix : stylefix
rachedkko Mar 3, 2024
79027ee
fix: Added suggested test case
Emiesce Mar 3, 2024
968bcf6
fix: Added suggested test case
Emiesce Mar 3, 2024
d670888
refactor: Moved searchAndParse and searchDirectory method to new Cita…
Emiesce Mar 4, 2024
c0b171e
fix: stylecheck fix
Emiesce Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Optional;
import java.util.concurrent.Future;

import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyListWrapper;
import javafx.beans.property.SimpleObjectProperty;
Expand All @@ -18,6 +19,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 +30,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 +58,8 @@ enum Status {
private Future<?> searchTask;
private LatexParserResult latexParserResult;
private BibEntry currentEntry;
private final FileUpdateMonitor fileUpdateMonitor;
private boolean hasListener;

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

this.fileUpdateMonitor = Globals.getFileUpdateMonitor();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a comment. I tried to think whether com.airhacks.afterburner.injection.Injector#instantiateModelOrService(java.lang.Class<T>) can be used. But it cannot be used, because it needs an empty constructor... Much more work at LatexCitationsTabViewModel required.

Background: The FileUpdateMonitor should not be retrieved by globals, but via the injector. One would need in org.jabref.gui.entryeditor.LatexCitationsTab#LatexCitationsTab at the first line (where the ViewModel is instanitated) to use com.airhacks.afterburner.injection.Injector#instantiateModelOrService(java.lang.Class<T>).

this.hasListener = false;
}

public void init(BibEntry entry) {
Expand All @@ -77,6 +85,8 @@ public void init(BibEntry entry) {
currentEntry = entry;
Optional<String> citeKey = entry.getCitationKey();

setListener(directory.get());

if (citeKey.isPresent()) {
startSearch(citeKey.get());
} else {
Expand Down Expand Up @@ -160,19 +170,41 @@ private List<Path> searchDirectory(Path directory) {
}
}

private void setListener(Path path) {
if (!hasListener) {
try {
fileUpdateMonitor.addListenerForFile(path, this::refreshLatexDirectory);
hasListener = true;
} catch (IOException e) {
LOGGER.error("Could not find file", e);
}
}
}

private void setListener(Path oldPath, Path newPath) {
try {
fileUpdateMonitor.removeListener(oldPath, this::refreshLatexDirectory);
fileUpdateMonitor.addListenerForFile(newPath, this::refreshLatexDirectory);
} catch (IOException e) {
LOGGER.error("Could not find file", e);
}
}

public void setLatexDirectory() {
DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder()
.withInitialDirectory(directory.get()).build();

dialogService.showDirectorySelectionDialog(directoryDialogConfiguration).ifPresent(selectedDirectory ->
databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost(), selectedDirectory.toAbsolutePath()));
dialogService.showDirectorySelectionDialog(directoryDialogConfiguration).ifPresent(selectedDirectory -> {
databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost(), selectedDirectory.toAbsolutePath());
setListener(directory.get(), selectedDirectory);
});

init(currentEntry);
}

public void refreshLatexDirectory() {
latexParserResult = null;
init(currentEntry);
Platform.runLater(() -> init(currentEntry));
}

public boolean shouldShow() {
Expand Down
Loading