-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
332 lines (262 loc) · 11.6 KB
/
mainwindow.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#include "mainwindow.h"
#include <QDockWidget>
#include <QMenu>
#include <QMenuBar>
#include <QToolBar>
#include <QInputDialog>
#include <QDesktopWidget>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
specificationEditor = new CodeEditor(this, true);
setCentralWidget(specificationEditor);
fileSystem = new FileSystem(specificationEditor, this);
processSystem = new ProcessSystem(fileSystem);
setupMenuBar();
setupToolbar();
setupDocks();
processSystem->setConsoleDock(consoleDock);
findAndReplaceDialog = new FindAndReplaceDialog(specificationEditor, this);
/* make the save project action enabled whenever a change is made */
saveProjectAction->setEnabled(false);
connect(fileSystem, SIGNAL(hasChanges(bool)), saveProjectAction, SLOT(setEnabled(bool)));
/* set the title of the main window */
setWindowTitle("mCRL2 IDE - Unnamed project");
resize(QSize(QDesktopWidget().availableGeometry(this).width() * 0.5, QDesktopWidget().availableGeometry(this).height() * 0.75));
}
MainWindow::~MainWindow()
{
}
void MainWindow::setupMenuBar()
{
/* Create the File menu */
QMenu *fileMenu = menuBar()->addMenu("File");
newProjectAction = fileMenu->addAction("New Project", this, &MainWindow::actionNewProject);
newProjectAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
newProjectAction->setIcon(QIcon(":/icons/new_project.png"));
fileMenu->addSeparator();
openProjectAction = fileMenu->addAction("Open Project", this, &MainWindow::actionOpenProject);
openProjectAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
openProjectAction->setIcon(QIcon(":/icons/open_project.png"));
openExampleProjectAction = fileMenu->addAction("Open Example Project", this, &MainWindow::actionOpenExampleProject);
fileMenu->addSeparator();
saveProjectAction = fileMenu->addAction("Save Project", this, &MainWindow::actionSaveProject);
saveProjectAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
saveProjectAction->setIcon(QIcon(":/icons/save_project.png"));
saveProjectAsAction = fileMenu->addAction("Save Project As", this, &MainWindow::actionSaveProjectAs);
fileMenu->addSeparator();
addPropertyAction = fileMenu->addAction("Add Property", this, &MainWindow::actionAddProperty);
addPropertyAction->setIcon(QIcon(":/icons/add_property.png"));
/* Create the Edit menu */
QMenu *editMenu = menuBar()->addMenu("Edit");
undoAction = editMenu->addAction("Undo", specificationEditor, &CodeEditor::undo);
undoAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z));
redoAction = editMenu->addAction("Redo", specificationEditor, &CodeEditor::redo);
redoAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Y));
editMenu->addSeparator();
findAndReplaceAction = editMenu->addAction("Find and Replace", this, &MainWindow::actionFindAndReplace);
findAndReplaceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F));
editMenu->addSeparator();
cutAction = editMenu->addAction("Cut", specificationEditor, &CodeEditor::cut);
cutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X));
copyAction = editMenu->addAction("Copy", specificationEditor, &CodeEditor::copy);
copyAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
pasteAction = editMenu->addAction("Paste", specificationEditor, &CodeEditor::paste);
pasteAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_V));
deleteAction = editMenu->addAction("Delete", specificationEditor, &CodeEditor::deleteChar);
deleteAction->setShortcut(QKeySequence(Qt::Key_Delete));
selectAllAction = editMenu->addAction("Select All", specificationEditor, &CodeEditor::selectAll);
selectAllAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A));
/* Create the View Menu (actions are added in setupDocks())*/
viewMenu = menuBar()->addMenu("View");
/* Create the Actions menu */
QMenu *actionsMenu = menuBar()->addMenu("Actions");
parseAction = actionsMenu->addAction("Parse", this, &MainWindow::actionParse);
parseAction->setIcon(QIcon(":/icons/parse_correct.png"));
simulateAction = actionsMenu->addAction("Simulate", this, &MainWindow::actionSimulate);
simulateAction->setIcon(QIcon(":/icons/simulate.png"));
actionsMenu->addSeparator();
createLTSAction = actionsMenu->addAction("Create LTS", this, &MainWindow::actionCreateLTS);
createLTSAction->setIcon(QIcon(":/icons/create_LTS.png"));
createReducedLTSAction = actionsMenu->addAction("Create reduced LTS", this, &MainWindow::actionCreateReducedLTS);
createReducedLTSAction->setIcon(QIcon(":/icons/create_reduced_LTS.png"));
abortLTSCreationAction = actionsMenu->addAction("Abort LTS creation", this, &MainWindow::actionAbortLTSCreation);
abortLTSCreationAction->setIcon(QIcon(":/icons/abort_LTS_creation.png"));
actionsMenu->addSeparator();
verifyAllPropertiesAction = actionsMenu->addAction("Verify all Properties", this, &MainWindow::actionVerifyAllProperties);
verifyAllPropertiesAction->setIcon(QIcon(":/icons/verify_all.png"));
abortVerificationAction = actionsMenu->addAction("Abort verification", this, &MainWindow::actionAbortVerification);
abortVerificationAction->setIcon(QIcon(":/icons/abort_verification.png"));
}
void MainWindow::setupToolbar()
{
toolbar = addToolBar("Actions");
toolbar->setIconSize(QSize(48, 48));
/* create each toolbar item by adding the actions */
toolbar->addAction(newProjectAction);
toolbar->addAction(openProjectAction);
toolbar->addAction(saveProjectAction);
toolbar->addSeparator();
toolbar->addAction(parseAction);
toolbar->addAction(simulateAction);
toolbar->addSeparator();
toolbar->addAction(createLTSAction);
toolbar->addAction(createReducedLTSAction);
toolbar->addAction(abortLTSCreationAction);
toolbar->addSeparator();
toolbar->addAction(addPropertyAction);
toolbar->addAction(verifyAllPropertiesAction);
toolbar->addAction(abortVerificationAction);
/* disable the abort actions since they should only be used when something is running */
abortLTSCreationAction->setEnabled(false);
abortVerificationAction->setEnabled(false);
}
void MainWindow::setDocksToDefault()
{
addDockWidget(propertiesDock->defaultArea, propertiesDock);
addDockWidget(consoleDock->defaultArea, consoleDock);
addDockWidget(rewriteDock->defaultArea, rewriteDock);
addDockWidget(solveDock->defaultArea, solveDock);
propertiesDock->setFloating(false);
consoleDock->setFloating(false);
rewriteDock->setFloating(false);
solveDock->setFloating(false);
rewriteDock->hide();
solveDock->hide();
}
void MainWindow::setupDocks()
{
/* instantiate the docks */
propertiesDock = new PropertiesDock(processSystem, fileSystem, this);
consoleDock = new ConsoleDock(this);
rewriteDock = new RewriteDock(this);
solveDock = new SolveDock(this);
/* add toggleable option in the view menu for each dock */
viewMenu->addAction(propertiesDock->toggleViewAction());
viewMenu->addAction(consoleDock->toggleViewAction());
viewMenu->addAction(rewriteDock->toggleViewAction());
viewMenu->addAction(solveDock->toggleViewAction());
/* place the docks in the default dock layout */
setDocksToDefault();
/* add option to view menu to put all docks back to their default layout */
viewMenu->addSeparator();
viewMenu->addAction("Revert to default layout", this, &MainWindow::setDocksToDefault);
}
void MainWindow::actionNewProject()
{
/* ask the user for a project name */
bool ok;
QString projectName = QInputDialog::getText(this, "New project", "Project name:", QLineEdit::Normal, "", &ok, Qt::WindowCloseButtonHint);
/* if user pressed ok, create the project and save the specification and properties in it */
if (ok) {
QString error = fileSystem->newProject(projectName);
if (error.isEmpty()) {
setWindowTitle(QString("mCRL2 IDE - ").append(projectName));
} else {
/* if there was an error, tell the user */
QMessageBox *msgBox = new QMessageBox(QMessageBox::Information, "New Project", error, QMessageBox::Ok, this, Qt::WindowCloseButtonHint);
msgBox->exec();
}
}
}
void MainWindow::actionOpenProject()
{
QStringList projects = fileSystem->getAllProjects();
if (projects.isEmpty()) {
QMessageBox *msgBox = new QMessageBox(QMessageBox::Information, "Open Project", "No projects found", QMessageBox::Ok, this, Qt::WindowCloseButtonHint);
msgBox->exec();
} else {
bool ok;
QString projectName = QInputDialog::getItem(this, "Open Project", "Project name:", projects, 0, false, &ok, Qt::WindowCloseButtonHint);
/* if user pressed ok, open the project by setting the specification and the properties in the window */
if (ok) {
std::list<Property*> properties = fileSystem->openProject(projectName);
propertiesDock->setToNoProperties();
for (Property *property : properties) {
propertiesDock->addProperty(property);
}
saveProjectAction->setEnabled(false);
setWindowTitle(QString("mCRL2 IDE - ").append(projectName));
}
}
}
void MainWindow::actionOpenExampleProject()
{
/* Not yet implemented */
}
void MainWindow::actionSaveProject()
{
/* if we have a project open, we have a location to save in so we can simply save, else use save as */
if (fileSystem->projectOpened()) {
fileSystem->saveSpecification();
propertiesDock->saveAllProperties();
saveProjectAction->setEnabled(false);
} else {
actionSaveProjectAs();
}
}
void MainWindow::actionSaveProjectAs()
{
/* ask the user for a project name */
bool ok;
QString projectName = QInputDialog::getText(this, "Save Project As", "Project name:", QLineEdit::Normal, "", &ok, Qt::WindowCloseButtonHint);
/* if user pressed ok, create the project and save the specification and properties in it */
if (ok) {
QString error = fileSystem->newProject(projectName);
if (error.isEmpty()) {
setWindowTitle(QString("mCRL2 IDE - ").append(projectName));
actionSaveProject();
} else {
/* if there was an error, tell the user */
QMessageBox *msgBox = new QMessageBox(QMessageBox::Information, "Save Project As", error, QMessageBox::Ok, this, Qt::WindowCloseButtonHint);
msgBox->exec();
}
}
}
void MainWindow::actionAddProperty()
{
addPropertyDialog = new AddEditPropertyDialog(true, propertiesDock, this);
/* if adding was succesful (Add button was pressed), add the property to the properties dock */
if (addPropertyDialog->exec()) {
Property *property = new Property(addPropertyDialog->getPropertyName(), addPropertyDialog->getPropertyText());
propertiesDock->addProperty(property);
}
}
void MainWindow::actionFindAndReplace()
{
if (findAndReplaceDialog->isVisible()) {
findAndReplaceDialog->setFocus();
findAndReplaceDialog->activateWindow();
} else {
findAndReplaceDialog->show();
}
}
void MainWindow::actionParse()
{
/* Not yet implemented */
}
void MainWindow::actionSimulate()
{
/* Not yet implemented */
}
void MainWindow::actionCreateLTS()
{
/* Not yet implemented */
}
void MainWindow::actionCreateReducedLTS()
{
/* Not yet implemented */
}
void MainWindow::actionAbortLTSCreation()
{
/* Not yet implemented */
}
void MainWindow::actionVerifyAllProperties()
{
propertiesDock->verifyAllProperties();
}
void MainWindow::actionAbortVerification()
{
/* Not yet implemented */
}