RBA::Macro#name and RBA::Action#menu

This commit is contained in:
Matthias Koefferlein 2017-10-29 09:58:30 +01:00
parent 9b7a887ad8
commit 998ea6df10
3 changed files with 41 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "layApplication.h"
#include "lymMacroInterpreter.h"
#include "lymMacro.h"
#include "gsiDecl.h"
#include <QDir>
#include <QUrl>
@ -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<QAction *, lym::Macro *>::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<lay::PluginDeclaration> 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<lay::Action> decl_ext_action (
gsi::method_ext ("macro", &macro_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"
)
);
}

View File

@ -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
*/

View File

@ -427,6 +427,11 @@ Class<lym::Macro> 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"