From bd7f0f395593462191c8fcc66d5f7e0e5dc4e1be Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 2 Sep 2023 01:15:15 +0200 Subject: [PATCH] Macro editor: provide a 'Tabs' context menu for the tab bar which allows selecting a tab from a list --- src/lay/lay/layMacroEditorDialog.cc | 39 +++++++++++++++++++++++++++++ src/lay/lay/layMacroEditorDialog.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index 6129038ee..d3e7c6259 100644 --- a/src/lay/lay/layMacroEditorDialog.cc +++ b/src/lay/lay/layMacroEditorDialog.cc @@ -429,6 +429,17 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection connect (action, SIGNAL (triggered ()), this, SLOT (close_all_right ())); tabWidget->addAction (action); + action = new QAction (); + action->setSeparator (true); + tabWidget->addAction (action); + + mp_tabs_menu = new QMenu (); + + action = new QAction (tr ("Tabs")); + action->setMenu (mp_tabs_menu); + connect (mp_tabs_menu, SIGNAL (aboutToShow ()), this, SLOT (tabs_menu_about_to_show ())); + tabWidget->addAction (action); + dbgOn->setEnabled (true); runButton->setEnabled (true); runThisButton->setEnabled (true); @@ -672,6 +683,34 @@ MacroEditorDialog::instance () return s_macro_editor_instance; } +void +MacroEditorDialog::tab_menu_selected () +{ + QAction *action = dynamic_cast (sender ()); + if (action) { + tabWidget->setCurrentIndex (action->data ().toInt ()); + } +} + +void +MacroEditorDialog::tabs_menu_about_to_show () +{ + mp_tabs_menu->clear (); + + for (int i = 0; i < tabWidget->count (); ++i) { + MacroEditorPage *page = dynamic_cast (tabWidget->widget (i)); + if (page) { + QAction *action = new QAction (tl::to_qstring (page->path ())); + action->setData (i); + connect (action, SIGNAL (triggered ()), this, SLOT (tab_menu_selected ())); + if (page->macro () == mp_run_macro) { + action->setIcon (QIcon (":/run_16px.png")); + } + mp_tabs_menu->addAction (action); + } + } +} + void MacroEditorDialog::select_category (const std::string &cat) { diff --git a/src/lay/lay/layMacroEditorDialog.h b/src/lay/lay/layMacroEditorDialog.h index 71c78ca02..c17f9e291 100644 --- a/src/lay/lay/layMacroEditorDialog.h +++ b/src/lay/lay/layMacroEditorDialog.h @@ -233,6 +233,8 @@ private slots: void del_watches (); void clear_watches (); void set_debugging_on (bool on); + void tabs_menu_about_to_show (); + void tab_menu_selected (); // edit trace navigation void forward (); @@ -359,6 +361,7 @@ private: std::vector m_changed_files, m_removed_files; tl::DeferredMethod dm_refresh_file_watcher; tl::DeferredMethod dm_update_ui_to_run_mode; + QMenu *mp_tabs_menu; }; }