Changeset View
Changeset View
Standalone View
Standalone View
addons/symbolviewer/plugin_katesymbolviewer.cpp
Context not available. | |||||
68 | 68 | | |||
---|---|---|---|---|---|
69 | K_PLUGIN_FACTORY_WITH_JSON (KatePluginSymbolViewerFactory, "katesymbolviewerplugin.json", registerPlugin<KatePluginSymbolViewer>();) | 69 | K_PLUGIN_FACTORY_WITH_JSON (KatePluginSymbolViewerFactory, "katesymbolviewerplugin.json", registerPlugin<KatePluginSymbolViewer>();) | ||
70 | 70 | | |||
71 | KatePluginSymbolViewerView::KatePluginSymbolViewerView(KatePluginSymbolViewer *plugin, KTextEditor::MainWindow *mw) | 71 | SymbolView::SymbolView(KatePluginSymbolViewer *plugin, KTextEditor::MainWindow *mw) | ||
72 | :QObject(mw) | 72 | :QObject(mw) | ||
73 | ,m_mainWindow(mw) | 73 | ,m_mainWindow(mw) | ||
74 | ,m_plugin(plugin) | 74 | ,m_plugin(plugin) | ||
Context not available. | |||||
82 | m_symbols = nullptr; | 82 | m_symbols = nullptr; | ||
83 | 83 | | |||
84 | m_popup = new QMenu(m_symbols); | 84 | m_popup = new QMenu(m_symbols); | ||
85 | m_treeOn = m_popup->addAction(i18n("Tree Mode"), this, &KatePluginSymbolViewerView::parseSymbols); | 85 | m_treeOn = m_popup->addAction(i18n("Tree Mode"), this, &SymbolView::parseSymbols); | ||
86 | m_treeOn->setCheckable(true); | 86 | m_treeOn->setCheckable(true); | ||
87 | m_sort = m_popup->addAction(i18n("Show Sorted"), this, &KatePluginSymbolViewerView::parseSymbols); | 87 | m_sort = m_popup->addAction(i18n("Show Sorted"), this, &SymbolView::parseSymbols); | ||
88 | m_sort->setCheckable(true); | 88 | m_sort->setCheckable(true); | ||
89 | m_popup->addSeparator(); | 89 | m_popup->addSeparator(); | ||
90 | m_macro = m_popup->addAction(i18n("Show Macros"), this, &KatePluginSymbolViewerView::parseSymbols); | 90 | m_macro = m_popup->addAction(i18n("Show Macros"), this, &SymbolView::parseSymbols); | ||
91 | m_macro->setCheckable(true); | 91 | m_macro->setCheckable(true); | ||
92 | m_struct = m_popup->addAction(i18n("Show Structures"), this, &KatePluginSymbolViewerView::parseSymbols); | 92 | m_struct = m_popup->addAction(i18n("Show Structures"), this, &SymbolView::parseSymbols); | ||
93 | m_struct->setCheckable(true); | 93 | m_struct->setCheckable(true); | ||
94 | m_func = m_popup->addAction(i18n("Show Functions"), this, &KatePluginSymbolViewerView::parseSymbols); | 94 | m_func = m_popup->addAction(i18n("Show Functions"), this, &SymbolView::parseSymbols); | ||
95 | m_func->setCheckable(true); | 95 | m_func->setCheckable(true); | ||
96 | 96 | | |||
97 | KConfigGroup config(KSharedConfig::openConfig(), "PluginSymbolViewer"); | 97 | KConfigGroup config(KSharedConfig::openConfig(), "PluginSymbolViewer"); | ||
Context not available. | |||||
105 | m_func->setChecked(true); | 105 | m_func->setChecked(true); | ||
106 | 106 | | |||
107 | m_updateTimer.setSingleShot(true); | 107 | m_updateTimer.setSingleShot(true); | ||
108 | connect(&m_updateTimer, &QTimer::timeout, this, &KatePluginSymbolViewerView::parseSymbols); | 108 | connect(&m_updateTimer, &QTimer::timeout, this, &SymbolView::parseSymbols); | ||
109 | 109 | | |||
110 | m_currItemTimer.setSingleShot(true); | 110 | m_currItemTimer.setSingleShot(true); | ||
111 | connect(&m_currItemTimer, &QTimer::timeout, this, &KatePluginSymbolViewerView::updateCurrTreeItem); | 111 | connect(&m_currItemTimer, &QTimer::timeout, this, &SymbolView::updateCurrTreeItem); | ||
112 | 112 | | |||
113 | QPixmap cls( ( const char** ) class_xpm ); | 113 | QPixmap cls( ( const char** ) class_xpm ); | ||
114 | 114 | | |||
Context not available. | |||||
126 | layout->addWidget(m_symbols, 10); | 126 | layout->addWidget(m_symbols, 10); | ||
127 | layout->setContentsMargins(0,0,0,0); | 127 | layout->setContentsMargins(0,0,0,0); | ||
128 | 128 | | |||
129 | connect(m_symbols, &QTreeWidget::itemClicked, this, &KatePluginSymbolViewerView::goToSymbol); | 129 | connect(m_symbols, &QTreeWidget::itemClicked, this, &SymbolView::goToSymbol); | ||
130 | connect(m_symbols, &QTreeWidget::customContextMenuRequested, this, &KatePluginSymbolViewerView::slotShowContextMenu); | 130 | connect(m_symbols, &QTreeWidget::customContextMenuRequested, this, &SymbolView::slotShowContextMenu); | ||
131 | 131 | | |||
132 | connect(m_mainWindow, &KTextEditor::MainWindow::viewChanged, this, &KatePluginSymbolViewerView::slotDocChanged); | 132 | connect(m_mainWindow, &KTextEditor::MainWindow::viewChanged, this, &SymbolView::slotDocChanged); | ||
133 | 133 | | |||
134 | QStringList titles; | 134 | QStringList titles; | ||
135 | titles << i18nc("@title:column", "Symbols") << i18nc("@title:column", "Position"); | 135 | titles << i18nc("@title:column", "Symbols") << i18nc("@title:column", "Position"); | ||
Context not available. | |||||
145 | m_toolview->installEventFilter(this); | 145 | m_toolview->installEventFilter(this); | ||
146 | } | 146 | } | ||
147 | 147 | | |||
148 | KatePluginSymbolViewerView::~KatePluginSymbolViewerView() | 148 | SymbolView::~SymbolView() | ||
149 | { | 149 | { | ||
150 | m_mainWindow->guiFactory()->removeClient (this); | 150 | m_mainWindow->guiFactory()->removeClient (this); | ||
151 | delete m_toolview; | 151 | delete m_toolview; | ||
152 | delete m_popup; | 152 | delete m_popup; | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | void KatePluginSymbolViewerView::slotDocChanged() | 155 | void SymbolView::slotDocChanged() | ||
156 | { | 156 | { | ||
157 | parseSymbols(); | 157 | parseSymbols(); | ||
158 | 158 | | |||
159 | KTextEditor::View *view = m_mainWindow->activeView(); | 159 | KTextEditor::View *view = m_mainWindow->activeView(); | ||
160 | //qDebug()<<"Document changed !!!!" << view; | 160 | //qDebug()<<"Document changed !!!!" << view; | ||
161 | if (view) { | 161 | if (view) { | ||
162 | connect(view, &KTextEditor::View::cursorPositionChanged, this, &KatePluginSymbolViewerView::cursorPositionChanged, Qt::UniqueConnection); | 162 | connect(view, &KTextEditor::View::cursorPositionChanged, this, &SymbolView::cursorPositionChanged, Qt::UniqueConnection); | ||
163 | 163 | | |||
164 | if (view->document()) { | 164 | if (view->document()) { | ||
165 | connect(view->document(), &KTextEditor::Document::textChanged, this, &KatePluginSymbolViewerView::slotDocEdited, Qt::UniqueConnection); | 165 | connect(view->document(), &KTextEditor::Document::textChanged, this, &SymbolView::slotDocEdited, Qt::UniqueConnection); | ||
166 | } | 166 | } | ||
167 | } | 167 | } | ||
168 | } | 168 | } | ||
169 | 169 | | |||
170 | void KatePluginSymbolViewerView::slotDocEdited() | 170 | void SymbolView::slotDocEdited() | ||
171 | { | 171 | { | ||
172 | m_currItemTimer.stop(); // Avoid unneeded update | 172 | m_currItemTimer.stop(); // Avoid unneeded update | ||
173 | m_updateTimer.start(500); | 173 | m_updateTimer.start(500); | ||
174 | } | 174 | } | ||
175 | 175 | | |||
176 | void KatePluginSymbolViewerView::cursorPositionChanged() | 176 | void SymbolView::cursorPositionChanged() | ||
177 | { | 177 | { | ||
178 | if (m_updateTimer.isActive()) { | 178 | if (m_updateTimer.isActive()) { | ||
179 | // No need for update, will come anyway | 179 | // No need for update, will come anyway | ||
Context not available. | |||||
182 | m_currItemTimer.start(100); | 182 | m_currItemTimer.start(100); | ||
183 | } | 183 | } | ||
184 | 184 | | |||
185 | void KatePluginSymbolViewerView::updateCurrTreeItem() | 185 | void SymbolView::updateCurrTreeItem() | ||
186 | { | 186 | { | ||
187 | if (!m_mainWindow) { | 187 | if (!m_mainWindow) { | ||
188 | return; | 188 | return; | ||
Context not available. | |||||
218 | } | 218 | } | ||
219 | } | 219 | } | ||
220 | 220 | | |||
221 | QTreeWidgetItem *KatePluginSymbolViewerView::newActveItem(int &newItemLine, int currLine, QTreeWidgetItem *item) | 221 | QTreeWidgetItem *SymbolView::newActveItem(int &newItemLine, int currLine, QTreeWidgetItem *item) | ||
222 | { | 222 | { | ||
223 | QTreeWidgetItem *newItem = nullptr; | 223 | QTreeWidgetItem *newItem = nullptr; | ||
224 | QTreeWidgetItem *tmp = nullptr; | 224 | QTreeWidgetItem *tmp = nullptr; | ||
Context not available. | |||||
236 | return newItem; | 236 | return newItem; | ||
237 | } | 237 | } | ||
238 | 238 | | |||
239 | bool KatePluginSymbolViewerView::eventFilter(QObject *obj, QEvent *event) | 239 | bool SymbolView::eventFilter(QObject *obj, QEvent *event) | ||
240 | { | 240 | { | ||
241 | if (event->type() == QEvent::KeyPress) { | 241 | if (event->type() == QEvent::KeyPress) { | ||
242 | QKeyEvent *ke = static_cast<QKeyEvent*>(event); | 242 | QKeyEvent *ke = static_cast<QKeyEvent*>(event); | ||
Context not available. | |||||
249 | return QObject::eventFilter(obj, event); | 249 | return QObject::eventFilter(obj, event); | ||
250 | } | 250 | } | ||
251 | 251 | | |||
252 | void KatePluginSymbolViewerView::slotShowContextMenu(const QPoint&) | 252 | void SymbolView::slotShowContextMenu(const QPoint&) | ||
253 | { | 253 | { | ||
254 | m_popup->popup(QCursor::pos(), m_treeOn); | 254 | m_popup->popup(QCursor::pos(), m_treeOn); | ||
255 | } | 255 | } | ||
256 | 256 | | |||
257 | void KatePluginSymbolViewerView::parseSymbols() | 257 | void SymbolView::parseSymbols() | ||
258 | { | 258 | { | ||
259 | if (!m_symbols) | 259 | if (!m_symbols) | ||
260 | return; | 260 | return; | ||
Context not available. | |||||
309 | m_symbols->sortItems(0, Qt::AscendingOrder); | 309 | m_symbols->sortItems(0, Qt::AscendingOrder); | ||
310 | } | 310 | } | ||
311 | 311 | | |||
312 | void KatePluginSymbolViewerView::goToSymbol(QTreeWidgetItem *it) | 312 | void SymbolView::goToSymbol(QTreeWidgetItem *it) | ||
313 | { | 313 | { | ||
314 | KTextEditor::View *kv = m_mainWindow->activeView(); | 314 | KTextEditor::View *kv = m_mainWindow->activeView(); | ||
315 | 315 | | |||
Context not available. | |||||
333 | //qDebug()<<"~KatePluginSymbolViewer"; | 333 | //qDebug()<<"~KatePluginSymbolViewer"; | ||
334 | } | 334 | } | ||
335 | 335 | | |||
336 | QObject *KatePluginSymbolViewer::createView (KTextEditor::MainWindow *mainWindow) | 336 | QObject *KatePluginSymbolViewer::createView(KTextEditor::MainWindow *mainWindow) | ||
337 | { | 337 | { | ||
338 | m_view = new KatePluginSymbolViewerView (this, mainWindow); | 338 | m_view = new SymbolView(this, mainWindow); | ||
339 | return m_view; | 339 | return m_view; | ||
340 | } | 340 | } | ||
341 | 341 | | |||
Context not available. |