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/views/dolphinview.cpp | 20 ++++++++++++++++++++ src/views/dolphinview.h | 13 +++++++++++++ 2 files changed, 33 insertions(+) (limited to 'src/views') diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index b48e1ae74..2213e2c82 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -639,6 +639,26 @@ QStringList DolphinView::mimeTypeFilters() const return m_model->mimeTypeFilters(); } +void DolphinView::setFilterMode(KFileItemModelFilter::FilterMode mode) +{ + m_model->setFilterMode(mode); +} + +KFileItemModelFilter::FilterMode DolphinView::filterMode() const +{ + return m_model->filterMode(); +} + +void DolphinView::setFilterCaseSensitive(bool caseSensitive) +{ + m_model->setFilterCaseSensitive(caseSensitive); +} + +bool DolphinView::isFilterCaseSensitive() const +{ + return m_model->isFilterCaseSensitive(); +} + void DolphinView::requestStatusBarText() { if (m_statJobForStatusBarText) { diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index 67233b668..6aa5b595d 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -10,6 +10,7 @@ #include "dolphin_export.h" #include "dolphintabwidget.h" +#include "kitemviews/private/kfileitemmodelfilter.h" #include "tooltips/tooltipmanager.h" #include "config-dolphin.h" @@ -276,6 +277,18 @@ public: void setMimeTypeFilters(const QStringList &filters); QStringList mimeTypeFilters() const; + /** + * Sets the filtering mode of the currently used nameFilter. + */ + void setFilterMode(KFileItemModelFilter::FilterMode mode); + KFileItemModelFilter::FilterMode filterMode() const; + + /** + * Enables or disable the caseSensitive matching of the currently used nameFilter. + */ + void setFilterCaseSensitive(bool caseSensitive); + bool isFilterCaseSensitive() const; + /** * Tells the view to generate an updated status bar text. The result * is returned through the statusBarTextChanged(QString statusBarText) signal. -- cgit v1.3