| 1 | /**************************************************************************** |
| 2 | ** SASM - simple IDE for assembler development |
| 3 | ** Copyright (C) 2013 Dmitriy Manushin |
| 4 | ** Contact: site: http://dman95.github.io/SASM/ |
| 5 | ** e-mail: [email protected] |
| 6 | ** |
| 7 | ** This file is part of SASM. |
| 8 | ** |
| 9 | ** SASM is free software: you can redistribute it and/or modify |
| 10 | ** it under the terms of the GNU General Public License as published by |
| 11 | ** the Free Software Foundation, either version 3 of the License, or |
| 12 | ** (at your option) any later version. |
| 13 | ** |
| 14 | ** SASM is distributed in the hope that it will be useful, |
| 15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | ** GNU General Public License for more details. |
| 18 | ** |
| 19 | ** You should have received a copy of the GNU General Public License |
| 20 | ** along with SASM. If not, see <http://www.gnu.org/licenses/>. |
| 21 | ** |
| 22 | ** Этот файл — часть SASM. |
| 23 | ** |
| 24 | ** SASM - свободная программа: вы можете перераспространять ее и/или |
| 25 | ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде, |
| 26 | ** в каком она была опубликована Фондом свободного программного обеспечения; |
| 27 | ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней |
| 28 | ** версии. |
| 29 | ** |
| 30 | ** SASM распространяется в надежде, что она будет полезной, |
| 31 | ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА |
| 32 | ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной |
| 33 | ** общественной лицензии GNU. |
| 34 | ** |
| 35 | ** Вы должны были получить копию Стандартной общественной лицензии GNU |
| 36 | ** вместе с этой программой. Если это не так, см. |
| 37 | ** <http://www.gnu.org/licenses/>.) |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #include "mainwindow.h" |
| 42 | |
| 43 | /** |
| 44 | * @file mainwindow.cpp |
| 45 | * Code for all of the windows and features. |
| 46 | */ |
| 47 | |
| 48 | MainWindow::MainWindow(const QStringList &args, QWidget *parent) |
| 49 | : QMainWindow(parent), settings("SASM Project", "SASM") |
| 50 | { |
| 51 | setWindowTitle("SASM"); |
| 52 | setWindowIcon(QIcon(":images/mainIcon.png")); |
| 53 | |
| 54 | //! Set save and open directory |
| 55 | saveOpenDirectory = settings.value("saveopendirectory", QString(Common::applicationDataPath() + "/Projects")).toString(); |
| 56 | |
| 57 | //! Initial variables |
| 58 | programIsBuilded = false; |
| 59 | prevCodeEditor = 0; |
| 60 | findDialog = 0; |
| 61 | settingsWindow = 0; |
| 62 | closeFromCloseAll = false; |
| 63 | settingsStartTextEditor = 0; |
| 64 | help = 0; |
| 65 | registersWindow = 0; |
| 66 | memoryWindow = 0; |
| 67 | debugger = 0; |
| 68 | programStopped = true; |
| 69 | highlighter = 0; |
| 70 | tabs = 0; |
| 71 | memoryDock = 0; |
| 72 | registersDock = 0; |
| 73 | |
| 74 | //! Initialize assembler |
| 75 | assembler = 0; |
| 76 | recreateAssembler(true); |
| 77 | |
| 78 | //! Set code field start text |
| 79 | startText = settings.value("starttext", QString()).toString(); |
| 80 | if (startText.isEmpty()) { |
| 81 | settings.setValue("starttext", assembler->getStartText()); |
| 82 | startText = assembler->getStartText(); |
| 83 | } |
| 84 | |
| 85 | timer = new QTimer; |
| 86 | timer->setInterval(100); |
| 87 | timer->stop(); |
| 88 | connect(timer, SIGNAL(timeout()), this, SLOT(testStopOfProgram())); |
| 89 | runProcess = new QProcess(); |
| 90 | |
| 91 | initUi(); |
| 92 | createActions(); |
| 93 | createMenus(); |
| 94 | createToolBars(); |
| 95 | refreshEditMenu(); |
| 96 | setAcceptDrops(true); |
| 97 | |
| 98 | //! Restore log splitter state |
| 99 | splitter->restoreState(settings.value("logsplitterstate").toByteArray()); |
| 100 | |
| 101 | //! Open documents from command line |
| 102 | for (int i = 1; i < args.size(); i++) |
| 103 | openFile(args[i]); |
| 104 | } |
| 105 | |
| 106 | void MainWindow::enableOrDisableLinkingEdit(int disableLinkingCheckboxState) |
| 107 | { |
| 108 | bool enabled = (disableLinkingCheckboxState == Qt::Unchecked); |
| 109 | settingsUi.linkingOptionsEdit->setEnabled(enabled); |
| 110 | settingsUi.linkerPathEdit->setEnabled(enabled); |
| 111 | } |
| 112 | |
| 113 | void MainWindow::initUi() |
| 114 | { |
| 115 | //! Resize |
| 116 | settings.beginGroup("MainWindow"); |
| 117 | resize(settings.value("size", QSize(1024, 650)).toSize()); //default 1024x650 |
| 118 | move(settings.value("pos", QPoint(200, 200)).toPoint()); |
| 119 | //! Set maximized |
| 120 | setWindowState(windowState() | (Qt::WindowState) settings.value("maximized", (int) Qt::WindowNoState).toInt()); |
| 121 | settings.endGroup(); |
| 122 | |
| 123 | //! Get Started window |
| 124 | getStartedWidget = new GetStartedWidget; |
| 125 | connect(getStartedWidget->newButton, SIGNAL(clicked()), this, SLOT(newFile())); |
| 126 | connect(getStartedWidget->openButton, SIGNAL(clicked()), this, SLOT(openFile())); |
| 127 | connect(getStartedWidget->prevSessionButton, SIGNAL(clicked()), this, SLOT(restorePrevSession())); |
| 128 | |
| 129 | //! Create form |
| 130 | splitter = new QSplitter; |
| 131 | splitter->setOrientation(Qt::Vertical); |
| 132 | workLayout = new QVBoxLayout; |
| 133 | workLayout->addWidget(splitter); |
| 134 | workLayout->setMargin(0); |
| 135 | workLayout->setSpacing(0); |
| 136 | workWidget = new QWidget; |
| 137 | workWidget->setLayout(workLayout); |
| 138 | |
| 139 | //! Stacked widget |
| 140 | mainWidget = new QStackedWidget; |
| 141 | mainWidget->addWidget(getStartedWidget); |
| 142 | mainWidget->addWidget(workWidget); |
| 143 | mainWidget->setCurrentIndex(0); //get started |
| 144 | setCentralWidget(mainWidget); |
| 145 | |
| 146 | //! Create highlighter |
| 147 | highlighter = new Highlighter(assembler); |
| 148 | |
| 149 | //! Create tabs |
| 150 | tabs = new QTabWidget; |
| 151 | connect(tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int))); |
| 152 | connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(changeCurrentTab(int))); |
| 153 | tabs->setTabsClosable(true); |
| 154 | tabs->setMovable(true); |
| 155 | |
| 156 | //! Create compiler field |
| 157 | compilerOut = new RuQTextEdit; |
| 158 | compilerOut->setReadOnly(true); |
| 159 | QFont compilerOutFont; |
| 160 | compilerOutFont.setPointSize(settings.value("fontsize", 12).toInt()); |
| 161 | compilerOut->setFont(compilerOutFont); |
| 162 | compilerOut->setText(tr("Build log:") + '\n'); |
| 163 | |
| 164 | //! Create gdb command widget |
| 165 | debugAnyCommandWidget = new DebugAnyCommandWidget; |
| 166 | |
| 167 | //! Add widgets on splitter |
| 168 | splitter->addWidget(tabs); |
| 169 | splitter->addWidget(compilerOut); |
| 170 | workLayout->addWidget(debugAnyCommandWidget); |
| 171 | int compilerOutSize = 100; |
| 172 | debugAnyCommandWidget->close(); |
| 173 | debugAnyCommandWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); |
| 174 | splitter->setSizes(QList<int>() << splitter->size().height() - compilerOutSize << compilerOutSize); |
| 175 | //! Restore previous session if it in settings |
| 176 | if (settings.value("startwindow", 0).toInt() == 1) |
| 177 | restorePrevSession(true); |
| 178 | } |
| 179 | |
| 180 | void MainWindow::createMenus() |
| 181 | { |
| 182 | fileMenu = menuBar()->addMenu(tr("File")); |
| 183 | fileMenu->addAction(newAction); |
| 184 | fileMenu->addSeparator(); |
| 185 | fileMenu->addAction(openAction); |
| 186 | fileMenu->addAction(closeAction); |
| 187 | fileMenu->addSeparator(); |
| 188 | fileMenu->addAction(saveAction); |
| 189 | fileMenu->addAction(saveAsAction); |
| 190 | fileMenu->addAction(saveExeAction); |
| 191 | fileMenu->addSeparator(); |
| 192 | fileMenu->addAction(exitAction); |
| 193 | editMenu = menuBar()->addMenu(tr("Edit")); |
| 194 | editMenu->addAction(findAction); |
| 195 | editMenu->addSeparator(); |
| 196 | editMenu->addAction(undoAction); |
| 197 | editMenu->addAction(redoAction); |
| 198 | editMenu->addSeparator(); |
| 199 | editMenu->addAction(cutAction); |
| 200 | editMenu->addAction(copyAction); |
| 201 | editMenu->addAction(pasteAction); |
| 202 | editMenu->addAction(deleteAction); |
| 203 | editMenu->addSeparator(); |
| 204 | editMenu->addAction(selectAllAction); |
| 205 | editMenu->addSeparator(); |
| 206 | editMenu->addAction(commentAction); |
| 207 | editMenu->addAction(uncommentAction); |
| 208 | editMenu->addSeparator(); |
| 209 | editMenu->addAction(putTabAction); |
| 210 | editMenu->addAction(deleteTabAction); |
| 211 | connect(editMenu, SIGNAL(aboutToShow()), this, SLOT(refreshEditMenu())); |
| 212 | connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(refreshEditMenu())); |
| 213 | buildMenu = menuBar()->addMenu(tr("Build")); |
| 214 | buildMenu->addAction(buildAction); |
| 215 | buildMenu->addSeparator(); |
| 216 | buildMenu->addAction(runAction); |
| 217 | #ifdef Q_OS_WIN32 |
| 218 | buildMenu->addAction(runExeAction); |
| 219 | #endif |
| 220 | buildMenu->addSeparator(); |
| 221 | buildMenu->addAction(stopAction); |
| 222 | debugMenu = menuBar()->addMenu(tr("Debug")); |
| 223 | debugMenu->addAction(debugAction); |
| 224 | debugMenu->addSeparator(); |
| 225 | debugMenu->addAction(debugNextNiAction); |
| 226 | debugMenu->addAction(debugNextAction); |
| 227 | debugMenu->addSeparator(); |
| 228 | debugMenu->addAction(debugToggleBreakpointAction); |
| 229 | debugMenu->addAction(debugShowRegistersAction); |
| 230 | debugMenu->addAction(debugShowMemoryAction); |
| 231 | debugMenu->addSeparator(); |
| 232 | debugMenu->addAction(stopAction); |
| 233 | settingsMenu = menuBar()->addMenu(tr("Settings")); |
| 234 | settingsMenu->addAction(settingsAction); |
| 235 | helpMenu = menuBar()->addMenu(tr("Help")); |
| 236 | helpMenu->addAction(helpAction); |
| 237 | helpMenu->addAction(aboutAction); |
| 238 | } |
| 239 | |
| 240 | void MainWindow::createActions() |
| 241 | { |
| 242 | QSettings keySettings(Common::applicationDataPath() + "/keys.ini", QSettings::IniFormat); |
| 243 | |
| 244 | newAction = new QAction(QIcon(":/images/new.png"), tr("New"), this); |
| 245 | QString key = keySettings.value("new", "default").toString(); |
| 246 | QKeySequence stdKey(QKeySequence::New); |
| 247 | if (key == "default") |
| 248 | key = stdKey.toString(); |
| 249 | newAction->setShortcut(key); |
| 250 | connect(newAction, SIGNAL(triggered()), this, SLOT(newFile())); |
| 251 | |
| 252 | openAction = new QAction(QIcon(":/images/open.png"), tr("Open"), this); |
| 253 | key = keySettings.value("open", "default").toString(); |
| 254 | stdKey = QKeySequence(QKeySequence::Open); |
| 255 | if (key == "default") |
| 256 | key = stdKey.toString(); |
| 257 | openAction->setShortcut(key); |
| 258 | connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); |
| 259 | |
| 260 | closeAction = new QAction(tr("Close file"), this); |
| 261 | key = keySettings.value("close", "default").toString(); |
| 262 | stdKey = QKeySequence(QKeySequence::Close); |
| 263 | if (key == "default") |
| 264 | key = stdKey.toString(); |
| 265 | closeAction->setShortcut(key); |
| 266 | connect(closeAction, SIGNAL(triggered()), this, SLOT(closeFile())); |
| 267 | |
| 268 | |
| 269 | saveAction = new QAction(QIcon(":/images/save.png"), tr("Save"), this); |
| 270 | key = keySettings.value("save", "default").toString(); |
| 271 | stdKey = QKeySequence(QKeySequence::Save); |
| 272 | if (key == "default") |
| 273 | key = stdKey.toString(); |
| 274 | saveAction->setShortcut(key); |
| 275 | connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); |
| 276 | |
| 277 | saveAsAction = new QAction(tr("Save as"), this); |
| 278 | key = keySettings.value("saveAs", "default").toString(); |
| 279 | stdKey = QKeySequence(QKeySequence::SaveAs); |
| 280 | if (key == "default") |
| 281 | key = stdKey.toString(); |
| 282 | saveAsAction->setShortcut(key); |
| 283 | connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAsFile())); |
| 284 | |
| 285 | saveExeAction = new QAction(tr("Save .exe"), this); |
| 286 | key = keySettings.value("save_exe", "default").toString(); |
| 287 | if (key == "default") |
| 288 | key = "Ctrl+Shift+E"; |
| 289 | saveExeAction->setShortcut(QKeySequence(key)); |
| 290 | connect(saveExeAction, SIGNAL(triggered()), this, SLOT(saveExe())); |
| 291 | |
| 292 | exitAction = new QAction(tr("Exit"), this); |
| 293 | key = keySettings.value("exit", "default").toString(); |
| 294 | stdKey = QKeySequence(QString("Ctrl+Q")); |
| 295 | if (key == "default") |
| 296 | key = stdKey.toString(); |
| 297 | exitAction->setShortcut(key); |
| 298 | connect(exitAction, SIGNAL(triggered()), this, SLOT(closeApp())); |
| 299 | |
| 300 | findAction = new QAction(tr("Find and replace"), this); |
| 301 | key = keySettings.value("find", "default").toString(); |
| 302 | stdKey = QKeySequence(QKeySequence::Find); |
| 303 | if (key == "default") |
| 304 | key = stdKey.toString(); |
| 305 | findAction->setShortcut(key); |
| 306 | connect(findAction, SIGNAL(triggered()), this, SLOT(find())); |
| 307 | |
| 308 | |
| 309 | undoAction = new QAction(QIcon(":/images/undo.png"), tr("Undo"), this); |
| 310 | key = keySettings.value("undo", "default").toString(); |
| 311 | stdKey = QKeySequence(QKeySequence::Undo); |
| 312 | if (key == "default") |
| 313 | key = stdKey.toString(); |
| 314 | undoAction->setShortcut(key); |
| 315 | |
| 316 | redoAction = new QAction(QIcon(":/images/redo.png"), tr("Redo"), this); |
| 317 | key = keySettings.value("redo", "default").toString(); |
| 318 | stdKey = QKeySequence(QKeySequence::Redo); |
| 319 | if (key == "default") |
| 320 | key = stdKey.toString(); |
| 321 | redoAction->setShortcut(key); |
| 322 | |
| 323 | cutAction = new QAction(QIcon(":/images/cut.png"), tr("Cut"), this); |
| 324 | key = keySettings.value("cut", "default").toString(); |
| 325 | stdKey = QKeySequence(QKeySequence::Cut); |
| 326 | if (key == "default") |
| 327 | key = stdKey.toString(); |
| 328 | cutAction->setShortcut(key); |
| 329 | |
| 330 | copyAction = new QAction(QIcon(":/images/copy.png"), tr("Copy"), this); |
| 331 | key = keySettings.value("copy", "default").toString(); |
| 332 | stdKey = QKeySequence(QKeySequence::Copy); |
| 333 | if (key == "default") |
| 334 | key = stdKey.toString(); |
| 335 | copyAction->setShortcut(key); |
| 336 | |
| 337 | pasteAction = new QAction(QIcon(":/images/paste.png"), tr("Paste"), this); |
| 338 | key = keySettings.value("paste", "default").toString(); |
| 339 | stdKey = QKeySequence(QKeySequence::Paste); |
| 340 | if (key == "default") |
| 341 | key = stdKey.toString(); |
| 342 | pasteAction->setShortcut(key); |
| 343 | |
| 344 | deleteAction = new QAction(tr("Delete"), this); |
| 345 | key = keySettings.value("delete", "default").toString(); |
| 346 | stdKey = QKeySequence(QKeySequence::Delete); |
| 347 | if (key == "default") |
| 348 | key = stdKey.toString(); |
| 349 | deleteAction->setShortcut(key); |
| 350 | |
| 351 | selectAllAction = new QAction(tr("Select all"), this); |
| 352 | key = keySettings.value("selectAll", "default").toString(); |
| 353 | stdKey = QKeySequence(QKeySequence::SelectAll); |
| 354 | if (key == "default") |
| 355 | key = stdKey.toString(); |
| 356 | selectAllAction->setShortcut(key); |
| 357 | |
| 358 | commentAction = new QAction(tr("Comment"), this); |
| 359 | key = keySettings.value("comment", "default").toString(); |
| 360 | stdKey = QKeySequence(QString("Shift+Ctrl+A")); |
| 361 | if (key == "default") |
| 362 | key = stdKey.toString(); |
| 363 | commentAction->setShortcut(key); |
| 364 | |
| 365 | uncommentAction = new QAction(tr("Remove comment"), this); |
| 366 | key = keySettings.value("uncomment", "default").toString(); |
| 367 | stdKey = QKeySequence(QString("Shift+Ctrl+Q")); |
| 368 | if (key == "default") |
| 369 | key = stdKey.toString(); |
| 370 | uncommentAction->setShortcut(key); |
| 371 | |
| 372 | putTabAction = new QAction(tr("Indent"), this); |
| 373 | key = keySettings.value("putTab", "default").toString(); |
| 374 | stdKey = QKeySequence(QString("Tab")); |
| 375 | if (key == "default") |
| 376 | key = stdKey.toString(); |
| 377 | putTabAction->setShortcut(key); |
| 378 | |
| 379 | deleteTabAction = new QAction(tr("Remove indent"), this); |
| 380 | key = keySettings.value("deleteTab", "default").toString(); |
| 381 | stdKey = QKeySequence(QString("Shift+Tab")); |
| 382 | if (key == "default") |
| 383 | key = stdKey.toString(); |
| 384 | deleteTabAction->setShortcut(key); |
| 385 | //! Action in edit menu connects in refreshEditMenu function! |
| 386 | |
| 387 | |
| 388 | buildAction = new QAction(QIcon(":/images/build.png"), tr("Build this"), this); |
| 389 | key = keySettings.value("build", "default").toString(); |
| 390 | stdKey = QKeySequence(QString("Ctrl+F9")); |
| 391 | if (key == "default") |
| 392 | key = stdKey.toString(); |
| 393 | buildAction->setShortcut(key); |
| 394 | connect(buildAction, SIGNAL(triggered()), this, SLOT(buildProgram())); |
| 395 | |
| 396 | runAction = new QAction(QIcon(":/images/run.png"), tr("Build and run"), this); |
| 397 | key = keySettings.value("run", "default").toString(); |
| 398 | stdKey = QKeySequence(QString("F9")); |
| 399 | if (key == "default") |
| 400 | key = stdKey.toString(); |
| 401 | runAction->setShortcut(key); |
| 402 | connect(runAction, SIGNAL(triggered()), this, SLOT(runProgram())); |
| 403 | |
| 404 | runExeAction = new QAction(tr("Run in new window"), this); |
| 405 | connect(runExeAction, SIGNAL(triggered()), this, SLOT(runExeProgram())); |
| 406 | |
| 407 | stopAction = new QAction(QIcon(":/images/stop.png"), tr("Stop"), this); |
| 408 | connect(stopAction, SIGNAL(triggered()), this, SLOT(stopProgram())); |
| 409 | //! Enable in runProgram(), disable in stop |
| 410 | stopAction->setEnabled(false); |
| 411 | |
| 412 | debugAction = new QAction(QIcon(":/images/debug.png"), tr("Debug"), this); |
| 413 | key = keySettings.value("debug", "default").toString(); |
| 414 | stdKey = QKeySequence(QString("F5")); |
| 415 | if (key == "default") |
| 416 | key = stdKey.toString(); |
| 417 | debugAction->setShortcut(key); |
| 418 | debugKey = key; |
| 419 | connect(debugAction, SIGNAL(triggered()), this, SLOT(debug())); |
| 420 | |
| 421 | debugNextNiAction = new QAction(QIcon(":/images/stepover.png"), tr("Step over"), this); |
| 422 | key = keySettings.value("stepOver", "default").toString(); |
| 423 | stdKey = QKeySequence(QString("F10")); |
| 424 | if (key == "default") |
| 425 | key = stdKey.toString(); |
| 426 | debugNextNiAction->setShortcut(key); |
| 427 | connect(debugNextNiAction, SIGNAL(triggered()), this, SLOT(debugNextNi())); |
| 428 | |
| 429 | debugNextAction = new QAction(QIcon(":/images/stepinto.png"), tr("Step into"), this); |
| 430 | key = keySettings.value("stepInto", "default").toString(); |
| 431 | stdKey = QKeySequence(QString("F11")); |
| 432 | if (key == "default") |
| 433 | key = stdKey.toString(); |
| 434 | debugNextAction->setShortcut(key); |
| 435 | connect(debugNextAction, SIGNAL(triggered()), this, SLOT(debugNext())); |
| 436 | |
| 437 | debugToggleBreakpointAction = new QAction(tr("Toggle breakpoint"), this); |
| 438 | key = keySettings.value("breakpoint", "default").toString(); |
| 439 | stdKey = QKeySequence(QString("F8")); |
| 440 | if (key == "default") |
| 441 | key = stdKey.toString(); |
| 442 | debugToggleBreakpointAction->setShortcut(key); |
| 443 | connect(debugToggleBreakpointAction, SIGNAL(triggered()), this, SLOT(debugToggleBreakpoint())); |
| 444 | |
| 445 | debugShowRegistersAction = new QAction(tr("Show registers"), this); |
| 446 | key = keySettings.value("showRegisters", "default").toString(); |
| 447 | stdKey = QKeySequence(QString("Ctrl+R")); |
| 448 | if (key == "default") |
| 449 | key = stdKey.toString(); |
| 450 | debugShowRegistersAction->setShortcut(key); |
| 451 | debugShowRegistersAction->setCheckable(true); |
| 452 | connect(debugShowRegistersAction, SIGNAL(toggled(bool)), this, SLOT(debugShowRegisters()), Qt::QueuedConnection); |
| 453 | |
| 454 | debugShowMemoryAction = new QAction(tr("Show memory"), this); |
| 455 | key = keySettings.value("showMemory", "default").toString(); |
| 456 | stdKey = QKeySequence(QString("Ctrl+M")); |
| 457 | if (key == "default") |
| 458 | key = stdKey.toString(); |
| 459 | debugShowMemoryAction->setShortcut(key); |
| 460 | debugShowMemoryAction->setCheckable(true); |
| 461 | connect(debugShowMemoryAction, SIGNAL(toggled(bool)), this, SLOT(debugShowMemory()), Qt::QueuedConnection); |
| 462 | |
| 463 | disableDebugActions(true); |
| 464 | |
| 465 | |
| 466 | settingsAction = new QAction(tr("Settings"), this); |
| 467 | connect(settingsAction, SIGNAL(triggered()), this, SLOT(openSettings())); |
| 468 | |
| 469 | connect(mainWidget, SIGNAL(currentChanged(int)), this, SLOT(changeActionsState(int))); |
| 470 | //! Disable some actions if get started widget opened |
| 471 | changeActionsState(mainWidget->currentIndex()); |
| 472 | |
| 473 | helpAction = new QAction(tr("Help"), this); |
| 474 | key = keySettings.value("help", "default").toString(); |
| 475 | stdKey = QKeySequence(QKeySequence::HelpContents); |
| 476 | if (key == "default") |
| 477 | key = stdKey.toString(); |
| 478 | helpAction->setShortcut(key); |
| 479 | connect(helpAction, SIGNAL(triggered()), this, SLOT(openHelp())); |
| 480 | |
| 481 | aboutAction = new QAction(tr("About"), this); |
| 482 | connect(aboutAction, SIGNAL(triggered()), this, SLOT(openAbout())); |
| 483 | } |
| 484 | |
| 485 | void MainWindow::createToolBars() |
| 486 | { |
| 487 | fileToolBar = addToolBar(tr("File")); |
| 488 | fileToolBar->addAction(newAction); |
| 489 | fileToolBar->addAction(openAction); |
| 490 | fileToolBar->addAction(saveAction); |
| 491 | fileToolBar->setObjectName("File"); |
| 492 | |
| 493 | editToolBar = addToolBar(tr("Edit")); |
| 494 | editToolBar->addAction(undoAction); |
| 495 | editToolBar->addAction(redoAction); |
| 496 | editToolBar->addAction(cutAction); |
| 497 | editToolBar->addAction(copyAction); |
| 498 | editToolBar->addAction(pasteAction); |
| 499 | editToolBar->setObjectName("Edit"); |
| 500 | |
| 501 | buildToolBar = addToolBar(tr("Build")); |
| 502 | buildToolBar->addAction(buildAction); |
| 503 | buildToolBar->addAction(runAction); |
| 504 | buildToolBar->addAction(stopAction); |
| 505 | buildToolBar->setObjectName("Build"); |
| 506 | |
| 507 | debugToolBar = addToolBar(tr("Debug")); |
| 508 | debugToolBar->addAction(debugAction); |
| 509 | debugToolBar->addAction(debugNextNiAction); |
| 510 | debugToolBar->addAction(debugNextAction); |
| 511 | debugToolBar->addAction(stopAction); |
| 512 | debugToolBar->setObjectName("Debug"); |
| 513 | |
| 514 | restoreState(settings.value("windowstate").toByteArray()); |
| 515 | } |
| 516 | |
| 517 | void MainWindow::refreshEditMenu() |
| 518 | { |
| 519 | CodeEditor *codeEditor = 0; |
| 520 | |
| 521 | //! Disconnect from previous |
| 522 | if (prevCodeEditor) { |
| 523 | disconnect(commentAction, SIGNAL(triggered()), prevCodeEditor, SLOT(commentSelectedCode())); |
| 524 | disconnect(uncommentAction, SIGNAL(triggered()), prevCodeEditor, SLOT(uncommentSelectedCode())); |
| 525 | disconnect(undoAction, SIGNAL(triggered()), prevCodeEditor, SLOT(undo())); |
| 526 | disconnect(redoAction, SIGNAL(triggered()), prevCodeEditor, SLOT(redo())); |
| 527 | disconnect(cutAction, SIGNAL(triggered()), prevCodeEditor, SLOT(cut())); |
| 528 | disconnect(copyAction, SIGNAL(triggered()), prevCodeEditor, SLOT(copy())); |
| 529 | disconnect(pasteAction, SIGNAL(triggered()), prevCodeEditor, SLOT(paste())); |
| 530 | disconnect(deleteAction, SIGNAL(triggered()), prevCodeEditor, SLOT(deleteSelected())); |
| 531 | disconnect(selectAllAction, SIGNAL(triggered()), prevCodeEditor, SLOT(selectAll())); |
| 532 | disconnect(putTabAction, SIGNAL(triggered()), prevCodeEditor, SLOT(putTab())); |
| 533 | disconnect(deleteTabAction, SIGNAL(triggered()), prevCodeEditor, SLOT(deleteTab())); |
| 534 | |
| 535 | disconnect(prevCodeEditor, SIGNAL(undoAvailable(bool)), undoAction, SLOT(setEnabled(bool))); |
| 536 | disconnect(prevCodeEditor, SIGNAL(redoAvailable(bool)), redoAction, SLOT(setEnabled(bool))); |
| 537 | } |
| 538 | |
| 539 | //! Connect to current |
| 540 | if (tabs->currentIndex() != -1) { |
| 541 | codeEditor = ((Tab *) tabs->currentWidget())->code; |
| 542 | connect(commentAction, SIGNAL(triggered()), codeEditor, SLOT(commentSelectedCode())); |
| 543 | connect(uncommentAction, SIGNAL(triggered()), codeEditor, SLOT(uncommentSelectedCode())); |
| 544 | connect(undoAction, SIGNAL(triggered()), codeEditor, SLOT(undo())); |
| 545 | connect(redoAction, SIGNAL(triggered()), codeEditor, SLOT(redo())); |
| 546 | connect(cutAction, SIGNAL(triggered()), codeEditor, SLOT(cut())); |
| 547 | connect(copyAction, SIGNAL(triggered()), codeEditor, SLOT(copy())); |
| 548 | connect(pasteAction, SIGNAL(triggered()), codeEditor, SLOT(paste())); |
| 549 | connect(deleteAction, SIGNAL(triggered()), codeEditor, SLOT(deleteSelected())); |
| 550 | connect(selectAllAction, SIGNAL(triggered()), codeEditor, SLOT(selectAll())); |
| 551 | connect(putTabAction, SIGNAL(triggered()), codeEditor, SLOT(putTab())); |
| 552 | connect(deleteTabAction, SIGNAL(triggered()), codeEditor, SLOT(deleteTab())); |
| 553 | |
| 554 | connect(codeEditor, SIGNAL(undoAvailable(bool)), undoAction, SLOT(setEnabled(bool))); |
| 555 | connect(codeEditor, SIGNAL(redoAvailable(bool)), redoAction, SLOT(setEnabled(bool))); |
| 556 | connect(codeEditor, SIGNAL(copyAvailable(bool)), cutAction, SLOT(setEnabled(bool))); |
| 557 | connect(codeEditor, SIGNAL(copyAvailable(bool)), copyAction, SLOT(setEnabled(bool))); |
| 558 | connect(codeEditor, SIGNAL(copyAvailable(bool)), commentAction, SLOT(setEnabled(bool))); |
| 559 | connect(codeEditor, SIGNAL(copyAvailable(bool)), uncommentAction, SLOT(setEnabled(bool))); |
| 560 | connect(codeEditor, SIGNAL(copyAvailable(bool)), deleteAction, SLOT(setEnabled(bool))); |
| 561 | } |
| 562 | |
| 563 | prevCodeEditor = codeEditor; |
| 564 | } |
| 565 | |
| 566 | void MainWindow::newFile() |
| 567 | { |
| 568 | if (tabs->count() > 0) { |
| 569 | settings.setValue("tabgeometry", ((Tab *) tabs->currentWidget())->saveGeometry()); |
| 570 | settings.setValue("tabwindowstate", ((Tab *) tabs->currentWidget())->saveState()); |
| 571 | } |
| 572 | //! Tabs |
| 573 | mainWidget->setCurrentIndex(1); |
| 574 | Tab *tab = new Tab; |
| 575 | tab->code->setPlainText(startText); |
| 576 | tabs->addTab(tab, tr("New")); |
| 577 | tabs->setCurrentWidget(tab); |
| 578 | connect(tab->code, SIGNAL(textChanged()), this, SLOT(setProgramBuildedFlagToFalse())); |
| 579 | connect(tab->code, SIGNAL(textChanged()), this, SLOT(findNextAfterTextChange())); |
| 580 | connect(tab->code, SIGNAL(modificationChanged(bool)), this, SLOT(changeCurrentSavedState(bool))); |
| 581 | connect(tab->code, SIGNAL(fileOpened(QString)), this, SLOT(openFile(QString))); |
| 582 | } |
| 583 | |
| 584 | void MainWindow::changeCurrentSavedState(bool changed) |
| 585 | { |
| 586 | if (changed) |
| 587 | tabs->setTabText(tabs->currentIndex(), '*' + tabs->tabText(tabs->currentIndex())); |
| 588 | else { |
| 589 | QString tabText = tabs->tabText(tabs->currentIndex()); |
| 590 | if (tabText[0] == '*') |
| 591 | tabText.remove(0, 1); |
| 592 | tabs->setTabText(tabs->currentIndex(), tabText); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | void MainWindow::openFile() |
| 597 | { |
| 598 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), saveOpenDirectory, |
| 599 | tr("Assembler source files (*.asm *.S *.s);;All files (*)")); |
| 600 | if (fileName.isEmpty()) { |
| 601 | return; |
| 602 | } |
| 603 | saveOpenDirectory = QFileInfo(fileName).absoluteDir().absolutePath(); |
| 604 | openFile(fileName); |
| 605 | } |
| 606 | |
| 607 | void MainWindow::openFile(QString path) |
| 608 | { |
| 609 | if (path.isEmpty()) { |
| 610 | return; |
| 611 | } |
| 612 | |
| 613 | newFile(); |
| 614 | Tab *curTab = (Tab *) tabs->currentWidget(); |
| 615 | curTab->loadCodeFromFile(path); |
| 616 | setTabPath(path); |
| 617 | //connect(curTab, SIGNAL(fileOpened(QString)), this, SLOT(openFile(QString))); |
| 618 | } |
| 619 | |
| 620 | void MainWindow::setTabPath(const QString &filePath, int index) |
| 621 | { |
| 622 | //! Taking name of file (without path) |
| 623 | int i; |
| 624 | if ((i = filePath.lastIndexOf('/')) == -1) |
| 625 | i = filePath.lastIndexOf('\\'); |
| 626 | QString caption = filePath.mid(i + 1); |
| 627 | if (index == -1) { |
| 628 | tabs->setTabToolTip(tabs->currentIndex(), filePath); |
| 629 | tabs->setTabText(tabs->currentIndex(), caption); |
| 630 | } else { |
| 631 | tabs->setTabToolTip(index, filePath); |
| 632 | tabs->setTabText(index, caption); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | void MainWindow::closeFile() |
| 637 | { |
| 638 | deleteTab(tabs->currentIndex()); |
| 639 | } |
| 640 | |
| 641 | bool MainWindow::saveFile(int index, bool openSaveAs) |
| 642 | { |
| 643 | Tab *tab; |
| 644 | if (index == -1) |
| 645 | tab = (Tab *) tabs->currentWidget(); |
| 646 | else |
| 647 | tab = (Tab *) tabs->widget(index); |
| 648 | QString filePath = tab->getCurrentFilePath(); |
| 649 | if (filePath.isEmpty()) { |
| 650 | if (openSaveAs) { |
| 651 | return saveAsFile(index); |
| 652 | } else { |
| 653 | return false; |
| 654 | } |
| 655 | } else { |
| 656 | tab->saveCodeToFile(filePath, assembler); |
| 657 | return true; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | bool MainWindow::saveAsFile(int index) |
| 662 | { |
| 663 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"), saveOpenDirectory, |
| 664 | tr("Assembler source files (*.asm);;All files (*)")); |
| 665 | if (fileName.isEmpty()) { |
| 666 | return false; |
| 667 | } |
| 668 | saveOpenDirectory = QFileInfo(fileName).absoluteDir().absolutePath(); |
| 669 | Tab *tab; |
| 670 | if (index == -1) |
| 671 | tab = (Tab *) tabs->currentWidget(); |
| 672 | else |
| 673 | tab = (Tab *) tabs->widget(index); |
| 674 | tab->saveCodeToFile(fileName, assembler); |
| 675 | setTabPath(fileName, index); |
| 676 | return true; |
| 677 | } |
| 678 | |
| 679 | void MainWindow::saveExe() |
| 680 | { |
| 681 | if (!programIsBuilded) { |
| 682 | buildProgram(); |
| 683 | } |
| 684 | if (!programIsBuilded) { |
| 685 | return; |
| 686 | } |
| 687 | QString saveFileName = QFileDialog::getSaveFileName(this, tr("Save .exe file"), saveOpenDirectory, |
| 688 | tr("Execution files (*.exe);;All files (*.*)")); |
| 689 | if (saveFileName.isEmpty()) |
| 690 | return; |
| 691 | saveOpenDirectory = QFileInfo(saveFileName).absoluteDir().absolutePath(); |
| 692 | QFile exeFile(Common::pathInTemp("SASMprog.exe")); |
| 693 | QFile::remove(saveFileName); |
| 694 | exeFile.copy(saveFileName); |
| 695 | } |
| 696 | |
| 697 | bool MainWindow::closeApp() |
| 698 | { |
| 699 | int tabsCount = tabs->count(); |
| 700 | if (tabsCount > 0) { |
| 701 | //! Consider all tabs |
| 702 | tabs->setCurrentIndex(0); |
| 703 | for (int i = 0; i < tabsCount; i++) { |
| 704 | //! Left only saved tabs |
| 705 | if (!deleteTab(tabs->currentIndex(), true)) |
| 706 | return false; |
| 707 | } |
| 708 | } |
| 709 | writeSettings(); |
| 710 | closeFromCloseAll = true; |
| 711 | close(); |
| 712 | return true; |
| 713 | } |
| 714 | |
| 715 | void MainWindow::closeEvent(QCloseEvent *e) |
| 716 | { |
| 717 | |
| 718 | if (!closeFromCloseAll) |
| 719 | if (closeApp()) { |
| 720 | closeAllChildWindows(); |
| 721 | e->accept(); |
| 722 | } else |
| 723 | e->ignore(); |
| 724 | else |
| 725 | e->accept(); |
| 726 | } |
| 727 | |
| 728 | void MainWindow::closeAllChildWindows() |
| 729 | { |
| 730 | if (findDialog) { |
| 731 | findDialog->close(); |
| 732 | delete findDialog; |
| 733 | } |
| 734 | if (settingsWindow) { |
| 735 | settingsWindow->close(); |
| 736 | delete settingsWindow; |
| 737 | } |
| 738 | if (help) { |
| 739 | help->close(); |
| 740 | delete help; |
| 741 | } |
| 742 | if (registersWindow) { |
| 743 | registersWindow->close(); |
| 744 | delete registersWindow; |
| 745 | registersWindow = 0; |
| 746 | } |
| 747 | if (memoryWindow) { |
| 748 | memoryWindow->close(); |
| 749 | delete memoryWindow; |
| 750 | memoryWindow = 0; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | bool MainWindow::deleteTab(int index, bool saveFileName) |
| 755 | { |
| 756 | settings.setValue("tabgeometry", ((Tab *) tabs->widget(index))->saveGeometry()); |
| 757 | settings.setValue("tabwindowstate", ((Tab *) tabs->widget(index))->saveState()); |
| 758 | if (okToContinue(index)) { |
| 759 | if (debugger && index == tabs->currentIndex()) |
| 760 | debugExit(); |
| 761 | if (tabs->count() == 1) |
| 762 | //! Get started |
| 763 | mainWidget->setCurrentIndex(0); |
| 764 | Tab *tabForDeleting = (Tab *) tabs->widget(index); |
| 765 | if (!saveFileName || tabForDeleting->getCurrentFilePath().isEmpty()) { |
| 766 | tabs->removeTab(index); |
| 767 | delete tabForDeleting; |
| 768 | } else { |
| 769 | //! If tab did not delete |
| 770 | tabs->setCurrentIndex(tabs->currentIndex() + 1); |
| 771 | } |
| 772 | if (tabForDeleting->code == prevCodeEditor) |
| 773 | prevCodeEditor = 0; |
| 774 | return true; |
| 775 | } |
| 776 | return false; |
| 777 | } |
| 778 | |
| 779 | bool MainWindow::okToContinue(int index) |
| 780 | { |
| 781 | Tab *deletingTab; |
| 782 | if (index == -1) |
| 783 | deletingTab = (Tab *) tabs->currentWidget(); |
| 784 | else |
| 785 | deletingTab = (Tab *) tabs->widget(index); |
| 786 | if (deletingTab->code->document()->isModified()) { |
| 787 | QMessageBox msgBox(this); |
| 788 | QPushButton *yesButton = msgBox.addButton(tr("Yes"), QMessageBox::YesRole); |
| 789 | msgBox.addButton(tr("No"), QMessageBox::NoRole); |
| 790 | QPushButton *cancelButton = msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole); |
| 791 | msgBox.setWindowTitle(tr("Save changes?")); |
| 792 | msgBox.setText(tr("Save changes?")); |
| 793 | msgBox.exec(); |
| 794 | |
| 795 | if (msgBox.clickedButton() == yesButton) { |
| 796 | return saveFile(index); |
| 797 | } else if (msgBox.clickedButton() == cancelButton) { |
| 798 | return false; |
| 799 | } |
| 800 | } |
| 801 | return true; |
| 802 | } |
| 803 | |
| 804 | void MainWindow::changeCurrentTab(int index) |
| 805 | { |
| 806 | //! Set highlighter |
| 807 | if (tabs->count() == 0) |
| 808 | return; |
| 809 | Tab *currentTab = (Tab *) tabs->widget(index); |
| 810 | highlighter->setDocument(currentTab->getCodeDocument()); |
| 811 | } |
| 812 | |
| 813 | void MainWindow::buildProgram(bool debugMode) |
| 814 | { |
| 815 | saveFile(-1, false); //save file before building if program already was saved |
| 816 | |
| 817 | programIsBuilded = false; |
| 818 | |
| 819 | using Common::applicationDataPath; |
| 820 | printLogWithTime(tr("Build started...") + '\n', settings.value("fontcolor", QColor(30, 30, 30)).value<QColor>()); |
| 821 | QCoreApplication::processEvents(); |
| 822 | |
| 823 | if (! QFile::exists(applicationDataPath())) { |
| 824 | printLogWithTime(tr("Error! Program directory does not exist. Please reinstall the program.") + '\n', Qt::red); |
| 825 | QMessageBox::critical(0, tr("Error!"), tr("Directory NASM does not exist. Please reinstall the program.")); |
| 826 | return; |
| 827 | } |
| 828 | |
| 829 | QString tempPath = Common::pathInTemp(QString()); |
| 830 | removeDirRecuresively(tempPath); |
| 831 | QString path = Common::pathInTemp("program.asm"); |
| 832 | |
| 833 | Tab *currentTab = (Tab *) tabs->currentWidget(); |
| 834 | currentTab->saveCodeToFile(path, assembler, false, debugMode && settings.value("insertdebugstring", true).toBool()); |
| 835 | |
| 836 | if (debugMode) { |
| 837 | //! Save input to file |
| 838 | QString inputPath = Common::pathInTemp("input.txt"); |
| 839 | Tab *currentTab = (Tab *) tabs->currentWidget(); |
| 840 | currentTab->saveInputToFile(inputPath); |
| 841 | } |
| 842 | |
| 843 | while (! QFile::exists(path)) { |
| 844 | } |
| 845 | |
| 846 | QString stdioMacros = Common::pathInTemp("macro.o"); |
| 847 | |
| 848 | //! Assembler |
| 849 | QString assemblerPath = assembler->getAssemblerPath(); |
| 850 | if (settings.contains("assemblerpath")) |
| 851 | assemblerPath = settings.value("assemblerpath").toString(); |
| 852 | QString assemblerOptions = assembler->getAssemblerOptions(); |
| 853 | if (settings.contains("assemblyoptions")) |
| 854 | assemblerOptions = settings.value("assemblyoptions").toString(); |
| 855 | QStringList assemblerArguments = assemblerOptions.split(QChar(' ')); |
| 856 | assemblerArguments.replaceInStrings("$SOURCE$", Common::pathInTemp("program.asm")); |
| 857 | assemblerArguments.replaceInStrings("$LSTOUTPUT$", Common::pathInTemp("program.lst")); |
| 858 | assemblerArguments.replaceInStrings("$PROGRAM.OBJ$", |
| 859 | Common::pathInTemp(settings.value("objectfilename", "program.o").toString())); |
| 860 | assemblerArguments.replaceInStrings("$PROGRAM$", Common::pathInTemp("SASMprog.exe")); |
| 861 | assemblerArguments.replaceInStrings("$MACRO.OBJ$", stdioMacros); |
| 862 | QProcess assemblerProcess; |
| 863 | QString assemblerOutput = Common::pathInTemp("compilererror.txt"); |
| 864 | assemblerProcess.setStandardOutputFile(assemblerOutput); |
| 865 | assemblerProcess.setStandardErrorFile(assemblerOutput, QIODevice::Append); |
| 866 | bool currentDir = settings.value("currentdir", false).toBool(); |
| 867 | if (currentDir) { |
| 868 | QString path = currentTab->getCurrentFilePath(); |
| 869 | if (!path.isEmpty()) { |
| 870 | QString dirPath = QFileInfo(path).absoluteDir().absolutePath(); |
| 871 | assemblerProcess.setWorkingDirectory(dirPath); |
| 872 | } else { |
| 873 | assemblerProcess.setWorkingDirectory(applicationDataPath() + "/include"); |
| 874 | } |
| 875 | } else { |
| 876 | assemblerProcess.setWorkingDirectory(applicationDataPath() + "/include"); |
| 877 | } |
| 878 | assemblerProcess.start(assemblerPath, assemblerArguments); |
| 879 | assemblerProcess.waitForFinished(); |
| 880 | |
| 881 | if (assemblerProcess.error() != QProcess::UnknownError) { |
| 882 | printLogWithTime(tr("Unable to start assembler. Check your settings.") + '\n', Qt::red); |
| 883 | return; |
| 884 | } |
| 885 | |
| 886 | //! GCC |
| 887 | QString linkerOptions = assembler->getLinkerOptions(); |
| 888 | if (settings.contains("linkingoptions")) |
| 889 | linkerOptions = settings.value("linkingoptions").toString(); |
| 890 | //! macro.c compilation/copying |
| 891 | QFile macro; |
| 892 | #ifdef Q_OS_WIN32 |
| 893 | QString linker = settings.value("linkerpath", applicationDataPath() + "/MinGW/bin/gcc.exe").toString(); |
| 894 | if (settings.value("mode", QString("x86")).toString() == "x86") { |
| 895 | macro.setFileName(applicationDataPath() + "/NASM/macro.o"); |
| 896 | } else { |
| 897 | macro.setFileName(applicationDataPath() + "/NASM/macro64.o"); |
| 898 | } |
| 899 | macro.copy(stdioMacros); |
| 900 | #else |
| 901 | QString gcc = "gcc"; |
| 902 | QString linker = settings.value("linkerpath", "gcc").toString(); |
| 903 | macro.setFileName(applicationDataPath() + "/NASM/macro.c"); |
| 904 | macro.copy(Common::pathInTemp("macro.c")); |
| 905 | |
| 906 | //! macro.c compilation |
| 907 | QStringList gccMArguments; |
| 908 | gccMArguments << "-x" << "c" << Common::pathInTemp("macro.c") << "-c" << "-g" << "-o" << stdioMacros; |
| 909 | if (settings.value("mode", QString("x86")).toString() == "x86") |
| 910 | gccMArguments << "-m32"; |
| 911 | else |
| 912 | gccMArguments << "-m64"; |
| 913 | QProcess gccMProcess; |
| 914 | gccMProcess.start(gcc, gccMArguments); |
| 915 | gccMProcess.waitForFinished(); |
| 916 | #endif |
| 917 | |
| 918 | //! Final linking |
| 919 | bool disableLinking = settings.value("disablelinking", false).toBool(); |
| 920 | QString linkerOutput; |
| 921 | if (!disableLinking) { |
| 922 | QStringList linkerArguments = linkerOptions.split(QChar(' ')); |
| 923 | linkerArguments.replaceInStrings("$PROGRAM.OBJ$", |
| 924 | Common::pathInTemp(settings.value("objectfilename", "program.o").toString())); |
| 925 | linkerArguments.replaceInStrings("$MACRO.OBJ$", stdioMacros); |
| 926 | linkerArguments.replaceInStrings("$PROGRAM$", Common::pathInTemp("SASMprog.exe")); |
| 927 | linkerArguments.replaceInStrings("$SOURCE$", Common::pathInTemp("program.asm")); |
| 928 | linkerArguments.replaceInStrings("$LSTOUTPUT$", Common::pathInTemp("program.lst")); |
| 929 | QProcess linkerProcess; |
| 930 | linkerOutput = Common::pathInTemp("linkererror.txt"); |
| 931 | linkerProcess.setStandardOutputFile(linkerOutput); |
| 932 | linkerProcess.setStandardErrorFile(linkerOutput, QIODevice::Append); |
| 933 | linkerProcess.start(linker, linkerArguments); |
| 934 | linkerProcess.waitForFinished(); |
| 935 | |
| 936 | if (linkerProcess.error() != QProcess::UnknownError) { |
| 937 | printLogWithTime(tr("Unable to start linker. Check your settings.") + '\n', Qt::red); |
| 938 | return; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | QFile logFile; |
| 943 | logFile.setFileName(assemblerOutput); |
| 944 | logFile.open(QIODevice::ReadOnly); |
| 945 | QTextStream log(&logFile); |
| 946 | QString logText = log.readAll(); |
| 947 | if (settings.value("assembler", QString("NASM")).toString() == "FASM" && logText.count(QChar('\n')) == 2 |
| 948 | && logText.contains(QRegExp(" bytes\\."))) |
| 949 | logText.clear(); |
| 950 | if (settings.value("assembler", QString("NASM")).toString() == "MASM") { |
| 951 | if (logText.count(QChar('\n')) == 1 && logText.startsWith(" Assembling:")) |
| 952 | logText.clear(); |
| 953 | if (logText.count(QChar('\n')) == 6 && logText.contains("ASCII build")) |
| 954 | logText.clear(); |
| 955 | } |
| 956 | logFile.close(); |
| 957 | |
| 958 | bool builded; |
| 959 | if (QFile::exists(Common::pathInTemp("SASMprog.exe"))) |
| 960 | builded = true; |
| 961 | else |
| 962 | builded = false; |
| 963 | if (!builded) { |
| 964 | printLogWithTime(tr("Warning! Errors have occurred in the build:") + '\n', Qt::red); |
| 965 | |
| 966 | //! Print errors |
| 967 | printLog(logText, Qt::red); |
| 968 | if (!disableLinking) { |
| 969 | logFile.setFileName(linkerOutput); |
| 970 | logFile.open(QIODevice::ReadOnly); |
| 971 | QTextStream logLinker(&logFile); |
| 972 | logText = logLinker.readAll(); |
| 973 | logFile.close(); |
| 974 | printLog(logText, Qt::red); |
| 975 | } |
| 976 | |
| 977 | //! QMessageBox::critical(0, tr("Warning!"), tr("Errors have occurred in the build!")); |
| 978 | } else { |
| 979 | printLogWithTime(tr("Built successfully.") + '\n', Qt::darkGreen); |
| 980 | //! print warnings |
| 981 | printLog(logText, Qt::red); |
| 982 | if (!disableLinking) { |
| 983 | logFile.setFileName(linkerOutput); |
| 984 | logFile.open(QIODevice::ReadOnly); |
| 985 | QTextStream logLinker(&logFile); |
| 986 | logText = logLinker.readAll(); |
| 987 | logFile.close(); |
| 988 | printLog(logText, Qt::red); |
| 989 | } |
| 990 | programIsBuilded = true; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | void MainWindow::runProgram() |
| 995 | { |
| 996 | if (!programStopped) { |
| 997 | QMessageBox::information(0, QString("SASM"), tr("The program is already running.")); |
| 998 | return; |
| 999 | } |
| 1000 | outputIndex = tabs->currentIndex(); |
| 1001 | if (!programIsBuilded) { |
| 1002 | buildProgram(); |
| 1003 | } |
| 1004 | if (!programIsBuilded) { |
| 1005 | return; |
| 1006 | } |
| 1007 | |
| 1008 | stopAction->setEnabled(true); |
| 1009 | debugAction->setEnabled(false); |
| 1010 | buildAction->setEnabled(false); |
| 1011 | |
| 1012 | ((Tab *) tabs->currentWidget())->clearOutput(); |
| 1013 | |
| 1014 | printLogWithTime(tr("The program is executing...") + '\n', settings.value("fontcolor", QColor(30, 30, 30)).value<QColor>()); |
| 1015 | QCoreApplication::processEvents(); |
| 1016 | |
| 1017 | QString input = Common::pathInTemp("input.txt"); |
| 1018 | Tab *currentTab = (Tab *) tabs->currentWidget(); |
| 1019 | currentTab->saveInputToFile(input); |
| 1020 | |
| 1021 | QString program = Common::pathInTemp("SASMprog.exe"); |
| 1022 | runProcess->setStandardInputFile(input); |
| 1023 | |
| 1024 | //! Run program in code directory if it exists |
| 1025 | QString codePath = currentTab->getCurrentFilePath(); |
| 1026 | if (!codePath.isEmpty()) { |
| 1027 | QString codeDirPath = QFileInfo(codePath).absoluteDir().absolutePath(); |
| 1028 | runProcess->setWorkingDirectory(codeDirPath); |
| 1029 | } |
| 1030 | |
| 1031 | connect(runProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(getOutput())); |
| 1032 | programStopped = false; |
| 1033 | connect(runProcess, SIGNAL(started()), this, SLOT(startCountProgramTime())); |
| 1034 | connect(runProcess, SIGNAL(finished(int)), this, SLOT(testStopOfProgram())); |
| 1035 | runProcess->start(program, QStringList()); |
| 1036 | |
| 1037 | timer->start(100); |
| 1038 | //Previous - connect(timer, SIGNAL(timeout()), this, SLOT(testStopOfProgram())); |
| 1039 | } |
| 1040 | |
| 1041 | void MainWindow::startCountProgramTime() |
| 1042 | { |
| 1043 | programExecutionTime.start(); |
| 1044 | } |
| 1045 | |
| 1046 | void MainWindow::getOutput() |
| 1047 | { |
| 1048 | QByteArray output = runProcess->readAllStandardOutput(); |
| 1049 | QString outputString = QString::fromLocal8Bit(output.constData(), output.size()); |
| 1050 | printOutput(outputString, outputIndex); |
| 1051 | } |
| 1052 | |
| 1053 | void MainWindow::testStopOfProgram() |
| 1054 | { |
| 1055 | QCoreApplication::processEvents(); |
| 1056 | if (runProcess->state() == QProcess::NotRunning) { |
| 1057 | stopAction->setEnabled(false); |
| 1058 | debugAction->setEnabled(true); |
| 1059 | buildAction->setEnabled(true); |
| 1060 | if (!programStopped) { |
| 1061 | if (runProcess->exitStatus() == QProcess::NormalExit) |
| 1062 | printLogWithTime(tr("The program finished normally. Execution time: %1 s") |
| 1063 | .arg(programExecutionTime.elapsed() / 1000.0) |
| 1064 | + '\n', Qt::darkGreen); |
| 1065 | else |
| 1066 | printLogWithTime(tr("The program crashed! Execution time: %1 s"). |
| 1067 | arg(programExecutionTime.elapsed() / 1000.0) |
| 1068 | + '\n', Qt::red); |
| 1069 | programStopped = true; |
| 1070 | } |
| 1071 | timer->stop(); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | void MainWindow::runExeProgram() |
| 1076 | { |
| 1077 | if (!programIsBuilded) { |
| 1078 | buildProgram(); |
| 1079 | } |
| 1080 | if (!programIsBuilded) { |
| 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | QString program = Common::pathInTemp("SASMprog.exe"); |
| 1085 | runProcess->startDetached(program, QStringList()); |
| 1086 | } |
| 1087 | |
| 1088 | void MainWindow::stopProgram() |
| 1089 | { |
| 1090 | if (timer->isActive()) { |
| 1091 | programStopped = true; |
| 1092 | timer->stop(); |
| 1093 | |
| 1094 | stopAction->setEnabled(false); |
| 1095 | |
| 1096 | runProcess->kill(); |
| 1097 | |
| 1098 | printLogWithTime(tr("The program stopped.") + '\n', Qt::darkGreen); |
| 1099 | } else { |
| 1100 | QMessageBox::information(0, QString("SASM"), tr("The program is not running.")); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | void MainWindow::printLogWithTime(const QString &message, const QColor &color) |
| 1105 | { |
| 1106 | QTime curTime = QTime::currentTime(); |
| 1107 | QString timeString = curTime.toString("[HH:mm:ss] "); |
| 1108 | printLog(timeString + message, color); |
| 1109 | } |
| 1110 | |
| 1111 | void MainWindow::printLog(const QString &message, const QColor &color) |
| 1112 | { |
| 1113 | QTextCursor cursor = QTextCursor(compilerOut->document()); |
| 1114 | cursor.movePosition(QTextCursor::End); |
| 1115 | compilerOut->setTextCursor(cursor); |
| 1116 | compilerOut->setTextColor(color); |
| 1117 | compilerOut->insertPlainText(message); |
| 1118 | cursor.movePosition(QTextCursor::End); |
| 1119 | compilerOut->setTextCursor(cursor); |
| 1120 | } |
| 1121 | |
| 1122 | void MainWindow::setProgramBuildedFlagToFalse() |
| 1123 | { |
| 1124 | programIsBuilded = false; |
| 1125 | } |
| 1126 | |
| 1127 | void MainWindow::printOutput(QString msg, int index) |
| 1128 | { |
| 1129 | Tab *tab = 0; |
| 1130 | if (index != -1) { |
| 1131 | tab = (Tab *) tabs->widget(index); |
| 1132 | } else |
| 1133 | tab = (Tab *) tabs->currentWidget(); |
| 1134 | tab->appendOutput(msg); |
| 1135 | } |
| 1136 | |
| 1137 | void MainWindow::debug() |
| 1138 | { |
| 1139 | //! Start debugger if true |
| 1140 | if (!debugger) { |
| 1141 | debuggerWasStarted = false; |
| 1142 | buildProgram(true); |
| 1143 | if (!programIsBuilded) { |
| 1144 | printLogWithTime(tr("Before debugging you need to build the program.") + '\n', Qt::red); |
| 1145 | return; |
| 1146 | } |
| 1147 | ((Tab *) tabs->currentWidget())->clearOutput(); |
| 1148 | printLogWithTime(tr("Debugging started...") + '\n', Qt::darkGreen); |
| 1149 | Tab *currentTab = (Tab *) tabs->currentWidget(); |
| 1150 | CodeEditor *code = currentTab->code; |
| 1151 | |
| 1152 | //! Determine executable path |
| 1153 | QString exePath = Common::pathInTemp("SASMprog.exe"); |
| 1154 | |
| 1155 | //! Determine working directory path |
| 1156 | QString workingDirectoryPath; |
| 1157 | QString codePath = currentTab->getCurrentFilePath(); |
| 1158 | if (!codePath.isEmpty()) { |
| 1159 | workingDirectoryPath = QFileInfo(codePath).absoluteDir().absolutePath(); |
| 1160 | } else { |
| 1161 | workingDirectoryPath = Common::pathInTemp(""); |
| 1162 | } |
| 1163 | workingDirectoryPath.replace("\\", "/"); |
| 1164 | |
| 1165 | //! Determine input path |
| 1166 | QString inputPath = Common::pathInTemp("input.txt"); |
| 1167 | inputPath.replace("\\", "/"); |
| 1168 | |
| 1169 | debugger = new Debugger(compilerOut, exePath, workingDirectoryPath, inputPath, assembler); |
| 1170 | connect(debugger, SIGNAL(highlightLine(int)), code, SLOT(updateDebugLine(int))); |
| 1171 | connect(debugger, SIGNAL(finished()), this, SLOT(debugExit()), Qt::QueuedConnection); |
| 1172 | connect(debugger, SIGNAL(started()), this, SLOT(enableDebugActions())); |
| 1173 | connect(debugger, SIGNAL(started()), this, SLOT(showAnyCommandWidget())); |
| 1174 | connect(code, SIGNAL(breakpointsChanged(quint64,bool)), debugger, SLOT(changeBreakpoint(quint64,bool))); |
| 1175 | connect(code, SIGNAL(addWatchSignal(const RuQPlainTextEdit::Watch &)), |
| 1176 | this, SLOT(setShowMemoryToChecked(RuQPlainTextEdit::Watch))); |
| 1177 | connect(debugger, SIGNAL(printLog(QString,QColor)), this, SLOT(printLog(QString,QColor))); |
| 1178 | connect(debugger, SIGNAL(printOutput(QString)), this, SLOT(printOutput(QString))); |
| 1179 | connect(debugger, SIGNAL(inMacro()), this, SLOT(debugNextNi()), Qt::QueuedConnection); |
| 1180 | connect(debugger, SIGNAL(wasStopped()), this, SLOT(changeDebugActionToStart())); |
| 1181 | connect(debugger, SIGNAL(needToContinue()), this, SLOT(debug())); |
| 1182 | code->setDebugEnabled(); |
| 1183 | } |
| 1184 | //Pause or continue debugger |
| 1185 | else { |
| 1186 | debugAction->setEnabled(false); |
| 1187 | if (debugger->isStopped()) { |
| 1188 | debugAction->setText(tr("Pause")); |
| 1189 | debugAction->setIcon(QIcon(":/images/debugPause.png")); |
| 1190 | debugger->doInput(QString("c\n"), ni); |
| 1191 | debugAction->setShortcut(QString()); |
| 1192 | } else { |
| 1193 | debugAction->setText(tr("Continue")); |
| 1194 | debugAction->setIcon(QIcon(":/images/continue.png")); |
| 1195 | debugAction->setShortcut(debugKey); |
| 1196 | debugger->pause(); |
| 1197 | } |
| 1198 | debugAction->setEnabled(true); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | void MainWindow::changeDebugActionToStart() |
| 1203 | { |
| 1204 | debugAction->setText(tr("Continue")); |
| 1205 | debugAction->setIcon(QIcon(":/images/continue.png")); |
| 1206 | debugAction->setShortcut(debugKey); |
| 1207 | if (!debuggerWasStarted) |
| 1208 | debuggerWasStarted = true; |
| 1209 | else { |
| 1210 | debugShowRegisters(); |
| 1211 | debugShowMemory(); |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | void MainWindow::enableDebugActions() |
| 1216 | { |
| 1217 | debugAction->setText(tr("Continue")); |
| 1218 | debugAction->setIcon(QIcon(":/images/continue.png")); |
| 1219 | |
| 1220 | //! Set all user's breakpoints |
| 1221 | CodeEditor *code = ((Tab *) tabs->currentWidget())->code; |
| 1222 | int lineNumber; |
| 1223 | foreach (lineNumber, *(code->getBreakpoints())) { |
| 1224 | debugger->changeBreakpoint(lineNumber, true); |
| 1225 | } |
| 1226 | |
| 1227 | //! Enable all actions |
| 1228 | debugNextAction->setEnabled(true); |
| 1229 | debugNextNiAction->setEnabled(true); |
| 1230 | debugShowRegistersAction->setEnabled(true); |
| 1231 | debugShowMemoryAction->setEnabled(true); |
| 1232 | stopAction->setEnabled(true); |
| 1233 | |
| 1234 | //! Change stopAction |
| 1235 | disconnect(stopAction, SIGNAL(triggered()), this, SLOT(stopProgram())); |
| 1236 | connect(stopAction, SIGNAL(triggered()), this, SLOT(debugExit())); |
| 1237 | |
| 1238 | //! Block run and build |
| 1239 | buildAction->setEnabled(false); |
| 1240 | runAction->setEnabled(false); |
| 1241 | |
| 1242 | //! Restore windows |
| 1243 | debugShowRegistersAction->setChecked(settings.value("debugregisters", false).toBool()); |
| 1244 | debugShowMemoryAction->setChecked(settings.value("debugmemory", false).toBool()); |
| 1245 | } |
| 1246 | |
| 1247 | void MainWindow::disableDebugActions(bool start) |
| 1248 | { |
| 1249 | debugAction->setText(tr("Debug")); |
| 1250 | debugAction->setIcon(QIcon(":/images/debug.png")); |
| 1251 | debugAction->setShortcut(debugKey); |
| 1252 | |
| 1253 | debugNextAction->setEnabled(false); |
| 1254 | debugNextNiAction->setEnabled(false); |
| 1255 | debugShowRegistersAction->setEnabled(false); |
| 1256 | debugShowMemoryAction->setEnabled(false); |
| 1257 | stopAction->setEnabled(false); |
| 1258 | |
| 1259 | //! Change stopAction |
| 1260 | if (!start) { |
| 1261 | disconnect(stopAction, SIGNAL(triggered()), this, SLOT(debugExit())); |
| 1262 | connect(stopAction, SIGNAL(triggered()), this, SLOT(stopProgram())); |
| 1263 | } |
| 1264 | |
| 1265 | //!Enable run and build |
| 1266 | buildAction->setEnabled(true); |
| 1267 | runAction->setEnabled(true); |
| 1268 | } |
| 1269 | |
| 1270 | void MainWindow::debugNext() |
| 1271 | { |
| 1272 | CodeEditor *code = ((Tab *) tabs->currentWidget())->code; |
| 1273 | if (code->isMacroOnCurrentDebugLine()) { |
| 1274 | debugNextNi(); |
| 1275 | } else { |
| 1276 | debugNextAction->setEnabled(false); |
| 1277 | debugger->doInput(QString("si\n"), si); |
| 1278 | debugNextAction->setEnabled(true); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | void MainWindow::debugToggleBreakpoint() |
| 1283 | { |
| 1284 | CodeEditor *code = ((Tab *) tabs->currentWidget())->code; |
| 1285 | code->setBreakpointOnCurrentLine(); |
| 1286 | } |
| 1287 | |
| 1288 | void MainWindow::debugNextNi() |
| 1289 | { |
| 1290 | debugNextNiAction->setEnabled(false); |
| 1291 | if (debugger) { |
| 1292 | debugger->doInput(QString("ni\n"), ni); |
| 1293 | } |
| 1294 | debugNextNiAction->setEnabled(true); |
| 1295 | } |
| 1296 | |
| 1297 | void MainWindow::debugShowMemory() |
| 1298 | { |
| 1299 | if (debugShowMemoryAction->isChecked()) { |
| 1300 | if (!memoryWindow) { |
| 1301 | memoryDock = new QDockWidget(tr("Memory"), this); |
| 1302 | memoryDock->setAllowedAreas(Qt::AllDockWidgetAreas); |
| 1303 | |
| 1304 | //! Create table |
| 1305 | memoryWindow = new DebugTableWidget(0, 3, memoryTable, memoryDock); |
| 1306 | connect(memoryWindow, SIGNAL(closeSignal()), this, SLOT(setShowMemoryToUnchecked())); |
| 1307 | connect(memoryWindow, SIGNAL(debugShowMemory()), this, SLOT(debugShowMemory())); |
| 1308 | CodeEditor *code = ((Tab *) tabs->currentWidget())->code; |
| 1309 | connect(code, SIGNAL(addWatchSignal(const RuQPlainTextEdit::Watch &)), |
| 1310 | memoryWindow, SLOT(addVariable(const RuQPlainTextEdit::Watch &))); |
| 1311 | connect(debugger, SIGNAL(printMemory(QList<Debugger::memoryInfo>)), |
| 1312 | memoryWindow, SLOT(setValuesFromDebugger(QList<Debugger::memoryInfo>))); |
| 1313 | |
| 1314 | memoryDock->setWidget(memoryWindow); |
| 1315 | memoryDock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); |
| 1316 | addDockWidget(Qt::TopDockWidgetArea, memoryDock); |
| 1317 | memoryDock->setObjectName("memoryDock"); |
| 1318 | |
| 1319 | restoreState(settings.value("debugstate").toByteArray()); |
| 1320 | if (registersDock) |
| 1321 | registersDock->show(); |
| 1322 | if (memoryDock) |
| 1323 | memoryDock->show(); |
| 1324 | |
| 1325 | //! Fill table |
| 1326 | memoryWindow->initializeMemoryWindow(watches); |
| 1327 | } |
| 1328 | if (debugger->isStopped()) { |
| 1329 | debugger->setWatchesCount(memoryWindow->rowCount() - 1); |
| 1330 | for (int i = 0; i < memoryWindow->rowCount() - 1; i++) { |
| 1331 | if (memoryWindow->cellWidget(i, 2)) { |
| 1332 | WatchSettingsWidget *settings = (WatchSettingsWidget *) memoryWindow->cellWidget(i, 2); |
| 1333 | |
| 1334 | int arraySize = 0; |
| 1335 | |
| 1336 | int size = settings->sizeComboBox->currentIndex(); |
| 1337 | QStringList sizeFormat; |
| 1338 | sizeFormat << "int" << "short" << "char" << "long long"; |
| 1339 | |
| 1340 | bool ok; |
| 1341 | arraySize = settings->arraySizeEdit->text().toInt(&ok); |
| 1342 | if (!ok && sizeFormat[size] == "long long") { |
| 1343 | arraySize = 1; |
| 1344 | ok = true; |
| 1345 | } |
| 1346 | QString watchAsArray; |
| 1347 | if (ok && arraySize > 0) |
| 1348 | watchAsArray = "[" + QString::number(arraySize) + "]"; |
| 1349 | |
| 1350 | int type = settings->typeComboBox->currentIndex(); |
| 1351 | QStringList printFormat; |
| 1352 | printFormat << "p" << "p/x" << "p/t" << "p/c" << "p/d" << "p/u" << "p/f"; |
| 1353 | //! If true, watch as variable |
| 1354 | if (! settings->addressCheckbox->isChecked()) { |
| 1355 | debugger->doInput(printFormat[type] + " (" + sizeFormat[size] + watchAsArray + ")" + |
| 1356 | "(" + memoryWindow->item(i, 0)->text() + ")" + "\n", infoMemory); |
| 1357 | } else { |
| 1358 | //! Watch as random address |
| 1359 | debugger->doInput(printFormat[type] + " (" + sizeFormat[size] + watchAsArray + ")" + |
| 1360 | "*((" + sizeFormat[size] + "*) " + "(" + memoryWindow->item(i, 0)->text() + ")" + ")" + |
| 1361 | "\n", infoMemory); |
| 1362 | } |
| 1363 | } |
| 1364 | } |
| 1365 | static SignalLocker locker; |
| 1366 | if (memoryWindow->rowCount() > 1 && locker.tryLock()) { |
| 1367 | connect(debugger, SIGNAL(printMemory(QList<Debugger::memoryInfo>)), &locker, SLOT(unlock()), Qt::UniqueConnection); |
| 1368 | connect(debugger, SIGNAL(finished()), &locker, SLOT(unlock()), Qt::UniqueConnection); |
| 1369 | } |
| 1370 | } |
| 1371 | } else |
| 1372 | if (memoryWindow) { |
| 1373 | saveWatches(memoryWindow); |
| 1374 | memoryWindow->close(); |
| 1375 | memoryWindow->clear(); |
| 1376 | delete memoryWindow; |
| 1377 | memoryWindow = 0; |
| 1378 | memoryDock->close(); |
| 1379 | delete memoryDock; |
| 1380 | memoryDock = 0; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | void MainWindow::saveWatches(DebugTableWidget *table) |
| 1385 | { |
| 1386 | watches.clear(); |
| 1387 | for (int i = 0; i < table->rowCount() - 1; i++) { |
| 1388 | RuQPlainTextEdit::Watch watch; |
| 1389 | watch.name = table->item(i, 0)->text(); |
| 1390 | WatchSettingsWidget *settings = (WatchSettingsWidget *) table->cellWidget(i, 2); |
| 1391 | watch.type = settings->typeComboBox->currentIndex(); |
| 1392 | watch.size = settings->sizeComboBox->currentIndex(); |
| 1393 | watch.address = settings->addressCheckbox->isChecked(); |
| 1394 | bool ok; |
| 1395 | watch.arraySize = settings->arraySizeEdit->text().toInt(&ok); |
| 1396 | if (!ok) |
| 1397 | watch.arraySize = 0; |
| 1398 | watches.append(watch); |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | void MainWindow::setShowMemoryToUnchecked() |
| 1403 | { |
| 1404 | debugShowMemoryAction->setChecked(false); |
| 1405 | } |
| 1406 | |
| 1407 | void MainWindow::setShowMemoryToChecked(const RuQPlainTextEdit::Watch &variable) |
| 1408 | { |
| 1409 | if (!debugShowMemoryAction->isChecked()) { |
| 1410 | watches.append(variable); |
| 1411 | debugShowMemoryAction->setChecked(true); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | void MainWindow::debugShowRegisters() |
| 1416 | { |
| 1417 | if (debugShowRegistersAction->isChecked()) { |
| 1418 | if (!registersWindow) { |
| 1419 | registersDock = new QDockWidget(tr("Registers"), this); |
| 1420 | registersDock->setAllowedAreas(Qt::AllDockWidgetAreas); |
| 1421 | |
| 1422 | int regCount; |
| 1423 | if (settings.value("mode", QString("x86")).toString() == "x86") { |
| 1424 | regCount = 16; |
| 1425 | } else { |
| 1426 | regCount = 24; |
| 1427 | } |
| 1428 | if (settings.value("allregisters", false).toBool()) { |
| 1429 | regCount += 33; |
| 1430 | } |
| 1431 | registersWindow = new DebugTableWidget(regCount, 3, registersTable, registersDock); |
| 1432 | connect(registersWindow, SIGNAL(closeSignal()), this, SLOT(setShowRegistersToUnchecked())); |
| 1433 | connect(debugger, SIGNAL(printRegisters(QList<Debugger::registersInfo>)), |
| 1434 | registersWindow, SLOT(setValuesFromDebugger(QList<Debugger::registersInfo>))); |
| 1435 | |
| 1436 | registersDock->setWidget(registersWindow); |
| 1437 | registersDock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); |
| 1438 | addDockWidget(Qt::RightDockWidgetArea, registersDock); |
| 1439 | registersDock->setObjectName("registersDock"); |
| 1440 | |
| 1441 | restoreState(settings.value("debugstate").toByteArray()); |
| 1442 | if (registersDock) |
| 1443 | registersDock->show(); |
| 1444 | if (memoryDock) |
| 1445 | memoryDock->show(); |
| 1446 | } |
| 1447 | static SignalLocker locker; |
| 1448 | if (debugger->isStopped() && locker.tryLock()) { |
| 1449 | connect(debugger, SIGNAL(printRegisters(QList<Debugger::registersInfo>)), &locker, SLOT(unlock()), Qt::UniqueConnection); |
| 1450 | connect(debugger, SIGNAL(finished()), &locker, SLOT(unlock()), Qt::UniqueConnection); |
| 1451 | if (settings.value("allregisters", false).toBool()) |
| 1452 | debugger->doInput(QString("info all-registers\n"), infoRegisters); |
| 1453 | else |
| 1454 | debugger->doInput(QString("info registers\n"), infoRegisters); |
| 1455 | } |
| 1456 | } else |
| 1457 | if (registersWindow) { |
| 1458 | registersWindow->close(); |
| 1459 | registersWindow->clear(); |
| 1460 | delete registersWindow; |
| 1461 | registersWindow = 0; |
| 1462 | registersDock->close(); |
| 1463 | delete registersDock; |
| 1464 | registersDock = 0; |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | void MainWindow::setShowRegistersToUnchecked() |
| 1469 | { |
| 1470 | debugShowRegistersAction->setChecked(false); |
| 1471 | } |
| 1472 | |
| 1473 | void MainWindow::debugExit() |
| 1474 | { |
| 1475 | settings.setValue("debugregisters", debugShowRegistersAction->isChecked()); |
| 1476 | settings.setValue("debugmemory", debugShowMemoryAction->isChecked()); |
| 1477 | settings.setValue("debugstate", saveState()); |
| 1478 | CodeEditor *code = ((Tab *) tabs->currentWidget())->code; |
| 1479 | disconnect(code, SIGNAL(addWatchSignal(const RuQPlainTextEdit::Watch &)), |
| 1480 | this, SLOT(setShowMemoryToChecked(RuQPlainTextEdit::Watch))); |
| 1481 | disconnect(debugger, SIGNAL(printLog(QString,QColor)), this, SLOT(printLog(QString,QColor))); |
| 1482 | disconnect(debugger, SIGNAL(printOutput(QString)), this, SLOT(printOutput(QString))); |
| 1483 | code->setDebugDisabled(); |
| 1484 | //! Many actions performed here - deleting of highlighting too |
| 1485 | delete debugger; |
| 1486 | debugger = 0; |
| 1487 | closeAnyCommandWidget(); |
| 1488 | debugShowRegistersAction->setChecked(false); |
| 1489 | debugShowMemoryAction->setChecked(false); |
| 1490 | printLogWithTime(tr("Debugging finished.") + '\n', Qt::darkGreen); |
| 1491 | disableDebugActions(); |
| 1492 | } |
| 1493 | |
| 1494 | void MainWindow::showAnyCommandWidget() |
| 1495 | { |
| 1496 | debugAnyCommandWidget->show(); |
| 1497 | debugAnyCommandWidget->setFocusOnLineEdit(); |
| 1498 | connect(debugAnyCommandWidget, SIGNAL(performCommand(QString,bool)), |
| 1499 | this, SLOT(debugRunCommand(QString,bool))); |
| 1500 | } |
| 1501 | |
| 1502 | void MainWindow::closeAnyCommandWidget() |
| 1503 | { |
| 1504 | disconnect(debugAnyCommandWidget, SIGNAL(performCommand(QString,bool)), |
| 1505 | this, SLOT(debugRunCommand(QString,bool))); |
| 1506 | debugAnyCommandWidget->close(); |
| 1507 | } |
| 1508 | |
| 1509 | void MainWindow::debugRunCommand(QString command, bool print) |
| 1510 | { |
| 1511 | static SignalLocker locker; |
| 1512 | if (debugger->isStopped() && locker.tryLock()) { |
| 1513 | connect(debugger, SIGNAL(printLog(QString,QColor)), &locker, SLOT(unlock()), Qt::UniqueConnection); |
| 1514 | connect(debugger, SIGNAL(finished()), &locker, SLOT(unlock()), Qt::UniqueConnection); |
| 1515 | printLog("> " + command + "\n", QColor(32, 71, 247)); |
| 1516 | if (print) |
| 1517 | debugger->doInput("p " + command + "\n", anyAction); |
| 1518 | else |
| 1519 | debugger->doInput(command + "\n", anyAction); |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | void MainWindow::find() |
| 1524 | { |
| 1525 | if (!findDialog) { |
| 1526 | findDialog = new FindDialog(this); |
| 1527 | connect(findDialog, SIGNAL(findNext(QString,Qt::CaseSensitivity,bool,bool,QString)), |
| 1528 | this, SLOT(findNext(QString,Qt::CaseSensitivity,bool,bool,QString))); |
| 1529 | } |
| 1530 | CodeEditor *code = ((Tab *) tabs->currentWidget())->code; |
| 1531 | QString selectedText = code->textCursor().selectedText(); |
| 1532 | if (!selectedText.isEmpty()) { |
| 1533 | findDialog->setSearchText(selectedText); |
| 1534 | } |
| 1535 | findDialog->show(); |
| 1536 | findDialog->activateWindow(); |
| 1537 | } |
| 1538 | |
| 1539 | void MainWindow::findNextAfterTextChange() |
| 1540 | { |
| 1541 | findNext(QString(), Qt::CaseSensitive, true, false); |
| 1542 | } |
| 1543 | |
| 1544 | void MainWindow::findNext(const QString &pattern, Qt::CaseSensitivity cs, bool all, |
| 1545 | bool replace, const QString &replaceText) |
| 1546 | { |
| 1547 | //! Clear all highlights and disable highlighting of current line |
| 1548 | for (int i = 0; i < tabs->count(); i++) { |
| 1549 | CodeEditor *code = ((Tab *) tabs->widget(i))->code; |
| 1550 | disconnect(code, SIGNAL(cursorPositionChanged()), code, SLOT(highlightCurrentLine())); |
| 1551 | code->setExtraSelections(QList<QTextEdit::ExtraSelection>()); |
| 1552 | } |
| 1553 | //! Restore highlight |
| 1554 | if (pattern.isEmpty()) { |
| 1555 | |
| 1556 | for (int i = 0; i < tabs->count(); i++) { |
| 1557 | CodeEditor *code = ((Tab *) tabs->widget(i))->code; |
| 1558 | connect(code, SIGNAL(cursorPositionChanged()), code, SLOT(highlightCurrentLine())); |
| 1559 | code->highlightCurrentLine(); |
| 1560 | if (code->debugMode) |
| 1561 | code->highlightDebugLine(code->currentDebugLine, false); |
| 1562 | } |
| 1563 | } else { |
| 1564 | //If true, find all |
| 1565 | if (all) { |
| 1566 | for (int i = 0; i < tabs->count(); i++) { |
| 1567 | QTextEdit::ExtraSelection selection; |
| 1568 | QList<QTextEdit::ExtraSelection> extraSelections; |
| 1569 | selection.format.setBackground(QBrush(Qt::green)); |
| 1570 | QTextDocument *document = ((Tab *) tabs->widget(i))->getCodeDocument(); |
| 1571 | QTextCursor newCursor = QTextCursor(document); |
| 1572 | CodeEditor *code = ((Tab *) tabs->widget(i))->code; |
| 1573 | |
| 1574 | while (!newCursor.isNull() && !newCursor.atEnd()) { |
| 1575 | if (cs == Qt::CaseSensitive) |
| 1576 | newCursor = document->find(pattern, newCursor, QTextDocument::FindCaseSensitively); |
| 1577 | else |
| 1578 | newCursor = document->find(pattern, newCursor, 0); |
| 1579 | //! Replace mode |
| 1580 | if (replace && i == tabs->currentIndex()) { |
| 1581 | newCursor.removeSelectedText(); |
| 1582 | newCursor.insertText(replaceText); |
| 1583 | } |
| 1584 | if (!newCursor.isNull()) { |
| 1585 | selection.cursor = newCursor; |
| 1586 | extraSelections.append(selection); |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | //! Highlight all |
| 1591 | code->setExtraSelections(extraSelections); |
| 1592 | } |
| 1593 | } |
| 1594 | //!Find next only |
| 1595 | else { |
| 1596 | QTextEdit::ExtraSelection selection; |
| 1597 | QList<QTextEdit::ExtraSelection> extraSelections; |
| 1598 | selection.format.setBackground(QBrush(Qt::green)); |
| 1599 | QTextDocument *document = ((Tab *) tabs->currentWidget())->getCodeDocument(); |
| 1600 | CodeEditor *code = ((Tab *) tabs->currentWidget())->code; |
| 1601 | static QTextCursor newCursor(document); |
| 1602 | //! if documents differ, cursor is ignored in QTextDocument::find() |
| 1603 | if (replace) { |
| 1604 | newCursor.removeSelectedText(); |
| 1605 | newCursor.insertText(replaceText); |
| 1606 | } |
| 1607 | if (cs == Qt::CaseSensitive) |
| 1608 | newCursor = document->find(pattern, newCursor, QTextDocument::FindCaseSensitively); |
| 1609 | else |
| 1610 | newCursor = document->find(pattern, newCursor, 0); |
| 1611 | //! Continue from start |
| 1612 | if (newCursor.isNull()) { |
| 1613 | if (cs == Qt::CaseSensitive) |
| 1614 | newCursor = document->find(pattern, newCursor, QTextDocument::FindCaseSensitively); |
| 1615 | else |
| 1616 | newCursor = document->find(pattern, newCursor, 0); |
| 1617 | } |
| 1618 | if (!newCursor.isNull()) { |
| 1619 | selection.cursor = newCursor; |
| 1620 | extraSelections.append(selection); |
| 1621 | QTextCursor cursor = newCursor; |
| 1622 | cursor.clearSelection(); |
| 1623 | code->setTextCursor(cursor); |
| 1624 | } |
| 1625 | |
| 1626 | code->setExtraSelections(extraSelections); |
| 1627 | } |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | void MainWindow::restorePrevSession(bool notNotify) |
| 1632 | { |
| 1633 | int count = settings.value("tabscount", 0).toInt(); |
| 1634 | if (count == 0 && !notNotify) { |
| 1635 | QMessageBox::information(0, QString("SASM"), |
| 1636 | tr("In the previous session was not open any of the saved tabs!")); |
| 1637 | return; |
| 1638 | } |
| 1639 | settings.beginGroup("Tabs"); |
| 1640 | for (int i = 0; i < count; i++) { |
| 1641 | QString fileName = settings.value(QString::number(i)).toString(); |
| 1642 | newFile(); |
| 1643 | Tab *curTab = (Tab *) tabs->currentWidget(); |
| 1644 | curTab->loadCodeFromFile(fileName); |
| 1645 | setTabPath(fileName); |
| 1646 | } |
| 1647 | settings.endGroup(); |
| 1648 | } |
| 1649 | |
| 1650 | void MainWindow::writeSettings() |
| 1651 | { |
| 1652 | //! GUI |
| 1653 | settings.beginGroup("MainWindow"); |
| 1654 | settings.setValue("size", size()); |
| 1655 | settings.setValue("pos", pos()); |
| 1656 | unsigned int maxFlag = windowState() & Qt::WindowMaximized; |
| 1657 | settings.setValue("maximized", maxFlag); |
| 1658 | settings.endGroup(); |
| 1659 | settings.setValue("windowstate", saveState()); |
| 1660 | |
| 1661 | //! Opened tabs |
| 1662 | int prevTabsCount = settings.value("tabscount", 0).toInt(); |
| 1663 | //! Remove previous |
| 1664 | for (int i = 0; i < prevTabsCount; i++) |
| 1665 | { |
| 1666 | settings.remove(QString("Tabs/") + QString::number(i)); |
| 1667 | } |
| 1668 | //! Create current |
| 1669 | settings.setValue("tabscount", tabs->count()); |
| 1670 | settings.beginGroup("Tabs"); |
| 1671 | for (int i = 0; i < tabs->count(); i++) { |
| 1672 | settings.setValue(QString::number(i), ((Tab *) tabs->widget(i))->getCurrentFilePath()); |
| 1673 | } |
| 1674 | settings.endGroup(); |
| 1675 | |
| 1676 | //! Save and open directory |
| 1677 | settings.setValue("saveopendirectory", saveOpenDirectory); |
| 1678 | |
| 1679 | //! Splitters state |
| 1680 | settings.setValue("logsplitterstate", splitter->saveState()); |
| 1681 | } |
| 1682 | |
| 1683 | void MainWindow::openSettings() |
| 1684 | { |
| 1685 | //! Initialize |
| 1686 | if (!settingsWindow) { |
| 1687 | settingsWindow = new QWidget(this, Qt::Window); |
| 1688 | settingsWindow->setWindowModality(Qt::WindowModal); |
| 1689 | settingsUi.setupUi(settingsWindow); |
| 1690 | connect(settingsUi.buttonBox->button(QDialogButtonBox::Ok), |
| 1691 | SIGNAL(clicked()), this, SLOT(exitSettings())); |
| 1692 | connect(settingsUi.buttonBox->button(QDialogButtonBox::Apply), |
| 1693 | SIGNAL(clicked()), this, SLOT(saveSettings())); |
| 1694 | connect(settingsUi.buttonBox->button(QDialogButtonBox::Cancel), |
| 1695 | SIGNAL(clicked()), this, SLOT(restoreSettingsAndExit())); |
| 1696 | connect(settingsUi.resetAllButton, SIGNAL(clicked()), this, SLOT(resetAllSettings())); |
| 1697 | connect(settingsUi.disableLinkingCheckbox, SIGNAL(stateChanged(int)), |
| 1698 | this, SLOT(enableOrDisableLinkingEdit(int))); |
| 1699 | |
| 1700 | //! Colors |
| 1701 | colorSignalMapper = new QSignalMapper(this); |
| 1702 | colorButtons << |
| 1703 | //! Foreground |
| 1704 | settingsUi.keywordsColorButton << settingsUi.registersColorButton << |
| 1705 | settingsUi.numbersColorButton << settingsUi.memoryColorButton << |
| 1706 | settingsUi.labelsColorButton << settingsUi.commentsColorButton << |
| 1707 | settingsUi.systemColorButton << settingsUi.iomacroColorButton << |
| 1708 | settingsUi.quotationColorButton << |
| 1709 | //! Background |
| 1710 | settingsUi.keywordsColorButton_2 << settingsUi.registersColorButton_2 << |
| 1711 | settingsUi.numbersColorButton_2 << settingsUi.memoryColorButton_2 << |
| 1712 | settingsUi.labelsColorButton_2 << settingsUi.commentsColorButton_2 << |
| 1713 | settingsUi.systemColorButton_2 << settingsUi.iomacroColorButton_2 << |
| 1714 | settingsUi.quotationColorButton_2 << |
| 1715 | //! Common |
| 1716 | settingsUi.backgroundColorButton << settingsUi.lineNumberPanelColorButton << |
| 1717 | settingsUi.fontColorButton << |
| 1718 | settingsUi.currentLineColorButton << settingsUi.debugLineColorButton << |
| 1719 | settingsUi.lineNumberFontColorButton; |
| 1720 | |
| 1721 | //! Add color buttons signal mapping |
| 1722 | for (int i = 0; i < colorButtons.size(); i++) { |
| 1723 | connect(colorButtons[i], SIGNAL(clicked()), colorSignalMapper, SLOT(map())); |
| 1724 | colorSignalMapper->setMapping(colorButtons[i], colorButtons[i]); |
| 1725 | } |
| 1726 | connect(colorSignalMapper, SIGNAL(mapped(QWidget*)), this, SLOT(pickColor(QWidget*))); |
| 1727 | |
| 1728 | //! Fonts |
| 1729 | fontsSignalMapper = new QSignalMapper(this); |
| 1730 | fontCheckBoxes << |
| 1731 | //! Bold |
| 1732 | settingsUi.keywordsBoldCheckBox << settingsUi.registersBoldCheckBox << |
| 1733 | settingsUi.numbersBoldCheckBox << settingsUi.memoryBoldCheckBox << |
| 1734 | settingsUi.labelsBoldCheckBox << settingsUi.commentsBoldCheckBox << |
| 1735 | settingsUi.systemBoldCheckBox << settingsUi.iomacroBoldCheckBox << |
| 1736 | settingsUi.quotationBoldCheckBox << |
| 1737 | //! Italic |
| 1738 | settingsUi.keywordsItalicCheckBox << settingsUi.registersItalicCheckBox << |
| 1739 | settingsUi.numbersItalicCheckBox << settingsUi.memoryItalicCheckBox << |
| 1740 | settingsUi.labelsItalicCheckBox << settingsUi.commentsItalicCheckBox << |
| 1741 | settingsUi.systemItalicCheckBox << settingsUi.iomacroItalicCheckBox << |
| 1742 | settingsUi.quotationItalicCheckBox; |
| 1743 | //! Add font to associative array |
| 1744 | for (int i = 0; i < fontCheckBoxes.size(); i++) { |
| 1745 | |
| 1746 | QString name = fontCheckBoxes[i]->objectName(); |
| 1747 | name.remove("CheckBox"); |
| 1748 | name = name.toLower(); |
| 1749 | |
| 1750 | connect(fontCheckBoxes[i], SIGNAL(clicked()), fontsSignalMapper, SLOT(map())); |
| 1751 | fontsSignalMapper->setMapping(fontCheckBoxes[i], fontCheckBoxes[i]); |
| 1752 | } |
| 1753 | connect(fontsSignalMapper, SIGNAL(mapped(QWidget*)), this, SLOT(changeHighlightingFont(QWidget*))); |
| 1754 | |
| 1755 | connect(settingsUi.currentLineCheckBox, SIGNAL(stateChanged(int)), this, SLOT(changeHighlightingLineMode(int))); |
| 1756 | |
| 1757 | connect(settingsUi.lightThemeButton, SIGNAL(clicked()), this, SLOT(changeColorButtonsLight())); |
| 1758 | connect(settingsUi.darkThemeButton, SIGNAL(clicked()), this, SLOT(changeColorButtonsDark())); |
| 1759 | |
| 1760 | backupSettings(); |
| 1761 | initAssemblerSettings(true); |
| 1762 | } else { |
| 1763 | initAssemblerSettings(false); |
| 1764 | } |
| 1765 | |
| 1766 | //! Set settings |
| 1767 | //! Common |
| 1768 | settingsUi.startWindow->setCurrentIndex(settings.value("startwindow", 0).toInt()); |
| 1769 | settingsUi.language->setCurrentIndex(settings.value("language", 0).toInt()); |
| 1770 | settingsUi.fontComboBox->setCurrentFont(QFont(settings.value("fontfamily", |
| 1771 | QString("Courier New")).value<QString>())); |
| 1772 | settingsUi.fontSizeSpinBox->setValue(settings.value("fontsize", 12).toInt()); |
| 1773 | if (settings.value("allregisters", false).toBool()) |
| 1774 | settingsUi.registersYesRadioButton->setChecked(true); |
| 1775 | else |
| 1776 | settingsUi.registersNoRadioButton->setChecked(true); |
| 1777 | settingsUi.insertDebugStringCheckBox->setChecked(settings.value("insertdebugstring", true).toBool()); |
| 1778 | |
| 1779 | //! Colors |
| 1780 | initColorButtons(false, false); |
| 1781 | //! Fonts |
| 1782 | for (int i = 0; i < fontCheckBoxes.size(); i++) { |
| 1783 | changeHighlightingFont((QWidget *) fontCheckBoxes[i], true); |
| 1784 | } |
| 1785 | |
| 1786 | settingsUi.currentLineCheckBox->setChecked(settings.value("currentlinemode", true).toBool()); |
| 1787 | settingsWindow->show(); |
| 1788 | } |
| 1789 | |
| 1790 | void MainWindow::initColorButtons(bool dark, bool ignoreSettings) { |
| 1791 | defaultColors.clear(); |
| 1792 | if (dark) { |
| 1793 | if (ignoreSettings) |
| 1794 | settingsUi.currentLineCheckBox->setChecked(false); |
| 1795 | defaultColors << |
| 1796 | //! According to colorButtons |
| 1797 | QColor(181, 206, 168) << QColor(144, 220, 254) << |
| 1798 | QColor(181, 206, 168) << QColor(212, 212, 212) << |
| 1799 | QColor(244, 71, 71) << QColor(106, 153, 85) << |
| 1800 | QColor(78, 201, 176) << QColor(28, 113, 216) << |
| 1801 | QColor(195, 145, 120) << |
| 1802 | QColor(30, 30, 30) << QColor(30, 30, 30) << |
| 1803 | QColor(30, 30, 30) << QColor(30, 30, 30) << |
| 1804 | QColor(30, 30, 30) << QColor(30, 30, 30) << |
| 1805 | QColor(30, 30, 30) << QColor(30, 30, 30) << |
| 1806 | QColor(30, 30, 30) << |
| 1807 | QColor(30, 30, 30) << QColor(50, 50, 50) << |
| 1808 | QColor(255, 255, 255) << |
| 1809 | QColor(232, 232, 255) << QColor(100, 78, 0) << |
| 1810 | QColor(255, 255, 255); |
| 1811 | } else { |
| 1812 | if (ignoreSettings) |
| 1813 | settingsUi.currentLineCheckBox->setChecked(true); |
| 1814 | defaultColors << |
| 1815 | //! According to colorButtons |
| 1816 | QColor(Qt::blue) << QColor(153, 0, 204) << |
| 1817 | QColor(255, 122, 0) << QColor(0, 128, 255) << |
| 1818 | QColor(128, 0, 0) << QColor(Qt::darkGreen) << |
| 1819 | QColor(Qt::darkCyan) << QColor(Qt::blue) << |
| 1820 | QColor(128, 128, 128) << |
| 1821 | QColor(255, 255, 255) << QColor(255, 255, 255) << |
| 1822 | QColor(255, 255, 255) << QColor(255, 255, 255) << |
| 1823 | QColor(255, 255, 255) << QColor(255, 255, 255) << |
| 1824 | QColor(255, 255, 255) << QColor(255, 255, 255) << |
| 1825 | QColor(255, 255, 255) << |
| 1826 | QColor(255, 255, 255) << QColor(235, 235, 235) << |
| 1827 | QColor(30, 30, 30) << |
| 1828 | QColor(232, 232, 255) << QColor(235, 200, 40) << |
| 1829 | QColor(30, 30, 30); |
| 1830 | } |
| 1831 | |
| 1832 | //! Add color to associative array |
| 1833 | for (int i = 0; i < colorButtons.size(); i++) { |
| 1834 | QString name = colorButtons[i]->objectName(); |
| 1835 | name.remove("Button"); |
| 1836 | name.replace("_2", "bg"); |
| 1837 | name = name.toLower(); |
| 1838 | colorsMap.insert(name, defaultColors[i]); |
| 1839 | } |
| 1840 | |
| 1841 | //! Colors |
| 1842 | for (int i = 0; i < colorButtons.size(); i++) { |
| 1843 | pickColor((QWidget *) colorButtons[i], true, ignoreSettings); |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | void MainWindow::changeColorButtonsLight() { |
| 1848 | initColorButtons(false, true); |
| 1849 | } |
| 1850 | |
| 1851 | void MainWindow::changeColorButtonsDark() { |
| 1852 | initColorButtons(true, true); |
| 1853 | } |
| 1854 | |
| 1855 | void MainWindow::initAssemblerSettings(bool firstOpening) |
| 1856 | { |
| 1857 | if (firstOpening) { |
| 1858 | /*! |
| 1859 | * |
| 1860 | * Assembler Dependent Options Begin |
| 1861 | * |
| 1862 | */ |
| 1863 | connect(settingsUi.nasmRadioButton, SIGNAL(clicked()), this, SLOT(changeAssembler())); |
| 1864 | connect(settingsUi.gasRadioButton, SIGNAL(clicked()), this, SLOT(changeAssembler())); |
| 1865 | connect(settingsUi.fasmRadioButton, SIGNAL(clicked()), this, SLOT(changeAssembler())); |
| 1866 | #ifdef Q_OS_WIN32 |
| 1867 | connect(settingsUi.masmRadioButton, SIGNAL(clicked()), this, SLOT(changeAssembler())); |
| 1868 | connect(settingsUi.masmRadioButton, SIGNAL(clicked()), this, SLOT(printMasmInfo())); |
| 1869 | //! Else it is Linux |
| 1870 | #else |
| 1871 | settingsUi.masmRadioButton->setEnabled(false); |
| 1872 | #endif |
| 1873 | |
| 1874 | /*! |
| 1875 | * |
| 1876 | * Assembler Dependent Options End |
| 1877 | * |
| 1878 | */ |
| 1879 | |
| 1880 | connect(settingsUi.x86RadioButton, SIGNAL(toggled(bool)), this, SLOT(changeMode(bool))); |
| 1881 | |
| 1882 | //! Start text editor |
| 1883 | settingsStartTextEditor = new CodeEditor(0, false); |
| 1884 | settingsHighlighter = new Highlighter(assembler); |
| 1885 | settingsHighlighter->setDocument(settingsStartTextEditor->document()); |
| 1886 | QVBoxLayout *startTextLayout = new QVBoxLayout; |
| 1887 | startTextLayout->addWidget(settingsStartTextEditor); |
| 1888 | settingsStartTextEditor->setFixedHeight(120); |
| 1889 | settingsUi.startTextWidget->setLayout(startTextLayout); |
| 1890 | } |
| 1891 | |
| 1892 | settingsStartTextEditor->setPlainText(settings.value("starttext").toString()); |
| 1893 | |
| 1894 | //! Build options |
| 1895 | QString options = assembler->getAssemblerOptions(); |
| 1896 | settingsUi.assemblyOptionsEdit->setText(settings.value("assemblyoptions", options).toString()); |
| 1897 | |
| 1898 | QString linkerOptions = assembler->getLinkerOptions(); |
| 1899 | settingsUi.linkingOptionsEdit->setText(settings.value("linkingoptions", linkerOptions).toString()); |
| 1900 | |
| 1901 | settingsUi.objectFileNameEdit->setText(settings.value("objectfilename", "program.o").toString()); |
| 1902 | |
| 1903 | settingsUi.disableLinkingCheckbox->setChecked(settings.value("disablelinking", false).toBool()); |
| 1904 | |
| 1905 | settingsUi.runInCurrentDirectoryCheckbox->setChecked(settings.value("currentdir", false).toBool()); |
| 1906 | |
| 1907 | QString assemblerPath = assembler->getAssemblerPath(); |
| 1908 | settingsUi.assemblerPathEdit->setText(settings.value("assemblerpath", assemblerPath).toString()); |
| 1909 | |
| 1910 | #ifdef Q_OS_WIN32 |
| 1911 | settingsUi.linkerPathEdit->setText(settings.value("linkerpath", Common::applicationDataPath() + "/MinGW/bin/gcc.exe").toString()); |
| 1912 | #else |
| 1913 | settingsUi.linkerPathEdit->setText(settings.value("linkerpath", "gcc").toString()); |
| 1914 | #endif |
| 1915 | |
| 1916 | disconnect(settingsUi.x86RadioButton, SIGNAL(toggled(bool)), this, SLOT(changeMode(bool))); |
| 1917 | //! Mode |
| 1918 | if (assembler->isx86()) |
| 1919 | settingsUi.x86RadioButton->setChecked(true); |
| 1920 | else |
| 1921 | settingsUi.x64RadioButton->setChecked(true); |
| 1922 | connect(settingsUi.x86RadioButton, SIGNAL(toggled(bool)), this, SLOT(changeMode(bool))); |
| 1923 | |
| 1924 | /*! |
| 1925 | * |
| 1926 | * Assembler Dependent Options Begin |
| 1927 | * |
| 1928 | */ |
| 1929 | |
| 1930 | QString assemblerName = settings.value("assembler", QString("NASM")).toString(); |
| 1931 | if (assemblerName == "MASM") { |
| 1932 | settingsUi.x64RadioButton->setEnabled(false); |
| 1933 | printMasmInfo(); |
| 1934 | } |
| 1935 | if (assemblerName == "NASM") { |
| 1936 | settingsUi.nasmRadioButton->setChecked(true); |
| 1937 | } else if (assemblerName == "GAS") { |
| 1938 | settingsUi.gasRadioButton->setChecked(true); |
| 1939 | } else if (assemblerName == "FASM") { |
| 1940 | settingsUi.fasmRadioButton->setChecked(true); |
| 1941 | } else if (assemblerName == "MASM") { |
| 1942 | settingsUi.masmRadioButton->setChecked(true); |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | /*! |
| 1947 | * |
| 1948 | * Assembler Dependent Options End |
| 1949 | * |
| 1950 | */ |
| 1951 | |
| 1952 | void MainWindow::printMasmInfo() |
| 1953 | { |
| 1954 | settingsUi.infoLabel->setText(tr("Please set path to MASM assembler (ml.exe) and linker (link.exe) on your computer ") + |
| 1955 | tr("in fields \"Assembler path\" and \"Linker path\" above.")); |
| 1956 | } |
| 1957 | /*! |
| 1958 | * |
| 1959 | * Assembler Dependent Options Begin |
| 1960 | * |
| 1961 | */ |
| 1962 | void MainWindow::changeAssembler() |
| 1963 | { |
| 1964 | if (settingsUi.nasmRadioButton->isChecked()) |
| 1965 | settings.setValue("assembler", QString("NASM")); |
| 1966 | else if (settingsUi.gasRadioButton->isChecked()) { |
| 1967 | settings.setValue("assembler", QString("GAS")); |
| 1968 | } else if (settingsUi.fasmRadioButton->isChecked()) { |
| 1969 | settings.setValue("assembler", QString("FASM")); |
| 1970 | } else if (settingsUi.masmRadioButton->isChecked()) { |
| 1971 | settings.setValue("assembler", QString("MASM")); |
| 1972 | } |
| 1973 | recreateAssembler(); |
| 1974 | } |
| 1975 | |
| 1976 | /*! |
| 1977 | * |
| 1978 | * Assembler Dependent Options End |
| 1979 | * |
| 1980 | */ |
| 1981 | |
| 1982 | void MainWindow::changeMode(bool x86) |
| 1983 | { |
| 1984 | if (x86) |
| 1985 | settings.setValue("mode", QString("x86")); |
| 1986 | else |
| 1987 | settings.setValue("mode", QString("x64")); |
| 1988 | recreateAssembler(); |
| 1989 | } |
| 1990 | |
| 1991 | void MainWindow::recreateAssembler(bool start) |
| 1992 | { |
| 1993 | if (assembler) { |
| 1994 | delete assembler; |
| 1995 | assembler = 0; |
| 1996 | } |
| 1997 | bool x86 = true; |
| 1998 | if (settings.value("mode", QString("x86")).toString() != "x86") |
| 1999 | x86 = false; |
| 2000 | /*! |
| 2001 | * |
| 2002 | * Assembler Dependent Options Begin |
| 2003 | * |
| 2004 | */ |
| 2005 | |
| 2006 | QString assemblerName = settings.value("assembler", QString("NASM")).toString(); |
| 2007 | if (!start) { |
| 2008 | if (assemblerName == "MASM") { |
| 2009 | settingsUi.x64RadioButton->setEnabled(false); |
| 2010 | if (settingsUi.x64RadioButton->isChecked()) { |
| 2011 | settingsUi.x86RadioButton->setChecked(true); |
| 2012 | return; |
| 2013 | } |
| 2014 | } else { |
| 2015 | settingsUi.x64RadioButton->setEnabled(true); |
| 2016 | settingsUi.infoLabel->setText(""); |
| 2017 | } |
| 2018 | } |
| 2019 | if (assemblerName == "NASM") { |
| 2020 | assembler = new NASM(x86); |
| 2021 | } else if (assemblerName == "GAS") { |
| 2022 | assembler = new GAS(x86); |
| 2023 | } else if (assemblerName == "FASM") { |
| 2024 | assembler = new FASM(x86); |
| 2025 | } else if (assemblerName == "MASM") { |
| 2026 | assembler = new MASM(x86); |
| 2027 | } |
| 2028 | |
| 2029 | /*! |
| 2030 | * |
| 2031 | * Assembler Dependent Options End |
| 2032 | * |
| 2033 | */ |
| 2034 | |
| 2035 | |
| 2036 | if (!start) { |
| 2037 | settingsUi.assemblyOptionsEdit->setText(assembler->getAssemblerOptions()); |
| 2038 | settingsUi.linkingOptionsEdit->setText(assembler->getLinkerOptions()); |
| 2039 | settingsUi.objectFileNameEdit->setText("program.o"); |
| 2040 | settingsUi.disableLinkingCheckbox->setChecked(false); |
| 2041 | settingsUi.runInCurrentDirectoryCheckbox->setChecked(false); |
| 2042 | settingsUi.assemblerPathEdit->setText(assembler->getAssemblerPath()); |
| 2043 | settingsUi.linkerPathEdit->setText(assembler->getLinkerPath()); |
| 2044 | settings.setValue("assemblyoptions", assembler->getAssemblerOptions()); |
| 2045 | settings.setValue("linkingoptions", assembler->getLinkerOptions()); |
| 2046 | settings.setValue("objectfilename", "program.o"); |
| 2047 | settings.setValue("disablelinking", false); |
| 2048 | settings.setValue("currentdir", false); |
| 2049 | settings.setValue("assemblerpath", assembler->getAssemblerPath()); |
| 2050 | settings.setValue("linkerpath", assembler->getLinkerPath()); |
| 2051 | changeStartText(); |
| 2052 | recreateHighlighter(); |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | void MainWindow::changeStartText() |
| 2057 | { |
| 2058 | settingsStartTextEditor->setPlainText(assembler->getStartText()); |
| 2059 | settings.setValue("starttext", assembler->getStartText()); |
| 2060 | } |
| 2061 | |
| 2062 | void MainWindow::backupSettings() |
| 2063 | { |
| 2064 | backupAssembler = settings.value("assembler", QString("NASM")).toString(); |
| 2065 | backupMode = settings.value("mode", QString("x86")).toString(); |
| 2066 | backupAssemblerOptions = settings.value("assemblyoptions", assembler->getAssemblerOptions()).toString(); |
| 2067 | backupAssemblerPath = settings.value("assemblerpath", assembler->getAssemblerPath()).toString(); |
| 2068 | backupLinkerOptions = settings.value("linkingoptions", assembler->getLinkerOptions()).toString(); |
| 2069 | backupObjectFileName = settings.value("objectfilename", "program.o").toString(); |
| 2070 | backupDisableLinking = settings.value("disablelinking", false).toBool(); |
| 2071 | backupCurrentDir = settings.value("currentdir", false).toBool(); |
| 2072 | backupStartText = settings.value("starttext", assembler->getStartText()).toString(); |
| 2073 | backupLinkerPath = settings.value("linkerpath", assembler->getLinkerPath()).toString(); |
| 2074 | } |
| 2075 | |
| 2076 | void MainWindow::restoreSettingsAndExit() |
| 2077 | { |
| 2078 | settings.setValue("assembler", backupAssembler); |
| 2079 | settings.setValue("mode", backupMode); |
| 2080 | recreateAssembler(); |
| 2081 | settings.setValue("assemblyoptions", backupAssemblerOptions); |
| 2082 | settings.setValue("assemblerpath", backupAssemblerPath); |
| 2083 | settings.setValue("linkingoptions", backupLinkerOptions); |
| 2084 | settings.setValue("objectfilename", backupObjectFileName); |
| 2085 | settings.setValue("disablelinking", backupDisableLinking); |
| 2086 | settings.setValue("currentdir", backupCurrentDir); |
| 2087 | settings.setValue("starttext", backupStartText); |
| 2088 | settings.setValue("linkerpath", backupLinkerPath); |
| 2089 | settingsWindow->close(); |
| 2090 | } |
| 2091 | |
| 2092 | void MainWindow::recreateHighlighter() |
| 2093 | { |
| 2094 | if (highlighter) { |
| 2095 | delete highlighter; |
| 2096 | highlighter = new Highlighter(assembler); |
| 2097 | } |
| 2098 | if (tabs && tabs->count() > 0) { |
| 2099 | Tab *currentTab = (Tab *) tabs->currentWidget(); |
| 2100 | highlighter->setDocument(currentTab->getCodeDocument()); |
| 2101 | } |
| 2102 | delete settingsHighlighter; |
| 2103 | settingsHighlighter = new Highlighter(assembler); |
| 2104 | settingsHighlighter->setDocument(settingsStartTextEditor->document()); |
| 2105 | } |
| 2106 | |
| 2107 | void MainWindow::saveSettings() |
| 2108 | { |
| 2109 | settings.setValue("startwindow", settingsUi.startWindow->currentIndex()); |
| 2110 | settings.setValue("language", settingsUi.language->currentIndex()); |
| 2111 | startText = settingsStartTextEditor->toPlainText(); |
| 2112 | settings.setValue("allregisters", settingsUi.registersYesRadioButton->isChecked()); |
| 2113 | settings.setValue("insertdebugstring", settingsUi.insertDebugStringCheckBox->isChecked()); |
| 2114 | |
| 2115 | //! Change fonts |
| 2116 | settings.setValue("fontfamily", settingsUi.fontComboBox->currentFont().family()); |
| 2117 | settings.setValue("fontsize", settingsUi.fontSizeSpinBox->value()); |
| 2118 | for (int i = 0; i < tabs->count(); i++) { |
| 2119 | Tab *tab = (Tab *) tabs->widget(i); |
| 2120 | tab->setFonts(); |
| 2121 | } |
| 2122 | QFont compilerOutFont; |
| 2123 | compilerOutFont.setPointSize(settings.value("fontsize", 12).toInt()); |
| 2124 | compilerOut->setFont(compilerOutFont); |
| 2125 | |
| 2126 | settings.setValue("assemblyoptions", settingsUi.assemblyOptionsEdit->text()); |
| 2127 | settings.setValue("linkingoptions", settingsUi.linkingOptionsEdit->text()); |
| 2128 | settings.setValue("objectfilename", settingsUi.objectFileNameEdit->text()); |
| 2129 | settings.setValue("disablelinking", settingsUi.disableLinkingCheckbox->isChecked()); |
| 2130 | settings.setValue("currentdir", settingsUi.runInCurrentDirectoryCheckbox->isChecked()); |
| 2131 | settings.setValue("assemblerpath", settingsUi.assemblerPathEdit->text()); |
| 2132 | settings.setValue("linkerpath", settingsUi.linkerPathEdit->text()); |
| 2133 | settings.setValue("starttext", settingsStartTextEditor->document()->toPlainText()); |
| 2134 | |
| 2135 | backupSettings(); |
| 2136 | } |
| 2137 | |
| 2138 | void MainWindow::pickColor(QWidget *button, bool init, bool ignoreSettings) |
| 2139 | { |
| 2140 | QPushButton *colorButton = (QPushButton *) button; |
| 2141 | QString name = colorButton->objectName(); |
| 2142 | name.remove("Button"); |
| 2143 | name.replace("_2", "bg"); |
| 2144 | name = name.toLower(); |
| 2145 | QColor color = (ignoreSettings) ? colorsMap[name] : settings.value(name, colorsMap[name]).value<QColor>(); |
| 2146 | if (!init) { |
| 2147 | QColor newColor = QColorDialog::getColor(settings.value(name, colorsMap[name]).value<QColor>()); |
| 2148 | if (newColor.isValid()) { |
| 2149 | color = newColor; |
| 2150 | } |
| 2151 | } |
| 2152 | settings.setValue(name, color); |
| 2153 | if (name == "backgroundcolor") { |
| 2154 | int r, g, b; |
| 2155 | color.getRgb(&r, &g, &b); |
| 2156 | for (int i = 9; i < 18; i++) { |
| 2157 | QString buttonName = colorButtons[i]->objectName(); |
| 2158 | buttonName.remove("Button"); |
| 2159 | buttonName.replace("_2", "bg"); |
| 2160 | buttonName = buttonName.toLower(); |
| 2161 | settings.setValue(buttonName, color); |
| 2162 | colorButtons[i]->setStyleSheet(QString("background-color: rgb(%1, %2, %3)").arg(r).arg(g).arg(b)); |
| 2163 | } |
| 2164 | } |
| 2165 | recreateHighlighter(); |
| 2166 | int r, g, b; |
| 2167 | color.getRgb(&r, &g, &b); |
| 2168 | colorButton->setStyleSheet(QString("background-color: rgb(%1, %2, %3)").arg(r).arg(g).arg(b)); |
| 2169 | } |
| 2170 | |
| 2171 | void MainWindow::changeHighlightingFont(QWidget *box, bool init) |
| 2172 | { |
| 2173 | QCheckBox *checkBox = (QCheckBox *) box; |
| 2174 | QString name = checkBox->objectName(); |
| 2175 | name.remove("CheckBox"); |
| 2176 | name = name.toLower(); |
| 2177 | if (init) { |
| 2178 | bool defaultState = (name == "keywordsbold") ? true : false; |
| 2179 | checkBox->setChecked(settings.value(name, defaultState).toBool()); |
| 2180 | } else { |
| 2181 | settings.setValue(name, checkBox->isChecked()); |
| 2182 | recreateHighlighter(); |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | void MainWindow::changeHighlightingLineMode(int mode) |
| 2187 | { |
| 2188 | if (mode == Qt::Unchecked) { |
| 2189 | settings.setValue("currentlinemode", false); |
| 2190 | } else if (mode == Qt::Checked) { |
| 2191 | settings.setValue("currentlinemode", true); |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | void MainWindow::exitSettings() |
| 2196 | { |
| 2197 | saveSettings(); |
| 2198 | settingsWindow->close(); |
| 2199 | } |
| 2200 | |
| 2201 | void MainWindow::resetAllSettings() |
| 2202 | { |
| 2203 | //! Ask before execution |
| 2204 | QMessageBox msgBox; |
| 2205 | msgBox.setIcon(QMessageBox::Warning); |
| 2206 | msgBox.addButton(tr("Yes"), QMessageBox::YesRole); |
| 2207 | QPushButton *cancelButton = msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole); |
| 2208 | msgBox.setWindowTitle(tr("Warning!")); |
| 2209 | msgBox.setText(tr("All settings will be deleted and all unsaved data will be lost. Are you sure?")); |
| 2210 | msgBox.exec(); |
| 2211 | if (msgBox.clickedButton() == cancelButton) { |
| 2212 | return; |
| 2213 | } |
| 2214 | |
| 2215 | settings.remove("MainWindow/size"); |
| 2216 | settings.remove("MainWindow/pos"); |
| 2217 | |
| 2218 | int prevTabsCount = settings.value("tabscount", 0).toInt(); |
| 2219 | //! Remove previous |
| 2220 | for (int i = 0; i < prevTabsCount; i++) |
| 2221 | settings.remove(QString("Tabs/") + QString::number(i)); |
| 2222 | |
| 2223 | settings.clear(); |
| 2224 | |
| 2225 | closeFromCloseAll = true; |
| 2226 | close(); |
| 2227 | } |
| 2228 | |
| 2229 | void MainWindow::changeActionsState(int widgetIndex) |
| 2230 | { |
| 2231 | //! Get started window |
| 2232 | if (widgetIndex == 0) { |
| 2233 | closeAction->setEnabled(false); |
| 2234 | saveAction->setEnabled(false); |
| 2235 | saveAsAction->setEnabled(false); |
| 2236 | saveExeAction->setEnabled(false); |
| 2237 | findAction->setEnabled(false); |
| 2238 | commentAction->setEnabled(false); |
| 2239 | uncommentAction->setEnabled(false); |
| 2240 | undoAction->setEnabled(false); |
| 2241 | redoAction->setEnabled(false); |
| 2242 | cutAction->setEnabled(false); |
| 2243 | copyAction->setEnabled(false); |
| 2244 | pasteAction->setEnabled(false); |
| 2245 | deleteAction->setEnabled(false); |
| 2246 | selectAllAction->setEnabled(false); |
| 2247 | putTabAction->setEnabled(false); |
| 2248 | deleteTabAction->setEnabled(false); |
| 2249 | buildAction->setEnabled(false); |
| 2250 | runAction->setEnabled(false); |
| 2251 | runExeAction->setEnabled(false); |
| 2252 | stopAction->setEnabled(false); |
| 2253 | debugAction->setEnabled(false); |
| 2254 | debugNextAction->setEnabled(false); |
| 2255 | debugNextNiAction->setEnabled(false); |
| 2256 | debugShowRegistersAction->setEnabled(false); |
| 2257 | debugToggleBreakpointAction->setEnabled(false); |
| 2258 | debugShowMemoryAction->setEnabled(false); |
| 2259 | } else { |
| 2260 | closeAction->setEnabled(true); |
| 2261 | saveAction->setEnabled(true); |
| 2262 | saveAsAction->setEnabled(true); |
| 2263 | saveExeAction->setEnabled(true); |
| 2264 | findAction->setEnabled(true); |
| 2265 | pasteAction->setEnabled(true); |
| 2266 | selectAllAction->setEnabled(true); |
| 2267 | putTabAction->setEnabled(true); |
| 2268 | deleteTabAction->setEnabled(true); |
| 2269 | buildAction->setEnabled(true); |
| 2270 | runAction->setEnabled(true); |
| 2271 | runExeAction->setEnabled(true); |
| 2272 | debugAction->setEnabled(true); |
| 2273 | debugToggleBreakpointAction->setEnabled(true); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | void MainWindow::openHelp() |
| 2278 | { |
| 2279 | help = new QTextBrowser; |
| 2280 | help->setAttribute(Qt::WA_DeleteOnClose); |
| 2281 | QFile helpFile; |
| 2282 | //! language 0=Russian |
| 2283 | if (settings.value("language", 0).toInt() == 0) { |
| 2284 | helpFile.setFileName(":help/help.html"); |
| 2285 | } else { |
| 2286 | //! English and other languages |
| 2287 | helpFile.setFileName(":help/helpENG.html"); |
| 2288 | } |
| 2289 | |
| 2290 | helpFile.open(QFile::ReadOnly); |
| 2291 | QTextStream helpText(&helpFile); |
| 2292 | helpText.setCodec("utf-8"); |
| 2293 | help->setHtml(helpText.readAll()); |
| 2294 | helpFile.close(); |
| 2295 | help->setWindowState(Qt::WindowMaximized); |
| 2296 | help->setOpenExternalLinks(true); |
| 2297 | help->setWindowTitle(tr("Help")); |
| 2298 | help->setWindowIcon(QIcon(":images/mainIcon.png")); |
| 2299 | |
| 2300 | QAction *closeHelpAction = new QAction(tr("Close help"), help); |
| 2301 | closeHelpAction->setShortcut(QKeySequence(Qt::Key_Escape)); |
| 2302 | connect(closeHelpAction, SIGNAL(triggered()), help, SLOT(close())); |
| 2303 | help->addAction(closeHelpAction); |
| 2304 | |
| 2305 | help->show(); |
| 2306 | } |
| 2307 | |
| 2308 | void MainWindow::openAbout() |
| 2309 | { |
| 2310 | QMessageBox::about(this, tr("About SASM"), |
| 2311 | tr("SASM (SimpleASM) ") + SASM_VERSION + " - " + |
| 2312 | tr("simple Open Source IDE for NASM, MASM, GAS and FASM assembler languages.") + '\n' + |
| 2313 | tr("Licensed under the GNU GPL v3.0") + '\n' + |
| 2314 | tr("Based on the Qt.") + '\n' + |
| 2315 | tr("Copyright (c) 2013 Dmitriy Manushin") + '\n' + |
| 2316 | tr("Development and idea - Dmitriy Manushin") + '\n' + |
| 2317 | tr("Icon and advices - Alick Gaybullaev") + '\n' + '\n' + |
| 2318 | tr("Wishes and error messages are sent to the e-mail: [email protected]") + '\n' + |
| 2319 | tr("More information on the site: http://dman95.github.io/SASM/") + '\n' + '\n' + |
| 2320 | tr("Donate:") + '\n' + |
| 2321 | tr("PayPal - [email protected]") + '\n' + |
| 2322 | tr("WMZ - Z282016332582") + '\n' + |
| 2323 | tr("WMR - R331674303467") |
| 2324 | ); |
| 2325 | } |
| 2326 | |
| 2327 | void MainWindow::onMessageReceived(const QString &message) |
| 2328 | { |
| 2329 | raise(); |
| 2330 | activateWindow(); |
| 2331 | if (message.startsWith("run")) { |
| 2332 | openFile(message.mid(3)); |
| 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | void MainWindow::dragEnterEvent(QDragEnterEvent *event) |
| 2337 | { |
| 2338 | if (event->mimeData()->hasUrls()) |
| 2339 | { |
| 2340 | event->acceptProposedAction(); |
| 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | void MainWindow::dropEvent(QDropEvent *event) |
| 2345 | { |
| 2346 | foreach (const QUrl &url, event->mimeData()->urls()) |
| 2347 | openFile(url.toLocalFile()); |
| 2348 | } |
| 2349 | |
| 2350 | bool MainWindow::removeDirRecuresively(const QString &dirName){ |
| 2351 | bool result = true; |
| 2352 | QDir dir(dirName); |
| 2353 | |
| 2354 | if (dir.exists(dirName)) { |
| 2355 | Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | |
| 2356 | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { |
| 2357 | if (info.isDir()) { |
| 2358 | result = removeDirRecuresively(info.absoluteFilePath()); |
| 2359 | } |
| 2360 | else { |
| 2361 | result = QFile::remove(info.absoluteFilePath()); |
| 2362 | } |
| 2363 | |
| 2364 | if (!result) { |
| 2365 | return result; |
| 2366 | } |
| 2367 | } |
| 2368 | result = dir.rmdir(dirName); |
| 2369 | } |
| 2370 | return result; |
| 2371 | } |
| 2372 | |
| 2373 | MainWindow::~MainWindow() |
| 2374 | { |
| 2375 | //! Delete all temporary files |
| 2376 | removeDirRecuresively(Common::pathInTemp(QString())); |
| 2377 | } |