Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.cpp
index 8cc05c494a8a75a01b8c96e38c0ecfd844f3d32e..7f0b02d9ae0e668688a24dbaaa15d1a65caf1a19 100644 (file)
@@ -2,15 +2,18 @@
  * XGUI_ActionsMgr.cpp
  */
 
-#include <XGUI_ActionsMgr.h>
-#include <XGUI_Command.h>
+#include "XGUI_ActionsMgr.h"
+#include "XGUI_Command.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_SalomeConnector.h"
+
 #include <QAction>
 
 
-XGUI_ActionsMgr::XGUI_ActionsMgr(QObject* theParent)
- : QObject(theParent)
+XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
+ : QObject(theParent), myWorkshop(theParent)
 {
-
+  
 }
 
 XGUI_ActionsMgr::~XGUI_ActionsMgr()
@@ -18,11 +21,12 @@ XGUI_ActionsMgr::~XGUI_ActionsMgr()
 }
 
 
-void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd)
+void XGUI_ActionsMgr::addCommand(QAction* theCmd)
 {
-  myActions.insert(theCmd->id(),theCmd);
-  myActionsState.insert(theCmd->id(), theCmd->enabled());
-  theCmd->connectTo(this, SLOT(setActionsDisabled(bool)));
+  QString aId = theCmd->data().toString();
+  myActions.insert(aId, theCmd);
+  myActionsState.insert(aId, theCmd->isEnabled());
+  connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool)));
 }
 
 void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
@@ -35,8 +39,11 @@ void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
   }
   //Disable all actions, but caller and unblockable (defined in a xml)
   saveCommandsState();
-  XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
-  QString aSkippedId = aToggledFeature->id();
+
+  QString aSkippedId;
+  QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
+  aSkippedId = aToggledFeature->data().toString();
+
   QStringList anActionIdsList = myActions.keys();
   foreach(QString eachKey, anActionIdsList) {
     if (eachKey == aSkippedId) {
@@ -44,7 +51,12 @@ void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
     }
     myActions[eachKey]->setEnabled(false);
   }
-  myNestedActions = aToggledFeature->unblockableCommands();
+  if (myWorkshop->isSalomeMode()) {
+    myNestedActions = myWorkshop->salomeConnector()->nestedActions(aSkippedId);
+  } else {
+    XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
+    myNestedActions = aToggledFeature->unblockableCommands();
+  }
 }
 
 void XGUI_ActionsMgr::saveCommandsState()
@@ -66,9 +78,25 @@ void XGUI_ActionsMgr::restoreCommandState()
   }
 }
 
+void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
+{
+  if(myActions.contains(theId)) {
+    myActions[theId]->setChecked(theChecked);
+  }
+}
+
+void XGUI_ActionsMgr::updateAction(const QString& theId)
+{
+  if(myActions.contains(theId)){
+    myActions[theId]->setEnabled(myActionsState[theId]);
+    myActions[theId]->setChecked(false);
+  }
+}
+
 void XGUI_ActionsMgr::setNestedActionsEnabled(bool isEnabled)
 {
   foreach(QString eachKey, myNestedActions) {
-    myActions[eachKey]->setEnabled(isEnabled);
+    if (myActions.contains(eachKey))
+      myActions[eachKey]->setEnabled(isEnabled);
   }
 }