diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index 90a0b1f27..dd1f2725f 100644 --- a/src/lay/lay/layMacroEditorDialog.cc +++ b/src/lay/lay/layMacroEditorDialog.cc @@ -392,6 +392,15 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection connect (tabWidget, SIGNAL (tabCloseRequested (int)), this, SLOT (tab_close_requested (int))); #endif + tabWidget->setContextMenuPolicy (Qt::ActionsContextMenu); + + QAction *action = new QAction (tr ("Close All"), this); + connect (action, SIGNAL (triggered ()), this, SLOT (close_all ())); + tabWidget->addAction (action); + action = new QAction (tr ("Close All Except Current"), this); + connect (action, SIGNAL (triggered ()), this, SLOT (close_all_but_current ())); + tabWidget->addAction (action); + dbgOn->setEnabled (true); runButton->setEnabled (true); runThisButton->setEnabled (true); @@ -2228,6 +2237,75 @@ MacroEditorDialog::new_macro() return m; } +void +MacroEditorDialog::close_all () +{ + if (m_in_exec) { + return; + } + +BEGIN_PROTECTED + + tabWidget->clear (); + + for (std::map ::iterator p = m_tab_widgets.begin (); p != m_tab_widgets.end (); ++p) { + if (p->second) { + p->second->connect_macro (0); + } + delete p->second; + } + + m_tab_widgets.clear (); + + refresh_file_watcher (); + +END_PROTECTED +} + +void +MacroEditorDialog::close_all_but_current () +{ + if (m_in_exec) { + return; + } + +BEGIN_PROTECTED + + QWidget *cw = tabWidget->currentWidget (); + int ci = tabWidget->currentIndex (); + + if (ci < 0) { + close_all (); + return; + } + + for (int i = tabWidget->count (); i > 0; ) { + --i; + if (i != ci) { + tabWidget->removeTab (i); + } + } + + std::map new_widgets; + + for (std::map ::iterator p = m_tab_widgets.begin (); p != m_tab_widgets.end (); ++p) { + if (cw && p->second == cw) { + new_widgets.insert (*p); + } else { + if (p->second) { + p->second->connect_macro (0); + } + delete p->second; + } + } + + m_tab_widgets.swap (new_widgets); + + refresh_file_watcher (); + +END_PROTECTED +} + void MacroEditorDialog::tab_close_requested (int index) { @@ -3405,7 +3483,12 @@ MacroEditorDialog::editor_for_macro (lym::Macro *macro) if (macro == mp_run_macro) { tabWidget->setTabIcon (index, QIcon (QString::fromUtf8 (m_in_exec ? (m_in_breakpoint ? ":/pause.png" : ":/stop.png") : ":/run.png"))); } + + bool f = m_add_edit_trace_enabled; + m_add_edit_trace_enabled = false; tabWidget->setCurrentWidget (editor); + m_add_edit_trace_enabled = f; + m_tab_widgets.insert (std::make_pair (macro, editor)); refresh_file_watcher (); diff --git a/src/lay/lay/layMacroEditorDialog.h b/src/lay/lay/layMacroEditorDialog.h index 7e6e363e0..e3c14c68d 100644 --- a/src/lay/lay/layMacroEditorDialog.h +++ b/src/lay/lay/layMacroEditorDialog.h @@ -212,6 +212,8 @@ private slots: void search_editing (); void search_finished (); void tab_close_requested (int); + void close_all (); + void close_all_but_current (); void replace_mode_button_clicked (); void replace_next_button_clicked (); void replace_all_button_clicked ();