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 3 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
2 changes: 1 addition & 1 deletion .idea/runConfigurations/JabRef_Main.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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 an extra option to ask the user whether they want to open the folder where they saved the file with the file selected [#8195] (https://github.com/JabRef/jabref/issues/8195)

### Changed

Expand Down
1 change: 0 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=8cc27038d5dbd815759851ba53e70cf62e481b87494cc97cfd97982ada5ba634
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
42 changes: 39 additions & 3 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.TimerTask;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

Expand All @@ -17,8 +18,10 @@
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.geometry.Orientation;
import javafx.scene.Group;
import javafx.scene.Node;
Expand Down Expand Up @@ -145,8 +148,10 @@
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.EasyObservableList;
import com.tobiasdiez.easybind.Subscription;
import org.controlsfx.control.NotificationPane;
import org.controlsfx.control.PopOver;
import org.controlsfx.control.TaskProgressView;
import org.controlsfx.control.action.Action;
import org.fxmisc.richtext.CodeArea;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -178,6 +183,7 @@ public class JabRefFrame extends BorderPane {
private TabPane tabbedPane;
private PopOver progressViewPopOver;
private PopOver entryFromIdPopOver;
private NotificationPane notificationPane;

private Subscription dividerSubscription;

Expand Down Expand Up @@ -437,6 +443,8 @@ private void initLayout() {
head.setSpacing(0d);
setTop(head);

// wrap the split pane into notification pane
notificationPane = new NotificationPane(splitPane);
splitPane.getItems().addAll(tabbedPane);
SplitPane.setResizableWithParent(sidePane, false);

Expand All @@ -455,7 +463,35 @@ public void invalidated(Observable observable) {
}
});

setCenter(splitPane);
setCenter(notificationPane);
}

// pass in the text value on the left, and the buttonName on the right of the notification bar
// and an eventHandler that act when the user click the button
public void showNotificationPane(String text, String buttonName, Consumer<ActionEvent> eventHandler) {
notificationPane.setText(text);
ObservableList<Action> actions = notificationPane.getActions();
Action action = new Action(buttonName, eventHandler);
// avoid multiple actions be added to the notification Pane, only one action is allowed
if (actions.isEmpty()) {
actions.add(action);
} else {
actions.set(0, action);
}
notificationPane.show();
// the notification bar will disappear if the user doesn't have actions in 10 seconds
new Thread(() -> {
calixtus marked this conversation as resolved.
Show resolved Hide resolved
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
// Ignore
}
Platform.runLater(() -> notificationPane.hide());
}).start();
}

public NotificationPane getNotificationPane() {
return notificationPane;
}

private void updateSidePane() {
Expand Down Expand Up @@ -710,8 +746,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(false, stateManager, dialogService, prefs, this)),
factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(true, stateManager, dialogService, prefs, this)),
factory.createMenuItem(StandardActions.SAVE_SELECTED_AS_PLAIN_BIBTEX, new SaveAction(SaveAction.SaveMethod.SAVE_SELECTED, this, prefs, stateManager))),

new SeparatorMenuItem(),
Expand Down
38 changes: 36 additions & 2 deletions src/main/java/org/jabref/gui/exporter/ExportCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.exporter;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -10,9 +11,12 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.JabRefFrame;
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.theme.Theme;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.FileFilterConverter;
Expand All @@ -28,9 +32,13 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.PreferencesService;

import org.controlsfx.control.NotificationPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.jabref.gui.theme.Theme.Type.DEFAULT;
import static org.jabref.gui.theme.Theme.Type.EMBEDDED;

/**
* Performs an export action
*/
Expand All @@ -41,14 +49,16 @@ public class ExportCommand extends SimpleCommand {
private final StateManager stateManager;
private final PreferencesService preferences;
private final DialogService dialogService;
private JabRefFrame jabRefFrame;

/**
* @param selectedOnly true if only the selected entries should be exported, otherwise all entries are exported
*/
public ExportCommand(boolean selectedOnly,
StateManager stateManager,
DialogService dialogService,
PreferencesService preferences) {
PreferencesService preferences,
JabRefFrame jabRefFrame) {
this.selectedOnly = selectedOnly;
this.stateManager = stateManager;
this.preferences = preferences;
Expand All @@ -57,6 +67,8 @@ public ExportCommand(boolean selectedOnly,
this.executable.bind(selectedOnly
? ActionHelper.needsEntriesSelected(stateManager)
: ActionHelper.needsDatabase(stateManager));

this.jabRefFrame = jabRefFrame;
}

@Override
Expand All @@ -82,6 +94,7 @@ public void execute() {
.ifPresent(path -> export(path, fileDialogConfiguration.getSelectedExtensionFilter(), exporters));
}

@SuppressWarnings("checkstyle:EmptyLineSeparator")
calixtus marked this conversation as resolved.
Show resolved Hide resolved
private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilter, List<Exporter> exporters) {
String selectedExtension = selectedExtensionFilter.getExtensions().get(0).replace("*", "");
if (!file.endsWith(selectedExtension)) {
Expand Down Expand Up @@ -114,14 +127,35 @@ 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(
x -> {
calixtus marked this conversation as resolved.
Show resolved Hide resolved
NotificationPane notificationPane = jabRefFrame.getNotificationPane();
Theme.Type themeType = preferences.getAppearancePreferences().getTheme().getType();
if (themeType == EMBEDDED) {
notificationPane.getStyleClass().add(NotificationPane.STYLE_CLASS_DARK);
}
if (themeType == DEFAULT) {
notificationPane.getStyleClass().remove(NotificationPane.STYLE_CLASS_DARK);
}
jabRefFrame.showNotificationPane(Localization.lang("Do you want to open the file in folder?"),
Localization.lang("Open"),
e -> {
calixtus marked this conversation as resolved.
Show resolved Hide resolved
try {
JabRefDesktop.openFolderAndSelectFile(file, preferences);
notificationPane.hide();
} catch (IOException ioException) {
LOGGER.info(Localization.lang("Error occurs when open the folder."));
calixtus marked this conversation as resolved.
Show resolved Hide resolved
}
});
})
.onFailure(this::handleError)
.executeWith(Globals.TASK_EXECUTOR);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Unable\ to\ monitor\ file\ changes.\ Please\ close\ files\ and\ processes\ and\

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

%0\ export\ successful=%0 export successful
Do\ you\ want\ to\ open\ the\ file\ in\ folder?=Do you want to open the file in folder?

Error\ occurs\ when\ open\ the\ folder.=Error occurs when open the folder.

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

Expand Down