Skip to content

Commit 41a3d08

Browse files
HollyqqqqqHollyqqqqq
andauthored
Add more menu items to library context menu (#6551)
* add context menu * add test * delete jabRefFrameTest * update * checkstyle * Update JabRef_en.properties * Update JabRef_en.properties Co-authored-by: Hollyqqqqq <[email protected]>
1 parent 473a911 commit 41a3d08

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jabref.gui;
22

33
import java.io.File;
4+
import java.io.IOException;
45
import java.nio.file.Path;
56
import java.util.ArrayList;
67
import java.util.Collections;
@@ -48,6 +49,7 @@
4849
import org.jabref.Globals;
4950
import org.jabref.JabRefExecutorService;
5051
import org.jabref.gui.actions.ActionFactory;
52+
import org.jabref.gui.actions.ActionHelper;
5153
import org.jabref.gui.actions.SimpleCommand;
5254
import org.jabref.gui.actions.StandardActions;
5355
import org.jabref.gui.auximport.NewSubLibraryAction;
@@ -59,6 +61,7 @@
5961
import org.jabref.gui.copyfiles.CopyFilesAction;
6062
import org.jabref.gui.customentrytypes.CustomizeEntryAction;
6163
import org.jabref.gui.customizefields.SetupGeneralFieldsAction;
64+
import org.jabref.gui.desktop.JabRefDesktop;
6265
import org.jabref.gui.dialogs.AutosaveUiManager;
6366
import org.jabref.gui.documentviewer.ShowDocumentViewerAction;
6467
import org.jabref.gui.duplicationFinder.DuplicateSearch;
@@ -1087,11 +1090,18 @@ public void updateAllTabTitles() {
10871090
}
10881091
}
10891092

1090-
private static ContextMenu createTabContextMenu(KeyBindingRepository keyBindingRepository, BasePanel panel, StateManager stateManager) {
1093+
private ContextMenu createTabContextMenu(KeyBindingRepository keyBindingRepository) {
10911094
ContextMenu contextMenu = new ContextMenu();
10921095
ActionFactory factory = new ActionFactory(keyBindingRepository);
10931096

1094-
contextMenu.getItems().add(factory.createMenuItem(StandardActions.LIBRARY_PROPERTIES, new LibraryPropertiesAction(panel.frame(), stateManager)));
1097+
contextMenu.getItems().addAll(
1098+
factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new CloseDatabaseAction()),
1099+
factory.createMenuItem(StandardActions.CLOSE_OTHER_LIBRARIES, new CloseOthersDatabaseAction()),
1100+
factory.createMenuItem(StandardActions.CLOSE_ALL_LIBRARIES, new CloseAllDatabaseAction()),
1101+
new SeparatorMenuItem(),
1102+
factory.createMenuItem(StandardActions.OPEN_DATABASE_FOLDER, new OpenDatabaseFolder()),
1103+
factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(stateManager))
1104+
);
10951105

10961106
return contextMenu;
10971107
}
@@ -1106,7 +1116,7 @@ public void addTab(BasePanel basePanel, boolean raisePanel) {
11061116
});
11071117

11081118
// add tab context menu
1109-
newTab.setContextMenu(createTabContextMenu(Globals.getKeyPrefs(), basePanel, stateManager));
1119+
newTab.setContextMenu(createTabContextMenu(Globals.getKeyPrefs()));
11101120

11111121
// update all tab titles
11121122
updateAllTabTitles();
@@ -1324,6 +1334,49 @@ public void execute() {
13241334
}
13251335
}
13261336

1337+
private class CloseOthersDatabaseAction extends SimpleCommand {
1338+
1339+
public CloseOthersDatabaseAction() {
1340+
this.executable.bind(ActionHelper.isOpenMultiDatabase(tabbedPane));
1341+
}
1342+
1343+
@Override
1344+
public void execute() {
1345+
BasePanel currentBasePanel = getCurrentBasePanel();
1346+
for (Tab tab : tabbedPane.getTabs()) {
1347+
BasePanel basePanel = getBasePanel(tab);
1348+
if (basePanel != currentBasePanel) {
1349+
closeTab(basePanel);
1350+
}
1351+
}
1352+
}
1353+
}
1354+
1355+
private class CloseAllDatabaseAction extends SimpleCommand {
1356+
1357+
@Override
1358+
public void execute() {
1359+
for (Tab tab : tabbedPane.getTabs()) {
1360+
BasePanel basePanel = getBasePanel(tab);
1361+
closeTab(basePanel);
1362+
}
1363+
}
1364+
}
1365+
1366+
private class OpenDatabaseFolder extends SimpleCommand {
1367+
1368+
@Override
1369+
public void execute() {
1370+
stateManager.getActiveDatabase().flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> {
1371+
try {
1372+
JabRefDesktop.openFolderAndSelectFile(path);
1373+
} catch (IOException e) {
1374+
LOGGER.info("Could not open folder", e);
1375+
}
1376+
});
1377+
}
1378+
}
1379+
13271380
private class UndoRedoEventManager {
13281381

13291382
@Subscribe

src/main/java/org/jabref/gui/actions/ActionHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import javafx.beans.binding.Bindings;
1010
import javafx.beans.binding.BooleanExpression;
1111
import javafx.collections.ObservableList;
12+
import javafx.scene.control.TabPane;
1213

1314
import org.jabref.gui.StateManager;
1415
import org.jabref.model.entry.BibEntry;
@@ -72,4 +73,8 @@ public static BooleanExpression isFilePresentForSelectedEntry(StateManager state
7273

7374
return BooleanExpression.booleanExpression(fileIsPresent);
7475
}
76+
77+
public static BooleanExpression isOpenMultiDatabase(TabPane tabbedPane) {
78+
return Bindings.size(tabbedPane.getTabs()).greaterThan(1);
79+
}
7580
}

src/main/java/org/jabref/gui/actions/StandardActions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public enum StandardActions implements Action {
7575
EXPORT_SELECTED(Localization.lang("Export selected entries"), KeyBinding.EXPORT_SELECTED),
7676
CONNECT_TO_SHARED_DB(Localization.lang("Connect to shared database"), IconTheme.JabRefIcons.CONNECT_DB),
7777
PULL_CHANGES_FROM_SHARED_DB(Localization.lang("Pull changes from shared database"), KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE),
78-
CLOSE_LIBRARY(Localization.lang("Close library"), Localization.lang("Close the current library"), IconTheme.JabRefIcons.CLOSE, KeyBinding.CLOSE_DATABASE),
78+
CLOSE_LIBRARY(Localization.lang("Close"), Localization.lang("Close the current library"), IconTheme.JabRefIcons.CLOSE, KeyBinding.CLOSE_DATABASE),
79+
CLOSE_OTHER_LIBRARIES(Localization.lang("Close others"), Localization.lang("Close other libraries"), IconTheme.JabRefIcons.CLOSE),
80+
CLOSE_ALL_LIBRARIES(Localization.lang("Close all"), Localization.lang("Close all libraries"), IconTheme.JabRefIcons.CLOSE),
7981
QUIT(Localization.lang("Quit"), Localization.lang("Quit JabRef"), IconTheme.JabRefIcons.CLOSE_JABREF, KeyBinding.QUIT_JABREF),
8082
UNDO(Localization.lang("Undo"), IconTheme.JabRefIcons.UNDO, KeyBinding.UNDO),
8183
REDO(Localization.lang("Redo"), IconTheme.JabRefIcons.REDO, KeyBinding.REDO),
@@ -89,6 +91,7 @@ public enum StandardActions implements Action {
8991
PARSE_LATEX(Localization.lang("Search for citations in LaTeX files..."), IconTheme.JabRefIcons.LATEX_CITATIONS),
9092
NEW_SUB_LIBRARY_FROM_AUX(Localization.lang("New sublibrary based on AUX file") + "...", Localization.lang("New BibTeX sublibrary") + Localization.lang("This feature generates a new library based on which entries are needed in an existing LaTeX document."), IconTheme.JabRefIcons.NEW),
9193
WRITE_XMP(Localization.lang("Write XMP metadata to PDFs"), Localization.lang("Will write XMP metadata to the PDFs linked from selected entries."), KeyBinding.WRITE_XMP),
94+
OPEN_DATABASE_FOLDER(Localization.lang("Reveal in file explorer")),
9295
OPEN_FOLDER(Localization.lang("Open folder"), Localization.lang("Open folder"), KeyBinding.OPEN_FOLDER),
9396
OPEN_FILE(Localization.lang("Open file"), Localization.lang("Open file"), IconTheme.JabRefIcons.FILE, KeyBinding.OPEN_FILE),
9497
OPEN_CONSOLE(Localization.lang("Open terminal here"), Localization.lang("Open terminal here"), IconTheme.JabRefIcons.CONSOLE, KeyBinding.OPEN_CONSOLE),

src/main/resources/l10n/JabRef_en.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,3 +2243,9 @@ Display\ count\ of\ items\ in\ group=Display count of items in group
22432243
Remove\ the\ following\ characters\:=Remove the following characters:
22442244
Truncate=Truncate
22452245
Truncates\ a\ string\ after\ a\ given\ index.=Truncates a string after a given index.
2246+
Close=Close
2247+
Close\ all=Close all
2248+
Close\ all\ libraries=Close all libraries
2249+
Close\ other\ libraries=Close other libraries
2250+
Close\ others=Close others
2251+
Reveal\ in\ file\ explorer=Reveal in file explorer

0 commit comments

Comments
 (0)