Skip to content

Commit 5e199c4

Browse files
committedMar 7, 2025
Merge branch 'fix-for-issue-JabRef#12272' of https://github.com/oops-shlok/jabref into fix-for-issue-JabRef#12272
2 parents fbf3405 + 970d7e8 commit 5e199c4

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed
 

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

+37-34
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,6 @@ public JabRefFrame(Stage mainStage,
123123
this.clipBoardManager = clipBoardManager;
124124
this.taskExecutor = taskExecutor;
125125

126-
this.fileHistory = new FileHistoryMenu(
127-
this.preferences.getLastFilesOpenedPreferences().getFileHistory(),
128-
dialogService,
129-
getOpenDatabaseAction());
130-
131-
this.setOnKeyTyped(key -> {
132-
if (this.fileHistory.isShowing()) {
133-
if (this.fileHistory.openFileByKey(key)) {
134-
this.fileHistory.getParentMenu().hide();
135-
}
136-
}
137-
});
138-
139-
fileHistory.disableProperty().bind(Bindings.isEmpty(fileHistory.getItems()));
140-
141126
setId("frame");
142127

143128
// Create components
@@ -187,6 +172,21 @@ public JabRefFrame(Stage mainStage,
187172
this.preferences,
188173
taskExecutor);
189174

175+
this.fileHistory = new FileHistoryMenu(
176+
this.preferences.getLastFilesOpenedPreferences().getFileHistory(),
177+
dialogService,
178+
getOpenDatabaseAction());
179+
180+
fileHistory.disableProperty().bind(Bindings.isEmpty(fileHistory.getItems()));
181+
182+
this.setOnKeyTyped(key -> {
183+
if (this.fileHistory.isShowing()) {
184+
if (this.fileHistory.openFileByKey(key)) {
185+
this.fileHistory.getParentMenu().hide();
186+
}
187+
}
188+
});
189+
190190
initLayout();
191191
initKeyBindings();
192192
frameDndHandler.initDragAndDrop();
@@ -450,8 +450,11 @@ private void updateTabBarVisible() {
450450
* Returns the currently viewed LibraryTab.
451451
*/
452452
public LibraryTab getCurrentLibraryTab() {
453-
return (LibraryTab) Optional.ofNullable(tabbedPane.getSelectionModel().getSelectedItem())
454-
.filter(tab -> tab instanceof LibraryTab).orElse(null);
453+
if (tabbedPane.getSelectionModel().getSelectedItem() == null
454+
|| !(tabbedPane.getSelectionModel().getSelectedItem() instanceof LibraryTab)) {
455+
return null;
456+
}
457+
return (LibraryTab) tabbedPane.getSelectionModel().getSelectedItem();
455458
}
456459

457460
public void showLibraryTab(@NonNull LibraryTab libraryTab) {
@@ -465,24 +468,24 @@ public void showWelcomeTab() {
465468
tabbedPane.getSelectionModel().select(tab);
466469
return;
467470
}
468-
469-
// If the WelcomeTab is not found, a new instance is created and added
470-
WelcomeTab welcomeTab = new WelcomeTab(
471-
this,
472-
preferences,
473-
aiService,
474-
dialogService,
475-
stateManager,
476-
fileUpdateMonitor,
477-
entryTypesManager,
478-
undoManager,
479-
clipBoardManager,
480-
taskExecutor,
481-
fileHistory
482-
);
483-
tabbedPane.getTabs().add(welcomeTab);
484-
tabbedPane.getSelectionModel().select(welcomeTab);
485471
}
472+
473+
// If the WelcomeTab is not found, a new instance is created and added
474+
WelcomeTab welcomeTab = new WelcomeTab(
475+
this,
476+
preferences,
477+
aiService,
478+
dialogService,
479+
stateManager,
480+
fileUpdateMonitor,
481+
entryTypesManager,
482+
undoManager,
483+
clipBoardManager,
484+
taskExecutor,
485+
fileHistory
486+
);
487+
tabbedPane.getTabs().add(welcomeTab);
488+
tabbedPane.getSelectionModel().select(welcomeTab);
486489
}
487490

488491
/**

‎src/main/java/org/jabref/gui/frame/MainMenu.java

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ private void createMenu() {
167167
factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(ExportCommand.ExportMethod.EXPORT_ALL, frame::getCurrentLibraryTab, stateManager, dialogService, preferences, entryTypesManager, abbreviationRepository, taskExecutor)),
168168
factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(ExportCommand.ExportMethod.EXPORT_SELECTED, frame::getCurrentLibraryTab, stateManager, dialogService, preferences, entryTypesManager, abbreviationRepository, taskExecutor)),
169169
factory.createMenuItem(StandardActions.SAVE_SELECTED_AS_PLAIN_BIBTEX, new SaveAction(SaveAction.SaveMethod.SAVE_SELECTED, frame::getCurrentLibraryTab, dialogService, preferences, stateManager))),
170+
170171
new SeparatorMenuItem(),
171172

172173
factory.createSubMenu(StandardActions.REMOTE_DB,
@@ -332,6 +333,7 @@ private void createMenu() {
332333

333334
factory.createMenuItem(StandardActions.NEXT_PREVIEW_STYLE, new PreviewSwitchAction(PreviewSwitchAction.Direction.NEXT, frame::getCurrentLibraryTab, stateManager)),
334335
factory.createMenuItem(StandardActions.PREVIOUS_PREVIEW_STYLE, new PreviewSwitchAction(PreviewSwitchAction.Direction.PREVIOUS, frame::getCurrentLibraryTab, stateManager)),
336+
335337
new SeparatorMenuItem(),
336338

337339
factory.createMenuItem(StandardActions.SHOW_PDF_VIEWER, new ShowDocumentViewerAction(stateManager, preferences)),

‎src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,13 @@ public FileDialogConfiguration getFileDialogConfiguration(Path initialDirectory)
145145
*/
146146
@VisibleForTesting
147147
Path getInitialDirectory() {
148-
if (tabContainer.getLibraryTabs().isEmpty()) {
148+
if (tabContainer.getLibraryTabs().isEmpty() || tabContainer.getCurrentLibraryTab() == null) {
149+
// currentTab might not be a LibraryTab but the WelcomeTab
149150
return preferences.getFilePreferences().getWorkingDirectory();
151+
} else {
152+
Optional<Path> databasePath = tabContainer.getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath();
153+
return databasePath.map(Path::getParent).orElse(preferences.getFilePreferences().getWorkingDirectory());
150154
}
151-
152-
// This is because of the WelcomeTab class.
153-
LibraryTab currentTab = tabContainer.getCurrentLibraryTab();
154-
if (currentTab == null) {
155-
return preferences.getFilePreferences().getWorkingDirectory();
156-
}
157-
158-
Optional<Path> databasePath = currentTab.getBibDatabaseContext().getDatabasePath();
159-
return databasePath.map(Path::getParent).orElse(preferences.getFilePreferences().getWorkingDirectory());
160155
}
161156

162157
/**

0 commit comments

Comments
 (0)