Commit 537ffc16 authored by Alain Laporte's avatar Alain Laporte Committed by Christoph Cullmann
Browse files

Symbol Viewer: add filter

parent be8168d7
......@@ -46,7 +46,9 @@
#include <KSharedConfig>
#include <KToggleAction>
#include <KXMLGUIFactory>
#include <KLineEdit>
#include <QAction>
#include <QLineEdit>
#include <ktexteditor/configinterface.h>
#include <ktexteditor/cursor.h>
......@@ -115,7 +117,7 @@ KatePluginSymbolViewerView::KatePluginSymbolViewerView(KatePluginSymbolViewer *p
m_toolview = m_mainWindow->createToolView(plugin, QStringLiteral("kate_plugin_symbolviewer"), KTextEditor::MainWindow::Left, cls, i18n("Symbol List"));
QWidget *container = new QWidget(m_toolview);
QHBoxLayout *layout = new QHBoxLayout(container);
QVBoxLayout *layout = new QVBoxLayout(container);
m_symbols = new QTreeWidget();
m_symbols->setFocusPolicy(Qt::NoFocus);
......@@ -128,6 +130,14 @@ KatePluginSymbolViewerView::KatePluginSymbolViewerView(KatePluginSymbolViewer *p
connect(m_symbols, &QTreeWidget::itemExpanded, this, &KatePluginSymbolViewerView::updateCurrTreeItem);
connect(m_symbols, &QTreeWidget::itemCollapsed, this, &KatePluginSymbolViewerView::updateCurrTreeItem);
m_filter = new KLineEdit(container);
m_filter->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
m_filter->setPlaceholderText(i18n("Filter..."));
m_filter->setClearButtonEnabled(true);
layout->addWidget(m_filter);
connect(m_filter, &KLineEdit::textChanged, this, &KatePluginSymbolViewerView::slotFilterChange);
connect(m_mainWindow, &KTextEditor::MainWindow::viewChanged, this, &KatePluginSymbolViewerView::slotDocChanged);
QStringList titles;
......@@ -377,6 +387,31 @@ void KatePluginSymbolViewerView::goToSymbol(QTreeWidgetItem *it)
kv->setCursorPosition(KTextEditor::Cursor(it->text(1).toInt(nullptr, 10), 0));
}
void KatePluginSymbolViewerView::slotFilterChange(const QString &text)
{
QString filter = text.trimmed();
for (int i = 0; i < m_symbols->invisibleRootItem()->childCount(); ++i) {
QTreeWidgetItem * group_item = m_symbols->invisibleRootItem()->child(i);
for (int j = 0; j < group_item->childCount(); ++j) {
filterSymbols(group_item->child(j), filter);
}
}
}
bool KatePluginSymbolViewerView::filterSymbols(QTreeWidgetItem * item, const QString & filter)
{
bool at_least_one_child_shown = false;
for (int i = 0; i < item->childCount(); ++i) {
if (filterSymbols(item->child(i), filter)) {
at_least_one_child_shown = true;
}
}
bool is_item_match = item->text(0).contains(filter, Qt::CaseInsensitive);
bool is_item_shown = at_least_one_child_shown || filter.isEmpty() || is_item_match;
item->setHidden(!is_item_shown);
return is_item_shown;
}
KatePluginSymbolViewer::KatePluginSymbolViewer(QObject *parent, const QList<QVariant> &)
: KTextEditor::Plugin(parent)
{
......
......@@ -41,6 +41,8 @@ enum class Symbol {
Method
};
class KLineEdit;
/**
* Plugin's config page
*/
......@@ -112,6 +114,7 @@ public Q_SLOTS:
QTreeWidgetItem *newActveItem(int &currMinLine, int currLine, QTreeWidgetItem *item);
void updateCurrTreeItem();
void slotDocEdited();
void slotFilterChange(const QString &);
protected:
bool eventFilter(QObject *obj, QEvent *ev) override;
......@@ -119,6 +122,7 @@ protected:
private:
KTextEditor::MainWindow *m_mainWindow;
KatePluginSymbolViewer *m_plugin;
KLineEdit *m_filter;
QMenu *m_popup;
QWidget *m_toolview;
QTreeWidget *m_symbols;
......@@ -136,6 +140,8 @@ private:
void updatePixmapScroll();
bool filterSymbols(QTreeWidgetItem *, const QString &);
void parseCppSymbols(void);
void parseTclSymbols(void);
void parseFortranSymbols(void);
......
Supports Markdown
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