diff --git a/src/Gui/Application.h b/src/Gui/Application.h index d5d8e71ee0..3dec079a50 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -222,6 +222,7 @@ public: PYFUNCDEF_S(sRunCommand); PYFUNCDEF_S(sAddCommand); + PYFUNCDEF_S(sListCommands); PYFUNCDEF_S(sHide); // deprecated PYFUNCDEF_S(sShow); // deprecated diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 1e3833fd5a..be69ecdf7e 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -121,6 +121,9 @@ PyMethodDef Application::Methods[] = { {"runCommand", (PyCFunction) Application::sRunCommand, 1, "runCommand(string) -> None\n\n" "Run command with name"}, + {"listCommands", (PyCFunction) Application::sListCommands,1, + "listCommands() -> list of strings\n\n" + "Returns a list of all commands known to FreeCAD."}, {"SendMsgToActiveView", (PyCFunction) Application::sSendActiveView, 1, "deprecated -- use class View"}, {"hide", (PyCFunction) Application::sHide, 1, @@ -1014,6 +1017,21 @@ PyObject* Application::sRunCommand(PyObject * /*self*/, PyObject *args,PyObject } } +PyObject* Application::sListCommands(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) +{ + if (!PyArg_ParseTuple(args, "")) // convert args: Python->C + return NULL; // NULL triggers exception + + std::vector cmds = Application::Instance->commandManager().getAllCommands(); + PyObject* pyList = PyList_New(cmds.size()); + int i=0; + for ( std::vector::iterator it = cmds.begin(); it != cmds.end(); ++it ) { + PyObject* str = PyString_FromString((*it)->getName()); + PyList_SetItem(pyList, i++, str); + } + return pyList; +} + PyObject* Application::sDoCommand(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/) { char *sCmd=0;