Skip to content

Commit

Permalink
[Gui::CommandPy] add new command resetShortcut() -- resets shortcut t…
Browse files Browse the repository at this point in the history
…o default
  • Loading branch information
mwganson authored and wwmayer committed Aug 6, 2020
1 parent 361f56d commit ee383b7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Gui/CommandPy.xml
Expand Up @@ -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>
Expand Down
32 changes: 32 additions & 0 deletions src/Gui/CommandPyImp.cpp
Expand Up @@ -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, ""))
Expand Down

0 comments on commit ee383b7

Please sign in to comment.