Gui: Add function to search custom commands
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -384,6 +384,31 @@ PyObject* CommandPy::removeCustomCommand(PyObject* args)
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* CommandPy::findCustomCommand(PyObject* args)
|
||||
{
|
||||
const char* macroScriptName = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "s", ¯oScriptName))
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user