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 an extra dialog to ask the user whether they want to open the saved file folder when the export the entries #8567

Merged
merged 21 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
### Added

- We added an extra option when right-clicking an entry in the Entry List to copy either the DOI or the DOI url.
- We added a new section to network preferences to allow using custom SSL certificates [#8126](https://github.com/JabRef/jabref/issues/8126)
- We improved the version check to take also beta version into account and now redirect to the right changelog for the version
- We added two new web and fulltext fetchers: SemanticScholar and ResearchGate
- We added an extra option to ask the user whether they want to open to reveal the folder holding the saved file with the file selected. [#8195](https://github.com/JabRef/jabref/issues/8195)
- We added a new section to network preferences to allow using custom SSL certificates. [#8126](https://github.com/JabRef/jabref/issues/8126)
- We improved the version check to take also beta version into account and now redirect to the right changelog for the version.
- We added two new web and fulltext fetchers: SemanticScholar and ResearchGate.

### Changed

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1277,3 +1277,7 @@ TextFlow * {
.text-field:invalid {
-fx-background-color: rgba(240, 128, 128, 0.5);
}

.notification-pane .notification-bar > .pane .label {
-fx-text-fill: -fx-mid-text-color;
}
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ private MenuBar createMenu() {
factory.createMenuItem(StandardActions.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(this, true, prefs, stateManager))),

factory.createSubMenu(StandardActions.EXPORT,
factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(false, stateManager, dialogService, prefs)),
factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(true, stateManager, dialogService, prefs)),
factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(ExportCommand.ExportMethod.EXPORT_ALL, this, stateManager, dialogService, prefs)),
factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(ExportCommand.ExportMethod.EXPORT_SELECTED, this, stateManager, dialogService, prefs)),
factory.createMenuItem(StandardActions.SAVE_SELECTED_AS_PLAIN_BIBTEX, new SaveAction(SaveAction.SaveMethod.SAVE_SELECTED, this, prefs, stateManager))),

new SeparatorMenuItem(),
Expand Down
46 changes: 34 additions & 12 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Objects;
import java.util.Optional;

import javafx.animation.PauseTransition;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
Expand All @@ -19,12 +20,12 @@
import javafx.scene.control.Tab;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.BorderPane;
import javafx.util.Duration;

import org.jabref.gui.autocompleter.AutoCompletePreferences;
import org.jabref.gui.autocompleter.PersonNameSuggestionProvider;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.collab.DatabaseChangeMonitor;
import org.jabref.gui.collab.DatabaseChangePane;
import org.jabref.gui.dialogs.AutosaveUiManager;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand Down Expand Up @@ -71,6 +72,8 @@
import com.google.common.eventbus.Subscribe;
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.Subscription;
import org.controlsfx.control.NotificationPane;
import org.controlsfx.control.action.Action;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -94,7 +97,8 @@ public class LibraryTab extends Tab {
private MainTable mainTable;
private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING;
private SplitPane splitPane;
private DatabaseChangePane changePane;
private DatabaseNotification databaseNotificationPane;

private boolean saving;
private PersonNameSuggestionProvider searchAutoCompleter;
// Used to track whether the base has changed since last save.
Expand Down Expand Up @@ -496,6 +500,8 @@ public void setupMainPanel() {
createMainTable();

splitPane.getItems().add(mainTable);
databaseNotificationPane = new DatabaseNotification(splitPane);
setContent(databaseNotificationPane);

// Saves the divider position as soon as it changes
// We need to keep a reference to the subscription, otherwise the binding gets garbage collected
Expand All @@ -506,17 +512,14 @@ public void setupMainPanel() {
// Add changePane in case a file is present - otherwise just add the splitPane to the panel
Optional<Path> file = bibDatabaseContext.getDatabasePath();
if (file.isPresent()) {
// create changeMonitor and changePane so we get notifications about outside changes to the file.
resetChangeMonitorAndChangePane();
resetChangeMonitor();
} else {
if (bibDatabaseContext.getDatabase().hasEntries()) {
// if the database is not empty and no file is assigned,
// the database came from an import and has to be treated somehow
// -> mark as changed
this.changedProperty.setValue(true);
}
changePane = null;
this.setContent(splitPane);
}
}

Expand Down Expand Up @@ -737,19 +740,16 @@ public FileAnnotationCache getAnnotationCache() {
return annotationCache;
}

public void resetChangeMonitorAndChangePane() {
public void resetChangeMonitor() {
changeMonitor.ifPresent(DatabaseChangeMonitor::unregister);
changeMonitor = Optional.of(new DatabaseChangeMonitor(bibDatabaseContext,
Globals.getFileUpdateMonitor(),
Globals.TASK_EXECUTOR,
dialogService,
preferencesService,
stateManager,
themeManager));

changePane = new DatabaseChangePane(splitPane, bibDatabaseContext, changeMonitor.get());

this.setContent(changePane);
themeManager,
databaseNotificationPane));
}

public void copy() {
Expand Down Expand Up @@ -920,4 +920,26 @@ public void listen(FieldChangedEvent fieldChangedEvent) {
public IndexingTaskManager getIndexingTaskManager() {
return indexingTaskManager;
}

public static class DatabaseNotification extends NotificationPane {
public DatabaseNotification(Node content) {
super(content);
}

public void notify(Node graphic, String text, List<Action> actions, Duration duration) {
this.setGraphic(graphic);
this.setText(text);
this.getActions().setAll(actions);
this.show();
if (duration != null && !duration.equals(Duration.ZERO)) {
PauseTransition delay = new PauseTransition(duration);
delay.setOnFinished(e -> this.hide());
delay.play();
}
}
}

public DatabaseNotification getNotificationPane() {
return databaseNotificationPane;
}
}
19 changes: 18 additions & 1 deletion src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
import java.util.ArrayList;
import java.util.List;

import javafx.util.Duration;

import org.jabref.gui.DialogService;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.util.FileUpdateListener;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

import org.controlsfx.control.action.Action;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,7 +42,8 @@ public DatabaseChangeMonitor(BibDatabaseContext database,
DialogService dialogService,
PreferencesService preferencesService,
StateManager stateManager,
ThemeManager themeManager) {
ThemeManager themeManager,
LibraryTab.DatabaseNotification notificationPane) {
this.database = database;
this.fileMonitor = fileMonitor;
this.taskExecutor = taskExecutor;
Expand All @@ -54,6 +61,16 @@ public DatabaseChangeMonitor(BibDatabaseContext database,
LOGGER.error("Error while trying to monitor " + path, e);
}
});

addListener(changes -> notificationPane.notify(
IconTheme.JabRefIcons.SAVE.getGraphicNode(),
Localization.lang("The library has been modified by another program."),
List.of(new Action(Localization.lang("Dismiss changes"), event -> notificationPane.hide()),
new Action(Localization.lang("Review changes"), event -> {
dialogService.showCustomDialogAndWait(new ChangeDisplayDialog(database, changes));
notificationPane.hide();
})),
Duration.ZERO));
}

@Override
Expand Down
44 changes: 0 additions & 44 deletions src/main/java/org/jabref/gui/collab/DatabaseChangePane.java

This file was deleted.

43 changes: 34 additions & 9 deletions src/main/java/org/jabref/gui/exporter/ExportCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package org.jabref.gui.exporter;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import javafx.stage.FileChooser;
import javafx.util.Duration;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.FileFilterConverter;
Expand All @@ -28,6 +34,7 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.PreferencesService;

import org.controlsfx.control.action.Action;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,25 +43,28 @@
*/
public class ExportCommand extends SimpleCommand {

public enum ExportMethod { EXPORT_ALL, EXPORT_SELECTED }

private static final Logger LOGGER = LoggerFactory.getLogger(ExportCommand.class);
private final boolean selectedOnly;

private final ExportMethod exportMethod;
private final JabRefFrame frame;
private final StateManager stateManager;
private final PreferencesService preferences;
private final DialogService dialogService;

/**
* @param selectedOnly true if only the selected entries should be exported, otherwise all entries are exported
*/
public ExportCommand(boolean selectedOnly,
public ExportCommand(ExportMethod exportMethod,
JabRefFrame frame,
StateManager stateManager,
DialogService dialogService,
PreferencesService preferences) {
this.selectedOnly = selectedOnly;
this.exportMethod = exportMethod;
this.frame = frame;
this.stateManager = stateManager;
this.preferences = preferences;
this.dialogService = dialogService;

this.executable.bind(selectedOnly
this.executable.bind(exportMethod == ExportMethod.EXPORT_SELECTED
? ActionHelper.needsEntriesSelected(stateManager)
: ActionHelper.needsDatabase(stateManager));
}
Expand Down Expand Up @@ -91,7 +101,7 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt
final Exporter format = FileFilterConverter.getExporter(selectedExtensionFilter, exporters)
.orElseThrow(() -> new IllegalStateException("User didn't selected a file type for the extension"));
List<BibEntry> entries;
if (selectedOnly) {
if (exportMethod == ExportMethod.EXPORT_SELECTED) {
// Selected entries
entries = stateManager.getSelectedEntries();
} else {
Expand All @@ -114,14 +124,29 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt
preferences.getImportExportPreferences().setExportWorkingDirectory(file.getParent());

final List<BibEntry> finEntries = entries;

BackgroundTask
.wrap(() -> {
format.export(stateManager.getActiveDatabase().get(),
file,
finEntries);
return null; // can not use BackgroundTask.wrap(Runnable) because Runnable.run() can't throw Exceptions
})
.onSuccess(x -> dialogService.notify(Localization.lang("%0 export successful", format.getName())))
.onSuccess(save -> {
LibraryTab.DatabaseNotification notificationPane = frame.getCurrentLibraryTab().getNotificationPane();
notificationPane.notify(
IconTheme.JabRefIcons.FOLDER.getGraphicNode(),
Localization.lang("%0 export successful. Open the folder containing the saved file?", format.get),
List.of(new Action(Localization.lang("Open"), event -> {
try {
JabRefDesktop.openFolderAndSelectFile(file, preferences);
} catch (IOException e) {
LOGGER.error("Could not open export folder.", e);
}
notificationPane.hide();
})),
Duration.seconds(5));
})
.onFailure(this::handleError)
.executeWith(Globals.TASK_EXECUTOR);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ boolean saveAs(Path file, SaveDatabaseMode mode) {
context.setDatabasePath(file);
libraryTab.updateTabTitle(false);

// Reinstall AutosaveManager and BackupManager for the new file name
libraryTab.resetChangeMonitorAndChangePane();
// Reset (here: uninstall and install again) AutosaveManager and BackupManager for the new file name
libraryTab.resetChangeMonitor();
if (readyForAutosave(context)) {
AutosaveManager autosaver = AutosaveManager.start(context);
autosaver.registerListener(new AutosaveUiManager(libraryTab));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Unable\ to\ monitor\ file\ changes.\ Please\ close\ files\ and\ processes\ and\

%0/%1\ entries=%0/%1 entries

%0\ export\ successful=%0 export successful
%0\ export\ successful.\ Open\ the\ folder\ containing\ the\ saved\ file?=%0 export successful. Open the folder containing the saved file?

%0\ matches\ the\ regular\ expression\ <b>%1</b>=%0 matches the regular expression <b>%1</b>

Expand Down