diff --git a/CHANGELOG.md b/CHANGELOG.md index bca01e2d50f..ce6a2adcd32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We moved the dropdown menu for selecting the push-application from the toolbar into the external application preferences. [#674](https://github.com/JabRef/jabref/issues/674) - We removed the alphabetical ordering of the custom tabs and updated the error message when trying to create a general field with a name containing an illegal character. [#5019](https://github.com/JabRef/jabref/issues/5019) - We added a context menu to the bib(la)tex-source-editor to copy'n'paste. [#5007](https://github.com/JabRef/jabref/pull/5007) +- We added a bibliographic references search, for finding references in several LaTeX files. This tool scans directories and shows which entries are used, how many times and where. ### Fixed diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 73f838d6315..9922adca817 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -101,6 +101,7 @@ import org.jabref.gui.search.GlobalSearchBar; import org.jabref.gui.shared.ConnectToSharedDatabaseCommand; import org.jabref.gui.specialfields.SpecialFieldMenuItemFactory; +import org.jabref.gui.texparser.ParseTexAction; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.DefaultTaskExecutor; @@ -768,6 +769,7 @@ private MenuBar createMenu() { pushToApplicationsManager.setMenuItem(pushToApplicationMenuItem); tools.getItems().addAll( + factory.createMenuItem(StandardActions.PARSE_TEX, new ParseTexAction(stateManager)), factory.createMenuItem(StandardActions.NEW_SUB_LIBRARY_FROM_AUX, new NewSubLibraryAction(this, stateManager)), factory.createMenuItem(StandardActions.FIND_UNLINKED_FILES, new FindUnlinkedFilesAction(this, stateManager)), factory.createMenuItem(StandardActions.WRITE_XMP, new OldDatabaseCommandWrapper(Actions.WRITE_XMP, this, stateManager)), diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index eb4c6508955..feb1e072275 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -85,6 +85,7 @@ public enum StandardActions implements Action { TOOGLE_OO(Localization.lang("OpenOffice/LibreOffice"), IconTheme.JabRefIcons.FILE_OPENOFFICE, KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION), TOGGLE_WEB_SEARCH(Localization.lang("Web search"), Localization.lang("Toggle web search interface"), IconTheme.JabRefIcons.WWW, KeyBinding.WEB_SEARCH), + PARSE_TEX(Localization.lang("LaTeX references search"), IconTheme.JabRefIcons.APPLICATION_TEXSTUDIO), 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), 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), OPEN_FOLDER(Localization.lang("Open folder"), Localization.lang("Open folder"), KeyBinding.OPEN_FOLDER), diff --git a/src/main/java/org/jabref/gui/texparser/FileNodeViewModel.java b/src/main/java/org/jabref/gui/texparser/FileNodeViewModel.java new file mode 100644 index 00000000000..63c743df3fc --- /dev/null +++ b/src/main/java/org/jabref/gui/texparser/FileNodeViewModel.java @@ -0,0 +1,58 @@ +package org.jabref.gui.texparser; + +import java.nio.file.Path; +import java.util.StringJoiner; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import org.jabref.logic.l10n.Localization; + +class FileNodeViewModel { + + private final Path path; + private final ObservableList children; + private int fileCount; + + public FileNodeViewModel(Path path) { + this.path = path; + this.fileCount = 0; + this.children = FXCollections.observableArrayList(); + } + + public Path getPath() { + return path; + } + + public int getFileCount() { + return fileCount; + } + + public void setFileCount(int fileCount) { + this.fileCount = fileCount; + } + + public ObservableList getChildren() { + return children; + } + + /** + * Return a string for displaying a node name (and its number of children if it is a directory). + */ + public String getDisplayText() { + if (path.toFile().isDirectory()) { + return String.format("%s (%s %s)", path.getFileName(), fileCount, + fileCount == 1 ? Localization.lang("file") : Localization.lang("files")); + } + return path.getFileName().toString(); + } + + @Override + public String toString() { + return new StringJoiner(", ", FileNodeViewModel.class.getSimpleName() + "[", "]") + .add("path=" + path) + .add("fileCount=" + fileCount) + .add("children=" + children) + .toString(); + } +} diff --git a/src/main/java/org/jabref/gui/texparser/ParseTexAction.java b/src/main/java/org/jabref/gui/texparser/ParseTexAction.java new file mode 100644 index 00000000000..b057f040ab2 --- /dev/null +++ b/src/main/java/org/jabref/gui/texparser/ParseTexAction.java @@ -0,0 +1,25 @@ +package org.jabref.gui.texparser; + +import org.jabref.gui.StateManager; +import org.jabref.gui.actions.SimpleCommand; +import org.jabref.model.database.BibDatabaseContext; + +import static org.jabref.gui.actions.ActionHelper.needsDatabase; + +public class ParseTexAction extends SimpleCommand { + + private final StateManager stateManager; + + public ParseTexAction(StateManager stateManager) { + this.stateManager = stateManager; + this.executable.bind(needsDatabase(stateManager)); + } + + @Override + public void execute() { + BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(NullPointerException::new); + ParseTexDialogView dialog = new ParseTexDialogView(database); + + dialog.showAndWait(); + } +} diff --git a/src/main/java/org/jabref/gui/texparser/ParseTexDialog.fxml b/src/main/java/org/jabref/gui/texparser/ParseTexDialog.fxml new file mode 100644 index 00000000000..ee6fa85c697 --- /dev/null +++ b/src/main/java/org/jabref/gui/texparser/ParseTexDialog.fxml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + +