|
2 | 2 |
|
3 | 3 | import java.io.IOException; |
4 | 4 | import java.nio.file.Path; |
5 | | -import java.util.ArrayList; |
6 | 5 | import java.util.List; |
7 | 6 | import java.util.Objects; |
8 | 7 | import java.util.Optional; |
@@ -119,9 +118,7 @@ public class LibraryTab extends Tab implements CommandSelectionTab { |
119 | 118 | private final BibEntryTypesManager entryTypesManager; |
120 | 119 | private final BooleanProperty changedProperty = new SimpleBooleanProperty(false); |
121 | 120 | private final BooleanProperty nonUndoableChangeProperty = new SimpleBooleanProperty(false); |
122 | | - private final List<BibEntry> previousEntries = new ArrayList<>(); |
123 | | - private final List<BibEntry> nextEntries = new ArrayList<>(); |
124 | | - private BibEntry currentlyShowing; |
| 121 | + private final NavigationHistory navigationHistory = new NavigationHistory(); |
125 | 122 | private final BooleanProperty canGoBackProperty = new SimpleBooleanProperty(false); |
126 | 123 | private final BooleanProperty canGoForwardProperty = new SimpleBooleanProperty(false); |
127 | 124 | private boolean backOrForwardNavigationActionTriggered = false; |
@@ -983,56 +980,36 @@ public void resetChangedProperties() { |
983 | 980 | } |
984 | 981 |
|
985 | 982 | public void back() { |
986 | | - navigateToEntry(previousEntries, nextEntries); |
| 983 | + navigationHistory.back().ifPresent(this::navigateToEntry); |
987 | 984 | } |
988 | 985 |
|
989 | 986 | public void forward() { |
990 | | - navigateToEntry(nextEntries, previousEntries); |
| 987 | + navigationHistory.forward().ifPresent(this::navigateToEntry); |
991 | 988 | } |
992 | 989 |
|
993 | | - private void navigateToEntry(List<BibEntry> sourceHistory, List<BibEntry> destinationHistory) { |
994 | | - if (!sourceHistory.isEmpty()) { |
995 | | - BibEntry toShow = sourceHistory.getLast(); |
996 | | - sourceHistory.removeLast(); |
997 | | - |
998 | | - // add current entry to destination history |
999 | | - if (currentlyShowing != null) { |
1000 | | - destinationHistory.add(currentlyShowing); |
1001 | | - } |
1002 | | - |
1003 | | - backOrForwardNavigationActionTriggered = true; |
1004 | | - clearAndSelect(toShow); |
1005 | | - updateNavigationState(); |
1006 | | - } |
| 990 | + private void navigateToEntry(BibEntry entry) { |
| 991 | + backOrForwardNavigationActionTriggered = true; |
| 992 | + clearAndSelect(entry); |
| 993 | + updateNavigationState(); |
1007 | 994 | } |
1008 | 995 |
|
1009 | 996 | public boolean canGoBack() { |
1010 | | - return !previousEntries.isEmpty(); |
| 997 | + return navigationHistory.canGoBack(); |
1011 | 998 | } |
1012 | 999 |
|
1013 | 1000 | public boolean canGoForward() { |
1014 | | - return !nextEntries.isEmpty(); |
| 1001 | + return navigationHistory.canGoForward(); |
1015 | 1002 | } |
1016 | 1003 |
|
1017 | 1004 | private void newEntryShowing(BibEntry entry) { |
1018 | 1005 | // skip history updates if this is from a back/forward operation |
1019 | 1006 | if (backOrForwardNavigationActionTriggered) { |
1020 | | - currentlyShowing = entry; |
1021 | 1007 | backOrForwardNavigationActionTriggered = false; |
1022 | | - updateNavigationState(); |
1023 | 1008 | return; |
1024 | 1009 | } |
1025 | 1010 |
|
1026 | | - nextEntries.clear(); // clear forward history when new entry selected in existing chronological sequence |
1027 | | - |
1028 | | - if (!Objects.equals(entry, currentlyShowing)) { |
1029 | | - // add the entry we are leaving to the history |
1030 | | - if (currentlyShowing != null) { |
1031 | | - previousEntries.add(currentlyShowing); |
1032 | | - } |
1033 | | - currentlyShowing = entry; |
1034 | | - updateNavigationState(); |
1035 | | - } |
| 1011 | + navigationHistory.add(entry); |
| 1012 | + updateNavigationState(); |
1036 | 1013 | } |
1037 | 1014 |
|
1038 | 1015 | /** |
|
0 commit comments