Commit ec8b5470 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Use fuzzy filter in kateprojectplugin

parent b01b6955
......@@ -27,6 +27,12 @@ target_link_libraries(
KF5::ThreadWeaver
)
target_include_directories(
kateprojectplugin
PUBLIC
${CMAKE_SOURCE_DIR}/shared
)
include(CheckFunctionExists)
check_function_exists(ctermid HAVE_CTERMID)
......
/* This file is part of the Kate project.
*
* SPDX-FileCopyrightText: 2012 Christoph Cullmann <cullmann@kde.org>
* SPDX-FileCopyrightText: 2021 Waqar Ahmed <waqar.17a@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KATEPROJECTFILTERMODEL_H
#define KATEPROJECTFILTERMODEL_H
#include <QSortFilterProxyModel>
#include <QDebug>
#include <kfts_fuzzy_match.h>
class KateProjectFilterProxyModel : public QSortFilterProxyModel
{
public:
KateProjectFilterProxyModel(QObject* parent = nullptr) :
QSortFilterProxyModel(parent)
{}
void setFilterString(const QString& string)
{
m_pattern = string;
invalidateFilter();
}
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
{
if (m_pattern.isEmpty())
return true;
int score = 0; // unused intentionally
QString file = sourceModel()->index(sourceRow, 0, sourceParent).data().toString();
return kfts::fuzzy_match(m_pattern, file, score);
}
private:
QString m_pattern;
};
#endif // KATEPROJECTFILTERMODEL_H
......@@ -7,6 +7,7 @@
#include "kateprojectview.h"
#include "kateprojectpluginview.h"
#include "kateprojectfiltermodel.h"
#include <ktexteditor/document.h>
#include <ktexteditor/view.h>
......@@ -64,7 +65,7 @@ void KateProjectView::filterTextChanged(const QString &filterText)
/**
* filter
*/
static_cast<QSortFilterProxyModel *>(m_treeView->model())->setFilterFixedString(filterText);
static_cast<KateProjectFilterProxyModel*>(m_treeView->model())->setFilterString(filterText);
/**
* expand
......
......@@ -8,14 +8,13 @@
#include "kateprojectviewtree.h"
#include "kateprojectpluginview.h"
#include "kateprojecttreeviewcontextmenu.h"
#include "kateprojectfiltermodel.h"
#include <ktexteditor/document.h>
#include <ktexteditor/view.h>
#include <QContextMenuEvent>
#include <QSortFilterProxyModel>
KateProjectViewTree::KateProjectViewTree(KateProjectPluginView *pluginView, KateProject *project)
: m_pluginView(pluginView)
, m_project(project)
......@@ -36,7 +35,7 @@ KateProjectViewTree::KateProjectViewTree(KateProjectPluginView *pluginView, Kate
*/
QItemSelectionModel *m = selectionModel();
QSortFilterProxyModel *sortModel = new QSortFilterProxyModel(this);
KateProjectFilterProxyModel *sortModel = new KateProjectFilterProxyModel(this);
// sortModel->setFilterRole(SortFilterRole);
// sortModel->setSortRole(SortFilterRole);
......
......@@ -11,6 +11,9 @@
#include "kateproject.h"
#include <QTreeView>
#include <QSortFilterProxyModel>
#include <kfts_fuzzy_match.h>
class KateProjectPluginView;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment