Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class StateManager {
private final ObservableList<BibEntry> selectedEntries = FXCollections.observableArrayList();
private final ObservableMap<BibDatabaseContext, ObservableList<GroupTreeNode>> selectedGroups = FXCollections.observableHashMap();
private final OptionalObjectProperty<SearchQuery> activeSearchQuery = OptionalObjectProperty.empty();
private final OptionalObjectProperty<SearchQuery> activeGlobalSearchQuery = OptionalObjectProperty.empty();
private final IntegerProperty globalSearchResultSize = new SimpleIntegerProperty(0);
private final ObservableMap<BibDatabaseContext, IntegerProperty> searchResultMap = FXCollections.observableHashMap();
private final OptionalObjectProperty<Node> focusOwner = OptionalObjectProperty.empty();
private final ObservableList<Pair<BackgroundTask<?>, Task<?>>> backgroundTasks = FXCollections.observableArrayList(task -> new Observable[]{task.getValue().progressProperty(), task.getValue().runningProperty()});
Expand Down Expand Up @@ -108,6 +110,14 @@ public IntegerProperty getSearchResultSize() {
return searchResultMap.getOrDefault(activeDatabase.getValue().orElse(new BibDatabaseContext()), new SimpleIntegerProperty(0));
}

public OptionalObjectProperty<SearchQuery> activeGlobalSearchQueryProperty() {
return activeGlobalSearchQuery;
}

public IntegerProperty getGlobalSearchResultSize() {
return globalSearchResultSize;
}

public ReadOnlyListProperty<GroupTreeNode> activeGroupProperty() {
return activeGroups.getReadOnlyProperty();
}
Expand Down Expand Up @@ -155,6 +165,14 @@ public void setSearchQuery(SearchQuery searchQuery) {
activeSearchQuery.setValue(Optional.of(searchQuery));
}

public void clearGlobalSearchQuery() {
activeGlobalSearchQuery.setValue(Optional.empty());
}

public void setGlobalSearchQuery(SearchQuery searchQuery) {
activeGlobalSearchQuery.setValue(Optional.of(searchQuery));
}

public OptionalObjectProperty<Node> focusOwnerProperty() {
return focusOwner;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public SourceTab(BibDatabaseContext bibDatabaseContext,
searchHighlightPattern = newValue.flatMap(SearchQuery::getPatternForWords);
highlightSearchPattern();
});

stateManager.activeGlobalSearchQueryProperty().addListener((observable, oldValue, newValue) -> {
searchHighlightPattern = newValue.flatMap(SearchQuery::getPatternForWords);
highlightSearchPattern();
});
}

private void highlightSearchPattern() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/preview/PreviewViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public PreviewViewer(BibDatabaseContext database,
}
if (!registered) {
stateManager.activeSearchQueryProperty().addListener(listener);
stateManager.activeGlobalSearchQueryProperty().addListener(listener);
registered = true;
}
highlightSearchPattern();
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 @@ -102,6 +102,7 @@ public class GlobalSearchBar extends HBox {
private final PreferencesService preferencesService;
private final Validator regexValidator;
private final UndoManager undoManager;
private final LibraryTabContainer tabContainer;

private final SearchPreferences searchPreferences;
private final DialogService dialogService;
Expand All @@ -120,6 +121,7 @@ public GlobalSearchBar(LibraryTabContainer tabContainer,
this.searchPreferences = preferencesService.getSearchPreferences();
this.undoManager = undoManager;
this.dialogService = dialogService;
this.tabContainer = tabContainer;

searchField.disableProperty().bind(needsDatabase(stateManager).not());

Expand Down Expand Up @@ -276,7 +278,7 @@ private void initSearchModifierButtons() {
initSearchModifierButton(openGlobalSearchButton);
openGlobalSearchButton.setOnAction(evt -> {
globalSearchActive.setValue(true);
globalSearchResultDialog = new GlobalSearchResultDialog(undoManager);
globalSearchResultDialog = new GlobalSearchResultDialog(undoManager, tabContainer);
updateSearchQuery();
dialogService.showCustomDialogAndWait(globalSearchResultDialog);
globalSearchActive.setValue(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
prefHeight="400.0" prefWidth="600.0">
<content>
<VBox>
<HBox spacing="10" alignment="CENTER_RIGHT">
<HBox fx:id="searchBarContainer" spacing="10" alignment="CENTER_RIGHT">
<ToggleButton fx:id="keepOnTop" styleClass="icon-button,narrow" prefHeight="20.0" prefWidth="20.0">
<graphic>
<JabRefIconView glyph="KEEP_ON_TOP"/>
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/org/jabref/gui/search/GlobalSearchResultDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import javafx.fxml.FXML;
import javafx.scene.control.SplitPane;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.HBox;
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;
import org.jabref.gui.StateManager;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.maintable.columns.SpecialFieldColumn;
Expand All @@ -28,9 +31,9 @@ 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 All @@ -39,8 +42,9 @@ public class GlobalSearchResultDialog extends BaseDialog<Void> {

private GlobalSearchResultDialogViewModel viewModel;

public GlobalSearchResultDialog(UndoManager undoManager) {
public GlobalSearchResultDialog(UndoManager undoManager, LibraryTabContainer libraryTabContainer) {
this.undoManager = undoManager;
this.libraryTabContainer = libraryTabContainer;

setTitle(Localization.lang("Search results from open libraries"));
ViewLoader.view(this)
Expand All @@ -53,6 +57,10 @@ public GlobalSearchResultDialog(UndoManager undoManager) {
private void initialize() {
viewModel = new GlobalSearchResultDialogViewModel(preferencesService);

SearchResultDialogSearchBar searchBar = new SearchResultDialogSearchBar(libraryTabContainer, stateManager, preferencesService, undoManager);
Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of having this as a separate component, but inside you have bascially duplicate functionality/content to the normal "SearchBar". Can the normal search bar also be adapted to use this new component?
DRY (Don't Repeat Yourself) Principle

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to avoid these duplications, but I don't know how to handle them. Should I create a new class containing some static methods and call them? Or what do you suggest? The only difference between the two classes is the removal of two buttons (keepSearchString, openGlobalSearchButton) and a change in the listener to listen to the newly introduced property activeGlobalSearchQuery.

Copy link
Member

Choose a reason for hiding this comment

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

Pass the listener as Consumer parameter and maybe pass an enum e.g. NORMAL_SEARCH, GLOBAL_SEARCH and adapt the buttons accordingly

searchBarContainer.getChildren().addFirst(searchBar);
HBox.setHgrow(searchBar, Priority.ALWAYS);

PreviewViewer previewViewer = new PreviewViewer(viewModel.getSearchDatabaseContext(), dialogService, preferencesService, stateManager, themeManager, taskExecutor);
previewViewer.setLayout(preferencesService.getPreviewPreferences().getSelectedPreviewLayout());

Expand Down Expand Up @@ -93,6 +101,7 @@ private void initialize() {
getDialogPane().getScene().getWindow().addEventHandler(WindowEvent.WINDOW_HIDDEN, event -> {
preferencesService.getSearchPreferences().setSearchWindowHeight(getHeight());
preferencesService.getSearchPreferences().setSearchWindowWidth(getWidth());
stateManager.clearGlobalSearchQuery();
});
}
}
Loading