forked from rochus-keller/VerilogCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VlProjectEditor.cpp
163 lines (142 loc) · 6.25 KB
/
VlProjectEditor.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Copyright 2018 Rochus Keller <mailto:me@rochus-keller.ch>
*
* 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 me@rochus-keller.ch.
*
* 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 "VlProjectEditor.h"
#include "VlConstants.h"
#include <QApplication>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorsettings.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <QtDebug>
#include <QMenu>
using namespace Vl;
using namespace TextEditor;
Editor2::Editor2()
{
addContext(Constants::LangQmake);
}
EditorFactory2::EditorFactory2()
{
setId(Constants::EditorId2);
setDisplayName(qApp->translate("OpenWith::Editors", Constants::EditorDisplayName2));
addMimeType(Constants::ProjectMimeType);
setDocumentCreator([]() { return new EditorDocument2; });
// setIndenterCreator([]() { return new Indenter; });
setEditorWidgetCreator([]() { return new EditorWidget2; });
setEditorCreator([]() { return new Editor2; });
//setAutoCompleterCreator([]() { return new AutoCompleter; });
//setCompletionAssistProvider(new CompletionAssistProvider);
QStringList vars;
vars << "INCDIRS" << "DEFINES" << "LIBDIRS" << "LIBFILES" << "LIBEXT" << "OTHER_FILES"
<< "SRCDIRS" << "SRCFILES" << "SRCEXT" << "CONFIG" << "TOPMOD"
<< "BUILD_UNDEFS" << "VLTR_UNDEFS" << "VLTR_ARGS" << "YOSYS_UNDEFS" << "YOSYS_CMDS";
vars.sort();
QStringList funcs;
funcs << "member" << "first" << "last" << "cat" << "fromfile" << "eval" << "list" << "sprintf"
<< "join" << "split" << "basename" << "dirname" << "section" << "find" << "system"
<< "unique" << "quote" << "escape_expand" << "upper" << "lower" << "re_escape"
<< "files" << "prompt" << "replace" << "requires" << "greaterThan" << "lessThan"
<< "equals" << "isEqual" << "exists" << "export" << "clear" << "unset" << "eval"
<< "CONFIG" << "if" << "isActiveConfig" << "system" << "return" << "break"
<< "next" << "defined" << "contains" << "infile" << "count" << "isEmpty"
<< "include" << "load" << "debug" << "error" << "message" << "warning";
funcs.sort();
TextEditor::Keywords keywords( vars, funcs , QMap<QString, QStringList>() );
setSyntaxHighlighterCreator([keywords]() { return new Highlighter2(keywords); });
setCommentStyle(Utils::CommentDefinition::HashStyle);
setParenthesesMatchingEnabled(true);
setCodeFoldingSupported(true);
setMarksVisible(true);
//addHoverHandler(new HoverHandler);
setEditorActionHandlers(TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor
);
}
EditorDocument2::EditorDocument2()
{
setId(Constants::EditorId2);
}
EditorWidget2::EditorWidget2()
{
}
void EditorWidget2::contextMenuEvent(QContextMenuEvent* e)
{
QPointer<QMenu> menu(new QMenu(this));
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(Vl::Constants::EditorContextMenuId2);
QMenu *contextMenu = mcontext->menu();
foreach (QAction *action, contextMenu->actions()) {
menu->addAction(action);
}
appendStandardContextMenuActions(menu);
menu->exec(e->globalPos());
if (!menu)
return;
delete menu;
}
static std::pair<int, TextEditor::TextStyle> make(int i,TextEditor::TextStyle s){
return std::pair<int, TextEditor::TextStyle>(i,s);}
Highlighter2::Highlighter2(const Keywords& keywords):m_keywords(keywords)
{
static QVector<TextStyle> categories;
categories << C_TYPE << C_KEYWORD << C_COMMENT << C_VISUAL_WHITESPACE;
setTextFormatCategories(categories);
}
void Highlighter2::highlightBlock(const QString& text)
{
if (text.isEmpty())
return;
QString buf;
bool inCommentMode = false;
QTextCharFormat emptyFormat;
int i = 0;
for (;;) {
const QChar c = text.at(i);
if (inCommentMode) {
setFormat(i, 1, formatForCategory(ProfileCommentFormat));
} else {
if (c.isLetter() || c == QLatin1Char('_') || c == QLatin1Char('.') || c.isDigit()) {
buf += c;
setFormat(i - buf.length()+1, buf.length(), emptyFormat);
if (!buf.isEmpty() && m_keywords.isFunction(buf))
setFormat(i - buf.length()+1, buf.length(), formatForCategory(ProfileFunctionFormat));
else if (!buf.isEmpty() && m_keywords.isVariable(buf))
setFormat(i - buf.length()+1, buf.length(), formatForCategory(ProfileVariableFormat));
} else if (c == QLatin1Char('(')) {
if (!buf.isEmpty() && m_keywords.isFunction(buf))
setFormat(i - buf.length(), buf.length(), formatForCategory(ProfileFunctionFormat));
buf.clear();
} else if (c == QLatin1Char('#')) {
inCommentMode = true;
setFormat(i, 1, formatForCategory(ProfileCommentFormat));
buf.clear();
} else {
if (!buf.isEmpty() && m_keywords.isVariable(buf))
setFormat(i - buf.length(), buf.length(), formatForCategory(ProfileVariableFormat));
buf.clear();
}
}
i++;
if (i >= text.length())
break;
}
applyFormatToSpaces(text, formatForCategory(ProfileVisualWhitespaceFormat));
}