[Gui::CommandPy] add new command resetShortcut() -- resets shortcut to default
This commit is contained in:
@@ -75,6 +75,14 @@ Returns string representing shortcut key accelerator for command.
|
||||
<UserDocu>setShortcut(string) -> bool
|
||||
|
||||
Sets shortcut for given command, returns bool True for success.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="resetShortcut">
|
||||
<Documentation>
|
||||
<UserDocu>resetShortcut() -> bool
|
||||
|
||||
Resets shortcut for given command back to the default, returns bool True for success.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
|
||||
@@ -232,6 +232,38 @@ PyObject* CommandPy::setShortcut(PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* CommandPy::resetShortcut(PyObject *args)
|
||||
{
|
||||
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
Command* cmd = this->getCommandPtr();
|
||||
if (cmd) {
|
||||
Action* action = cmd->getAction();
|
||||
if (action){
|
||||
QString default_shortcut = QString::fromLatin1(cmd->getAccel());
|
||||
action->setShortcut(default_shortcut);
|
||||
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Shortcut");
|
||||
hGrp->RemoveASCII(cmd->getName());
|
||||
/** test to see if we successfully reset the shortcut by loading it back and comparing */
|
||||
QString spc = QString::fromLatin1(" ");
|
||||
QString new_shortcut = action->shortcut().toString();
|
||||
if (default_shortcut.remove(spc).toUpper() == new_shortcut.remove(spc).toUpper()){
|
||||
return Py::new_reference_to(Py::Boolean(true));
|
||||
} else {
|
||||
return Py::new_reference_to(Py::Boolean(false));
|
||||
}
|
||||
} else {
|
||||
return Py::new_reference_to(Py::Boolean(false));
|
||||
}
|
||||
|
||||
} else {
|
||||
PyErr_Format(Base::BaseExceptionFreeCADError, "No such command");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* CommandPy::getInfo(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
|
||||
Reference in New Issue
Block a user