From 4102ccb80457eea44ea280f0ace2a419602bc34b Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Mon, 7 Apr 2025 21:09:00 +0000 Subject: Rewrite search integration This huge commit is a nearly complete rewrite of the Dolphin search code. It implements most of the improved Dolphin search UI/UX as designed and discussed in a collaborative effort by Kristen McWilliam, Jin Liu, Andy Betts, Tagwerk, a few others and me. See https://invent.kde.org/system/dolphin/-/issues/46. # Notable changes - A toggle to change the search tool is provided as most contributors deemed that useful in https://invent.kde.org/system/dolphin/-/merge_requests/642#note_985112. - The default search is changed to filenamesearch for maximum reliability. - Removing all search parameters will take users back to the view state prior to starting a search instead of keeping the search results open. - The UI for choosing file types or modification dates has been made more powerful with more granularity and more options. - Most search parameters can be configured from a popup menu which gives us extra space for extra clarity. - Labels and help buttons as well as hyperlinks to settings makes sure the user always knows why some search parameters are unavailable in some contexts. - Chips show important search parameters while the popup is closed. They allow quickly removing filters. - The titles of the search and the input field placeholder message change to make clear whether file names or file contents are searched. - When the user actively switches the search tool, whether content should be searched, or whether to search everywhere, this is preserved for the initial state of the search bar when the user opens it the next time after restarting Dolphin. # Architecture - The new DolphinQuery class is independent of the UI and contains all search parameters modifiable in Dolphin as easy setters and getters. - DolphinQuery objects are also used to update the states of every component in the search UI. There is now a clear separation of UI and search configuration/DolphinQuery. - DolphinQuery is responsible for exporting to and importing from search URLs. - The search UI always reflects the currently configured DolphinQuery no matter if the user changed the UI to change the DolphinQuery or loaded a DolphinQuery/older search URL which then is reflected in the UI. - I tried to simplify all classes and their interaction between each other as much as possible. - I added some tests BUG: 386754 CCBUG: 435119 CCBUG: 458761 BUG: 446387 BUG: 470136 CCBUG: 471556 CCBUG: 475439 CCBUG: 477969 BUG: 480001 BUG: 483578 BUG: 488047 BUG: 488845 BUG: 500103 FIXED-IN: 25.08 --- src/dolphinviewcontainer.h | 71 ++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 30 deletions(-) (limited to 'src/dolphinviewcontainer.h') diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index a509bab3d..e827c0885 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -31,7 +31,10 @@ class FilterBar; class QAction; class QGridLayout; class QUrl; -class DolphinSearchBox; +namespace Search +{ +class Bar; +} class DolphinStatusBar; class KFileItemList; namespace SelectionMode @@ -39,6 +42,11 @@ namespace SelectionMode class TopBar; } +/** + * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://). + */ +bool isSearchUrl(const QUrl &url); + /** * @short Represents a view for the directory content * including the navigation bar, filter bar and status bar. @@ -78,10 +86,7 @@ public: * as soon as the URL has been changed. Per default the grabbing * of the focus is enabled. */ - void setAutoGrabFocus(bool grab); - bool autoGrabFocus() const; - - QString currentSearchText() const; + void setGrabFocusOnUrlChange(bool grabFocus); const DolphinStatusBar *statusBar() const; DolphinStatusBar *statusBar(); @@ -133,6 +138,28 @@ public: */ void disconnectUrlNavigator(); + /** + * Sets the visibility of this objects search configuration user interface. This search bar is the primary interface in Dolphin to search for files and + * folders. + * + * The signal searchBarVisibilityChanged will be emitted when the new visibility state is different from the old. + * + * Typically an animation will play when the search bar is shown or hidden, so the visibility of the bar will not necessarily match @p visible when this + * method returns. Instead use isSearchBarVisible(), which will always communicate the visibility state the search bar is heading to. + * + * @see Search::Bar. + * @see isSearchBarVisible(). + */ + void setSearchBarVisible(bool visible); + + /** @returns true if the search bar is visible while not being in the process to hide itself. */ + bool isSearchBarVisible() const; + + /** + * Moves keyboard focus to the search bar. The search term is fully selected to allow easy replacing. + */ + void setFocusToSearchBar(); + /** * Sets a selection mode that is useful for quick and easy selecting or deselecting of files. * This method is the central authority about enabling or disabling selection mode: @@ -166,9 +193,6 @@ public: * false, if it is hidden or currently animating towards a hidden state. */ bool isFilterBarVisible() const; - /** Returns true if the search mode is enabled. */ - bool isSearchModeEnabled() const; - /** * @return Text that should be used for the current URL when creating * a new place. @@ -221,12 +245,6 @@ public Q_SLOTS: */ void setFilterBarVisible(bool visible); - /** - * Enables the search mode, if \p enabled is true. In the search mode the URL navigator - * will be hidden and replaced by a line editor that allows to enter a search term. - */ - void setSearchModeEnabled(bool enabled); - /** Used to notify the m_selectionModeBottomBar that there is no other ViewContainer in the tab. */ void slotSplitTabDisabled(); @@ -236,9 +254,14 @@ Q_SIGNALS: */ void showFilterBarChanged(bool shown); /** - * Is emitted whenever the search mode has changed its state. + * Is emitted whenever a change to the search bar's visibility is invoked. The visibility change might not have actually already taken effect by the time + * this signal is emitted because typically the showing and hiding is animated. + * @param visible The visibility state the search bar is going to end up at. + * @see Search::Bar. + * @see setSearchBarVisible(). + * @see isSearchBarVisible(). */ - void searchModeEnabledChanged(bool enabled); + void searchBarVisibilityChanged(bool visible); void selectionModeChanged(bool enabled); @@ -373,13 +396,6 @@ private Q_SLOTS: /** Requests the focus for the view \a m_view. */ void requestFocus(); - /** - * Gets the search URL from the searchbox and starts searching. - */ - void startSearching(); - void openSearchBox(); - void closeSearchBox(); - /** * Stops the loading of a directory. Is connected with the "stopPressed" signal * from the statusbar. @@ -411,11 +427,6 @@ private Q_SLOTS: void slotOpenUrlFinished(KJob *job); private: - /** - * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://). - */ - bool isSearchUrl(const QUrl &url) const; - /** * Saves the state of the current view: contents position, * root URL, ... @@ -463,7 +474,7 @@ private: */ QPointer m_urlNavigatorConnected; - DolphinSearchBox *m_searchBox; + Search::Bar *m_searchBar; bool m_searchModeEnabled; /// A bar shown at the top of the view to signify that the view is currently viewed and acted on with elevated privileges. @@ -486,7 +497,7 @@ private: DolphinStatusBar *m_statusBar; QTimer *m_statusBarTimer; // Triggers a delayed update QElapsedTimer m_statusBarTimestamp; // Time in ms since last update - bool m_autoGrabFocus; + bool m_grabFocusOnUrlChange; /** * The visual state to be applied to the next UrlNavigator that gets * connected to this ViewContainer. -- cgit v1.3