forked from rochus-keller/VerilogCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VlPlugin.cpp
205 lines (166 loc) · 7.32 KB
/
VlPlugin.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* 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 "VlPlugin.h"
#include "VlProjectManager.h"
#include "VlConstants.h"
#include "VlVerilogEditor.h"
#include "VlProjectEditor.h"
#include "VlSdfEditor.h"
#include "VlModelManager.h"
#include "VlConfigurationFactory.h"
#include "VlProject.h"
#include "VlOutlineWidget.h"
#include "VlModuleLocator.h"
#include "VlCompletionAssistProvider.h"
#include "VlSymbolLocator.h"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>
#include <projectexplorer/taskhub.h>
#include <projectexplorer/projecttree.h>
#include <texteditor/texteditorsettings.h>
#include <utils/mimetypes/mimedatabase.h>
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/texteditorconstants.h>
#include <QAction>
#include <QMessageBox>
#include <QMainWindow>
#include <QMenu>
#include <QtPlugin>
#include <QtDebug>
using namespace VerilogCreator::Internal;
VerilogCreatorPlugin* VerilogCreatorPlugin::d_instance = 0;
// NOTE: damit *.v mit diesem Plugin assoziiert wird, muss man in QtCreator/Options/Environment die bereits
// bestehende Bindung von text/x-verilog *.v löschen!!!!
// Problem gelöst, indem ich hier Mime text/x-verilog verwende und bestehendes damit überschreibe.
VerilogCreatorPlugin::VerilogCreatorPlugin()
{
d_instance = this;
}
VerilogCreatorPlugin::~VerilogCreatorPlugin()
{
// Unregister objects from the plugin manager's object pool
// Delete members
d_instance = 0;
}
VerilogCreatorPlugin*VerilogCreatorPlugin::instance()
{
return d_instance;
}
bool VerilogCreatorPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(errorString);
Q_UNUSED(arguments);
Vl::ModelManager::instance();
initializeToolsSettings();
addAutoReleasedObject(new Vl::EditorFactory1);
addAutoReleasedObject(new Vl::EditorFactory2);
addAutoReleasedObject(new Vl::EditorFactory3);
addAutoReleasedObject(new Vl::OutlineWidgetFactory);
addAutoReleasedObject(new Vl::ModuleLocator);
addAutoReleasedObject(new Vl::SymbolLocator);
addAutoReleasedObject(new Vl::ProjectManager);
addAutoReleasedObject(new Vl::MakeStepFactory);
addAutoReleasedObject(new Vl::BuildConfigurationFactory);
addAutoReleasedObject(new Vl::RunConfigurationFactory);
// TODO Core::IWizardFactory::registerFactoryCreator([]() {
// return QList<Core::IWizardFactory *>() << new ProjectWizard;
// });
//addAutoReleasedObject(new ProjectWizard);
Core::Context context(Vl::Constants::EditorId1);
Core::ActionContainer *contextMenu1 = Core::ActionManager::createMenu(Vl::Constants::EditorContextMenuId1);
Core::ActionContainer * contextMenu2 = Core::ActionManager::createMenu(Vl::Constants::EditorContextMenuId2);
Core::Command *cmd;
Core::ActionContainer * toolsMenu = Core::ActionManager::createMenu(Vl::Constants::ToolsMenuId);
toolsMenu->menu()->setTitle(tr("&Verilog"));
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(toolsMenu);
cmd = Core::ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR);
contextMenu1->addAction(cmd);
toolsMenu->addAction(cmd);
d_findUsagesAction = new QAction(tr("Find Usages"), this);
cmd = Core::ActionManager::registerAction(d_findUsagesAction, Vl::Constants::FindUsagesCmd, context);
cmd->setKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
connect(d_findUsagesAction, SIGNAL(triggered()), this, SLOT(onFindUsages()));
contextMenu1->addAction(cmd);
toolsMenu->addAction(cmd);
d_gotoOuterBlockAction = new QAction(tr("Go to Outer Block"), this);
cmd = Core::ActionManager::registerAction(d_gotoOuterBlockAction, Vl::Constants::GotoOuterBlockCmd, context);
cmd->setDefaultKeySequence(QKeySequence(tr("ALT+Up")));
connect(d_gotoOuterBlockAction, SIGNAL(triggered()), this, SLOT(onGotoOuterBlock()));
contextMenu1->addAction(cmd);
toolsMenu->addAction(cmd);
Core::Command *sep = contextMenu1->addSeparator();
cmd = Core::ActionManager::command(TextEditor::Constants::AUTO_INDENT_SELECTION);
contextMenu1->addAction(cmd);
contextMenu2->addAction(cmd);
cmd = Core::ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
contextMenu1->addAction(cmd);
contextMenu2->addAction(cmd);
ProjectExplorer::TaskHub::addCategory(Vl::Constants::TaskId, tr("Verilog Parser"));
Core::ActionContainer *mproject = Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
d_reloadProject = new QAction(tr("Reload Project"), this);
cmd = Core::ActionManager::registerAction(d_reloadProject, Vl::Constants::ReloadProjectCmd,
Core::Context(ProjectExplorer::Constants::C_PROJECT_TREE));
connect(d_reloadProject, SIGNAL(triggered()), this, SLOT(onReloadProject()));
mproject->addAction(cmd, ProjectExplorer::Constants::G_PROJECT_FILES);
return true;
}
void VerilogCreatorPlugin::extensionsInitialized()
{
}
ExtensionSystem::IPlugin::ShutdownFlag VerilogCreatorPlugin::aboutToShutdown()
{
delete Vl::ModelManager::instance();
return SynchronousShutdown;
}
void VerilogCreatorPlugin::onFindUsages()
{
if (Vl::EditorWidget1 *editorWidget = currentEditorWidget())
editorWidget->onFindUsages();
}
void VerilogCreatorPlugin::onGotoOuterBlock()
{
if (Vl::EditorWidget1 *editorWidget = currentEditorWidget())
editorWidget->onGotoOuterBlock();
}
void VerilogCreatorPlugin::onReloadProject()
{
Vl::Project* currentProject = dynamic_cast<Vl::Project*>( ProjectExplorer::ProjectTree::currentProject() );
if( currentProject )
{
currentProject->reload();
}
}
Vl::EditorWidget1*VerilogCreatorPlugin::currentEditorWidget()
{
return qobject_cast<Vl::EditorWidget1*>(Core::EditorManager::currentEditor()->widget());
}
void VerilogCreatorPlugin::initializeToolsSettings()
{
Utils::MimeDatabase::addMimeTypes(QLatin1String(":/VlEditor/VlEditor.mimetypes.xml"));
Utils::MimeDatabase db;
//qDebug() << db.mimeTypesForFileName("test.v");
// qDebug() << "global patterns" << db.allGlobPatterns();
TextEditor::TextEditorSettings::registerMimeTypeForLanguageId(Vl::Constants::MimeType, Vl::Constants::LangVerilog);
TextEditor::TextEditorSettings::registerMimeTypeForLanguageId(Vl::Constants::ProjectMimeType, Vl::Constants::LangQmake);
TextEditor::TextEditorSettings::registerMimeTypeForLanguageId(Vl::Constants::SdfMimeType, Vl::Constants::LangSdf);
}