forked from rochus-keller/VerilogCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVlOutlineWidget.cpp
142 lines (117 loc) · 4.09 KB
/
VlOutlineWidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright 2019 Rochus Keller <mailto:[email protected]>
*
* This file is part of the VerilogCreator plugin.
*
* The following is the license that applies to this copy of the
* plugin. For a license to use the plugin under conditions
* other than those described here, please email to [email protected].
*
* GNU General Public License Usage
* This file may be used under the terms of the GNU General Public
* License (GPL) versions 2.0 or 3.0 as published by the Free Software
* Foundation and appearing in the file LICENSE.GPL included in
* the packaging of this file. Please review the following information
* to ensure GNU General Public Licensing requirements will be met:
* http://www.fsf.org/licensing/licenses/info/GPLv2.html and
* http://www.gnu.org/copyleft/gpl.html.
*/
#include "VlOutlineWidget.h"
#include "VlVerilogEditor.h"
#include "VlOutlineMdl.h"
#include <QLabel>
#include <QMenu>
#include <QVBoxLayout>
#include <QtDebug>
#include <utils/fileutils.h>
#include <coreplugin/editormanager/editormanager.h>
using namespace Vl;
OutlineWidget::OutlineWidget(EditorWidget1 *parent) : TextEditor::IOutlineWidget(),
d_edit(parent),d_enableCursorSync(true),d_blockCursorSync(false)
{
d_tree = new OutlineTreeView(this);
QVBoxLayout* box = new QVBoxLayout(this);
box->setMargin(0);
box->setSpacing(0);
box->addWidget(d_tree);
// TODO box->addWidget(Core::ItemViewFind::createSearchableWrapper(d_tree));
d_mdl = new OutlineMdl2( this );
const QString fileName = parent->textDocument()->filePath().toString();
d_tree->setModel(d_mdl);
connect(d_mdl,SIGNAL(modelReset()), d_tree, SLOT(expandAll()) );
d_mdl->setFile(fileName);
connect(d_tree, SIGNAL(activated(QModelIndex)), this, SLOT(onItemActivated(QModelIndex)));
connect(d_edit,SIGNAL(sigGotoSymbol(quint32,quint16)), this, SLOT(onGotoSymbol(quint32,quint16)) );
//qDebug() << "OutlineWidget creator";
}
OutlineWidget::~OutlineWidget()
{
//qDebug() << "OutlineWidget destructor";
}
QList<QAction*> OutlineWidget::filterMenuActions() const
{
return QList<QAction*>();
}
void OutlineWidget::setCursorSynchronization(bool syncWithCursor)
{
d_enableCursorSync = syncWithCursor;
if (d_enableCursorSync)
; // updateSelectionInTree(m_editor->outline()->modelIndex());
}
void OutlineWidget::onItemActivated(QModelIndex index)
{
if (!index.isValid())
return;
const CrossRefModel::Symbol* sym = d_mdl->getSymbol(index);
if( sym )
{
d_blockCursorSync = true;
Core::EditorManager::cutForwardNavigationHistory();
Core::EditorManager::addCurrentPositionToNavigationHistory();
// line has to be 1 based, column 0 based!
d_edit->gotoLine( sym->tok().d_lineNr, sym->tok().d_colNr - 1);
d_blockCursorSync = false;
}
d_edit->setFocus();
}
void OutlineWidget::onGotoSymbol(quint32 line, quint16 col)
{
if (!( d_enableCursorSync && !d_blockCursorSync ) )
return;
QModelIndex index = d_mdl->findSymbol( line, col );
d_blockCursorSync = true;
d_tree->setCurrentIndex(index);
d_tree->scrollTo(index);
d_blockCursorSync = false;
}
bool OutlineWidgetFactory::supportsEditor(Core::IEditor* editor) const
{
if (qobject_cast<Editor1*>(editor))
return true;
return false;
}
TextEditor::IOutlineWidget*OutlineWidgetFactory::createWidget(Core::IEditor* editor)
{
Editor1* e = qobject_cast<Editor1*>(editor);
EditorWidget1* w = qobject_cast<EditorWidget1*>(e->widget());
OutlineWidget *widget = new OutlineWidget(w);
return widget;
}
OutlineTreeView::OutlineTreeView(QWidget* parent):
Utils::NavigationTreeView(parent)
{
setExpandsOnDoubleClick(false);
setDragEnabled(true);
setDragDropMode(QAbstractItemView::DragOnly);
setSortingEnabled(false);
}
void OutlineTreeView::contextMenuEvent(QContextMenuEvent* event)
{
if (!event)
return;
QMenu contextMenu;
contextMenu.addAction(tr("Expand All"), this, SLOT(expandAll()));
contextMenu.addAction(tr("Collapse All"), this, SLOT(collapseAll()));
contextMenu.exec(event->globalPos());
event->accept();
}