Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into storeColumnSortOrder
Browse files Browse the repository at this point in the history
* upstream/master:
  Fix that web search pane steals input (#4335)
  Fix entry editor field display (#4333)
  Convert update worker to BackgroundTask (#4334)
  Fix that "Rename and move file" throws file not found exception (#4317)
  • Loading branch information
Siedlerchr committed Sep 12, 2018
2 parents 6e9a564 + 7775e05 commit 5aad511
Show file tree
Hide file tree
Showing 79 changed files with 711 additions and 895 deletions.
12 changes: 3 additions & 9 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.dialogs.BackupUIManager;
import org.jabref.gui.help.VersionWorker;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.importer.ParserResultWarningDialog;
import org.jabref.gui.importer.actions.OpenDatabaseAction;
import org.jabref.gui.shared.SharedDatabaseUIManager;
import org.jabref.gui.worker.VersionWorker;
import org.jabref.logic.autosaveandbackup.BackupManager;
import org.jabref.logic.importer.OpenDatabase;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
import org.jabref.logic.util.Version;
import org.jabref.model.database.shared.DatabaseNotSupportedException;
import org.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -60,13 +59,8 @@ public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBl
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));

openWindow(mainStage);
JabRefGUI.checkForNewVersion(false);
}

public static void checkForNewVersion(boolean manualExecution) {
Version toBeIgnored = Globals.prefs.getVersionPreferences().getIgnoredVersion();
Version currentVersion = Globals.BUILD_INFO.getVersion();
new VersionWorker(JabRefGUI.getMainFrame(), manualExecution, currentVersion, toBeIgnored).execute();
new VersionWorker(Globals.BUILD_INFO.getVersion(), Globals.prefs.getVersionPreferences().getIgnoredVersion(), JabRefGUI.getMainFrame().getDialogService(), Globals.TASK_EXECUTOR)
.checkForNewVersionAsync(false);
}

private void openWindow(Stage mainStage) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
BibDatabaseContext databaseContext = pr.getDatabaseContext();
databaseContext.setDatabaseFile(theFile);
Globals.prefs.fileDirForDatabase = databaseContext
.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());
.getFileDirectories(Globals.prefs.getFilePreferences());
System.out.println(Localization.lang("Exporting") + ": " + data[0]);
Optional<Exporter> exporter = Globals.exportFactory.getExporterByName(data[1]);
if (!exporter.isPresent()) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas
this.tableModel = new MainTableDataModel(getBibDatabaseContext());

citationStyleCache = new CitationStyleCache(bibDatabaseContext);
annotationCache = new FileAnnotationCache(bibDatabaseContext, Globals.prefs.getFileDirectoryPreferences());
annotationCache = new FileAnnotationCache(bibDatabaseContext, Globals.prefs.getFilePreferences());

setupMainPanel();

Expand Down Expand Up @@ -368,7 +368,7 @@ private void setupActions() {
actions.put(Actions.OPEN_EXTERNAL_FILE, this::openExternalFile);

actions.put(Actions.OPEN_FOLDER, () -> JabRefExecutorService.INSTANCE.execute(() -> {
final List<Path> files = FileUtil.getListOfLinkedFiles(mainTable.getSelectedEntries(), bibDatabaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences()));
final List<Path> files = FileUtil.getListOfLinkedFiles(mainTable.getSelectedEntries(), bibDatabaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()));
for (final Path f : files) {
try {
JabRefDesktop.openFolderAndSelectFile(f.toAbsolutePath());
Expand Down Expand Up @@ -1398,7 +1398,7 @@ public void searchAndOpen() {
}

final Set<ExternalFileType> types = ExternalFileTypes.getInstance().getExternalFileTypeSelection();
final List<Path> dirs = basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
final List<Path> dirs = basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences());
final List<String> extensions = types.stream().map(ExternalFileType::getExtension).collect(Collectors.toList());

// Run the search operation:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ private MenuBar createMenu() {

new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.SEARCH_FOR_UPDATES, new SearchForUpdateAction()),
factory.createMenuItem(StandardActions.SEARCH_FOR_UPDATES, new SearchForUpdateAction(Globals.BUILD_INFO, prefs.getVersionPreferences(), dialogService, Globals.TASK_EXECUTOR)),
factory.createSubMenu(StandardActions.WEB_MENU,
factory.createMenuItem(StandardActions.OPEN_WEBPAGE, new OpenBrowserAction("https://jabref.org/")),
factory.createMenuItem(StandardActions.OPEN_BLOG, new OpenBrowserAction("https://blog.jabref.org/")),
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/org/jabref/gui/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.event.FieldChangedEvent;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreviewPreferences;

import com.google.common.eventbus.Subscribe;
Expand Down Expand Up @@ -89,12 +88,10 @@ public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext, KeyBind
this.keyBindingRepository = keyBindingRepository;

fileHandler = new NewDroppedFileHandler(dialogService, databaseContext, externalFileTypes,
Globals.prefs.getFileDirectoryPreferences(),
Globals.prefs.getCleanupPreferences(Globals.journalAbbreviationLoader).getFileDirPattern(),
Globals.prefs.getFilePreferences(),
Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getUpdateFieldPreferences(),
Globals.getFileUpdateMonitor(),
Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN));
Globals.getFileUpdateMonitor());

// Set up scroll pane for preview pane
setFitToHeight(true);
Expand Down Expand Up @@ -153,8 +150,7 @@ public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext, KeyBind
});

createKeyBindings();
updateLayout(preferences);

updateLayout(preferences, true);
}

private void createKeyBindings() {
Expand Down Expand Up @@ -211,6 +207,10 @@ public void setBasePanel(BasePanel basePanel) {
}

public void updateLayout(PreviewPreferences previewPreferences) {
updateLayout(previewPreferences, false);
}

private void updateLayout(PreviewPreferences previewPreferences, boolean init) {
if (fixedLayout) {
LOGGER.debug("cannot change the layout because the layout is fixed");
return;
Expand All @@ -223,12 +223,16 @@ public void updateLayout(PreviewPreferences previewPreferences) {
CitationStyle.createCitationStyleFromFile(style)
.ifPresent(citationStyle -> {
basePanel.get().getCitationStyleCache().setCitationStyle(citationStyle);
basePanel.get().output(Localization.lang("Preview style changed to: %0", citationStyle.getTitle()));
if (!init) {
basePanel.get().output(Localization.lang("Preview style changed to: %0", citationStyle.getTitle()));
}
});
}
} else {
updatePreviewLayout(previewPreferences.getPreviewStyle(), previewPreferences.getLayoutFormatterPreferences());
basePanel.ifPresent(panel -> panel.output(Localization.lang("Preview style changed to: %0", Localization.lang("Preview"))));
if (!init) {
basePanel.ifPresent(panel -> panel.output(Localization.lang("Preview style changed to: %0", Localization.lang("Preview"))));
}
}

update();
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/org/jabref/gui/actions/CleanupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ private void doCleanup(CleanupPreset preset, BibEntry entry, NamedCompound ce) {
Globals.journalAbbreviationLoader));
List<FieldChange> changes = cleaner.cleanup(preset, entry);

unsuccessfulRenames = cleaner.getUnsuccessfulRenames();

if (changes.isEmpty()) {
return;
}
Expand All @@ -90,11 +88,7 @@ private void showResults() {
if (isCanceled) {
return;
}
if (unsuccessfulRenames > 0) { //Rename failed for at least one entry
dialogService.showErrorDialogAndWait(
Localization.lang("Autogenerate PDF Names"),
Localization.lang("File rename failed for %0 entries.", Integer.toString(unsuccessfulRenames)));
}

if (modifiedEntriesCount > 0) {
panel.updateEntryEditorIfShowing();
panel.markBaseChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IntegrityCheckAction(JabRefFrame frame) {
@Override
public void execute() {
IntegrityCheck check = new IntegrityCheck(frame.getCurrentBasePanel().getBibDatabaseContext(),
Globals.prefs.getFileDirectoryPreferences(),
Globals.prefs.getFilePreferences(),
Globals.prefs.getBibtexKeyPatternPreferences(),
Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()),
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/org/jabref/gui/actions/SearchForUpdateAction.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
package org.jabref.gui.actions;

import org.jabref.JabRefGUI;
import org.jabref.gui.DialogService;
import org.jabref.gui.help.VersionWorker;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.util.BuildInfo;
import org.jabref.preferences.VersionPreferences;

public class SearchForUpdateAction extends SimpleCommand {

private final BuildInfo buildInfo;
private final VersionPreferences versionPreferences;
private final DialogService dialogService;
private final TaskExecutor taskExecutor;

public SearchForUpdateAction(BuildInfo buildInfo, VersionPreferences versionPreferences, DialogService dialogService, TaskExecutor taskExecutor) {
this.buildInfo = buildInfo;
this.versionPreferences = versionPreferences;
this.dialogService = dialogService;
this.taskExecutor = taskExecutor;
}

@Override
public void execute() {
JabRefGUI.checkForNewVersion(true);
new VersionWorker(buildInfo.getVersion(), versionPreferences.getIgnoredVersion(), dialogService, taskExecutor)
.checkForNewVersionAsync(true);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/actions/WriteXMPAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void writeXMP() {
// Make a list of all PDFs linked from this entry:
List<Path> files = entry.getFiles().stream()
.filter(file -> file.getFileType().equalsIgnoreCase("pdf"))
.map(file -> file.findIn(basePanel.getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences()))
.map(file -> file.findIn(basePanel.getBibDatabaseContext(), Globals.prefs.getFilePreferences()))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void init() {
cleanUpISSN = new JCheckBox(Localization.lang("Reformat ISSN"));

Optional<Path> firstExistingDir = databaseContext
.getFirstExistingFileDir(JabRefPreferences.getInstance().getFileDirectoryPreferences());
.getFirstExistingFileDir(JabRefPreferences.getInstance().getFilePreferences());
if (firstExistingDir.isPresent()) {
cleanUpMovePDF = new JCheckBox(Localization.lang("Move linked files to default file directory %0",
firstExistingDir.get().toString()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected List<CopyFilesResultItemViewModel> call() throws InterruptedException,

LinkedFile fileName = files.get(j);

Optional<Path> fileToExport = fileName.findIn(databaseContext, Globals.prefs.getFileDirectoryPreferences());
Optional<Path> fileToExport = fileName.findIn(databaseContext, Globals.prefs.getFilePreferences());

newPath = OptionalUtil.combine(Optional.of(exportPath), fileToExport, resolvePathFilename);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void openExternalViewer(BibDatabaseContext databaseContext, String
String fieldName = initialFieldName;
if (FieldName.PS.equals(fieldName) || FieldName.PDF.equals(fieldName)) {
// Find the default directory for this field type:
List<String> dir = databaseContext.getFileDirectories(fieldName, Globals.prefs.getFileDirectoryPreferences());
List<String> dir = databaseContext.getFileDirectories(fieldName, Globals.prefs.getFilePreferences());

Optional<Path> file = FileHelper.expandFilename(link, dir);

Expand Down Expand Up @@ -128,7 +128,7 @@ public static boolean openExternalFileAnyFormat(final BibDatabaseContext databas
return true;
}

Optional<Path> file = FileHelper.expandFilename(databaseContext, link, Globals.prefs.getFileDirectoryPreferences());
Optional<Path> file = FileHelper.expandFilename(databaseContext, link, Globals.prefs.getFilePreferences());
if (file.isPresent() && Files.exists(file.get())) {
// Open the file:
String filePath = file.get().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ private void setCurrentDocument(Path path) {
public void switchToFile(LinkedFile file) {
if (file != null) {
stateManager.getActiveDatabase().ifPresent(database ->
file.findIn(database, Globals.prefs.getFileDirectoryPreferences())
.ifPresent(this::setCurrentDocument));
file.findIn(database, Globals.prefs.getFilePreferences())
.ifPresent(this::setCurrentDocument));
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.JabRefPreferences;

import com.airhacks.afterburner.views.ViewLoader;
import org.fxmisc.easybind.EasyBind;
Expand Down Expand Up @@ -102,12 +101,10 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpda
this.dialogService = dialogService;

fileHandler = new NewDroppedFileHandler(dialogService, databaseContext, externalFileTypes,
Globals.prefs.getFileDirectoryPreferences(),
Globals.prefs.getCleanupPreferences(Globals.journalAbbreviationLoader).getFileDirPattern(),
Globals.prefs.getFilePreferences(),
Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getUpdateFieldPreferences(),
Globals.getFileUpdateMonitor(),
Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN));
Globals.getFileUpdateMonitor());

ViewLoader.view(this)
.root(this)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/exporter/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel()
.getBibDatabaseContext()
.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());
.getBibDatabaseContext()
.getFileDirectories(Globals.prefs.getFilePreferences());

// Make sure we remember which filter was used, to set
// the default for next time:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private String exportToClipboard(Exporter exporter) {
// Set the global variable for this database's file directory before exporting,
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences()).stream().map(Path::toString).collect(Collectors.toList());
Globals.prefs.fileDirForDatabase = panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()).stream().map(Path::toString).collect(Collectors.toList());

Path tmp = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.metadata.FileDirectoryPreferences;
import org.jabref.model.metadata.FilePreferences;
import org.jabref.model.util.FileHelper;

import org.slf4j.Logger;
Expand All @@ -31,8 +31,8 @@ public class AutoSetFileLinksUtil {
private AutoLinkPreferences autoLinkPreferences;
private ExternalFileTypes externalFileTypes;

public AutoSetFileLinksUtil(BibDatabaseContext databaseContext, FileDirectoryPreferences fileDirectoryPreferences, AutoLinkPreferences autoLinkPreferences, ExternalFileTypes externalFileTypes) {
this(databaseContext.getFileDirectoriesAsPaths(fileDirectoryPreferences), autoLinkPreferences, externalFileTypes);
public AutoSetFileLinksUtil(BibDatabaseContext databaseContext, FilePreferences filePreferences, AutoLinkPreferences autoLinkPreferences, ExternalFileTypes externalFileTypes) {
this(databaseContext.getFileDirectoriesAsPaths(filePreferences), autoLinkPreferences, externalFileTypes);
}

public AutoSetFileLinksUtil(List<Path> directories, AutoLinkPreferences autoLinkPreferences, ExternalFileTypes externalFileTypes) {
Expand Down Expand Up @@ -68,7 +68,7 @@ public List<LinkedFile> findAssociatedNotLinkedFiles(BibEntry entry) throws IOEx
.orElse(Optional.of(new UnknownExternalFileType("")));

String strType = type.isPresent() ? type.get().getName() : "";
String relativeFilePath = FileUtil.shortenFileName(foundFile, directories).toString();
String relativeFilePath = FileUtil.relativize(foundFile, directories).toString();
LinkedFile linkedFile = new LinkedFile("", relativeFilePath, strType);
linkedFiles.add(linkedFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static Runnable autoSetLinks(final List<BibEntry> entries, final NamedCom

Runnable r = () -> {
boolean foundAny = false;
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(databaseContext, Globals.prefs.getFileDirectoryPreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance());
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(databaseContext, Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance());

for (BibEntry entry : entries) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void download(URL url, String mimeType, final DownloadCallback callback)
fileType = ExternalFileTypes.getInstance().getExternalFileTypeByExt(suffix);
}
String suggestedName = getSuggestedFileName(suffix);
List<String> fDirectory = databaseContext.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());
List<String> fDirectory = databaseContext.getFileDirectories(Globals.prefs.getFilePreferences());
String directory;
if (fDirectory.isEmpty()) {
directory = null;
Expand Down
Loading

0 comments on commit 5aad511

Please sign in to comment.