diff options
| author | Alessio Bonfiglio <[email protected]> | 2026-03-11 20:52:55 +0100 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2026-03-12 10:51:45 +0000 |
| commit | 3084a4e11e54b71065a408c7d288489bc72ea8a2 (patch) | |
| tree | 77b44ab7462b05af02822a2ab264d32796bfa7e6 /src/dolphinviewcontainer.cpp | |
| parent | 287ff66e678f4f5a4edea28fc2699d73cefc3233 (diff) | |
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.
Diffstat (limited to 'src/dolphinviewcontainer.cpp')
| -rw-r--r-- | src/dolphinviewcontainer.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 5c054eab8..4d7472ed3 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -110,6 +110,8 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent) m_filterBar->setVisible(GeneralSettings::filterBar(), WithoutAnimation); connect(m_filterBar, &FilterBar::filterChanged, this, &DolphinViewContainer::setNameFilter); + connect(m_filterBar, &FilterBar::filterModeChanged, this, &DolphinViewContainer::setFilterMode); + connect(m_filterBar, &FilterBar::caseSensitiveChanged, this, &DolphinViewContainer::setFilterCaseSensitive); connect(m_filterBar, &FilterBar::closeRequest, this, &DolphinViewContainer::closeFilterBar); connect(m_filterBar, &FilterBar::focusViewRequest, this, &DolphinViewContainer::requestFocus); @@ -208,6 +210,10 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent) connect(placesModel, &KFilePlacesModel::rowsRemoved, this, &DolphinViewContainer::slotPlacesModelChanged); QApplication::instance()->installEventFilter(this); + + // Update the view with the current state of the filter bar (from the state config) + m_view->setFilterMode(m_filterBar->filterMode()); + m_view->setFilterCaseSensitive(m_filterBar->isCaseSensitive()); } DolphinViewContainer::~DolphinViewContainer() = default; @@ -867,6 +873,18 @@ void DolphinViewContainer::setNameFilter(const QString &nameFilter) delayedStatusBarUpdate(); } +void DolphinViewContainer::setFilterMode(const KFileItemModelFilter::FilterMode mode) +{ + m_view->setFilterMode(mode); + delayedStatusBarUpdate(); +} + +void DolphinViewContainer::setFilterCaseSensitive(const bool caseSensitive) +{ + m_view->setFilterCaseSensitive(caseSensitive); + delayedStatusBarUpdate(); +} + void DolphinViewContainer::activate() { setActive(true); |
