Skip to content

Commit

Permalink
Disable menu items for unsaved library
Browse files Browse the repository at this point in the history
Fixes #11920
  • Loading branch information
Siedlerchr committed Nov 17, 2024
1 parent f232ae8 commit 02f76c2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We changed the name of the library-based file directory from 'General File Directory' to 'Library-specific File Directory' per issue. [#571](https://github.com/koppor/jabref/issues/571)
- We changed the defualt [unwanted charachters](https://docs.jabref.org/setup/citationkeypatterns#removing-unwanted-characters) in the citation key generator and allow a dash (`-`) and colon (`:`) being part of a citation key. [#12144](https://github.com/JabRef/jabref/pull/12144)
- The CitationKey column is now a default shown column for the entry table. [#10510](https://github.com/JabRef/jabref/issues/10510)
- We disabled the actions "Open Terminal here" and "Reveal in file explorer" for unsaved libraries [#11920](https://github.com/JabRef/jabref/issues/11920)

### Fixed

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/jabref/gui/actions/ActionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public static BooleanExpression needsDatabase(StateManager stateManager) {
return stateManager.activeDatabaseProperty().isPresent();
}

public static BooleanExpression needsSavedLocalDatabase(StateManager stateManager) {
EasyBinding<Boolean> binding = EasyBind.map(stateManager.activeDatabaseProperty(), context -> context.filter(c -> c.getLocation() == DatabaseLocation.LOCAL && c.getDatabasePath().isPresent()).isPresent());
return BooleanExpression.booleanExpression(binding);
}

public static BooleanExpression needsSharedDatabase(StateManager stateManager) {
EasyBinding<Boolean> binding = EasyBind.map(stateManager.activeDatabaseProperty(), context -> context.filter(c -> c.getLocation() == DatabaseLocation.SHARED).isPresent());
return BooleanExpression.booleanExpression(binding);
Expand All @@ -49,7 +54,7 @@ public static BooleanExpression needsEntriesSelected(StateManager stateManager)

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

public static BooleanExpression isFieldSetForSelectedEntry(Field field, StateManager stateManager) {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
* Represents the inner frame of the JabRef window
*/
Expand All @@ -79,7 +82,6 @@ public class JabRefFrame extends BorderPane implements LibraryTabContainer, UiMe
private final GlobalSearchBar globalSearchBar;

private final FileHistoryMenu fileHistory;
private final FrameDndHandler frameDndHandler;

@SuppressWarnings({"FieldCanBeLocal"}) private EasyObservableList<BibDatabaseContext> openDatabaseList;

Expand Down Expand Up @@ -136,7 +138,7 @@ public JabRefFrame(Stage mainStage,
taskExecutor);
Injector.setModelOrService(UiMessageHandler.class, viewModel);

this.frameDndHandler = new FrameDndHandler(
FrameDndHandler frameDndHandler = new FrameDndHandler(
tabbedPane,
mainStage::getScene,
this::getOpenDatabaseAction,
Expand Down Expand Up @@ -425,7 +427,7 @@ public void showLibraryTab(@NonNull LibraryTab libraryTab) {
/**
* Opens a new tab with existing data.
* Asynchronous loading is done at {@link LibraryTab#createLibraryTab}.
* Similar method: {@link OpenDatabaseAction#openTheFile(Path)}
* Similar method: {@link OpenDatabaseAction#openTheFile(Path)} (Path)}
*/
public void addTab(@NonNull BibDatabaseContext databaseContext, boolean raisePanel) {
Objects.requireNonNull(databaseContext);
Expand Down Expand Up @@ -637,6 +639,7 @@ private class OpenDatabaseFolder extends SimpleCommand {

public OpenDatabaseFolder(Supplier<BibDatabaseContext> databaseContext) {
this.databaseContext = databaseContext;
this.executable.bind(needsSavedLocalDatabase(stateManager));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/frame/OpenConsoleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public OpenConsoleAction(Supplier<BibDatabaseContext> databaseContext, StateMana
this.preferences = preferences;
this.dialogService = dialogService;

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

/**
Expand Down

0 comments on commit 02f76c2

Please sign in to comment.