Commit 5b0ca33d authored by Ahmad Samir's avatar Ahmad Samir
Browse files

filetree plugin: make it possible to filter items in the tree view

Like the one in the Project plugin, it's useful when you have many
documents open at the same time.
parent 94529e1c
......@@ -26,7 +26,9 @@
#include <QAction>
#include <QApplication>
#include <QLineEdit>
#include <QStyle>
#include <QTimer>
#include "katefiletreedebug.h"
......@@ -143,12 +145,23 @@ KateFileTreePluginView::KateFileTreePluginView(KTextEditor::MainWindow *mainWind
m_proxyModel = new KateFileTreeProxyModel(this);
m_proxyModel->setSourceModel(m_documentModel);
m_proxyModel->setDynamicSortFilter(true);
m_proxyModel->setRecursiveFilteringEnabled(true);
m_documentModel->setShowFullPathOnRoots(m_plug->settings().showFullPathOnRoots());
m_documentModel->setShadingEnabled(m_plug->settings().shadingEnabled());
m_documentModel->setViewShade(m_plug->settings().viewShade());
m_documentModel->setEditShade(m_plug->settings().editShade());
m_filter = new QLineEdit(m_toolView);
m_filter->setPlaceholderText(QStringLiteral("Filter..."));
m_filter->setClearButtonEnabled(true);
connect(m_filter, &QLineEdit::textChanged, this, [this](const QString &text) {
m_proxyModel->setFilterRegularExpression(text);
if (!text.isEmpty()) {
QTimer::singleShot(100, m_fileTree, &QTreeView::expandAll);
}
});
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentWillBeDeleted, m_documentModel, &KateFileTreeModel::documentClosed);
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentCreated, this, &KateFileTreePluginView::documentOpened);
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentWillBeDeleted, this, &KateFileTreePluginView::documentClosed);
......
......@@ -28,6 +28,8 @@ class KateFileTreeProxyModel;
class KateFileTreeConfigPage;
class KateFileTreePluginView;
class QLineEdit;
class KateFileTreePlugin : public KTextEditor::Plugin
{
Q_OBJECT
......@@ -103,6 +105,7 @@ private:
KToolBar *m_toolbar;
KateFileTree *m_fileTree;
KateFileTreeProxyModel *m_proxyModel;
QLineEdit *m_filter;
KateFileTreeModel *m_documentModel;
bool m_hasLocalPrefs = false;
bool m_loadingDocuments;
......
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