Gui: Add function to search custom commands

This commit is contained in:
Chris Hennes
2022-02-19 20:43:17 -06:00
parent 126c9aace0
commit 3be45f4087
2 changed files with 35 additions and 0 deletions

View File

@@ -117,5 +117,15 @@ Returns True if something was removed, or False if not.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="findCustomCommand" Static='true'>
<Documentation>
<UserDocu>Find the name of a custom command, given a macro name
findCustomCommand(name) -> Optional[str]
--
Given the name of a macro, return the name of the custom command for that macro, or
None if there is no command matching that macro script name.
</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -384,6 +384,31 @@ PyObject* CommandPy::removeCustomCommand(PyObject* args)
}
}
PyObject* CommandPy::findCustomCommand(PyObject* args)
{
const char* macroScriptName = nullptr;
if (!PyArg_ParseTuple(args, "s", &macroScriptName))
return nullptr;
CommandManager& commandManager = Application::Instance->commandManager();
std::vector<Command*> macros = commandManager.getGroupCommands("Macros");
auto action = std::find_if(macros.begin(), macros.end(), [macroScriptName](const Command* c) {
if (auto mc = dynamic_cast<const MacroCommand*>(c))
if (std::string(mc->getScriptName()) == std::string(macroScriptName))
return true;
return false;
});
if (action != macros.end()) {
return PyUnicode_FromString((*action)->getName());
}
else {
Py_INCREF(Py_None);
return Py_None;
}
}
PyObject *CommandPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;