Skip to content
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

Selected entry in search window selects entry in the main table #11010

Merged
merged 10 commits into from
Mar 21, 2024
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added the ability to zoom in and out in the document viewer using <kbd>Ctrl</kbd> + <kbd>Scroll</kbd>. [#10964](https://github.com/JabRef/jabref/pull/10964)
- We added a Cleanup for removing non-existent files and grouped the related options [#10929](https://github.com/JabRef/jabref/issues/10929)
- We added the functionality to parse the bibliography of PDFs using the GROBID online service. [#10200](https://github.com/JabRef/jabref/issues/10200)
- We added support for BibTeX String constants during copy & paste between libraries [#10872](https://github.com/JabRef/jabref/issues/10872)
- We added the field `langid` which is important for hyphenation and casing in LaTeX. [#10868](https://github.com/JabRef/jabref/issues/10868).
- We added a seperated search bar for the global search window. [#11032](https://github.com/JabRef/jabref/pull/11032)
- We added ability to double-click on an entry in the global search window to select the corresponding entry in the main table. [#11010](https://github.com/JabRef/jabref/pull/11010)
- We added support for BibTeX String constants during copy & paste between libraries. [#10872](https://github.com/JabRef/jabref/issues/10872)
- We added the field `langid` which is important for hyphenation and casing in LaTeX. [#10868](https://github.com/JabRef/jabref/issues/10868)

### Changed

Expand All @@ -50,7 +52,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- When normalizing author names, complete enclosing braces are kept. [#10031](https://github.com/JabRef/jabref/issues/10031)
- We enhanced the dialog for adding new fields in the content selector with a selection box containing a list of standard fields. [#10912](https://github.com/JabRef/jabref/pull/10912)
- We store the citation relations in an LRU cache to avoid bloating the memory and out-of-memory exceptions. [#10958](https://github.com/JabRef/jabref/issues/10958)
- Keywords filed are now displayed as tags. [#10910](https://github.com/JabRef/jabref/pull/10910)
- Keywords field are now displayed as tags. [#10910](https://github.com/JabRef/jabref/pull/10910)
Comment on lines -53 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment: In future, try to separate these small side changes to other pull requests. Reason: If a PR takes long to review, these kind of changes will be "outdated" (e.g., causing conflicts, because other PRs also touch these places).

On Linux (and Mac) you can try GitButler for "carving out" unrelated changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux (and Mac) you can try GitButler for "carving out" unrelated changes.

GitButler is now supported on Windows, but for some reason it didn't work with JabRef 😅

- Citation relations now get more information, and have quick access to view the articles in a browser without adding them to the library [#10869](https://github.com/JabRef/jabref/issues/10869)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ public ObservableValue<String> getFields(OrFields fields) {
return value;
}

public StringProperty bibDatabaseContextProperty() {
public StringProperty bibDatabasePathProperty() {
return new ReadOnlyStringWrapper(bibDatabaseContext.getDatabasePath().map(Path::toString).orElse(""));
}

public BibDatabaseContext getBibDatabaseContext() {
return bibDatabaseContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public LibraryColumn(MainTableColumnModel model) {
setText(Localization.lang("Library"));
new ValueTableCellFactory<BibEntryTableViewModel, String>().withText(FileUtil::getBaseName)
.install(this);
setCellValueFactory(param -> param.getValue().bibDatabaseContextProperty());
setCellValueFactory(param -> param.getValue().bibDatabasePathProperty());
}

public LibraryColumn() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ private void initSearchModifierButtons() {
initSearchModifierButton(openGlobalSearchButton);
openGlobalSearchButton.setOnAction(evt -> {
globalSearchActive.setValue(true);
globalSearchResultDialog = new GlobalSearchResultDialog(undoManager, tabContainer);
if (globalSearchResultDialog == null) {
globalSearchResultDialog = new GlobalSearchResultDialog(undoManager, tabContainer);
}
updateSearchQuery();
dialogService.showCustomDialogAndWait(globalSearchResultDialog);
globalSearchActive.setValue(false);
Expand Down
38 changes: 25 additions & 13 deletions src/main/java/org/jabref/gui/search/GlobalSearchResultDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import javafx.scene.layout.Priority;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

import org.jabref.gui.DialogService;
import org.jabref.gui.LibraryTabContainer;
Expand All @@ -32,8 +31,10 @@ public class GlobalSearchResultDialog extends BaseDialog<Void> {
@FXML private SplitPane container;
@FXML private ToggleButton keepOnTop;
@FXML private HBox searchBarContainer;

private final UndoManager undoManager;
private final LibraryTabContainer libraryTabContainer;

@Inject private PreferencesService preferencesService;
@Inject private StateManager stateManager;
@Inject private DialogService dialogService;
Expand Down Expand Up @@ -68,37 +69,48 @@ private void initialize() {
SearchResultsTable resultsTable = new SearchResultsTable(model, viewModel.getSearchDatabaseContext(), preferencesService, undoManager, dialogService, stateManager, taskExecutor);

resultsTable.getColumns().removeIf(SpecialFieldColumn.class::isInstance);
resultsTable.getSelectionModel().selectFirst();

if (resultsTable.getSelectionModel().getSelectedItem() != null) {
previewViewer.setEntry(resultsTable.getSelectionModel().getSelectedItem().getEntry());
}

resultsTable.getSelectionModel().selectedItemProperty().addListener((obs, old, newValue) -> {
resultsTable.getSelectionModel().selectedItemProperty().addListener((obs, oldValue, newValue) -> {
if (newValue != null) {
previewViewer.setEntry(newValue.getEntry());
} else {
previewViewer.setEntry(old.getEntry());
previewViewer.setEntry(oldValue.getEntry());
}
});

Stage stage = (Stage) getDialogPane().getScene().getWindow();

resultsTable.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) {
var selectedEntry = resultsTable.getSelectionModel().getSelectedItem();
libraryTabContainer.getLibraryTabs().stream()
.filter(tab -> tab.getBibDatabaseContext().equals(selectedEntry.getBibDatabaseContext()))
.findFirst()
.ifPresent(libraryTabContainer::showLibraryTab);

stateManager.clearSearchQuery();
stateManager.activeTabProperty().get().ifPresent(tab -> tab.clearAndSelect(selectedEntry.getEntry()));
stage.close();
}
});

container.getItems().addAll(resultsTable, previewViewer);

keepOnTop.selectedProperty().bindBidirectional(viewModel.keepOnTop());

EasyBind.subscribe(viewModel.keepOnTop(), value -> {
Stage stage = (Stage) getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(value);
keepOnTop.setGraphic(value
? IconTheme.JabRefIcons.KEEP_ON_TOP.getGraphicNode()
: IconTheme.JabRefIcons.KEEP_ON_TOP_OFF.getGraphicNode());
});

getDialogPane().getScene().getWindow().addEventHandler(WindowEvent.WINDOW_SHOWN, event -> {
getDialogPane().setPrefHeight(preferencesService.getSearchPreferences().getSearchWindowHeight());
getDialogPane().setPrefWidth(preferencesService.getSearchPreferences().getSearchWindowWidth());
stage.setOnShown(event -> {
stage.setHeight(preferencesService.getSearchPreferences().getSearchWindowHeight());
stage.setWidth(preferencesService.getSearchPreferences().getSearchWindowWidth());
});

getDialogPane().getScene().getWindow().addEventHandler(WindowEvent.WINDOW_HIDDEN, event -> {
stage.setOnHidden(event -> {
preferencesService.getSearchPreferences().setSearchWindowHeight(getHeight());
preferencesService.getSearchPreferences().setSearchWindowWidth(getWidth());
});
Expand Down
Loading