void XGUI_ContextMenuMgr::onRename()
{
QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
- if (!myWorkshop->abortAllOperations())
+ if (!myWorkshop->operationMgr()->abortAllOperations())
return;
// restore selection in case if dialog box was shown
myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
}
if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll);
- QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
+ QObject::connect(anAction, SIGNAL(triggered()),
+ anOperationMgr, SLOT(onAbortAllOperations()));
aNestedActList << anAction;
}
}
}
if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll);
- QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
+ QObject::connect(anAction, SIGNAL(triggered()),
+ anOperationMgr, SLOT(onAbortAllOperations()));
aNestedActList << anAction;
}
anAction = aSalomeConnector->addFeatureOfNested(theWchName.c_str(), aFeatureInfo,
return isStarted;
}
-bool XGUI_OperationMgr::abortAllOperations()
+void XGUI_OperationMgr::onAbortAllOperations()
+{
+ abortAllOperations();
+}
+
+bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind)
{
bool aResult = true;
if(!hasOperation())
if (operationsCount() == 1) {
ModuleBase_Operation* aCurrentOperation = currentOperation();
- if (canStopOperation(aCurrentOperation)) {
+ if (canStopOperation(aCurrentOperation, theMessageKind)) {
abortOperation(aCurrentOperation);
}
else
aResult = false;
}
else {
- aResult = QMessageBox::question(qApp->activeWindow(),
- tr("Abort operation"),
- tr("All active operations will be aborted."),
- QMessageBox::Ok | QMessageBox::Cancel,
- QMessageBox::Cancel) == QMessageBox::Ok;
+ if (theMessageKind == XGUI_AbortOperationMessage) {
+ aResult = QMessageBox::question(qApp->activeWindow(),
+ tr("Abort operation"),
+ tr("All active operations will be aborted."),
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Cancel) == QMessageBox::Ok;
+ }
+ else if (theMessageKind == XGUI_InformationMessage) {
+ QString aMessage = tr("Please validate all your active operations before saving.");
+ QMessageBox::question(qApp->activeWindow(),
+ tr("Validate operation"),
+ aMessage,
+ QMessageBox::Ok,
+ QMessageBox::Ok);
+ aResult = false; // do not perform abort
+ }
while(aResult && hasOperation()) {
abortOperation(currentOperation());
}
while (hasOperation()) {
ModuleBase_Operation* anOperation = currentOperation();
if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
- anOperationProcessed = onCommitOperation();
+ anOperationProcessed = commitOperation();
} else {
abortOperation(anOperation);
anOperationProcessed = true;
onValidateOperation();
}
-bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
+bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
+ const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
{
//in case of nested (sketch) operation no confirmation needed
if (isGrantedOperation(theOperation->id()))
return true;
if (theOperation && theOperation->isModified()) {
- QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
- int anAnswer = QMessageBox::question(qApp->activeWindow(),
- tr("Abort operation"),
- aMessage,
- QMessageBox::Ok | QMessageBox::Cancel,
- QMessageBox::Cancel);
- return anAnswer == QMessageBox::Ok;
+ if (theMessageKind == XGUI_AbortOperationMessage) {
+ QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
+ int anAnswer = QMessageBox::question(qApp->activeWindow(),
+ tr("Abort operation"),
+ aMessage,
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Cancel);
+ return anAnswer == QMessageBox::Ok;
+ }
+ else if (theMessageKind == XGUI_InformationMessage) {
+ QString aMessage = tr("Please validate your %1 before saving.").arg(theOperation->id());
+ QMessageBox::question(qApp->activeWindow(),
+ tr("Validate operation"),
+ aMessage,
+ QMessageBox::Ok,
+ QMessageBox::Ok);
+ return false;
+ }
}
return true;
}
-bool XGUI_OperationMgr::commitOperation()
-{
- //if (hasOperation() && currentOperation()->isValid()) {
- // onCommitOperation();
- // return true;
- //}
- //return false;
- return onCommitOperation();
-}
-
void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
{
theOperation->resume();
}
}
-bool XGUI_OperationMgr::onCommitOperation()
+bool XGUI_OperationMgr::commitOperation()
{
bool isCommitted = false;
ModuleBase_Operation* anOperation = currentOperation();
class XGUI_EXPORT XGUI_OperationMgr : public QObject
{
Q_OBJECT
- public:
+public:
+ /// Enumeration of kind of message that is used when trying to stop the active operation
+ enum XGUI_MessageKind
+ {
+ XGUI_AbortOperationMessage, //< warns and give possibility to abort current operation
+ XGUI_InformationMessage //< ask to apply the current operation before performing something
+ };
+
+public:
/// Constructor
/// \param theParent the parent
/// \param theWorkshop a reference to workshop
/// Returns true if the operation can be aborted. If the operation is modified,
/// the warning message box is shown.
/// \param theOperation an operation which is checked on stop
- bool canStopOperation(ModuleBase_Operation* theOperation);
+ /// \param theMessageKind a kind of message in warning message box
+ bool canStopOperation(ModuleBase_Operation* theOperation,
+ const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage);
/// Find and return operation by its Id.
ModuleBase_Operation* findOperation(const QString& theId) const;
/// \param theOperation an aborted operation
void abortOperation(ModuleBase_Operation* theOperation);
- /// Slot that commits the current operation.
- bool onCommitOperation();
+ bool abortAllOperations(const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage);
public slots:
/// Slot that aborts the current operation.
/// Commit all operations
bool commitAllOperations();
/// Abort all operations
- bool abortAllOperations();
+ void onAbortAllOperations();
+
+protected slots:
+
signals:
/// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
(anOperationMgr->currentOperation());
if (aFOperation) {
//if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
- myOperationMgr->onCommitOperation();
+ myOperationMgr->commitOperation();
}
}
}
QApplication::restoreOverrideCursor();
}
-//******************************************************
-bool XGUI_Workshop::abortAllOperations()
-{
- return myOperationMgr->abortAllOperations();
-}
-
//******************************************************
void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
{
//******************************************************
void XGUI_Workshop::onOpen()
{
- if(!abortAllOperations())
+ if(!myOperationMgr->abortAllOperations())
return;
//save current file before close if modified
SessionPtr aSession = ModelAPI_Session::get();
//******************************************************
bool XGUI_Workshop::onSave()
{
- if(!abortAllOperations())
+ if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
return false;
if (myCurrentDir.isEmpty()) {
return onSaveAs();
//******************************************************
bool XGUI_Workshop::onSaveAs()
{
- if(!abortAllOperations())
+ if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
return false;
QFileDialog dialog(desktop());
dialog.setWindowTitle(tr("Select directory to save files..."));
}
QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
- if (!abortAllOperations())
+ if (!myOperationMgr->abortAllOperations())
return;
bool hasResult = false;
//**************************************************************
void XGUI_Workshop::cleanHistory()
{
- if (!abortAllOperations())
+ if (!myOperationMgr->abortAllOperations())
return;
QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
//**************************************************************
void XGUI_Workshop::moveObjects()
{
- if (!abortAllOperations())
+ if (!myOperationMgr->abortAllOperations())
return;
SessionPtr aMgr = ModelAPI_Session::get();
if (aColor.size() != 3)
return;
- if (!abortAllOperations())
+ if (!myOperationMgr->abortAllOperations())
return;
// 2. show the dialog to change the value
XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
if (aDeflection < 0)
return;
- if (!abortAllOperations())
+ if (!myOperationMgr->abortAllOperations())
return;
// 2. show the dialog to change the value
XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
*/
void saveDocument(const QString& theName, std::list<std::string>& theFileNames);
- /**
- * If there is an active (uncommitted) operation shows a prompt to abort it
- * and performs abortion if user agreed. Returns true if
- * - operation aborted successfully
- * - there is no active operation
- */
- bool abortAllOperations();
-
/// Updates workshop state according to the started operation, e.g. visualizes the property panel
/// and connect to it.
/// \param theOpertion a started operation
void operationStarted(ModuleBase_Operation* theOperation);
-
//! Delete features. Delete the referenced features. There can be a question with a list of
//! referenced objects.
//! \param theFeatures a list of objects to be deleted