Skip to content

Commit df50edc

Browse files
committed
Extend implementation to per-tab
1 parent 1d75410 commit df50edc

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

jabgui/src/main/java/org/jabref/gui/JabRefGuiStateManager.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,4 @@ public BooleanProperty canGoBackProperty() {
319319
public BooleanProperty canGoForwardProperty() {
320320
return canGoForward;
321321
}
322-
323-
@Override
324-
public void updateNavigationState(boolean canGoBack, boolean canGoForward) {
325-
this.canGoBack.set(canGoBack);
326-
this.canGoForward.set(canGoForward);
327-
}
328-
329-
/**
330-
* Called when switching tabs to reset navigation state
331-
*/
332-
@Override
333-
public void clearNavigationHistory() {
334-
updateNavigationState(false, false);
335-
}
336322
}

jabgui/src/main/java/org/jabref/gui/LibraryTab.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public class LibraryTab extends Tab implements CommandSelectionTab {
122122
private final List<BibEntry> previousEntries = new ArrayList<>();
123123
private final List<BibEntry> nextEntries = new ArrayList<>();
124124
private BibEntry currentlyShowing;
125+
private final BooleanProperty canGoBackProperty = new SimpleBooleanProperty(false);
126+
private final BooleanProperty canGoForwardProperty = new SimpleBooleanProperty(false);
125127
private boolean backOrForwardInProgress = false;
126128

127129

@@ -1037,9 +1039,8 @@ private void newEntryShowing(BibEntry entry) {
10371039
* Only update if this is the active tab
10381040
*/
10391041
public void updateNavigationState() {
1040-
if (stateManager.activeTabProperty().get().filter(tab -> tab == this).isPresent()) {
1041-
stateManager.updateNavigationState(canGoBack(), canGoForward());
1042-
}
1042+
canGoBackProperty.set(canGoBack());
1043+
canGoForwardProperty.set(canGoForward());
10431044
}
10441045

10451046
/**
@@ -1112,6 +1113,14 @@ public static LibraryTab createLibraryTab(@NonNull BibDatabaseContext databaseCo
11121113
false);
11131114
}
11141115

1116+
public BooleanProperty canGoBackProperty() {
1117+
return canGoBackProperty;
1118+
}
1119+
1120+
public BooleanProperty canGoForwardProperty() {
1121+
return canGoForwardProperty;
1122+
}
1123+
11151124
private class GroupTreeListener {
11161125

11171126
@Subscribe

jabgui/src/main/java/org/jabref/gui/StateManager.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,4 @@ public interface StateManager extends SrvStateManager {
112112
BooleanProperty canGoBackProperty();
113113

114114
BooleanProperty canGoForwardProperty();
115-
116-
void updateNavigationState(boolean canGoBack, boolean canGoForward);
117-
118-
void clearNavigationHistory();
119115
}

jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javafx.beans.InvalidationListener;
1212
import javafx.beans.binding.Bindings;
1313
import javafx.beans.property.ObjectProperty;
14+
import javafx.beans.property.SimpleBooleanProperty;
1415
import javafx.beans.property.SimpleObjectProperty;
1516
import javafx.beans.value.ObservableValue;
1617
import javafx.collections.ListChangeListener;
@@ -419,8 +420,6 @@ private void initBindings() {
419420
// Listen for auto-completer changes after real context is loaded
420421
libraryTab.setAutoCompleterChangedListener(() -> globalSearchBar.setAutoCompleter(libraryTab.getAutoCompleter()));
421422

422-
libraryTab.updateNavigationState();
423-
424423
// [impl->req~maintable.focus~1]
425424
Platform.runLater(() -> libraryTab.getMainTable().requestFocus());
426425

@@ -444,7 +443,6 @@ private void initBindings() {
444443
stateManager.setActiveDatabase(null);
445444
stateManager.activeTabProperty().set(Optional.empty());
446445
stateManager.setSelectedEntries(List.of());
447-
stateManager.clearNavigationHistory();
448446
mainStage.titleProperty().unbind();
449447
mainStage.setTitle(FRAME_TITLE);
450448
}
@@ -463,6 +461,22 @@ private void initBindings() {
463461
// Hide tab bar
464462
stateManager.getOpenDatabases().addListener((ListChangeListener<BibDatabaseContext>) _ -> updateTabBarVisible());
465463
EasyBind.subscribe(preferences.getWorkspacePreferences().hideTabBarProperty(), _ -> updateTabBarVisible());
464+
465+
stateManager.canGoBackProperty().bind(
466+
stateManager.activeTabProperty().flatMap(
467+
optionalTab -> optionalTab
468+
.map(LibraryTab::canGoBackProperty)
469+
.orElse(new SimpleBooleanProperty(false))
470+
)
471+
);
472+
473+
stateManager.canGoForwardProperty().bind(
474+
stateManager.activeTabProperty().flatMap(
475+
optionalTab -> optionalTab
476+
.map(LibraryTab::canGoForwardProperty)
477+
.orElse(new SimpleBooleanProperty(false))
478+
)
479+
);
466480
}
467481

468482
private void updateTabBarVisible() {

0 commit comments

Comments
 (0)