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

Fix default directory of the "LaTeX Citations" tab #8209

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- The metadata-to-pdf actions now also embeds the bibfile to the PDF. [#8037](https://github.com/JabRef/jabref/pull/8037)
- The snap was updated to use the core20 base and to use lzo compression for better startup performance [#8109](https://github.com/JabRef/jabref/pull/8109)
- We improved the Drag and Drop behavior in the "Customize Entry Types" Dialog [#6338](https://github.com/JabRef/jabref/issues/6338)
- When determing the URL of an ArXiV eprint, the URL now points to the version [#8149](https://github.com/JabRef/jabref/pull/8149)
- When determining the URL of an ArXiV eprint, the URL now points to the version [#8149](https://github.com/JabRef/jabref/pull/8149)
- We Included all standard fields with citation key when exporting to Old OpenOffice/LibreOffice Calc Format [#8176](https://github.com/JabRef/jabref/pull/8176)

### Fixed

- We fixed an issue where an exception ocurred when a linked online file was edited in the entry editor [#8008](https://github.com/JabRef/jabref/issues/8008)
- We fixed an issue where an exception occurred when a linked online file was edited in the entry editor [#8008](https://github.com/JabRef/jabref/issues/8008)
- We fixed an issue when checking for a new version when JabRef is used behind a corporate proxy. [#7884](https://github.com/JabRef/jabref/issues/7884)
- We fixed some icons that were drawn in the wrong color when JabRef used a custom theme. [#7853](https://github.com/JabRef/jabref/issues/7853)
- We fixed an issue where the `Aux file` on `Edit group` doesn't support relative sub-directories path to import. [#7719](https://github.com/JabRef/jabref/issues/7719).
Expand All @@ -54,6 +54,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where typing an invalid UNC path into the "Main file directory" text field caused an error. [#8107](https://github.com/JabRef/jabref/issues/8107)
- We fixed an issue where "Open Folder" didn't select the file on macOS in Finder [#8130](https://github.com/JabRef/jabref/issues/8130)
- We fixed an issue where importing PDFs resulted in an uncaught exception [#8143](https://github.com/JabRef/jabref/issues/8143)
- The default directory of the "LaTeX Citations" tab is now the directory of the currently opened database (and not the directory chosen at the last open file dialog or the last database save) [koppor#538](https://github.com/koppor/jabref/issues/538)
- We fixed an issue where right-clicking on a tab and selecting close will close the focused tab even if it is not the tab we right-clicked [#8193](https://github.com/JabRef/jabref/pull/8193)

### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.texparser.DefaultLatexParser;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.texparser.Citation;
Expand Down Expand Up @@ -65,8 +66,8 @@ public LatexCitationsTabViewModel(BibDatabaseContext databaseContext, Preference
this.preferencesService = preferencesService;
this.taskExecutor = taskExecutor;
this.dialogService = dialogService;
this.directory = new SimpleObjectProperty<>(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser())
.orElseGet(preferencesService::getWorkingDir));
this.directory = new SimpleObjectProperty(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser())
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService)));
this.citationList = FXCollections.observableArrayList();
this.status = new SimpleObjectProperty<>(Status.IN_PROGRESS);
this.searchError = new SimpleStringProperty("");
Expand Down Expand Up @@ -126,8 +127,9 @@ private void cancelSearch() {
}

private Collection<Citation> searchAndParse(String citeKey) throws IOException {
// we need to check whether the user meanwhile set the LaTeX file directory or the database changed locations
Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser())
.orElseGet(preferencesService::getWorkingDir);
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService));

if (latexParserResult == null || !newDirectory.equals(directory.get())) {
directory.set(newDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ public void texGroupBrowse() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(StandardFileType.AUX)
.withDefaultExtension(StandardFileType.AUX)
.withInitialDirectory(preferencesService.getWorkingDir()).build();
.withInitialDirectory(currentDatabase.getMetaData()
.getLatexFileDirectory(preferencesService.getUser())
.orElse(FileUtil.getInitialDirectory(currentDatabase, preferencesService))).build();
dialogService.showFileOpenDialog(fileDialogConfiguration)
.ifPresent(file -> texGroupFilePathProperty.setValue(
FileUtil.relativize(file.toAbsolutePath(), getFileDirectoriesAsPaths()).toString()
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/org/jabref/gui/slr/ExistingStudySearchAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.GeneralPreferences;
Expand Down Expand Up @@ -61,7 +62,9 @@ public ExistingStudySearchAction(JabRefFrame frame,
this.importFormatPreferences = preferencesService.getImportFormatPreferences();
this.savePreferences = preferencesService.getSavePreferences();

this.workingDirectory = getInitialDirectory(preferencesService.getWorkingDir());
this.workingDirectory = stateManager.getActiveDatabase()
.map(database -> FileUtil.getInitialDirectory(database, preferencesService))
.orElse(preferencesService.getWorkingDir());
}

@Override
Expand Down Expand Up @@ -102,9 +105,9 @@ public void crawl() {
}
dialogService.notify(Localization.lang("Searching"));
BackgroundTask.wrap(() -> {
crawler.performCrawl();
return 0; // Return any value to make this a callable instead of a runnable. This allows throwing exceptions.
})
crawler.performCrawl();
return 0; // Return any value to make this a callable instead of a runnable. This allows throwing exceptions.
})
.onFailure(e -> {
LOGGER.error("Error during persistence of crawling results.");
dialogService.showErrorDialogAndWait(Localization.lang("Error during persistence of crawling results."), e);
Expand All @@ -123,11 +126,4 @@ public void crawl() {
protected void setupRepository(Path studyRepositoryRoot) throws IOException, GitAPIException {
// Do nothing as repository is already setup
}

/**
* @return Path of current panel database directory or the standard working directory
*/
private Path getInitialDirectory(Path standardWorkingDirectory) {
return stateManager.getActiveDatabase().flatMap(database -> database.getDatabasePath().map(Path::getParent)).orElse(standardWorkingDirectory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.texparser.DefaultLatexParser;
import org.jabref.logic.texparser.TexBibEntriesResolver;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;
Expand Down Expand Up @@ -58,16 +59,18 @@ public class ParseLatexDialogViewModel extends AbstractViewModel {
private final BooleanProperty searchInProgress;
private final BooleanProperty successfulSearch;

public ParseLatexDialogViewModel(BibDatabaseContext databaseContext, DialogService dialogService,
TaskExecutor taskExecutor, PreferencesService preferencesService,
public ParseLatexDialogViewModel(BibDatabaseContext databaseContext,
DialogService dialogService,
TaskExecutor taskExecutor,
PreferencesService preferencesService,
FileUpdateMonitor fileMonitor) {
this.databaseContext = databaseContext;
this.dialogService = dialogService;
this.taskExecutor = taskExecutor;
this.preferencesService = preferencesService;
this.fileMonitor = fileMonitor;
this.latexFileDirectory = new SimpleStringProperty(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser())
.orElseGet(preferencesService::getWorkingDir)
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService))
.toAbsolutePath().toString());
this.root = new SimpleObjectProperty<>();
this.checkedFileList = FXCollections.observableArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static AbstractGroup texGroupFromString(String string, FileUpdateMonitor
return newGroup;
} catch (IOException ex) {
// Problem accessing file -> create without file monitoring
LOGGER.warn("Could not access file " + path + ". The group " + name + " will not reflect changes to the aux file.", ex);
LOGGER.warn("Could not access file {}. The group {} will not reflect changes to the aux file.", path, name, ex);

TexGroup newGroup = TexGroup.createWithoutFileMonitoring(name, context, path, new DefaultAuxParser(new BibDatabase()), fileMonitor, metaData);
addGroupDetails(tok, newGroup);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/logic/util/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

import org.jabref.logic.citationkeypattern.BracketedPattern;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.util.OptionalUtil;
import org.jabref.preferences.PreferencesService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -374,4 +376,11 @@ public static boolean isBibFile(Path file) {
public static boolean isPDFFile(Path file) {
return getFileExtension(file).filter(type -> "pdf".equals(type)).isPresent();
}

/**
* @return Path of current panel database directory or the standard working directory in case the datbase was not saved yet
*/
public static Path getInitialDirectory(BibDatabaseContext databaseContext, PreferencesService preferencesService) {
return databaseContext.getDatabasePath().map(Path::getParent).orElse(preferencesService.getWorkingDir());
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/preferences/PreferencesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,15 @@ public interface PreferencesService {

void clearEditedFiles();

/**
* Gets the directory for file browsing dialogs. This ensures that each browse dialog starts in the last visited
* browse directory.
*/
Path getWorkingDir();

/**
* Stores the directory for file browsing dialogs
*/
void setWorkingDirectory(Path dir);

//*************************************************************************************************************
Expand Down