From 3084a4e11e54b71065a408c7d288489bc72ea8a2 Mon Sep 17 00:00:00 2001 From: Alessio Bonfiglio Date: Wed, 11 Mar 2026 20:52:55 +0100 Subject: filterbar: Add support to match case and glob patterns for the filter bar Currently, Dolphin's filter bar defaults to plain text, but it actually has a hidden regex functionality too: it tries to auto-detect and switch to a regular expression if characters like '*', '?', or '[' are present in the search string. This approach has a couple of issues. First, the regex/wildcard functionality is completely hidden from the user. Second, the auto-detection is flawed because those are perfectly valid characters in Linux filenames. If a user tries to filter for a file literally named [draft].txt, the auto-switching kicks in and causes unexpected behavior. This MR fixes this by making the filtering modes explicit through a ComboBox at the side of the filter bar, with the options 'Plain Text', 'Glob' and 'Regular Expression'. It also adds a button to toggle the case sensitive matching. A visual feedback for when the user is inputting an invalid expression has also been implemented by turning the bar background red and making appear an error symbol. --- src/filterbar/filterbar.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/filterbar/filterbar.h') diff --git a/src/filterbar/filterbar.h b/src/filterbar/filterbar.h index 1424f4cb8..924c6dba3 100644 --- a/src/filterbar/filterbar.h +++ b/src/filterbar/filterbar.h @@ -10,9 +10,12 @@ #define FILTERBAR_H #include "animatedheightwidget.h" +#include "kitemviews/private/kfileitemmodelfilter.h" class QLineEdit; class QToolButton; +class QComboBox; +class QAction; /** * @brief Provides an input field for filtering the currently shown items. @@ -35,6 +38,9 @@ public: */ void selectAll(); + KFileItemModelFilter::FilterMode filterMode() const; + bool isCaseSensitive() const; + public Q_SLOTS: /** Clears the input field. */ void clear(); @@ -50,6 +56,16 @@ Q_SIGNALS: */ void filterChanged(const QString &nameFilter); + /** + * Emitted when the case sensitive mode has been changed + */ + void caseSensitiveChanged(bool caseSensitive); + + /** + * Emitted when the filter mode has been changed + */ + void filterModeChanged(KFileItemModelFilter::FilterMode mode); + /** * Emitted as soon as the filterbar should get closed. */ @@ -70,6 +86,12 @@ protected: private: QLineEdit *m_filterInput; QToolButton *m_lockButton; + QToolButton *m_caseSensitiveButton; + QComboBox *m_filterModeComboBox; + QAction *m_invalidPatternAction; + + /** Enable or disable the alterative view for when a pattern is invalid */ + void updateInvalidPatternView(); }; #endif -- cgit v1.3