Skip to content

Commit

Permalink
Merge branch 'replace_deprecated'
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Mar 6, 2020
2 parents d9a8088 + 17eb38b commit b6d6b79
Show file tree
Hide file tree
Showing 35 changed files with 992 additions and 920 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Added

- We added support for searching ShortScience for an entry through the user's browser. [#6018](https://github.com/JabRef/jabref/pull/6018)

### Changed

### Fixed
Expand All @@ -26,6 +28,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We reintroduced the index column. [#5844](https://github.com/JabRef/jabref/pull/5844)
- Filenames of external files can no longer contain curly braces. [#5926](https://github.com/JabRef/jabref/pull/5926)
- We made the filters more easily accessible in the integrity check dialog. [#5955](https://github.com/JabRef/jabref/pull/5955)
- We reimplemented and improved the dialog "Customize entry types" [#4719](https://github.com/JabRef/jabref/issues/4719)
- We reimplemented and improved the dialog "Customize entry types". [#4719](https://github.com/JabRef/jabref/issues/4719)

### Fixed
Expand Down
372 changes: 0 additions & 372 deletions src/main/java/org/jabref/gui/BasePanel.java

Large diffs are not rendered by default.

121 changes: 38 additions & 83 deletions src/main/java/org/jabref/gui/JabRefFrame.java

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions src/main/java/org/jabref/gui/OpenConsoleAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jabref.gui;

import java.io.IOException;

import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.model.database.BibDatabaseContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OpenConsoleAction extends SimpleCommand {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenConsoleAction.class);
private final StateManager stateManager;

public OpenConsoleAction(StateManager stateManager) {
this.stateManager = stateManager;

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

@Override
public void execute() {
stateManager.getActiveDatabase().flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> {
try {
JabRefDesktop.openConsole(path.toFile());
} catch (IOException e) {
LOGGER.info("Could not open console", e);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.gui.worker;
package org.jabref.gui;

import java.awt.Desktop;
import java.io.IOException;
Expand All @@ -9,15 +9,15 @@
import java.util.List;

import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.actions.BaseAction;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.logic.bibtex.BibEntryWriter;
import org.jabref.logic.bibtex.FieldWriter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.JabRefPreferences;

Expand All @@ -34,49 +34,50 @@
* are opened. This feature is disabled by default and can be switched on at
* preferences/external programs
*/
public class SendAsEMailAction implements BaseAction {
public class SendAsEMailAction extends SimpleCommand {

private static final Logger LOGGER = LoggerFactory.getLogger(SendAsEMailAction.class);
private final JabRefFrame frame;
private DialogService dialogService;
private StateManager stateManager;

public SendAsEMailAction(JabRefFrame frame) {
this.frame = frame;
public SendAsEMailAction(DialogService dialogService, StateManager stateManager) {
this.dialogService = dialogService;
this.stateManager = stateManager;

this.executable.bind(ActionHelper.needsEntriesSelected(stateManager));
}

@Override
public void action() {
public void execute() {
BackgroundTask.wrap(this::sendEmail)
.onSuccess(frame.getDialogService()::notify)
.onSuccess(dialogService::notify)
.onFailure(e -> {
String message = Localization.lang("Error creating email");
LOGGER.warn(message, e);
frame.getDialogService().notify(message);
dialogService.notify(message);
})
.executeWith(Globals.TASK_EXECUTOR);
}

private String sendEmail() throws Exception {
if (!Desktop.isDesktopSupported()) {
if (!Desktop.isDesktopSupported() || stateManager.getActiveDatabase().isEmpty()) {
return Localization.lang("Error creating email");
}

BasePanel panel = frame.getCurrentBasePanel();
if (panel == null) {
throw new IllegalStateException("Base panel is not available.");
}
if (panel.getSelectedEntries().isEmpty()) {
if (stateManager.getSelectedEntries().isEmpty()) {
return Localization.lang("This operation requires one or more entries to be selected.");
}

StringWriter sw = new StringWriter();
List<BibEntry> bes = panel.getSelectedEntries();
StringWriter rawEntries = new StringWriter();
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get();
List<BibEntry> entries = stateManager.getSelectedEntries();

// write the entries using sw, which is used later to form the email content
BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(Globals.prefs.getFieldWriterPreferences()), Globals.entryTypesManager);

for (BibEntry entry : bes) {
for (BibEntry entry : entries) {
try {
bibtexEntryWriter.write(entry, sw, panel.getBibDatabaseContext().getMode());
bibtexEntryWriter.write(entry, rawEntries, databaseContext.getMode());
} catch (IOException e) {
LOGGER.warn("Problem creating BibTeX file for mailing.", e);
}
Expand All @@ -88,20 +89,19 @@ private String sendEmail() throws Exception {
// the unofficial "mailto:attachment" property
boolean openFolders = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES);

List<Path> fileList = FileUtil.getListOfLinkedFiles(bes, frame.getCurrentBasePanel().getBibDatabaseContext()
.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()));
for (Path f : fileList) {
attachments.add(f.toAbsolutePath().toString());
List<Path> fileList = FileUtil.getListOfLinkedFiles(entries, databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()));
for (Path path : fileList) {
attachments.add(path.toAbsolutePath().toString());
if (openFolders) {
try {
JabRefDesktop.openFolderAndSelectFile(f.toAbsolutePath());
JabRefDesktop.openFolderAndSelectFile(path.toAbsolutePath());
} catch (IOException e) {
LOGGER.debug("Cannot open file", e);
}
}
}

String mailTo = "?Body=".concat(sw.getBuffer().toString());
String mailTo = "?Body=".concat(rawEntries.getBuffer().toString());
mailTo = mailTo.concat("&Subject=");
mailTo = mailTo.concat(JabRefPreferences.getInstance().get(JabRefPreferences.EMAIL_SUBJECT));
for (String path : attachments) {
Expand All @@ -114,6 +114,6 @@ private String sendEmail() throws Exception {
Desktop desktop = Desktop.getDesktop();
desktop.mail(uriMailTo);

return String.format("%s: %d", Localization.lang("Entries added to an email"), bes.size());
return String.format("%s: %d", Localization.lang("Entries added to an email"), entries.size());
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import javafx.scene.Node;

import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.search.SearchQuery;
Expand All @@ -27,6 +28,7 @@
* - currently selected group
* - active search
* - active number of search results
* - focus owner
*/
public class StateManager {

Expand All @@ -36,6 +38,7 @@ public class StateManager {
private final ObservableMap<BibDatabaseContext, ObservableList<GroupTreeNode>> selectedGroups = FXCollections.observableHashMap();
private final OptionalObjectProperty<SearchQuery> activeSearchQuery = OptionalObjectProperty.empty();
private final ObservableMap<BibDatabaseContext, IntegerProperty> searchResultMap = FXCollections.observableHashMap();
private final OptionalObjectProperty<Node> focusOwner = OptionalObjectProperty.empty();

public StateManager() {
activeGroups.bind(Bindings.valueAt(selectedGroups, activeDatabase.orElse(null)));
Expand Down Expand Up @@ -99,4 +102,8 @@ public void clearSearchQuery() {
public void setSearchQuery(SearchQuery searchQuery) {
activeSearchQuery.setValue(Optional.of(searchQuery));
}

public OptionalObjectProperty<Node> focusOwnerProperty() { return focusOwner; }

public Optional<Node> getFocusOwner() { return focusOwner.get(); }
}
23 changes: 23 additions & 0 deletions src/main/java/org/jabref/gui/actions/ActionHelper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package org.jabref.gui.actions;

import java.util.Collections;
import java.util.List;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanExpression;

import org.jabref.gui.StateManager;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;

public class ActionHelper {
public static BooleanExpression needsDatabase(StateManager stateManager) {
Expand All @@ -13,4 +18,22 @@ public static BooleanExpression needsDatabase(StateManager stateManager) {
public static BooleanExpression needsEntriesSelected(StateManager stateManager) {
return Bindings.isNotEmpty(stateManager.getSelectedEntries());
}

public static BooleanExpression needsEntriesSelected(int numberOfEntries, StateManager stateManager) {
return Bindings.createBooleanBinding(
() -> stateManager.getSelectedEntries().size() == numberOfEntries,
stateManager.getSelectedEntries());
}

public static BooleanExpression isFieldSetForSelectedEntry(Field field, StateManager stateManager) {
return isAnyFieldSetForSelectedEntry(Collections.singletonList(field), stateManager);
}

public static BooleanExpression isAnyFieldSetForSelectedEntry(List<Field> fields, StateManager stateManager) {
BibEntry entry = stateManager.getSelectedEntries().get(0);
return Bindings.createBooleanBinding(
() -> entry.getFields().stream().anyMatch(fields::contains),
entry.getFieldsObservable(),
stateManager.getSelectedEntries());
}
}
43 changes: 1 addition & 42 deletions src/main/java/org/jabref/gui/actions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ public enum Actions {
ABBREVIATE_SHORTEST_UNIQUE,
ADD_FILE_LINK,
CLEANUP,
COPY,
COPY_CITATION_ASCII_DOC,
COPY_CITATION_XSLFO,
COPY_CITATION_HTML,
COPY_CITATION_RTF,
COPY_CITATION_TEXT,
COPY_KEY,
COPY_CITE_KEY,
COPY_KEY_AND_TITLE,
COPY_KEY_AND_LINK,
COPY_TITLE,
CUT,
DELETE,
DOWNLOAD_FULL_TEXT,
EDIT,
EDIT_PREAMBLE,
Expand All @@ -31,42 +18,14 @@ public enum Actions {
MAKE_KEY,
MANAGE_SELECTORS,
MERGE_DATABASE,
MERGE_ENTRIES,
MERGE_WITH_FETCHED_ENTRY,
NEXT_PREVIEW_STYLE,
OPEN_CONSOLE,
OPEN_EXTERNAL_FILE,
OPEN_FOLDER,
OPEN_URL,
PASTE,
PREVIOUS_PREVIEW_STYLE,
PULL_CHANGES_FROM_SHARED_DATABASE,
REDO,
REPLACE_ALL,
SAVE,
SAVE_AS,
SAVE_SELECTED_AS_PLAIN,
SELECT_ALL,
SEND_AS_EMAIL,
TOGGLE_GROUPS,
UNABBREVIATE,
UNDO,
WRITE_XMP,
PRINT_PREVIEW,
TOGGLE_PRINTED,
CLEAR_PRIORITY,
SET_PRIORITY_1,
SET_PRIORITY_2,
SET_PRIORITY_3,
TOGGLE_QUALITY_ASSURED,
CLEAR_RANK,
SET_RANK_1,
SET_RANK_2,
SET_RANK_3,
SET_RANK_4,
SET_RANK_5,
CLEAR_READ_STATUS,
SET_READ_STATUS_TO_READ,
SET_READ_STATUS_TO_SKIMMED,
TOGGLE_RELEVANCE
UNDO
}
5 changes: 4 additions & 1 deletion src/main/java/org/jabref/gui/actions/JabRefAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ private String getActionName(Action action, Command command) {
return action.getText();
} else {
String commandName = command.getClass().getSimpleName();
if ((command instanceof OldDatabaseCommandWrapper) || (command instanceof OldCommandWrapper) || commandName.contains("EditAction")) {
if ((command instanceof OldDatabaseCommandWrapper)
|| commandName.contains("EditAction")
|| commandName.contains("CopyMoreAction")
|| commandName.contains("CopyCitationAction")) {
return command.toString();
} else {
return commandName;
Expand Down
56 changes: 0 additions & 56 deletions src/main/java/org/jabref/gui/actions/OldCommandWrapper.java

This file was deleted.

Loading

0 comments on commit b6d6b79

Please sign in to comment.