diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index a4a8f492f..1ace00570 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -159,7 +159,7 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled) : QMainWindow (0), tl::Object (), lay::DispatcherDelegate (), - m_dispatcher (this), + m_dispatcher (this, this), m_text_progress (this, 10 /*verbosity threshold*/), m_mode (std::numeric_limits::max ()), mp_setup_form (0), @@ -179,9 +179,6 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled) mp_app (app), m_manager (undo_enabled) { - // install us as menu widget parent - m_dispatcher.set_menu_parent_widget (this); - // ensures the deferred method scheduler is present tl::DeferredMethodScheduler::instance (); diff --git a/src/laybasic/laybasic/layDispatcher.cc b/src/laybasic/laybasic/layDispatcher.cc index 92642df97..f856140e4 100644 --- a/src/laybasic/laybasic/layDispatcher.cc +++ b/src/laybasic/laybasic/layDispatcher.cc @@ -36,7 +36,6 @@ static Dispatcher *ms_dispatcher_instance = 0; Dispatcher::Dispatcher (Plugin *parent, bool standalone) : Plugin (parent, standalone), - m_menu (this), mp_menu_parent_widget (0), mp_delegate (0) { @@ -45,13 +44,38 @@ Dispatcher::Dispatcher (Plugin *parent, bool standalone) } } +Dispatcher::Dispatcher (QWidget *menu_parent_widget, Plugin *parent, bool standalone) + : Plugin (parent, standalone), + mp_menu_parent_widget (menu_parent_widget), + mp_delegate (0) +{ + if (mp_menu_parent_widget) { + mp_menu.reset (new lay::AbstractMenu (this)); + } + if (! parent && ! ms_dispatcher_instance) { + ms_dispatcher_instance = this; + } +} + Dispatcher::Dispatcher (DispatcherDelegate *delegate, Plugin *parent, bool standalone) : Plugin (parent, standalone), - m_menu (this), mp_menu_parent_widget (0), mp_delegate (delegate) { - if (! ms_dispatcher_instance) { + if (! parent && ! ms_dispatcher_instance) { + ms_dispatcher_instance = this; + } +} + +Dispatcher::Dispatcher (QWidget *menu_parent_widget, DispatcherDelegate *delegate, Plugin *parent, bool standalone) + : Plugin (parent, standalone), + mp_menu_parent_widget (menu_parent_widget), + mp_delegate (delegate) +{ + if (mp_menu_parent_widget) { + mp_menu.reset (new lay::AbstractMenu (this)); + } + if (! parent && ! ms_dispatcher_instance) { ms_dispatcher_instance = this; } } @@ -66,9 +90,11 @@ Dispatcher::~Dispatcher () bool Dispatcher::configure (const std::string &name, const std::string &value) { - std::vector ca = m_menu.configure_actions (name); - for (std::vector::const_iterator a = ca.begin (); a != ca.end (); ++a) { - (*a)->configure (value); + if (mp_menu) { + std::vector ca = mp_menu->configure_actions (name); + for (std::vector::const_iterator a = ca.begin (); a != ca.end (); ++a) { + (*a)->configure (value); + } } if (mp_delegate) { diff --git a/src/laybasic/laybasic/layDispatcher.h b/src/laybasic/laybasic/layDispatcher.h index 307787514..b192ac950 100644 --- a/src/laybasic/laybasic/layDispatcher.h +++ b/src/laybasic/laybasic/layDispatcher.h @@ -117,6 +117,15 @@ public: */ Dispatcher (Plugin *parent = 0, bool standalone = false); + /** + * @brief The constructor + * + * @param menu_parent_widget If not 0, indicates that this is a GUI mode dispatcher providing an abstract menu + * @param parent Usually 0, but a dispatcher may have parents. In this case, the dispatcher is not the actual dispatcher, but the real plugin chain's root is. + * @param standalone The standalone flag passed to the plugin constructor. + */ + Dispatcher (QWidget *menu_parent_widget, Plugin *parent = 0, bool standalone = false); + /** * @brief The root constructor * @@ -124,6 +133,14 @@ public: */ Dispatcher (DispatcherDelegate *delegate, Plugin *parent = 0, bool standalone = false); + /** + * @brief The root constructor + * + * @param menu_parent_widget If not 0, indicates that this is a GUI mode dispatcher providing an abstract menu + * @param delegate The notification receiver for dispatcher events + */ + Dispatcher (QWidget *menu_parent_widget, DispatcherDelegate *delegate, Plugin *parent = 0, bool standalone = false); + /** * @brief Destructor */ @@ -207,14 +224,6 @@ public: return mp_menu_parent_widget; } - /** - * @brief Gets the parent widget - */ - void set_menu_parent_widget (QWidget *w) - { - mp_menu_parent_widget = w; - } - /** * @brief Returns true, if the dispatcher supplies a user interface */ @@ -227,7 +236,7 @@ public: */ AbstractMenu *menu () { - return (dispatcher () == this) ? &m_menu : dispatcher ()->menu (); + return (dispatcher () == this) ? mp_menu.get () : dispatcher ()->menu (); } protected: @@ -239,7 +248,7 @@ private: Dispatcher (const Dispatcher &); Dispatcher &operator= (const Dispatcher &); - lay::AbstractMenu m_menu; + std::unique_ptr mp_menu; QWidget *mp_menu_parent_widget; DispatcherDelegate *mp_delegate; }; diff --git a/src/laybasic/laybasic/layLayoutView.cc b/src/laybasic/laybasic/layLayoutView.cc index 1c0ebef5d..f4ee5e352 100644 --- a/src/laybasic/laybasic/layLayoutView.cc +++ b/src/laybasic/laybasic/layLayoutView.cc @@ -252,7 +252,7 @@ static LayoutView *ms_current = 0; LayoutView::LayoutView (db::Manager *manager, bool editable, lay::Plugin *plugin_parent, QWidget *parent, const char *name, unsigned int options) : QFrame (parent), - lay::Dispatcher (plugin_parent, false /*not standalone*/), + lay::Dispatcher (this, plugin_parent, false /*not standalone*/), m_editable (editable), m_options (options), m_annotation_shapes (manager), @@ -261,7 +261,6 @@ LayoutView::LayoutView (db::Manager *manager, bool editable, lay::Plugin *plugin { // either it's us or the parent has a dispatcher tl_assert (dispatcher () != 0); - set_menu_parent_widget (this); // ensures the deferred method scheduler is present tl::DeferredMethodScheduler::instance ();