Skip to content

Commit

Permalink
Macro editor: provide a 'Tabs' context menu for the tab bar which all…
Browse files Browse the repository at this point in the history
…ows selecting a tab from a list
  • Loading branch information
Matthias Koefferlein committed Sep 1, 2023
1 parent 3ddd204 commit bd7f0f3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/lay/lay/layMacroEditorDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -672,6 +683,34 @@ MacroEditorDialog::instance ()
return s_macro_editor_instance;
}

void
MacroEditorDialog::tab_menu_selected ()
{
QAction *action = dynamic_cast<QAction *> (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<MacroEditorPage *> (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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/lay/lay/layMacroEditorDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down Expand Up @@ -359,6 +361,7 @@ protected slots:
std::vector<QString> m_changed_files, m_removed_files;
tl::DeferredMethod<MacroEditorDialog> dm_refresh_file_watcher;
tl::DeferredMethod<MacroEditorDialog> dm_update_ui_to_run_mode;
QMenu *mp_tabs_menu;
};

}
Expand Down

0 comments on commit bd7f0f3

Please sign in to comment.