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

Fix context menu of the search bar #11446

Merged
merged 21 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b0017fb
Fix selecting group triggers in all open libraries
LoayGhreeb Jun 29, 2024
b89a9ed
Change color of the search modifier buttons for dark theme
LoayGhreeb Jun 29, 2024
61413f3
Add shortcut to open global search window "Ctrl+shift+F"
LoayGhreeb Jun 29, 2024
fda8f4c
fix keep on top subscription
LoayGhreeb Jun 29, 2024
e26dc17
Fix context menu of the search bar
LoayGhreeb Jun 29, 2024
579abed
Store preview divider position in global search window
LoayGhreeb Jun 30, 2024
6d3a5b7
prevent NPE
LoayGhreeb Jun 29, 2024
d6d455c
Fix update search query triggers in all open libraries
LoayGhreeb Jul 1, 2024
b8a52cc
Adapt GUI test
LoayGhreeb Jul 1, 2024
e13e6a2
Merge branch 'main' into improveSearchPerformance
LoayGhreeb Jul 1, 2024
e537364
Clear search highlight in SourceTab after resetting search query
LoayGhreeb Jul 3, 2024
b7ab701
Merge branch 'main' into improveSearchPerformance
LoayGhreeb Jul 3, 2024
feedcae
Revert "Fix update search query triggers in all open libraries"
LoayGhreeb Jul 8, 2024
0b901a8
Revert "Fix selecting group triggers in all open libraries"
LoayGhreeb Jul 8, 2024
8dd73e9
Merge branch 'main' into improveSearchPerformance
LoayGhreeb Jul 8, 2024
bb2ba59
Remove regexValidator
LoayGhreeb Jul 8, 2024
a6692e6
Merge branch 'improveSearchPerformance' of https://github.com/LoayGhr…
LoayGhreeb Jul 8, 2024
c68c5bf
listen for changes for search flags
LoayGhreeb Jul 8, 2024
227f3c0
Merge branch 'main' into improveSearchPerformance
LoayGhreeb Jul 11, 2024
839bf79
Merge branch 'main' into improveSearchPerformance
LoayGhreeb Jul 17, 2024
21eb34a
Merge remote-tracking branch 'upstream/main' into improveSearchPerfor…
Siedlerchr Jul 24, 2024
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
16 changes: 6 additions & 10 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1072,29 +1072,25 @@ TextFlow > .tooltip-text-monospaced {
}

/* search modifier buttons */
.mainToolbar .search-field .toggle-button:selected {
.global-search-bar .toggle-button:selected {
-fx-background-color: transparent;
}

.mainToolbar .search-field .toggle-button:hover,
.mainToolbar .search-field .toggle-button:selected:hover {
.global-search-bar .toggle-button:hover,
.global-search-bar .toggle-button:selected:hover {
-fx-background-color: -jr-icon-background-active;
}

.mainToolbar .search-field .toggle-button .glyph-icon {
-fx-fill: derive(-jr-search-text, 80%);
-fx-text-fill: derive(-jr-search-text, 80%);
.global-search-bar .toggle-button .glyph-icon {
-fx-icon-color: derive(-jr-search-text, 80%);
}

.mainToolbar .search-field .toggle-button:selected .glyph-icon {
-fx-fill: -jr-search-text;
-fx-text-fill: -jr-search-text;
.global-search-bar .toggle-button:selected .glyph-icon {
-fx-icon-color: -jr-search-text;
}

/* search text */
.mainToolbar .search-field .label {
.global-search-bar .label {
-fx-padding: 0em 1.8em 0em 0em;
}

Expand Down
18 changes: 2 additions & 16 deletions src/main/java/org/jabref/gui/Dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,8 @@
-fx-background-color: -jr-background;
}

.mainToolbar .search-field .button .glyph-icon {
-fx-fill: derive(-fx-light-text-color, 80%);
-fx-text-fill: derive(-fx-light-text-color, 80%);
-fx-icon-color: derive(-fx-light-text-color, 80%);
}

.mainToolbar .search-field .toggle-button .glyph-icon {
-fx-fill: -jr-search-text;
-fx-text-fill: -jr-search-text;
-fx-icon-color:-jr-search-text;
}

.mainToolbar .search-field .toggle-button:selected .glyph-icon {
-fx-fill: derive(-fx-light-text-color, 80%);
-fx-text-fill: derive(-fx-light-text-color, 80%);
-fx-icon-color: derive(-fx-light-text-color, 80%);
.global-search-bar .toggle-button .glyph-icon {
-fx-icon-color: derive(-jr-search-background, 50%);
}

.notification-bar > .pane {
Expand Down
56 changes: 31 additions & 25 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import javafx.animation.PauseTransition;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.value.ObservableBooleanValue;
import javafx.collections.ListChangeListener;
import javafx.event.Event;
Expand Down Expand Up @@ -55,6 +59,7 @@
import org.jabref.gui.undo.UndoableInsertEntries;
import org.jabref.gui.undo.UndoableRemoveEntries;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.logic.citationstyle.CitationStyleCache;
Expand Down Expand Up @@ -85,6 +90,7 @@
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.util.DirectoryMonitor;
import org.jabref.model.util.DirectoryMonitorManager;
import org.jabref.model.util.FileUpdateMonitor;
Expand Down Expand Up @@ -146,8 +152,9 @@ private enum PanelMode { MAIN_TABLE, MAIN_TABLE_AND_ENTRY_EDITOR }
@SuppressWarnings({"FieldCanBeLocal"})
private Subscription dividerPositionSubscription;

// the query the user searches when this BasePanel is active
private Optional<SearchQuery> currentSearchQuery = Optional.empty();
private final OptionalObjectProperty<SearchQuery> searchQueryProperty = OptionalObjectProperty.empty();
private final IntegerProperty resultSize = new SimpleIntegerProperty(0);
private ListProperty<GroupTreeNode> selectedGroups;

private Optional<DatabaseChangeMonitor> changeMonitor = Optional.empty();

Expand All @@ -159,15 +166,15 @@ private enum PanelMode { MAIN_TABLE, MAIN_TABLE_AND_ENTRY_EDITOR }
private final DirectoryMonitorManager directoryMonitorManager;

private LibraryTab(BibDatabaseContext bibDatabaseContext,
LibraryTabContainer tabContainer,
DialogService dialogService,
PreferencesService preferencesService,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor,
BibEntryTypesManager entryTypesManager,
CountingUndoManager undoManager,
ClipBoardManager clipBoardManager,
TaskExecutor taskExecutor) {
LibraryTabContainer tabContainer,
DialogService dialogService,
PreferencesService preferencesService,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor,
BibEntryTypesManager entryTypesManager,
CountingUndoManager undoManager,
ClipBoardManager clipBoardManager,
TaskExecutor taskExecutor) {
this.tabContainer = Objects.requireNonNull(tabContainer);
this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext);
this.undoManager = undoManager;
Expand All @@ -184,7 +191,8 @@ private LibraryTab(BibDatabaseContext bibDatabaseContext,
bibDatabaseContext.getDatabase().registerListener(this);
bibDatabaseContext.getMetaData().registerListener(this);

this.tableModel = new MainTableDataModel(getBibDatabaseContext(), preferencesService, stateManager);
this.selectedGroups = new SimpleListProperty<>(stateManager.getSelectedGroups(bibDatabaseContext));
this.tableModel = new MainTableDataModel(bibDatabaseContext, preferencesService, selectedGroups, searchQueryProperty, resultSize);

citationStyleCache = new CitationStyleCache(bibDatabaseContext);
annotationCache = new FileAnnotationCache(bibDatabaseContext, preferencesService.getFilePreferences());
Expand Down Expand Up @@ -307,7 +315,9 @@ private void setDatabaseContext(BibDatabaseContext bibDatabaseContext) {
bibDatabaseContext.getDatabase().registerListener(this);
bibDatabaseContext.getMetaData().registerListener(this);

this.tableModel = new MainTableDataModel(getBibDatabaseContext(), preferencesService, stateManager);
tableModel.removeBinding();
this.selectedGroups = new SimpleListProperty<>(stateManager.getSelectedGroups(bibDatabaseContext));
this.tableModel = new MainTableDataModel(bibDatabaseContext, preferencesService, selectedGroups, searchQueryProperty, resultSize);
citationStyleCache = new CitationStyleCache(bibDatabaseContext);
annotationCache = new FileAnnotationCache(bibDatabaseContext, preferencesService.getFilePreferences());

Expand Down Expand Up @@ -385,7 +395,7 @@ public void updateTabTitle(boolean isChanged) {
toolTipText.append(databasePath.toAbsolutePath());

if (databaseLocation == DatabaseLocation.SHARED) {
tabTitle.append(" \u2013 ");
tabTitle.append(" ");
addSharedDbInformation(tabTitle, bibDatabaseContext);
toolTipText.append(' ');
addSharedDbInformation(toolTipText, bibDatabaseContext);
Expand Down Expand Up @@ -870,6 +880,9 @@ private void onClosed(Event event) {
LOGGER.error("Problem when shutting down backup manager", e);
}

if (tableModel != null) {
tableModel.removeBinding();
}
// clean up the groups map
stateManager.clearSelectedGroups(bibDatabaseContext);
}
Expand Down Expand Up @@ -911,19 +924,12 @@ public MainTable getMainTable() {
return mainTable;
}

public Optional<SearchQuery> getCurrentSearchQuery() {
return currentSearchQuery;
}

/**
* Set the query the user currently searches while this basepanel is active
*/
public void setCurrentSearchQuery(Optional<SearchQuery> currentSearchQuery) {
this.currentSearchQuery = currentSearchQuery;
public OptionalObjectProperty<SearchQuery> searchQueryProperty() {
return searchQueryProperty;
}

public CitationStyleCache getCitationStyleCache() {
return citationStyleCache;
public IntegerProperty resultSizeProperty() {
return resultSize;
}

public FileAnnotationCache getAnnotationCache() {
Expand Down
64 changes: 11 additions & 53 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
import java.util.Optional;

import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyListProperty;
import javafx.beans.property.ReadOnlyListWrapper;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
Expand All @@ -21,6 +18,7 @@
import javafx.util.Pair;

import org.jabref.gui.edit.automaticfiededitor.LastAutomaticFieldEditorEdit;
import org.jabref.gui.search.SearchType;
import org.jabref.gui.sidepane.SidePaneType;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.CustomLocalDragboard;
Expand Down Expand Up @@ -55,29 +53,22 @@ public class StateManager {
private final ObservableList<BibDatabaseContext> openDatabases = FXCollections.observableArrayList();
private final OptionalObjectProperty<BibDatabaseContext> activeDatabase = OptionalObjectProperty.empty();
private final OptionalObjectProperty<LibraryTab> activeTab = OptionalObjectProperty.empty();
private final ReadOnlyListWrapper<GroupTreeNode> activeGroups = new ReadOnlyListWrapper<>(FXCollections.observableArrayList());
private final ObservableList<BibEntry> selectedEntries = FXCollections.observableArrayList();
private final ObservableMap<String, 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<String, IntegerProperty> searchResultMap = FXCollections.observableHashMap();
private final IntegerProperty searchResultSize = new SimpleIntegerProperty(0);
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()});
private final EasyBinding<Boolean> anyTaskRunning = EasyBind.reduce(backgroundTasks, tasks -> tasks.map(Pair::getValue).anyMatch(Task::isRunning));
private final EasyBinding<Boolean> anyTasksThatWillNotBeRecoveredRunning = EasyBind.reduce(backgroundTasks, tasks -> tasks.anyMatch(task -> !task.getKey().willBeRecoveredAutomatically() && task.getValue().isRunning()));
private final EasyBinding<Double> tasksProgress = EasyBind.reduce(backgroundTasks, tasks -> tasks.map(Pair::getValue).filter(Task::isRunning).mapToDouble(Task::getProgress).average().orElse(1));
private final ObservableMap<String, DialogWindowState> dialogWindowStates = FXCollections.observableHashMap();
private final ObservableList<SidePaneType> visibleSidePanes = FXCollections.observableArrayList();

private final ObjectProperty<LastAutomaticFieldEditorEdit> lastAutomaticFieldEditorEdit = new SimpleObjectProperty<>();

private final ObservableList<String> searchHistory = FXCollections.observableArrayList();

public StateManager() {
activeGroups.bind(Bindings.valueAt(selectedGroups, activeDatabase.orElseOpt(null).map(BibDatabaseContext::getUid)));
}

public ObservableList<SidePaneType> getVisibleSidePaneComponents() {
return visibleSidePanes;
}
Expand All @@ -102,32 +93,16 @@ public OptionalObjectProperty<SearchQuery> activeSearchQueryProperty() {
return activeSearchQuery;
}

public void setActiveSearchResultSize(BibDatabaseContext database, IntegerProperty resultSize) {
searchResultMap.put(database.getUid(), resultSize);
}

public IntegerProperty getSearchResultSize() {
return searchResultMap.getOrDefault(activeDatabase.getValue().orElse(new BibDatabaseContext()).getUid(), new SimpleIntegerProperty(0));
}

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

public IntegerProperty getGlobalSearchResultSize() {
return globalSearchResultSize;
}

public IntegerProperty getSearchResultSize(OptionalObjectProperty<SearchQuery> searchQueryProperty) {
if (searchQueryProperty.equals(activeSearchQuery)) {
return getSearchResultSize();
} else {
return getGlobalSearchResultSize();
}
public OptionalObjectProperty<SearchQuery> activeSearchQuery(SearchType type) {
return type == SearchType.NORMAL_SEARCH ? activeSearchQuery : activeGlobalSearchQuery;
}

public ReadOnlyListProperty<GroupTreeNode> activeGroupProperty() {
return activeGroups.getReadOnlyProperty();
public IntegerProperty searchResultSize(SearchType type) {
return type == SearchType.NORMAL_SEARCH ? searchResultSize : globalSearchResultSize;
}

public ObservableList<BibEntry> getSelectedEntries() {
Expand All @@ -138,18 +113,17 @@ public void setSelectedEntries(List<BibEntry> newSelectedEntries) {
selectedEntries.setAll(newSelectedEntries);
}

public void setSelectedGroups(BibDatabaseContext database, List<GroupTreeNode> newSelectedGroups) {
public void setSelectedGroups(BibDatabaseContext context, List<GroupTreeNode> newSelectedGroups) {
Objects.requireNonNull(newSelectedGroups);
selectedGroups.put(database.getUid(), FXCollections.observableArrayList(newSelectedGroups));
selectedGroups.computeIfAbsent(context.getUid(), k -> FXCollections.observableArrayList()).setAll(newSelectedGroups);
}

public ObservableList<GroupTreeNode> getSelectedGroups(BibDatabaseContext context) {
ObservableList<GroupTreeNode> selectedGroupsForDatabase = selectedGroups.get(context.getUid());
return selectedGroupsForDatabase != null ? selectedGroupsForDatabase : FXCollections.observableArrayList();
return selectedGroups.computeIfAbsent(context.getUid(), k -> FXCollections.observableArrayList());
}

public void clearSelectedGroups(BibDatabaseContext database) {
selectedGroups.remove(database.getUid());
public void clearSelectedGroups(BibDatabaseContext context) {
selectedGroups.computeIfAbsent(context.getUid(), k -> FXCollections.observableArrayList()).clear();
}

public Optional<BibDatabaseContext> getActiveDatabase() {
Expand All @@ -165,18 +139,6 @@ public void setActiveDatabase(BibDatabaseContext database) {
}
}

public void clearSearchQuery() {
activeSearchQuery.setValue(Optional.empty());
}

public void setSearchQuery(OptionalObjectProperty<SearchQuery> searchQueryProperty, SearchQuery query) {
searchQueryProperty.setValue(Optional.of(query));
}

public void clearSearchQuery(OptionalObjectProperty<SearchQuery> searchQueryProperty) {
searchQueryProperty.setValue(Optional.empty());
}

public OptionalObjectProperty<Node> focusOwnerProperty() {
return focusOwner;
}
Expand Down Expand Up @@ -217,10 +179,6 @@ public ObjectProperty<LastAutomaticFieldEditorEdit> lastAutomaticFieldEditorEdit
return lastAutomaticFieldEditorEdit;
}

public LastAutomaticFieldEditorEdit getLastAutomaticFieldEditorEdit() {
return lastAutomaticFieldEditorEditProperty().get();
}

public void setLastAutomaticFieldEditorEdit(LastAutomaticFieldEditorEdit automaticFieldEditorEdit) {
lastAutomaticFieldEditorEditProperty().set(automaticFieldEditorEdit);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ private List<EntryEditorTab> createTabs() {
preferencesService.getImportFormatPreferences(),
fileMonitor,
dialogService,
stateManager,
bibEntryTypesManager,
keyBindingRepository);
keyBindingRepository,
libraryTab.searchQueryProperty());
tabs.add(sourceTab);
tabs.add(new LatexCitationsTab(databaseContext, preferencesService, dialogService, directoryMonitorManager));
tabs.add(new FulltextSearchResultsTab(stateManager, preferencesService, dialogService, taskExecutor));
tabs.add(new FulltextSearchResultsTab(stateManager, preferencesService, dialogService, taskExecutor, libraryTab.searchQueryProperty()));

return tabs;
}
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import javafx.scene.input.KeyEvent;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.actions.StandardActions;
Expand All @@ -32,6 +31,7 @@
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableChangeType;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.logic.bibtex.BibEntryWriter;
import org.jabref.logic.bibtex.FieldPreferences;
Expand Down Expand Up @@ -104,9 +104,9 @@ public SourceTab(BibDatabaseContext bibDatabaseContext,
ImportFormatPreferences importFormatPreferences,
FileUpdateMonitor fileMonitor,
DialogService dialogService,
StateManager stateManager,
BibEntryTypesManager entryTypesManager,
KeyBindingRepository keyBindingRepository) {
KeyBindingRepository keyBindingRepository,
OptionalObjectProperty<SearchQuery> searchQuery) {
this.mode = bibDatabaseContext.getMode();
this.setText(Localization.lang("%0 source", mode.getFormattedName()));
this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName())));
Expand All @@ -119,12 +119,7 @@ public SourceTab(BibDatabaseContext bibDatabaseContext,
this.entryTypesManager = entryTypesManager;
this.keyBindingRepository = keyBindingRepository;

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

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