Skip to content

Commit

Permalink
Preview and XMPWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed Feb 17, 2020
1 parent 40fc897 commit 0d2efc4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 20 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.jabref.gui.edit.ReplaceStringAction;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.exporter.SaveDatabaseAction;
import org.jabref.gui.exporter.WriteXMPAction;
import org.jabref.gui.externalfiles.DownloadFullTextAction;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand Down Expand Up @@ -355,16 +354,16 @@ private void setupActions() {
new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame));
}

actions.put(Actions.NEXT_PREVIEW_STYLE, () -> {
/* actions.put(Actions.NEXT_PREVIEW_STYLE, () -> {
entryEditor.nextPreviewStyle();
});
actions.put(Actions.PREVIOUS_PREVIEW_STYLE, () -> {
entryEditor.previousPreviewStyle();
});
}); */

actions.put(Actions.SEND_AS_EMAIL, new SendAsEMailAction(frame));

actions.put(Actions.WRITE_XMP, new WriteXMPAction(this)::execute);
// actions.put(Actions.WRITE_XMP, new WriteXMPAction(this)::execute);

actions.put(Actions.ABBREVIATE_DEFAULT, new AbbreviateAction(this, AbbreviationType.DEFAULT));
actions.put(Actions.ABBREVIATE_MEDLINE, new AbbreviateAction(this, AbbreviationType.MEDLINE));
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@
import org.jabref.gui.edit.ManageKeywordsAction;
import org.jabref.gui.edit.MassSetFieldsAction;
import org.jabref.gui.edit.OpenBrowserAction;
import org.jabref.gui.entryeditor.EntryEditorPreviewChangeAction;
import org.jabref.gui.exporter.ExportCommand;
import org.jabref.gui.exporter.ExportToClipboardAction;
import org.jabref.gui.exporter.ManageCustomExportsAction;
import org.jabref.gui.exporter.SaveAllAction;
import org.jabref.gui.exporter.SaveDatabaseAction;
import org.jabref.gui.exporter.WriteXMPAction;
import org.jabref.gui.externalfiles.AutoLinkFilesAction;
import org.jabref.gui.externalfiles.FindUnlinkedFilesAction;
import org.jabref.gui.externalfiletype.EditExternalFileTypesAction;
Expand Down Expand Up @@ -765,7 +767,7 @@ private MenuBar createMenu() {
factory.createMenuItem(StandardActions.PARSE_TEX, new ParseTexAction(stateManager)),
factory.createMenuItem(StandardActions.NEW_SUB_LIBRARY_FROM_AUX, new NewSubLibraryAction(this, stateManager)),
factory.createMenuItem(StandardActions.FIND_UNLINKED_FILES, new FindUnlinkedFilesAction(this, stateManager)),
factory.createMenuItem(StandardActions.WRITE_XMP, new OldDatabaseCommandWrapper(Actions.WRITE_XMP, this, stateManager)),
factory.createMenuItem(StandardActions.WRITE_XMP, new WriteXMPAction(stateManager, dialogService)),
factory.createMenuItem(StandardActions.COPY_LINKED_FILES, new CopyFilesAction(stateManager, this.getDialogService())),
factory.createMenuItem(StandardActions.EXTRACT_BIBTEX, new ExtractBibtexAction(stateManager)),

Expand Down Expand Up @@ -803,8 +805,8 @@ private MenuBar createMenu() {

new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.NEXT_PREVIEW_STYLE, new OldDatabaseCommandWrapper(Actions.NEXT_PREVIEW_STYLE, this, stateManager)),
factory.createMenuItem(StandardActions.PREVIOUS_PREVIEW_STYLE, new OldDatabaseCommandWrapper(Actions.PREVIOUS_PREVIEW_STYLE, this, stateManager)),
factory.createMenuItem(StandardActions.NEXT_PREVIEW_STYLE, new EntryEditorPreviewChangeAction(EntryEditorPreviewChangeAction.Direction.NEXT, this, stateManager)),
factory.createMenuItem(StandardActions.PREVIOUS_PREVIEW_STYLE, new EntryEditorPreviewChangeAction(EntryEditorPreviewChangeAction.Direction.PREVIOUS, this, stateManager)),

new SeparatorMenuItem(),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jabref.gui.entryeditor;

import org.jabref.gui.JabRefFrame;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;

import static org.jabref.gui.actions.ActionHelper.needsDatabase;

public class EntryEditorPreviewChangeAction extends SimpleCommand {

public enum Direction { PREVIOUS, NEXT }

private final JabRefFrame frame;
private final Direction direction;

public EntryEditorPreviewChangeAction(Direction direction, JabRefFrame frame, StateManager stateManager) {
this.frame = frame;
this.direction = direction;

this.executable.bind(needsDatabase(stateManager));
}

@Override
public void execute() {
if (direction == Direction.NEXT) {
frame.getCurrentBasePanel().getEntryEditor().nextPreviewStyle();
} else {
frame.getCurrentBasePanel().getEntryEditor().previousPreviewStyle();
}
}
}
33 changes: 20 additions & 13 deletions src/main/java/org/jabref/gui/exporter/WriteXMPAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,38 @@
import javafx.stage.Stage;

import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.FXDialog;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.xmp.XmpUtilWriter;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;

import static org.jabref.gui.actions.ActionHelper.needsDatabase;

public class WriteXMPAction extends SimpleCommand {

private final BasePanel basePanel;
private OptionsDialog optionsDialog;
private final StateManager stateManager;
private final DialogService dialogService;

private Collection<BibEntry> entries;
private OptionsDialog optionsDialog;

private BibDatabase database;
private Collection<BibEntry> entries;

private boolean shouldContinue = true;

private int skipped;
private int entriesChanged;
private int errors;
private final DialogService dialogService;

public WriteXMPAction(BasePanel basePanel) {
this.basePanel = basePanel;
dialogService = basePanel.frame().getDialogService();
public WriteXMPAction(StateManager stateManager, DialogService dialogService) {
this.stateManager = stateManager;
this.dialogService = dialogService;

this.executable.bind(needsDatabase(stateManager));
}

@Override
Expand All @@ -60,9 +63,13 @@ public void execute() {
}

public void init() {
database = basePanel.getDatabase();
if (stateManager.getActiveDatabase().isEmpty()) {
return;
}

database = stateManager.getActiveDatabase().get().getDatabase();
// Get entries and check if it makes sense to perform this operation
entries = basePanel.getSelectedEntries();
entries = stateManager.getSelectedEntries();

if (entries.isEmpty()) {

Expand Down Expand Up @@ -97,15 +104,15 @@ public void init() {
}

private void writeXMP() {
if (!shouldContinue) {
if (!shouldContinue || stateManager.getActiveDatabase().isEmpty()) {
return;
}

for (BibEntry entry : entries) {
// 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.getFilePreferences()))
.map(file -> file.findIn(stateManager.getActiveDatabase().get(), Globals.prefs.getFilePreferences()))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
Expand Down

0 comments on commit 0d2efc4

Please sign in to comment.