diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index 4fa07ac8d..0d75c4a7e 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -772,14 +772,8 @@ UndoAction::~UndoAction() void UndoAction::addTo (QWidget * w) { if (w->inherits("QToolBar")) { - // Do NOT set the shortcut again for _toolAction since this is already - // reserved for _action. Otherwise we get an ambiguity of it with the - // result that it doesn't work anymore. - _toolAction->setText(_action->text()); - _toolAction->setToolTip(_action->toolTip()); - _toolAction->setStatusTip(_action->statusTip()); - _toolAction->setWhatsThis(_action->whatsThis()); - _toolAction->setIcon(_action->icon()); + actionChanged(); + connect(_action, SIGNAL(changed()), this, SLOT(actionChanged())); w->addAction(_toolAction); } else { @@ -787,6 +781,18 @@ void UndoAction::addTo (QWidget * w) } } +void UndoAction::actionChanged() +{ + // Do NOT set the shortcut again for _toolAction since this is already + // reserved for _action. Otherwise we get an ambiguity of it with the + // result that it doesn't work anymore. + _toolAction->setText(_action->text()); + _toolAction->setToolTip(_action->toolTip()); + _toolAction->setStatusTip(_action->statusTip()); + _toolAction->setWhatsThis(_action->whatsThis()); + _toolAction->setIcon(_action->icon()); +} + void UndoAction::setEnabled(bool b) { Action::setEnabled(b); @@ -819,14 +825,8 @@ RedoAction::~RedoAction() void RedoAction::addTo ( QWidget * w ) { if (w->inherits("QToolBar")) { - // Do NOT set the shortcut again for _toolAction since this is already - // reserved for _action. Otherwise we get an ambiguity of it with the - // result that it doesn't work anymore. - _toolAction->setText(_action->text()); - _toolAction->setToolTip(_action->toolTip()); - _toolAction->setStatusTip(_action->statusTip()); - _toolAction->setWhatsThis(_action->whatsThis()); - _toolAction->setIcon(_action->icon()); + actionChanged(); + connect(_action, SIGNAL(changed()), this, SLOT(actionChanged())); w->addAction(_toolAction); } else { @@ -834,6 +834,18 @@ void RedoAction::addTo ( QWidget * w ) } } +void RedoAction::actionChanged() +{ + // Do NOT set the shortcut again for _toolAction since this is already + // reserved for _action. Otherwise we get an ambiguity of it with the + // result that it doesn't work anymore. + _toolAction->setText(_action->text()); + _toolAction->setToolTip(_action->toolTip()); + _toolAction->setStatusTip(_action->statusTip()); + _toolAction->setWhatsThis(_action->whatsThis()); + _toolAction->setIcon(_action->icon()); +} + void RedoAction::setEnabled ( bool b ) { Action::setEnabled(b); diff --git a/src/Gui/Action.h b/src/Gui/Action.h index 99c47c78f..aa4208275 100644 --- a/src/Gui/Action.h +++ b/src/Gui/Action.h @@ -219,6 +219,9 @@ public: void setEnabled(bool); void setVisible(bool); +private Q_SLOTS: + void actionChanged(); + private: QAction* _toolAction; }; @@ -241,6 +244,9 @@ public: void setEnabled(bool); void setVisible(bool); +private Q_SLOTS: + void actionChanged(); + private: QAction* _toolAction; }; diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 0b6bf8df2..d28a639ee 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -557,35 +557,41 @@ const char * Command::endCmdHelp(void) return "\n\n"; } -void Command::applyCommandData(Action* action) +void Command::applyCommandData(const char* context, Action* action) { action->setText(QCoreApplication::translate( - this->className(), sMenuText, 0, + context, getMenuText(), 0, QCoreApplication::UnicodeUTF8)); action->setToolTip(QCoreApplication::translate( - this->className(), sToolTipText, 0, + context, getToolTipText(), 0, QCoreApplication::UnicodeUTF8)); if (sStatusTip) action->setStatusTip(QCoreApplication::translate( - this->className(), sStatusTip, 0, + context, getStatusTip(), 0, QCoreApplication::UnicodeUTF8)); else action->setStatusTip(QCoreApplication::translate( - this->className(), sToolTipText, 0, + context, getToolTipText(), 0, QCoreApplication::UnicodeUTF8)); if (sWhatsThis) action->setWhatsThis(QCoreApplication::translate( - this->className(), sWhatsThis, 0, + context, getWhatsThis(), 0, QCoreApplication::UnicodeUTF8)); else action->setWhatsThis(QCoreApplication::translate( - this->className(), sToolTipText, 0, + context, getToolTipText(), 0, QCoreApplication::UnicodeUTF8)); - QString accel = action->shortcut().toString(); + QString accel = action->shortcut().toString(QKeySequence::NativeText); if (!accel.isEmpty()) { - QString tip = QString::fromAscii("(%1)\t%2") + // show shortcut inside tooltip + QString ttip = QString::fromLatin1("%1 (%2)") + .arg(action->toolTip()).arg(accel); + action->setToolTip(ttip); + + // show shortcut inside status tip + QString stip = QString::fromLatin1("(%1)\t%2") .arg(accel).arg(action->statusTip()); - action->setStatusTip(tip); + action->setStatusTip(stip); } } @@ -647,10 +653,10 @@ Action * Command::createAction(void) Action *pcAction; pcAction = new Action(this,getMainWindow()); - applyCommandData(pcAction); + pcAction->setShortcut(QString::fromAscii(sAccel)); + applyCommandData(this->className(), pcAction); if (sPixmap) pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); - pcAction->setShortcut(QString::fromAscii(sAccel)); return pcAction; } @@ -658,7 +664,7 @@ Action * Command::createAction(void) void Command::languageChange() { if (_pcAction) { - applyCommandData(_pcAction); + applyCommandData(this->className(), _pcAction); } } @@ -700,10 +706,26 @@ Action * MacroCommand::createAction(void) pcAction->setText(QString::fromUtf8(sMenuText)); pcAction->setToolTip(QString::fromUtf8(sToolTipText)); pcAction->setStatusTip(QString::fromUtf8(sStatusTip)); + if (pcAction->statusTip().isEmpty()) + pcAction->setStatusTip(pcAction->toolTip()); pcAction->setWhatsThis(QString::fromUtf8(sWhatsThis)); - if ( sPixmap ) + if (sPixmap) pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); - pcAction->setShortcut(QString::fromAscii(sAccel)); + pcAction->setShortcut(QString::fromAscii(sAccel)); + + QString accel = pcAction->shortcut().toString(QKeySequence::NativeText); + if (!accel.isEmpty()) { + // show shortcut inside tooltip + QString ttip = QString::fromLatin1("%1 (%2)") + .arg(pcAction->toolTip()).arg(accel); + pcAction->setToolTip(ttip); + + // show shortcut inside status tip + QString stip = QString::fromLatin1("(%1)\t%2") + .arg(accel).arg(pcAction->statusTip()); + pcAction->setStatusTip(stip); + } + return pcAction; } @@ -854,12 +876,7 @@ bool PythonCommand::isActive(void) void PythonCommand::languageChange() { if (_pcAction) { - _pcAction->setText (qApp->translate(getName(), getMenuText ())); - _pcAction->setToolTip (qApp->translate(getName(), getToolTipText())); - _pcAction->setStatusTip (qApp->translate(getName(), getStatusTip ())); - _pcAction->setWhatsThis (qApp->translate(getName(), getWhatsThis ())); - if (_pcAction->statusTip().isEmpty()) - _pcAction->setStatusTip(qApp->translate(getName(), getToolTipText())); + applyCommandData(getName(), _pcAction); } } @@ -879,16 +896,10 @@ Action * PythonCommand::createAction(void) Action *pcAction; pcAction = new Action(this,getMainWindow()); - - pcAction->setText (qApp->translate(getName(), getMenuText ())); - pcAction->setToolTip (qApp->translate(getName(), getToolTipText())); - pcAction->setStatusTip (qApp->translate(getName(), getStatusTip ())); - pcAction->setWhatsThis (qApp->translate(getName(), getWhatsThis ())); - if (pcAction->statusTip().isEmpty()) - pcAction->setStatusTip(qApp->translate(getName(), getToolTipText())); + pcAction->setShortcut(QString::fromAscii(getAccel())); + applyCommandData(this->getName(), pcAction); if (strcmp(getResource("Pixmap"),"") != 0) pcAction->setIcon(Gui::BitmapFactory().pixmap(getResource("Pixmap"))); - pcAction->setShortcut (QString::fromAscii(getAccel())); return pcAction; } diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 1aea9972c..5a436ea32 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -160,7 +160,7 @@ protected: /// Creates the used Action virtual Action * createAction(void); /// Applies the menu text, tool and status tip to the passed action object - void applyCommandData(Action* ); + void applyCommandData(const char* context, Action* ); const char* keySequenceToAccel(int) const; void adjustCameraPosition(); //@} diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 87e16a578..f707b65b4 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -724,10 +724,10 @@ Action * StdCmdUndo::createAction(void) Action *pcAction; pcAction = new UndoAction(this,getMainWindow()); - applyCommandData(pcAction); + pcAction->setShortcut(QString::fromAscii(sAccel)); + applyCommandData(this->className(), pcAction); if (sPixmap) pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); - pcAction->setShortcut(QString::fromAscii(sAccel)); return pcAction; } @@ -767,10 +767,10 @@ Action * StdCmdRedo::createAction(void) Action *pcAction; pcAction = new RedoAction(this,getMainWindow()); - applyCommandData(pcAction); + pcAction->setShortcut(QString::fromAscii(sAccel)); + applyCommandData(this->className(), pcAction); if (sPixmap) pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); - pcAction->setShortcut(QString::fromAscii(sAccel)); return pcAction; } diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index fd135f7f8..1d6bd6467 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -125,10 +125,10 @@ Action * StdCmdWorkbench::createAction(void) Action *pcAction; pcAction = new WorkbenchGroup(this,getMainWindow()); - applyCommandData(pcAction); + pcAction->setShortcut(QString::fromAscii(sAccel)); + applyCommandData(this->className(), pcAction); if (sPixmap) pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); - pcAction->setShortcut(QString::fromAscii(sAccel)); return pcAction; } @@ -169,7 +169,7 @@ Action * StdCmdRecentFiles::createAction(void) RecentFilesAction* pcAction = new RecentFilesAction(this, getMainWindow()); pcAction->setObjectName(QLatin1String("recentFiles")); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); return pcAction; } diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 913296ada..8afd1aa77 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -224,7 +224,7 @@ Action * StdCmdFreezeViews::createAction(void) { ActionGroup* pcAction = new ActionGroup(this, getMainWindow()); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); // add the action items saveView = pcAction->addAction(QObject::tr("Save views...")); @@ -559,7 +559,7 @@ Gui::Action * StdCmdDrawStyle::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); QAction* a0 = pcAction->addAction(QString()); a0->setCheckable(true); diff --git a/src/Gui/CommandWindow.cpp b/src/Gui/CommandWindow.cpp index 3142ef2c4..68472a987 100644 --- a/src/Gui/CommandWindow.cpp +++ b/src/Gui/CommandWindow.cpp @@ -316,7 +316,7 @@ Action * StdCmdDockViewMenu::createAction(void) { Action *pcAction; pcAction = new DockWidgetAction(this, getMainWindow()); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); return pcAction; } @@ -351,7 +351,7 @@ Action * StdCmdToolBarMenu::createAction(void) { Action *pcAction; pcAction = new ToolBarAction(this, getMainWindow()); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); return pcAction; } diff --git a/src/Gui/DlgActionsImp.cpp b/src/Gui/DlgActionsImp.cpp index 664277bcb..1783e10d8 100644 --- a/src/Gui/DlgActionsImp.cpp +++ b/src/Gui/DlgActionsImp.cpp @@ -28,6 +28,7 @@ # include # include # include +# include # include # include #endif @@ -261,7 +262,7 @@ void DlgCustomActionsImp::on_buttonAddAction_clicked() m_sPixmap = QString::null; if (!actionAccel->text().isEmpty()) { - macro->setAccel(actionAccel->text().toAscii()); + macro->setAccel(actionAccel->text().toAscii()); } actionAccel->clear(); @@ -329,9 +330,22 @@ void DlgCustomActionsImp::on_buttonReplaceAction_clicked() action->setToolTip(QString::fromUtf8(macro->getToolTipText())); action->setWhatsThis(QString::fromUtf8(macro->getWhatsThis())); action->setStatusTip(QString::fromUtf8(macro->getStatusTip())); - if( macro->getPixmap() ) + if (macro->getPixmap()) action->setIcon(Gui::BitmapFactory().pixmap(macro->getPixmap())); action->setShortcut(QString::fromAscii(macro->getAccel())); + + QString accel = action->shortcut().toString(QKeySequence::NativeText); + if (!accel.isEmpty()) { + // show shortcut inside tooltip + QString ttip = QString::fromLatin1("%1 (%2)") + .arg(action->toolTip()).arg(accel); + action->setToolTip(ttip); + + // show shortcut inside status tip + QString stip = QString::fromLatin1("(%1)\t%2") + .arg(accel).arg(action->statusTip()); + action->setStatusTip(stip); + } } // emit signal to notify the container widget diff --git a/src/Gui/DlgKeyboardImp.cpp b/src/Gui/DlgKeyboardImp.cpp index e36d3bdf9..c181f1263 100644 --- a/src/Gui/DlgKeyboardImp.cpp +++ b/src/Gui/DlgKeyboardImp.cpp @@ -198,11 +198,43 @@ void DlgCustomKeyboardImp::on_buttonAssign_clicked() CommandManager & cCmdMgr = Application::Instance->commandManager(); Command* cmd = cCmdMgr.getCommandByName(name.constData()); if (cmd && cmd->getAction()) { + Action* action = cmd->getAction(); QKeySequence shortcut = editShortcut->text(); - cmd->getAction()->setShortcut(shortcut); + action->setShortcut(shortcut); accelLineEditShortcut->setText(editShortcut->text()); editShortcut->clear(); + // update the tool tip + QString accel = shortcut.toString(QKeySequence::NativeText); + QString toolTip = QCoreApplication::translate(cmd->className(), + cmd->getToolTipText(), 0, QCoreApplication::UnicodeUTF8); + if (!accel.isEmpty()) { + if (!toolTip.isEmpty()) { + QString tip = QString::fromLatin1("%1 (%2)") + .arg(toolTip).arg(accel); + action->setToolTip(tip); + } + } + else { + action->setToolTip(toolTip); + } + + // update the status tip + QString statusTip = QCoreApplication::translate(cmd->className(), + cmd->getStatusTip(), 0, QCoreApplication::UnicodeUTF8); + if (statusTip.isEmpty()) + statusTip = toolTip; + if (!accel.isEmpty()) { + if (!statusTip.isEmpty()) { + QString tip = QString::fromLatin1("(%1)\t%2") + .arg(accel).arg(statusTip); + action->setStatusTip(tip); + } + } + else { + action->setStatusTip(statusTip); + } + ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Shortcut"); hGrp->SetASCII(name.constData(), accelLineEditShortcut->text().toUtf8()); buttonAssign->setEnabled(false); diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp index f4f6d0030..e737504fa 100644 --- a/src/Mod/Drawing/Gui/Command.cpp +++ b/src/Mod/Drawing/Gui/Command.cpp @@ -118,7 +118,7 @@ Gui::Action * CmdDrawingNewPage::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); QAction* defaultAction = 0; int defaultId = 0; diff --git a/src/Mod/Raytracing/Gui/Command.cpp b/src/Mod/Raytracing/Gui/Command.cpp index a9e480154..78e0013dc 100644 --- a/src/Mod/Raytracing/Gui/Command.cpp +++ b/src/Mod/Raytracing/Gui/Command.cpp @@ -355,7 +355,7 @@ Gui::Action * CmdRaytracingNewPovrayProject::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); QAction* defaultAction = 0; int defaultId = 0; @@ -744,7 +744,7 @@ Gui::Action * CmdRaytracingNewLuxProject::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); QAction* defaultAction = 0; int defaultId = 0; diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 9eae22b5d..d436d363b 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -1560,7 +1560,7 @@ Gui::Action * CmdSketcherCompCreateArc::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); QAction* arc1 = pcAction->addAction(QString()); arc1->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateArc", QSize(24,24))); @@ -2036,7 +2036,7 @@ Gui::Action * CmdSketcherCompCreateCircle::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); QAction* arc1 = pcAction->addAction(QString()); arc1->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateCircle", QSize(24,24))); @@ -3466,7 +3466,7 @@ Gui::Action * CmdSketcherCompCreateRegularPolygon::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); - applyCommandData(pcAction); + applyCommandData(this->className(), pcAction); QAction* triangle = pcAction->addAction(QString()); triangle->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateTriangle", QSize(24,24)));