diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 830ee3a236..9b9c7c2d93 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -852,34 +852,24 @@ const char * Command::endCmdHelp(void) return "\n\n"; } -void Command::applyCommandData(const char* context, Action* action) +void Command::recreateTooltip(const char* context, Action* action) { - action->setText(QCoreApplication::translate( + QString tooltip; + tooltip.append(QString::fromLatin1("

")); + tooltip.append(QCoreApplication::translate( context, getMenuText())); - // build the tooltip - QString tooltip; - tooltip.append(QString::fromLatin1("

")); - tooltip.append(QCoreApplication::translate( - context, getMenuText())); - tooltip.append(QString::fromLatin1("

")); - QRegularExpression re(QString::fromLatin1("([^&])&([^&])")); - tooltip.replace(re, QString::fromLatin1("\\1\\2")); - tooltip.replace(QString::fromLatin1("&&"), QString::fromLatin1("&")); - tooltip.append(QCoreApplication::translate( - context, getToolTipText())); - tooltip.append(QString::fromLatin1("
(")); - tooltip.append(QCoreApplication::translate( - context, getWhatsThis())); - tooltip.append(QString::fromLatin1(") ")); - action->setToolTip(tooltip); - action->setWhatsThis(QCoreApplication::translate( + tooltip.append(QString::fromLatin1("")); + QRegularExpression re(QString::fromLatin1("([^&])&([^&])")); + tooltip.replace(re, QString::fromLatin1("\\1\\2")); + tooltip.replace(QString::fromLatin1("&&"), QString::fromLatin1("&")); + tooltip.append(QCoreApplication::translate( + context, getToolTipText())); + tooltip.append(QString::fromLatin1("
(")); + tooltip.append(QCoreApplication::translate( context, getWhatsThis())); - if (sStatusTip) - action->setStatusTip(QCoreApplication::translate( - context, getStatusTip())); - else - action->setStatusTip(QCoreApplication::translate( - context, getToolTipText())); + tooltip.append(QString::fromLatin1(") ")); + action->setToolTip(tooltip); + QString accel = action->shortcut().toString(QKeySequence::NativeText); if (!accel.isEmpty()) { // show shortcut inside tooltip @@ -892,6 +882,22 @@ void Command::applyCommandData(const char* context, Action* action) .arg(accel, action->statusTip()); action->setStatusTip(stip); } + + if (sStatusTip) + action->setStatusTip(QCoreApplication::translate( + context, getStatusTip())); + else + action->setStatusTip(QCoreApplication::translate( + context, getToolTipText())); +} + +void Command::applyCommandData(const char* context, Action* action) +{ + action->setText(QCoreApplication::translate( + context, getMenuText())); + recreateTooltip(context, action); + action->setWhatsThis(QCoreApplication::translate( + context, getWhatsThis())); } const char* Command::keySequenceToAccel(int sk) const diff --git a/src/Gui/Command.h b/src/Gui/Command.h index c3f7a2c982..8bf8e84171 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -343,6 +343,8 @@ public: void testActive(void); /// Enables or disables the command void setEnabled(bool); + /// (Re)Create the text for the tooltip (for example, when the shortcut is changed) + void recreateTooltip(const char* context, Action*); /// Command trigger source enum TriggerSource { /// No external trigger, e.g. invoked through Python diff --git a/src/Gui/DlgKeyboardImp.cpp b/src/Gui/DlgKeyboardImp.cpp index e6c9403c06..44e1c47af9 100644 --- a/src/Gui/DlgKeyboardImp.cpp +++ b/src/Gui/DlgKeyboardImp.cpp @@ -234,35 +234,8 @@ void DlgCustomKeyboardImp::setShortcutOfCurrentAction(const QString& accelText) ui->editShortcut->clear(); } - // update the tool tip - QString toolTip = QCoreApplication::translate(cmd->className(), - cmd->getToolTipText()); - if (!nativeText.isEmpty()) { - if (!toolTip.isEmpty()) { - QString tip = QString::fromLatin1("%1 (%2)") - .arg(toolTip, nativeText); - action->setToolTip(tip); - } - } - else { - action->setToolTip(toolTip); - } - - // update the status tip - QString statusTip = QCoreApplication::translate(cmd->className(), - cmd->getStatusTip()); - if (statusTip.isEmpty()) - statusTip = toolTip; - if (!nativeText.isEmpty()) { - if (!statusTip.isEmpty()) { - QString tip = QString::fromLatin1("(%1)\t%2") - .arg(nativeText, statusTip); - action->setStatusTip(tip); - } - } - else { - action->setStatusTip(statusTip); - } + // update the tool tip (and status tip) + cmd->recreateTooltip(cmd->className(), action); // The shortcuts for macros are store in a different location, // also override the command's shortcut directly @@ -313,6 +286,9 @@ void DlgCustomKeyboardImp::on_buttonReset_clicked() ui->accelLineEditShortcut->setText((txt.isEmpty() ? tr("none") : txt)); ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Shortcut"); hGrp->RemoveASCII(name.constData()); + + // update the tool tip (and status tip) + cmd->recreateTooltip(cmd->className(), cmd->getAction()); } ui->buttonReset->setEnabled( false ); @@ -327,6 +303,10 @@ void DlgCustomKeyboardImp::on_buttonResetAll_clicked() if ((*it)->getAction()) { (*it)->getAction()->setShortcut(QKeySequence(QString::fromLatin1((*it)->getAccel())) .toString(QKeySequence::NativeText)); + + + // update the tool tip (and status tip) + (*it)->recreateTooltip((*it)->className(), (*it)->getAction()); } } diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index 715d2623c8..877f18d7df 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -325,6 +325,7 @@ void Workbench::setupCustomShortcuts() const QString str = QString::fromUtf8(it->second.c_str()); QKeySequence shortcut = str; cmd->getAction()->setShortcut(shortcut.toString(QKeySequence::NativeText)); + cmd->recreateTooltip(it->first.c_str(), cmd->getAction()); // The tooltip has the shortcut in it... } } }