Salome HOME
Avoid redisplay of sketcher while it is not finished
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.cpp
index 514c5b2f116c1f760e975a7dbc1f86efb86bda20..8a3b36e12ca8755668b625de5c2f3df25eb958ca 100644 (file)
@@ -46,6 +46,8 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
   connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
   connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
   connect(theOperation, SIGNAL(resumed()), this, SIGNAL(operationResumed()));
+  connect(theOperation, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)),
+          this, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)));
 
   theOperation->start();
   return true;
@@ -106,30 +108,44 @@ bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
 
 bool XGUI_OperationMgr::canStopOperation()
 {
-  int anAnswer = QMessageBox::question(0, tr("Operation launch"),
-                              tr("Previous operation is not finished and will be aborted"),
-                              QMessageBox::Ok, QMessageBox::Cancel);
-  return anAnswer == QMessageBox::Ok;
+  ModuleBase_Operation* anOperation = currentOperation();
+  if (anOperation) {
+    if (anOperation->isModified()) {
+      int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Operation launch"),
+                                  tr("Previous operation is not finished and will be aborted"),
+                                  QMessageBox::Ok, QMessageBox::Cancel);
+      return anAnswer == QMessageBox::Ok;
+    }
+  }
+  return true;
 }
 
 void XGUI_OperationMgr::onCommitOperation()
 {
   ModuleBase_Operation* anOperation = currentOperation();
-  if (anOperation) {
-    if (anOperation->canBeCommitted())
-      anOperation->commit();
-    else
-      anOperation->abort();
-  }
+  if (anOperation)
+    anOperation->commit();
 }
 
 void XGUI_OperationMgr::onAbortOperation()
 {
   ModuleBase_Operation* anOperation = currentOperation();
-  if (anOperation)
+  if (anOperation && canAbortOperation())
     anOperation->abort();
 }
 
+bool XGUI_OperationMgr::canAbortOperation()
+{
+  ModuleBase_Operation* anOperation = currentOperation();
+  if (anOperation && anOperation->isModified()) {
+      int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Cancel operation"),
+                                  tr("Operation %1 will be cancelled. Continue?").arg(anOperation->id()),
+                                  QMessageBox::Yes, QMessageBox::No);
+      return anAnswer == QMessageBox::Yes;
+  }
+  return true;
+}
+
 void XGUI_OperationMgr::onOperationStopped()
 {
   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
@@ -164,3 +180,10 @@ void XGUI_OperationMgr::onKeyReleased(const std::string& theName, QKeyEvent* the
   if (anOperation)
     anOperation->keyReleased(theName, theEvent);
 }
+
+void XGUI_OperationMgr::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
+{
+  ModuleBase_Operation* anOperation = currentOperation();
+  if (anOperation)
+    anOperation->onWidgetActivated(theWidget);
+}