diff options
author | saturneric <[email protected]> | 2024-11-26 16:23:46 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-11-26 16:23:46 +0000 |
commit | f19beee8e28621bb045e45d71c963fbba1307f4b (patch) | |
tree | 20a8f52df99724f10bb20aa5273fe506f08e614e /src/ui/main_window/MainWindow.cpp | |
parent | fix: change "Advance" to "Advanced" (diff) | |
download | GpgFrontend-f19beee8e28621bb045e45d71c963fbba1307f4b.tar.gz GpgFrontend-f19beee8e28621bb045e45d71c963fbba1307f4b.zip |
refactor: optimum code and reduce duplicate
Diffstat (limited to 'src/ui/main_window/MainWindow.cpp')
-rw-r--r-- | src/ui/main_window/MainWindow.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index 597697f4..47e7487b 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -98,11 +98,11 @@ void MainWindow::Init() noexcept { UISignalStation::GetInstance(), &UISignalStation::SignalKeyDatabaseRefresh); - connect(edit_->tab_widget_, &TextEditTabWidget::currentChanged, this, - &MainWindow::slot_disable_tab_actions); + connect(edit_->TabWidget(), &TextEditTabWidget::currentChanged, this, + &MainWindow::slot_switch_menu_control_mode); connect(UISignalStation::GetInstance(), &UISignalStation::SignalRefreshStatusBar, this, - [=](const QString &message, int timeout) { + [=](const QString& message, int timeout) { statusBar()->showMessage(message, timeout); }); connect(UISignalStation::GetInstance(), @@ -131,6 +131,8 @@ void MainWindow::Init() noexcept { edit_->CurTextPage()->setFocus(); + info_board_->AssociateTabWidget(edit_->TabWidget()); + Module::ListenRTPublishEvent( this, kVersionCheckingModuleID, "version.loading_done", [=](Module::Namespace, Module::Key, int, std::any) { @@ -190,7 +192,7 @@ void MainWindow::recover_editor_unsaved_pages_from_cache() { bool first = true; auto unsaved_page_array = json_data.array(); - for (const auto &value_ref : unsaved_page_array) { + for (const auto& value_ref : unsaved_page_array) { if (!value_ref.isObject()) continue; auto unsaved_page_json = value_ref.toObject(); @@ -222,7 +224,7 @@ void MainWindow::close_attachment_dock() { attachment_dock_created_ = false; } -void MainWindow::closeEvent(QCloseEvent *event) { +void MainWindow::closeEvent(QCloseEvent* event) { /* * ask to save changes, if there are * modified documents in any tab @@ -243,4 +245,19 @@ void MainWindow::closeEvent(QCloseEvent *event) { } } +auto MainWindow::create_action( + const QString& id, const QString& name, const QString& icon, + const QString& too_tip, const QList<QKeySequence>& shortcuts) -> QAction* { + auto* action = new QAction(name, this); + action->setIcon(QIcon(icon)); + action->setToolTip(too_tip); + + if (!shortcuts.isEmpty()) { + action->setShortcuts(shortcuts); + } + + buffered_actions_.insert(id, {action}); + return action; +} + } // namespace GpgFrontend::UI |