From 998ea6df10a4bbfe35d0a034915863882c40ca38 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 29 Oct 2017 09:58:30 +0100 Subject: [PATCH] RBA::Macro#name and RBA::Action#menu --- src/lay/lay/layMacroController.cc | 30 ++++++++++++++++++++++++++++++ src/lay/lay/layMacroController.h | 6 ++++++ src/lym/lym/gsiDeclLymMacro.cc | 5 +++++ 3 files changed, 41 insertions(+) diff --git a/src/lay/lay/layMacroController.cc b/src/lay/lay/layMacroController.cc index 3ea71c08a..7f56d0188 100644 --- a/src/lay/lay/layMacroController.cc +++ b/src/lay/lay/layMacroController.cc @@ -30,6 +30,7 @@ #include "layApplication.h" #include "lymMacroInterpreter.h" #include "lymMacro.h" +#include "gsiDecl.h" #include #include @@ -680,6 +681,18 @@ MacroController::add_macro_items_to_menu (lym::MacroCollection &collection, int } } +lym::Macro * +MacroController::macro_for_action (const lay::Action *action) +{ + if (action) { + std::map::const_iterator a2m = m_action_to_macro.find (action->qaction ()); + if (a2m != m_action_to_macro.end ()) { + return a2m->second; + } + } + return 0; +} + void MacroController::sync_with_external_sources () { @@ -797,5 +810,22 @@ MacroController::instance () // The singleton instance of the macro controller static tl::RegisteredClass macro_controller_decl (new lay::MacroController (), 120, "MacroController"); +static lym::Macro *macro_for_action (const lay::Action *action) +{ + return MacroController::instance () ? MacroController::instance ()->macro_for_action (action) : 0; +} + +// extend lay::Action with the ability to associate a macro with it +static +gsi::ClassExt decl_ext_action ( + gsi::method_ext ("macro", ¯o_for_action, + "@brief Gets the macro associated with the action\n" + "If the action is associated with a macro, this method returns a reference to the \\Macro object. " + "Otherwise, this method returns nil.\n" + "\n" + "\nThis method has been added in version 0.25.\n" + ) +); + } diff --git a/src/lay/lay/layMacroController.h b/src/lay/lay/layMacroController.h index 1ceff83cd..aa8668715 100644 --- a/src/lay/lay/layMacroController.h +++ b/src/lay/lay/layMacroController.h @@ -43,6 +43,7 @@ namespace lay class MacroEditorDialog; class MainWindow; class Technology; +class Action; /** * @brief A controller for the macro environment @@ -159,6 +160,11 @@ public: */ void add_temp_macro (lym::Macro *m); + /** + * @brief Gets the macro associated with an Action or nil if there is none + */ + lym::Macro *macro_for_action (const lay::Action *action); + /** * @brief Obtain the list of macro categories */ diff --git a/src/lym/lym/gsiDeclLymMacro.cc b/src/lym/lym/gsiDeclLymMacro.cc index 2ea6b43e3..1f0ccf31d 100644 --- a/src/lym/lym/gsiDeclLymMacro.cc +++ b/src/lym/lym/gsiDeclLymMacro.cc @@ -427,6 +427,11 @@ Class decl_Macro ("Macro", "The path is the path where the macro is stored, starting with an abstract group identifier. " "The path is used to identify the macro in the debugger for example." ) + + gsi::method ("name", &lym::Macro::name, + "@brief Gets the name of the macro\n" + "\n" + "This attribute has been added in version 0.25." + ) + gsi::method ("description", &lym::Macro::description, "@brief Gets the description text\n" "\n"