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

Fixes empty metadata in library properties called from right click menu #8358

Merged
merged 2 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue where clicking on headings in the entry preview could lead to an exception [#8292](https://github.com/JabRef/jabref/issues/8292)
- We fixed an issue where clicking on headings in the entry preview could lead to an exception. [#8292](https://github.com/JabRef/jabref/issues/8292)
- We fixed an issue about empty metadata in library properties when called from the right click menu. [#8358](https://github.com/JabRef/jabref/issues/8358)

### Removed

Expand Down
13 changes: 7 additions & 6 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.Supplier;
import java.util.stream.Collectors;

import javafx.application.Platform;
Expand Down Expand Up @@ -1052,9 +1053,9 @@ private ContextMenu createTabContextMenuFor(LibraryTab tab, KeyBindingRepository
ActionFactory factory = new ActionFactory(keyBindingRepository);

contextMenu.getItems().addAll(
factory.createMenuItem(StandardActions.LIBRARY_PROPERTIES, new LibraryPropertiesAction(tab.getBibDatabaseContext(), stateManager)),
factory.createMenuItem(StandardActions.OPEN_DATABASE_FOLDER, new OpenDatabaseFolder(tab.getBibDatabaseContext())),
factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(tab.getBibDatabaseContext(), stateManager, prefs)),
factory.createMenuItem(StandardActions.LIBRARY_PROPERTIES, new LibraryPropertiesAction(tab::getBibDatabaseContext, stateManager)),
factory.createMenuItem(StandardActions.OPEN_DATABASE_FOLDER, new OpenDatabaseFolder(tab::getBibDatabaseContext)),
factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(tab::getBibDatabaseContext, stateManager, prefs)),
new SeparatorMenuItem(),
factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new CloseDatabaseAction(tab)),
factory.createMenuItem(StandardActions.CLOSE_OTHER_LIBRARIES, new CloseOthersDatabaseAction(tab)),
Expand Down Expand Up @@ -1340,15 +1341,15 @@ public void execute() {
}

private class OpenDatabaseFolder extends SimpleCommand {
private final BibDatabaseContext databaseContext;
private final Supplier<BibDatabaseContext> databaseContext;

public OpenDatabaseFolder(BibDatabaseContext databaseContext) {
public OpenDatabaseFolder(Supplier<BibDatabaseContext> databaseContext) {
this.databaseContext = databaseContext;
}

@Override
public void execute() {
Optional.of(databaseContext).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> {
Optional.of(databaseContext.get()).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> {
try {
JabRefDesktop.openFolderAndSelectFile(path, prefs);
} catch (IOException e) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jabref/gui/OpenConsoleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.Optional;
import java.util.function.Supplier;

import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
Expand All @@ -15,11 +16,11 @@
public class OpenConsoleAction extends SimpleCommand {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenConsoleAction.class);
private final BibDatabaseContext databaseContext;
private final Supplier<BibDatabaseContext> databaseContext;
private final StateManager stateManager;
private final PreferencesService preferencesService;

public OpenConsoleAction(BibDatabaseContext databaseContext, StateManager stateManager, PreferencesService preferencesService) {
public OpenConsoleAction(Supplier<BibDatabaseContext> databaseContext, StateManager stateManager, PreferencesService preferencesService) {
this.databaseContext = databaseContext;
this.stateManager = stateManager;
this.preferencesService = preferencesService;
Expand All @@ -36,7 +37,7 @@ public OpenConsoleAction(StateManager stateManager, PreferencesService preferenc

@Override
public void execute() {
Optional.ofNullable(databaseContext).or(stateManager::getActiveDatabase).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> {
Optional.ofNullable(databaseContext.get()).or(stateManager::getActiveDatabase).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> {
try {
JabRefDesktop.openConsole(path.toFile(), preferencesService);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.libraryproperties;

import java.util.function.Supplier;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;
Expand All @@ -15,14 +17,14 @@ public class LibraryPropertiesAction extends SimpleCommand {
private static final Logger LOGGER = LoggerFactory.getLogger(LibraryPropertiesAction.class);

private final StateManager stateManager;
private final BibDatabaseContext alternateDatabase;
private final Supplier<BibDatabaseContext> alternateDatabase;

public LibraryPropertiesAction(StateManager stateManager) {
this(null, stateManager);
this.executable.bind(needsDatabase(stateManager));
}

public LibraryPropertiesAction(BibDatabaseContext databaseContext, StateManager stateManager) {
public LibraryPropertiesAction(Supplier<BibDatabaseContext> databaseContext, StateManager stateManager) {
this.stateManager = stateManager;
this.alternateDatabase = databaseContext;
}
Expand All @@ -32,7 +34,7 @@ public void execute() {
DialogService dialogService = Injector.instantiateModelOrService(DialogService.class);

if (alternateDatabase != null) {
dialogService.showCustomDialogAndWait(new LibraryPropertiesView(alternateDatabase));
dialogService.showCustomDialogAndWait(new LibraryPropertiesView(alternateDatabase.get()));
} else {
if (stateManager.getActiveDatabase().isPresent()) {
dialogService.showCustomDialogAndWait(new LibraryPropertiesView(stateManager.getActiveDatabase().get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class LibraryPropertiesView extends BaseDialog<LibraryPropertiesViewModel> {

public TabPane tabPane;
@FXML private TabPane tabPane;
@FXML private ButtonType saveButton;

private final BibDatabaseContext databaseContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GeneralPropertiesViewModel implements PropertiesTabViewModel {
private final PreferencesService preferencesService;

private final BibDatabaseContext databaseContext;
private final MetaData initialMetaData;
private final MetaData metaData;
private final DirectoryDialogConfiguration directoryDialogConfiguration;
private final UndoManager undoManager;

Expand All @@ -51,7 +51,7 @@ public class GeneralPropertiesViewModel implements PropertiesTabViewModel {
this.preferencesService = preferencesService;
this.undoManager = undoManager;
this.databaseContext = databaseContext;
this.initialMetaData = databaseContext.getMetaData();
this.metaData = databaseContext.getMetaData();

this.directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder()
.withInitialDirectory(preferencesService.getFilePreferences().getWorkingDirectory()).build();
Expand All @@ -62,11 +62,11 @@ public void setValues() {
boolean isShared = (databaseContext.getLocation() == DatabaseLocation.SHARED);
encodingDisableProperty.setValue(isShared); // the encoding of shared database is always UTF-8

selectedEncodingProperty.setValue(initialMetaData.getEncoding().orElse(preferencesService.getGeneralPreferences().getDefaultEncoding()));
selectedDatabaseModeProperty.setValue(initialMetaData.getMode().orElse(BibDatabaseMode.BIBLATEX));
generalFileDirectoryProperty.setValue(initialMetaData.getDefaultFileDirectory().orElse("").trim());
userSpecificFileDirectoryProperty.setValue(initialMetaData.getUserFileDirectory(preferencesService.getFilePreferences().getUser()).orElse("").trim());
laTexFileDirectoryProperty.setValue(initialMetaData.getLatexFileDirectory(preferencesService.getFilePreferences().getUser()).map(Path::toString).orElse(""));
selectedEncodingProperty.setValue(metaData.getEncoding().orElse(preferencesService.getGeneralPreferences().getDefaultEncoding()));
selectedDatabaseModeProperty.setValue(metaData.getMode().orElse(BibDatabaseMode.BIBLATEX));
generalFileDirectoryProperty.setValue(metaData.getDefaultFileDirectory().orElse("").trim());
userSpecificFileDirectoryProperty.setValue(metaData.getUserFileDirectory(preferencesService.getFilePreferences().getUser()).orElse("").trim());
laTexFileDirectoryProperty.setValue(metaData.getLatexFileDirectory(preferencesService.getFilePreferences().getUser()).map(Path::toString).orElse(""));

preambleProperty.setValue(databaseContext.getDatabase().getPreamble().orElse(""));
}
Expand Down