From: sbh Date: Fri, 8 Aug 2014 04:15:09 +0000 (+0400) Subject: Shortcuts can be registered from XML without conflicts X-Git-Tag: V_0.4.4~113^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=14c15eee9ba021bc0c44447b47211d947cb130d9;p=modules%2Fshaper.git Shortcuts can be registered from XML without conflicts --- diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index 611976e2a..4bfb31b9d 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -9,18 +9,27 @@ #include "XGUI_SalomeConnector.h" #include +#include #include #ifdef _DEBUG +#include #include #endif XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent) - : QObject(theParent), myOperationMgr(theParent->operationMgr()) + : QObject(theParent), + myWorkshop(theParent), + myOperationMgr(theParent->operationMgr()) { - + // Default shortcuts + myShortcuts << QKeySequence::Save; + myShortcuts << QKeySequence::Undo; + myShortcuts << QKeySequence::Redo; + myShortcuts << QKeySequence::Open; + myShortcuts << QKeySequence::Close; } XGUI_ActionsMgr::~XGUI_ActionsMgr() @@ -132,4 +141,19 @@ bool XGUI_ActionsMgr::isNested(const QString& theId) const return true; } return false; -} \ No newline at end of file +} + +QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence) +{ + if(theKeySequence.isEmpty()) { + return QKeySequence(); + } + QKeySequence aResult(theKeySequence); + if(myShortcuts.contains(aResult)) { + QString aMessage = tr("Shortcut %1 is already defined. Ignore.").arg(theKeySequence); + Events_Error::send(aMessage.toStdString()); + return QKeySequence(); + } + myShortcuts.append(aResult); + return aResult; +} diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index 89e3b70b7..5f8c4ab93 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -9,7 +9,9 @@ #include #include +#include #include +#include class XGUI_Command; class XGUI_Workshop; @@ -35,6 +37,8 @@ public: bool isNested(const QString& theId) const; + QKeySequence registerShortcut(const QString& theKeySequence); + public slots: //! Update workbench actions according to OperationMgr state: //! No active operations: all actions but nested are available @@ -58,7 +62,9 @@ protected: private: QMap myActions; QMap myNestedActions; + QList myShortcuts; + XGUI_Workshop* myWorkshop; XGUI_OperationMgr* myOperationMgr; }; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 5cf57b2aa..8577da961 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -436,15 +436,15 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) QString aWchName = QString::fromStdString(theMessage->workbenchId()); QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures()); bool isUsePropPanel = theMessage->isUseInput(); - QString aId = QString::fromStdString(theMessage->id()); + QString aFeatureId = QString::fromStdString(theMessage->id()); if (isSalomeMode()) { QAction* aAction = salomeConnector()->addFeature(aWchName, - aId, + aFeatureId, QString::fromStdString(theMessage->text()), QString::fromStdString(theMessage->tooltip()), QIcon(theMessage->icon().c_str()), QKeySequence(), isUsePropPanel); - salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" ")); + salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ")); myActionsMgr->addCommand(aAction); myModule->featureCreated(aAction); } else { @@ -460,12 +460,15 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) if (!aGroup) { aGroup = aPage->addGroup(aGroupName); } - //Create feature... - XGUI_Command* aCommand = aGroup->addFeature(aId, + // Check if hotkey sequence is already defined: + QKeySequence aHotKey = myActionsMgr->registerShortcut( + QString::fromStdString(theMessage->keysequence())); + // Create feature... + XGUI_Command* aCommand = aGroup->addFeature(aFeatureId, QString::fromStdString(theMessage->text()), QString::fromStdString(theMessage->tooltip()), QIcon(theMessage->icon().c_str()), - QKeySequence(), isUsePropPanel); + aHotKey, isUsePropPanel); aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts)); myActionsMgr->addCommand(aCommand); myModule->featureCreated(aCommand); @@ -1063,4 +1066,4 @@ void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup { for (int i = 0; i < theDoc->size(theGroup); i++) myDisplayer->display(theDoc->object(theGroup, i), false); -} \ No newline at end of file +}