diff --git a/TODO b/TODO index 13111d8c3..e76d1ab33 100644 --- a/TODO +++ b/TODO @@ -28,3 +28,11 @@ Plan: 10. Provide the layer toolbox for GSI +Tests: + - compare menu layout + - test every menu function + - adding of new tech + - adding of rulers/removing + - ruby plugin (debugging, re-running) + - changing of macro title, move macro to different place + diff --git a/src/lay/lay/gsiDeclLayMainWindow.cc b/src/lay/lay/gsiDeclLayMainWindow.cc index f783c07d2..68f86901a 100644 --- a/src/lay/lay/gsiDeclLayMainWindow.cc +++ b/src/lay/lay/gsiDeclLayMainWindow.cc @@ -182,10 +182,20 @@ gsi::Methods cm_method_decl () "Use \"call_menu('" + std::string (cm_symbols[NUM]) + "')\" instead."); } +// NOTE: this avoids an issue with binding: C++ (at least clang +// will resolve lay::MainWindow::menu to lay::Dispatcher::menu, +// the method declaration will be based on "lay::Dispatcher", and +// calling this on a MainWindow object fails, because Dispatcher +// is not the first base class. +static lay::AbstractMenu *menu (lay::MainWindow *mw) +{ + return mw->menu (); +} + Class decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "lay", "MainWindow", // QMainWindow interface - gsi::method ("menu", &lay::MainWindow::menu, + gsi::method_ext ("menu", &menu, "@brief Returns a reference to the abstract menu\n" "\n" "@return A reference to an \\AbstractMenu object representing the menu system" diff --git a/src/lay/lay/layMainConfigPages.cc b/src/lay/lay/layMainConfigPages.cc index c3d63e1b6..9a638996b 100644 --- a/src/lay/lay/layMainConfigPages.cc +++ b/src/lay/lay/layMainConfigPages.cc @@ -402,11 +402,11 @@ CustomizeMenuConfigPage::apply (const std::vectormenu (), std::string (), m_current_bindings, false); + get_shortcuts (*lay::Dispatcher::instance ()->menu (), std::string (), m_current_bindings, false); // get the default bindings std::map default_bindings; - get_shortcuts (*lay::MainWindow::instance ()->menu (), std::string (), default_bindings, true); + get_shortcuts (*lay::Dispatcher::instance ()->menu (), std::string (), default_bindings, true); m_enable_event = false; @@ -416,7 +416,7 @@ CustomizeMenuConfigPage::apply (const std::vector::iterator kb = m_current_bindings.begin (); kb != m_current_bindings.end (); ++kb) { std::map::iterator bb = b.find (kb->first); if (bb != b.end ()) { - lay::Action a = lay::MainWindow::instance ()->menu ()->action (kb->first); + lay::Action a = lay::Dispatcher::instance ()->menu ()->action (kb->first); kb->second = a.get_effective_shortcut_for (bb->second); } else { kb->second.clear (); @@ -470,7 +470,7 @@ CustomizeMenuConfigPage::apply (const std::vectorfirst == tl_menu) { QTreeWidgetItem *item = new QTreeWidgetItem (top_level_item); - lay::Action action = lay::MainWindow::instance ()->menu ()->action (cb->first); + lay::Action action = lay::Dispatcher::instance ()->menu ()->action (cb->first); item->setData (0, Qt::ToolTipRole, tl::to_qstring (rem_path)); item->setData (0, Qt::DisplayRole, tl::to_qstring (rem_path)); item->setData (1, Qt::ToolTipRole, tl::to_qstring (action.get_title ())); @@ -530,7 +530,7 @@ CustomizeMenuConfigPage::commit (lay::Dispatcher *root) for (std::vector >::iterator kb = key_bindings.begin (); kb != key_bindings.end (); ++kb) { std::map::iterator cb = m_current_bindings.find (kb->first); if (cb != m_current_bindings.end ()) { - lay::Action a = lay::MainWindow::instance ()->menu ()->action (kb->first); + lay::Action a = lay::Dispatcher::instance ()->menu ()->action (kb->first); if (cb->second != a.get_default_shortcut ()) { if (cb->second.empty ()) { kb->second = lay::Action::no_shortcut (); @@ -580,7 +580,7 @@ CustomizeMenuConfigPage::text_cleared () } std::string path = tl::to_string (item->data (0, Qt::UserRole).toString ()); - lay::Action a = lay::MainWindow::instance ()->menu ()->action (path); + lay::Action a = lay::Dispatcher::instance ()->menu ()->action (path); // "clear" reverts to default mp_ui->binding_le->setText (tl::to_qstring (a.get_default_shortcut ())); @@ -634,7 +634,7 @@ CustomizeMenuConfigPage::update_list_item (QTreeWidgetItem *item) bool is_default = false; - lay::Action a = lay::MainWindow::instance ()->menu ()->action (path); + lay::Action a = lay::Dispatcher::instance ()->menu ()->action (path); std::string def_shortcut = a.get_default_shortcut (); is_default = (def_shortcut == shortcut); @@ -643,7 +643,7 @@ CustomizeMenuConfigPage::update_list_item (QTreeWidgetItem *item) item->setData (2, Qt::ForegroundRole, palette ().color (is_default ? QPalette::Disabled : QPalette::Normal, QPalette::Text)); // Set the aliases too - const lay::AbstractMenu &menu = *lay::MainWindow::instance ()->menu (); + const lay::AbstractMenu &menu = *lay::Dispatcher::instance ()->menu (); if (menu.is_valid (path)) { QAction *qaction = menu.action (path).qaction (); std::map >::const_iterator a = m_paths_for_action.find (qaction); @@ -688,7 +688,7 @@ CustomizeMenuConfigPage::current_changed (QTreeWidgetItem *current, QTreeWidgetI if (current && !current->data (0, Qt::UserRole).isNull ()) { std::string path = tl::to_string (current->data (0, Qt::UserRole).toString ()); - if (lay::MainWindow::instance ()->menu ()->is_menu (path)) { + if (lay::Dispatcher::instance ()->menu ()->is_menu (path)) { mp_ui->binding_le->setText (QString ()); #if QT_VERSION >= 0x40700 @@ -700,7 +700,7 @@ CustomizeMenuConfigPage::current_changed (QTreeWidgetItem *current, QTreeWidgetI std::string shortcut = m_current_bindings[path]; - lay::Action a = lay::MainWindow::instance ()->menu ()->action (path); + lay::Action a = lay::Dispatcher::instance ()->menu ()->action (path); std::string def_shortcut = a.get_default_shortcut (); diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index 4da3a5cf2..90184d899 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -735,7 +735,7 @@ MainWindow::init_menu () // make the plugins create their menu items for (tl::Registrar::iterator cls = tl::Registrar::begin (); cls != tl::Registrar::end (); ++cls) { // TODO: get rid of the const_cast hack - const_cast (&*cls)->init_menu (this); + const_cast (&*cls)->init_menu (dispatcher ()); } // if in "viewer-only mode", hide all entries in the "hide_vo" group diff --git a/src/laybasic/laybasic/layDispatcher.h b/src/laybasic/laybasic/layDispatcher.h index 53ad5ab0f..7b4e7df61 100644 --- a/src/laybasic/laybasic/layDispatcher.h +++ b/src/laybasic/laybasic/layDispatcher.h @@ -116,8 +116,13 @@ public: /** * @brief Gets the AbstractMenu object + * + * This will deliver the actual menu - the one that is the root dispatcher's menu */ - AbstractMenu *menu () { return &m_menu; } + AbstractMenu *menu () + { + return (dispatcher () == this) ? &m_menu : dispatcher ()->menu (); + } /** * @brief Creates a configuration action with the given title, parameter name and value diff --git a/src/laybasic/laybasic/layLayoutView.cc b/src/laybasic/laybasic/layLayoutView.cc index 45525bef6..d1094f6cb 100644 --- a/src/laybasic/laybasic/layLayoutView.cc +++ b/src/laybasic/laybasic/layLayoutView.cc @@ -272,7 +272,7 @@ LayoutView::LayoutView (db::Manager *manager, bool editable, lay::Plugin *plugin tl::DeferredMethodScheduler::instance (); setObjectName (QString::fromUtf8 (name)); - init (manager, dispatcher (), parent); + init (manager, parent); } LayoutView::LayoutView (lay::LayoutView *source, db::Manager *manager, bool editable, lay::Plugin *plugin_parent, QWidget *parent, const char *name, unsigned int options) @@ -293,7 +293,7 @@ LayoutView::LayoutView (lay::LayoutView *source, db::Manager *manager, bool edit m_annotation_shapes = source->m_annotation_shapes; - init (manager, dispatcher (), parent); + init (manager, parent); // set the handle reference and clear all cell related stuff m_cellviews = source->cellview_list (); @@ -355,12 +355,12 @@ LayoutView::eventFilter(QObject *obj, QEvent *event) } void -LayoutView::init (db::Manager *mgr, lay::Dispatcher *dispatcher, QWidget * /*parent*/) +LayoutView::init (db::Manager *mgr, QWidget * /*parent*/) { manager (mgr); - if (! dispatcher) { - // build the context menus, nothing else so far. + if (dispatcher () == this) { + // if we're the root dispatcher build the context menus, nothing else so far. menu ()->build (0, 0); } @@ -6473,13 +6473,6 @@ LayoutView::intrinsic_mouse_modes (std::vector *descriptions) return 2; } -AbstractMenu * -LayoutView::menu () -{ - // NOTE: dispatcher is either this or the real end of the chain - return dispatcher ()->menu (); -} - int LayoutView::default_mode () { diff --git a/src/laybasic/laybasic/layLayoutView.h b/src/laybasic/laybasic/layLayoutView.h index c8e03cc56..c25cae0af 100644 --- a/src/laybasic/laybasic/layLayoutView.h +++ b/src/laybasic/laybasic/layLayoutView.h @@ -220,12 +220,6 @@ public: */ static LayoutView *current (); - /** - * @brief Gets the abstract menu object for this view - * This is either the global menu object or the local one. - */ - AbstractMenu *menu (); - /** * @brief Determine if there is something to copy * @@ -2892,7 +2886,7 @@ private: bool m_active_cellview_changed_event_enabled; tl::DeferredMethod dm_prop_changed; - void init (db::Manager *mgr, lay::Dispatcher *dispatcher, QWidget *parent); + void init (db::Manager *mgr, QWidget *parent); void do_prop_changed (); void do_redraw (int layer);