]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Shortcuts can be registered from XML without conflicts
authorsbh <sergey.belash@opencascade.com>
Fri, 8 Aug 2014 04:15:09 +0000 (08:15 +0400)
committersbh <sergey.belash@opencascade.com>
Fri, 8 Aug 2014 04:15:09 +0000 (08:15 +0400)
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_Workshop.cpp

index 611976e2a91c3da4186b17d8acf72da68f951f9b..4bfb31b9d6e31eb7807415815e4a04f815149c66 100644 (file)
@@ -9,18 +9,27 @@
 #include "XGUI_SalomeConnector.h"
 
 #include <ModuleBase_Operation.h>
+#include <Events_Error.h>
 
 #include <QAction>
 
 #ifdef _DEBUG
+#include <iostream>
 #include <QDebug>
 #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;
+}
index 89e3b70b7ae0139b985285456dd02305940588d0..5f8c4ab93a6131fc5249cc7a7479a06359706669 100644 (file)
@@ -9,7 +9,9 @@
 
 #include <QObject>
 #include <QMap>
+#include <QList>
 #include <QStringList>
+#include <QKeySequence>
 
 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<QString, QAction*> myActions;
   QMap<QString, QStringList> myNestedActions;
+  QList<QKeySequence> myShortcuts;
 
+  XGUI_Workshop* myWorkshop;
   XGUI_OperationMgr* myOperationMgr;
 };
 
index 5cf57b2aabedd86da81bea8d71135418680bfb3c..8577da961fe51ba063fb32468a4b73f9c105c30c 100644 (file)
@@ -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
+}