-
-
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
Use binding to update global state manager #5325
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,65 +163,8 @@ public JabRefFrame(Stage mainStage) { | |
this.undoManager = Globals.undoManager; | ||
} | ||
|
||
public void init() { | ||
sidePaneManager = new SidePaneManager(Globals.prefs, this); | ||
sidePane = sidePaneManager.getPane(); | ||
|
||
tabbedPane = new TabPane(); | ||
tabbedPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER); | ||
|
||
initLayout(); | ||
|
||
initKeyBindings(); | ||
|
||
initDragAndDrop(); | ||
|
||
//setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); | ||
//WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X, | ||
// JabRefPreferences.SIZE_Y); | ||
//pw.displayWindowAtStoredLocation(); | ||
|
||
/* | ||
* The following state listener makes sure focus is registered with the | ||
* correct database when the user switches tabs. Without this, | ||
* cut/paste/copy operations would some times occur in the wrong tab. | ||
*/ | ||
EasyBind.subscribe(tabbedPane.getSelectionModel().selectedItemProperty(), e -> { | ||
if (e == null) { | ||
stateManager.activeDatabaseProperty().setValue(Optional.empty()); | ||
return; | ||
} | ||
|
||
BasePanel currentBasePanel = getCurrentBasePanel(); | ||
if (currentBasePanel == null) { | ||
return; | ||
} | ||
|
||
// Poor-mans binding to global state | ||
stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext())); | ||
stateManager.setSelectedEntries(currentBasePanel.getSelectedEntries()); | ||
|
||
// Update search query | ||
String content = ""; | ||
Optional<SearchQuery> currentSearchQuery = currentBasePanel.getCurrentSearchQuery(); | ||
if (currentSearchQuery.isPresent()) { | ||
content = currentSearchQuery.get().getQuery(); | ||
} | ||
globalSearchBar.setSearchTerm(content); | ||
|
||
// groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); | ||
//previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); | ||
//generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class)); | ||
//openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); | ||
|
||
setWindowTitle(); | ||
// Update search autocompleter with information for the correct database: | ||
currentBasePanel.updateSearchManager(); | ||
|
||
currentBasePanel.getUndoManager().postUndoRedoEvent(); | ||
currentBasePanel.getMainTable().requestFocus(); | ||
}); | ||
initShowTrackingNotification(); | ||
private static BasePanel getBasePanel(Tab tab) { | ||
return (BasePanel) tab.getContent(); | ||
} | ||
|
||
public void initDragAndDrop() { | ||
|
@@ -612,14 +555,74 @@ public void showBasePanel(BasePanel bp) { | |
tabbedPane.getSelectionModel().select(getTab(bp)); | ||
} | ||
|
||
public void init() { | ||
sidePaneManager = new SidePaneManager(Globals.prefs, this); | ||
sidePane = sidePaneManager.getPane(); | ||
|
||
tabbedPane = new TabPane(); | ||
tabbedPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER); | ||
|
||
initLayout(); | ||
|
||
initKeyBindings(); | ||
|
||
initDragAndDrop(); | ||
|
||
//setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); | ||
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. Can this be removed or why is this (still) uncommented? What did it do? 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. To be honest, I have no idea ;-) Probably to restore the window size on start. Feel free to investigate ;-) |
||
//WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X, | ||
// JabRefPreferences.SIZE_Y); | ||
//pw.displayWindowAtStoredLocation(); | ||
|
||
// Bind global state | ||
stateManager.activeDatabaseProperty().bind( | ||
EasyBind.map(tabbedPane.getSelectionModel().selectedItemProperty(), | ||
tab -> Optional.ofNullable(tab).map(JabRefFrame::getBasePanel).map(BasePanel::getBibDatabaseContext))); | ||
/* | ||
* The following state listener makes sure focus is registered with the | ||
* correct database when the user switches tabs. Without this, | ||
* cut/paste/copy operations would some times occur in the wrong tab. | ||
*/ | ||
EasyBind.subscribe(tabbedPane.getSelectionModel().selectedItemProperty(), tab -> { | ||
if (tab == null) { | ||
return; | ||
} | ||
|
||
BasePanel newBasePanel = getBasePanel(tab); | ||
|
||
// Poor-mans binding to global state | ||
stateManager.setSelectedEntries(newBasePanel.getSelectedEntries()); | ||
|
||
// Update search query | ||
String content = ""; | ||
Optional<SearchQuery> currentSearchQuery = newBasePanel.getCurrentSearchQuery(); | ||
if (currentSearchQuery.isPresent()) { | ||
content = currentSearchQuery.get().getQuery(); | ||
} | ||
globalSearchBar.setSearchTerm(content); | ||
|
||
// groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); | ||
//previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); | ||
//generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class)); | ||
//openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); | ||
|
||
setWindowTitle(); | ||
// Update search autocompleter with information for the correct database: | ||
newBasePanel.updateSearchManager(); | ||
|
||
newBasePanel.getUndoManager().postUndoRedoEvent(); | ||
newBasePanel.getMainTable().requestFocus(); | ||
}); | ||
initShowTrackingNotification(); | ||
} | ||
|
||
/** | ||
* Returns the currently viewed BasePanel. | ||
*/ | ||
public BasePanel getCurrentBasePanel() { | ||
if ((tabbedPane == null) || (tabbedPane.getSelectionModel().getSelectedItem() == null)) { | ||
return null; | ||
} | ||
return (BasePanel) tabbedPane.getSelectionModel().getSelectedItem().getContent(); | ||
return getBasePanel(tabbedPane.getSelectionModel().getSelectedItem()); | ||
} | ||
|
||
/** | ||
|
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.
Yeah, I was about to report that. Encountered this yesterday but forgot to report it