diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 3a6f5435..edf14eaa 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -181,21 +181,21 @@ void MainWindow::initUI() */ dockWidgets.reserve(14); - // Add disassembly view (dockable) - this->disassemblyDock = new DisassemblyWidget(tr("Disassembly"), this); - dockWidgets.push_back(disassemblyDock); - - sidebarDock = new SidebarWidget(tr("Sidebar"), this); - dockWidgets.push_back(sidebarDock); - - hexdumpDock = new HexdumpWidget(tr("Hexdump"), this); - dockWidgets.push_back(hexdumpDock); - - pseudocodeDock = new PseudocodeWidget(tr("Pseudocode"), this); - dockWidgets.push_back(pseudocodeDock); - - consoleDock = new ConsoleWidget(tr("Console"), this); - dockWidgets.push_back(consoleDock); +#define ADD_DOCK(cls, dockMember, action) \ +{ \ + (dockMember) = new cls(this); \ + dockWidgets.push_back(dockMember); \ + connect((action), &QAction::triggered, this, [this](bool checked) \ + { \ + toggleDockWidget((dockMember), checked); \ + }); \ + dockWidgetActions[action] = (dockMember); \ +} + ADD_DOCK(DisassemblyWidget, disassemblyDock, ui->actionDisassembly); + ADD_DOCK(SidebarWidget, sidebarDock, ui->actionSidebar); + ADD_DOCK(HexdumpWidget, hexdumpDock, ui->actionHexdump); + ADD_DOCK(PseudocodeWidget, pseudocodeDock, ui->actionPseudocode); + ADD_DOCK(ConsoleWidget, consoleDock, ui->actionConsole); // Add graph view as dockable graphDock = new QDockWidget(tr("Graph"), this); @@ -223,54 +223,25 @@ void MainWindow::initUI() } }); dockWidgets.push_back(graphDock); + connect(ui->actionGraph, &QAction::triggered, this, [this](bool checked) + { + toggleDockWidget(graphDock, checked); + }); - // Add Sections dock panel - this->sectionsDock = new SectionsDock(this); - dockWidgets.push_back(sectionsDock); - - // Add entrypoint DockWidget - this->entrypointDock = new EntrypointWidget(this); - dockWidgets.push_back(entrypointDock); - - // Add functions DockWidget - this->functionsDock = new FunctionsWidget(this); - dockWidgets.push_back(functionsDock); - - // Add imports DockWidget - this->importsDock = new ImportsWidget(this); - dockWidgets.push_back(importsDock); - - // Add exports DockWidget - this->exportsDock = new ExportsWidget(this); - dockWidgets.push_back(exportsDock); - - // Add symbols DockWidget - this->symbolsDock = new SymbolsWidget(this); - dockWidgets.push_back(symbolsDock); - - // Add relocs DockWidget - this->relocsDock = new RelocsWidget(this); - dockWidgets.push_back(relocsDock); - - // Add comments DockWidget - this->commentsDock = new CommentsWidget(this); - dockWidgets.push_back(commentsDock); - - // Add strings DockWidget - this->stringsDock = new StringsWidget(this); - dockWidgets.push_back(stringsDock); - - // Add flags DockWidget - this->flagsDock = new FlagsWidget(this); - dockWidgets.push_back(flagsDock); - - // Add Notepad Dock panel - this->notepadDock = new Notepad(this); - dockWidgets.push_back(notepadDock); - - //Add Dashboard Dock panel - this->dashboardDock = new Dashboard(this); - dockWidgets.push_back(dashboardDock); + ADD_DOCK(SectionsDock, sectionsDock, ui->actionSections); + ADD_DOCK(EntrypointWidget, entrypointDock, ui->actionEntrypoints); + ADD_DOCK(FunctionsWidget, functionsDock, ui->actionFunctions); + ADD_DOCK(ImportsWidget, importsDock, ui->actionImports); + ADD_DOCK(ExportsWidget, exportsDock, ui->actionExports); + ADD_DOCK(SymbolsWidget, symbolsDock, ui->actionSymbols); + ADD_DOCK(RelocsWidget, relocsDock, ui->actionRelocs); + ADD_DOCK(CommentsWidget, commentsDock, ui->actionComments); + ADD_DOCK(StringsWidget, stringsDock, ui->actionStrings); + ADD_DOCK(FlagsWidget, flagsDock, ui->actionFlags); + ADD_DOCK(Notepad, notepadDock, ui->actionNotepad); + ADD_DOCK(Dashboard, dashboardDock, ui->actionDashboard); + ADD_DOCK(SdbDock, sdbDock, ui->actionSDBBrowser); +#undef ADD_DOCK // Set up dock widgets default layout resetToDefaultLayout(); @@ -462,6 +433,7 @@ void MainWindow::readSettings() setPanelLock(); tabsOnTop = settings.value("tabsOnTop").toBool(); setTabLocation(); + updateDockActionsChecked(); } void MainWindow::saveSettings() @@ -580,61 +552,6 @@ void MainWindow::on_actionTabs_triggered() setTabLocation(); } -void MainWindow::on_actionEntry_points_triggered() -{ - toggleDockWidget(entrypointDock); -} - -void MainWindow::on_actionFunctions_triggered() -{ - toggleDockWidget(functionsDock); -} - -void MainWindow::on_actionImports_triggered() -{ - toggleDockWidget(importsDock); -} - -void MainWindow::on_actionExports_triggered() -{ - toggleDockWidget(exportsDock); -} - -void MainWindow::on_actionSymbols_triggered() -{ - toggleDockWidget(symbolsDock); -} - -void MainWindow::on_actionReloc_triggered() -{ - toggleDockWidget(relocsDock); -} - -void MainWindow::on_actionStrings_triggered() -{ - toggleDockWidget(stringsDock); -} - -void MainWindow::on_actionSections_triggered() -{ - toggleDockWidget(sectionsDock); -} - -void MainWindow::on_actionFlags_triggered() -{ - toggleDockWidget(flagsDock); -} - -void MainWindow::on_actionComents_triggered() -{ - toggleDockWidget(commentsDock); -} - -void MainWindow::on_actionNotepad_triggered() -{ - toggleDockWidget(notepadDock); -} - void MainWindow::on_actionAbout_triggered() { AboutDialog *a = new AboutDialog(this); @@ -646,9 +563,9 @@ void MainWindow::on_actionRefresh_Panels_triggered() this->refreshAll(); } -void MainWindow::toggleDockWidget(QDockWidget *dock_widget) +void MainWindow::toggleDockWidget(QDockWidget *dock_widget, bool show) { - if (dock_widget->isVisible()) + if (!show) { dock_widget->close(); } @@ -707,6 +624,8 @@ void MainWindow::restoreDocks() tabifyDockWidget(dashboardDock, notepadDock); dashboardDock->raise(); + + updateDockActionsChecked(); } @@ -716,6 +635,16 @@ void MainWindow::hideAllDocks() { w->hide(); } + + updateDockActionsChecked(); +} + +void MainWindow::updateDockActionsChecked() +{ + for(auto i=dockWidgetActions.constBegin(); i!=dockWidgetActions.constEnd(); i++) + { + i.key()->setChecked(!i.value()->isHidden()); + } } void MainWindow::showDefaultDocks() @@ -744,6 +673,8 @@ void MainWindow::showDefaultDocks() w->show(); } } + + updateDockActionsChecked(); } void MainWindow::resetToDefaultLayout() @@ -845,14 +776,6 @@ void MainWindow::on_actionWhite_Theme_triggered() this->setDefaultTheme(); } -void MainWindow::on_actionSDBBrowser_triggered() -{ - this->sdbDock = new SdbDock(this); - //this->tabifyDockWidget(this->previewDock, this->sdbDock); - this->sdbDock->setFloating(true); - this->sdbDock->show(); -} - void MainWindow::on_actionLoad_triggered() { QProcess process(this); @@ -860,19 +783,6 @@ void MainWindow::on_actionLoad_triggered() process.startDetached(qApp->applicationFilePath()); } -void MainWindow::on_actionDashboard_triggered() -{ - if (this->dashboardDock->isVisible()) - { - this->dashboardDock->close(); - } - else - { - this->dashboardDock->show(); - this->dashboardDock->raise(); - } -} - void MainWindow::toggleResponsive(bool maybe) { this->responsive = maybe; diff --git a/src/MainWindow.h b/src/MainWindow.h index 6d06466f..f0fa5ddc 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -93,18 +93,6 @@ public slots: void setDarkTheme(); void setDefaultTheme(); - void on_actionEntry_points_triggered(); - void on_actionFunctions_triggered(); - void on_actionImports_triggered(); - void on_actionExports_triggered(); - void on_actionSymbols_triggered(); - void on_actionReloc_triggered(); - void on_actionStrings_triggered(); - void on_actionSections_triggered(); - void on_actionFlags_triggered(); - void on_actionComents_triggered(); - void on_actionNotepad_triggered(); - void on_actionLock_triggered(); void on_actionLockUnlock_triggered(); @@ -113,8 +101,6 @@ public slots: void lockUnlock_Docks(bool what); - void on_actionDashboard_triggered(); - void on_actionDark_Theme_triggered(); void on_actionRun_Script_triggered(); @@ -124,7 +110,6 @@ public slots: void backButton_clicked(); private slots: - void on_actionAbout_triggered(); void on_actionRefresh_Panels_triggered(); @@ -145,8 +130,6 @@ private slots: void on_actionWhite_Theme_triggered(); - void on_actionSDBBrowser_triggered(); - void on_actionLoad_triggered(); void on_actionForward_triggered(); @@ -183,7 +166,6 @@ private: ut64 hexdumpTopOffset; ut64 hexdumpBottomOffset; QString filename; - QList dockWidgets; std::unique_ptr ui; Highlighter *highlighter; AsciiHighlighter *hex_highlighter; @@ -204,13 +186,17 @@ private: SectionsDock *sectionsDock; ConsoleWidget *consoleDock; - void toggleDockWidget(QDockWidget *dock_widget); + QList dockWidgets; + QMap dockWidgetActions; + + void toggleDockWidget(QDockWidget *dock_widget, bool show); void resetToDefaultLayout(); void restoreDocks(); void hideAllDocks(); void showDefaultDocks(); + void updateDockActionsChecked(); public: QString getFilename() const { return filename; } diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 4651b040..b238efd5 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -166,7 +166,7 @@ border-top: 0px; 0 0 1013 - 22 + 23 @@ -180,8 +180,8 @@ border-top: 0px; 273 133 - 173 - 206 + 140 + 239 @@ -233,20 +233,27 @@ border-top: 0px; - + + + + + + + - + - + + @@ -473,7 +480,7 @@ QToolButton:pressed { - false + true Strings @@ -484,7 +491,7 @@ QToolButton:pressed { - false + true Sections @@ -495,7 +502,7 @@ QToolButton:pressed { - false + true Functions @@ -506,7 +513,7 @@ QToolButton:pressed { - false + true Imports @@ -517,7 +524,7 @@ QToolButton:pressed { - false + true Symbols @@ -526,9 +533,9 @@ QToolButton:pressed { Show/Hide Symbols panel - + - false + true Relocs @@ -539,7 +546,7 @@ QToolButton:pressed { - false + true Flags @@ -598,9 +605,9 @@ QToolButton:pressed { Refresh - + - false + true Comments @@ -643,11 +650,6 @@ QToolButton:pressed { Bindiff - - - Graph - - Search @@ -853,11 +855,17 @@ QToolButton:pressed { + + true + Notepad + + true + SDB Browser @@ -868,6 +876,9 @@ QToolButton:pressed { + + true + Dashboard @@ -892,6 +903,9 @@ QToolButton:pressed { + + true + Exports @@ -923,7 +937,10 @@ QToolButton:pressed { Show pseudocode rather than assembly - + + + true + Entry Points @@ -954,6 +971,54 @@ QToolButton:pressed { Tmp + + + true + + + Disassembly + + + + + true + + + Graph + + + + + true + + + Pseudocode + + + + + true + + + Hexdump + + + + + true + + + Sidebar + + + + + true + + + Console + + diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index 51a70445..4aa10b8a 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -47,6 +47,8 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent) cursorLineOffset = 0; seekFromCursor = false; + setWindowTitle(tr("Disassembly")); + QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(mDisasTextEdit); layout->setMargin(0); @@ -153,12 +155,6 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent) #undef ADD_SHORTCUT } -DisassemblyWidget::DisassemblyWidget(const QString &title, QWidget *parent) : - DisassemblyWidget(parent) -{ - this->setWindowTitle(title); -} - QWidget* DisassemblyWidget::getTextWidget() { return mDisasTextEdit; diff --git a/src/widgets/DisassemblyWidget.h b/src/widgets/DisassemblyWidget.h index 767230ea..db277614 100644 --- a/src/widgets/DisassemblyWidget.h +++ b/src/widgets/DisassemblyWidget.h @@ -17,7 +17,6 @@ class DisassemblyWidget : public QDockWidget Q_OBJECT public: explicit DisassemblyWidget(QWidget *parent = nullptr); - explicit DisassemblyWidget(const QString &title, QWidget *parent = nullptr); QWidget* getTextWidget(); public slots: