-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Toggle enable status of menu items #4872
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
041dafc
Toggle enable status of menu items (prototype)
tobiasdiez d35f375
Merge branch 'master' of https://github.com/JabRef/jabref into fix4795
tobiasdiez 2cb6610
Use for pushtoapplication
tobiasdiez 219909b
Improve code around push to applications
tobiasdiez 407d762
Set enable status for all actions
tobiasdiez ba8266e
Fix tests and checkstyle
tobiasdiez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.jabref.gui.actions; | ||
|
||
import javafx.beans.binding.Bindings; | ||
import javafx.beans.binding.BooleanExpression; | ||
|
||
import org.jabref.gui.StateManager; | ||
|
||
public class ActionHelper { | ||
public static BooleanExpression needsDatabase(StateManager stateManager) { | ||
return stateManager.activeDatabaseProperty().isPresent(); | ||
} | ||
|
||
public static BooleanExpression needsEntriesSelected(StateManager stateManager) { | ||
return Bindings.isNotEmpty(stateManager.getSelectedEntries()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 12 additions & 15 deletions
27
src/main/java/org/jabref/gui/edit/ManageKeywordsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
package org.jabref.gui.edit; | ||
|
||
import org.jabref.gui.BasePanel; | ||
import org.jabref.gui.JabRefFrame; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.actions.SimpleCommand; | ||
import org.jabref.gui.util.BindingsHelper; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
import static org.jabref.gui.actions.ActionHelper.needsDatabase; | ||
import static org.jabref.gui.actions.ActionHelper.needsEntriesSelected; | ||
|
||
/** | ||
* An Action for launching keyword managing dialog | ||
* | ||
*/ | ||
public class ManageKeywordsAction extends SimpleCommand { | ||
|
||
private final JabRefFrame frame; | ||
private final StateManager stateManager; | ||
|
||
public ManageKeywordsAction(StateManager stateManager) { | ||
this.stateManager = stateManager; | ||
|
||
public ManageKeywordsAction(JabRefFrame frame) { | ||
this.frame = frame; | ||
this.executable.bind(needsDatabase(stateManager).and(needsEntriesSelected(stateManager))); | ||
this.statusMessage.bind(BindingsHelper.ifThenElse(this.executable, "", Localization.lang("Select at least one entry to manage keywords."))); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
BasePanel basePanel = frame.getCurrentBasePanel(); | ||
if (basePanel == null) { | ||
return; | ||
} | ||
if (basePanel.getSelectedEntries().isEmpty()) { | ||
basePanel.output(Localization.lang("Select at least one entry to manage keywords.")); | ||
return; | ||
} | ||
|
||
ManageKeywordsDialog dialog = new ManageKeywordsDialog(basePanel.getSelectedEntries()); | ||
ManageKeywordsDialog dialog = new ManageKeywordsDialog(stateManager.getSelectedEntries()); | ||
dialog.showAndWait(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import javafx.css.PseudoClass; | ||
import javafx.scene.Node; | ||
|
||
import org.fxmisc.easybind.EasyBind; | ||
import org.fxmisc.easybind.PreboundBinding; | ||
|
||
/** | ||
|
@@ -176,6 +177,16 @@ protected String computeValue() { | |
}; | ||
} | ||
|
||
public static <T> ObservableValue<T> ifThenElse(ObservableValue<Boolean> condition, T value, T other) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either github does somehow have a problem with this, or it is somehow commented out`, as it's not syntax highlighted |
||
return EasyBind.map(condition, conditionValue -> { | ||
if (conditionValue) { | ||
return value; | ||
} else { | ||
return other; | ||
} | ||
}); | ||
} | ||
|
||
private static class BidirectionalBinding<A, B> { | ||
|
||
private final ObservableValue<A> propertyA; | ||
|
45 changes: 45 additions & 0 deletions
45
src/main/java/org/jabref/gui/util/OptionalObjectProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.jabref.gui.util; | ||
|
||
import java.util.Optional; | ||
|
||
import javafx.beans.binding.BooleanExpression; | ||
import javafx.beans.binding.ObjectBinding; | ||
import javafx.beans.property.SimpleObjectProperty; | ||
|
||
import org.fxmisc.easybind.PreboundBinding; | ||
|
||
/** | ||
* Similar to {@link org.fxmisc.easybind.monadic.MonadicObservableValue} | ||
*/ | ||
public class OptionalObjectProperty<T> extends SimpleObjectProperty<Optional<T>> { | ||
|
||
private OptionalObjectProperty(Optional<T> initialValue) { | ||
super(initialValue); | ||
} | ||
|
||
public static <T> OptionalObjectProperty<T> empty() { | ||
return new OptionalObjectProperty<>(Optional.empty()); | ||
} | ||
|
||
/** | ||
* Returns a new ObservableValue that holds the value held by this | ||
* ObservableValue, or {@code other} when this ObservableValue is empty. | ||
*/ | ||
public ObjectBinding<T> orElse(T other) { | ||
return new PreboundBinding<T>(this) { | ||
@Override | ||
protected T computeValue() { | ||
return OptionalObjectProperty.this.getValue().orElse(other); | ||
} | ||
}; | ||
} | ||
|
||
public BooleanExpression isPresent() { | ||
return BooleanExpression.booleanExpression(new PreboundBinding<Boolean>(this) { | ||
@Override | ||
protected Boolean computeValue() { | ||
return OptionalObjectProperty.this.getValue().isPresent(); | ||
} | ||
}); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can you bind it if it's read only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrapper itself is not readonly, but allows the construction of an readonly property. It's a bit confusing.