X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FXGUI%2FXGUI_ActionsMgr.cpp;h=4bfb31b9d6e31eb7807415815e4a04f815149c66;hb=e8f6a194e38ff95708bf0984081d9f4e7d9ab115;hp=0d652dceba7eed7cdeba455230e3056d03bc361f;hpb=f3c113af79cf08e90316b2d27303a0a12d93fddc;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index 0d652dceb..4bfb31b9d 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -2,15 +2,34 @@ * XGUI_ActionsMgr.cpp */ -#include -#include +#include "XGUI_ActionsMgr.h" +#include "XGUI_Command.h" +#include "XGUI_Workshop.h" +#include "XGUI_OperationMgr.h" +#include "XGUI_SalomeConnector.h" + +#include +#include + #include +#ifdef _DEBUG +#include +#include +#endif -XGUI_ActionsMgr::XGUI_ActionsMgr(QObject* theParent) - : QObject(theParent) -{ +XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent) + : 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() @@ -18,50 +37,123 @@ 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(); + if(aId.isEmpty()) { + return; + } + myActions.insert(aId, theCmd); + XGUI_Command* aXCmd = dynamic_cast(theCmd); + if (aXCmd) { + myNestedActions[aId] = aXCmd->nestedCommands(); + } else { + XGUI_Workshop* aWorkshop = static_cast(parent()); + myNestedActions[aId] = aWorkshop->salomeConnector()->nestedActions(aId); + } } -void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled) +void XGUI_ActionsMgr::addNestedCommands(const QString& theId, const QStringList& theCommands) { - //Re-enable actions (just restore their state) - if (!isDisabled) { - restoreCommandState(); - return; + myNestedActions[theId] = theCommands; +} + +void XGUI_ActionsMgr::update() +{ + if(myOperationMgr->hasOperation()) { + setAllEnabled(false); + ModuleBase_Operation* anOperation = myOperationMgr->currentOperation(); + QString anOperationId = anOperation->id(); + setActionEnabled(anOperationId, true); + bool isNestedEnabled = anOperation->isNestedOperationsEnabled(); + setNestedCommandsEnabled(isNestedEnabled, anOperationId); + } else { + setAllEnabled(true); + setNestedCommandsEnabled(false); } - //Disable all actions, but caller and unblockable (defined in a xml) - saveCommandsState(); - QStringList aSkippedIds; - XGUI_Command* aToggledFeature = dynamic_cast(sender()); - aSkippedIds.append(aToggledFeature->unblockableCommands()); - aSkippedIds.append(aToggledFeature->id()); - QStringList anActionIdsList = myActions.keys(); - foreach(QString eachKey, anActionIdsList) { - if (aSkippedIds.removeAll(eachKey) > 0) { - continue; + updateCheckState(); +} + +void XGUI_ActionsMgr::setAllEnabled(bool isEnabled) +{ + foreach(QString eachAction, myActions.keys()) { + setActionEnabled(eachAction, isEnabled); + } +} + +//! +void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent) +{ + QStringList ltNestedActions; + if(theParent.isEmpty()) { //Disable ALL nested + foreach(QString eachParent, myNestedActions.keys()) { + ltNestedActions << myNestedActions[eachParent]; } - myActions[eachKey]->setEnabled(false); + } else { + ltNestedActions << myNestedActions[theParent]; + } + foreach(QString eachNested, ltNestedActions) { + setActionEnabled(eachNested, theEnabled); + } +} + +void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked) +{ + QAction* anAction = myActions[theId]; + if(anAction && anAction->isCheckable()) { + anAction->setChecked(theChecked); + } +} + + +void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled) +{ + QAction* anAction = myActions[theId]; + if(anAction) { + anAction->setEnabled(theEnabled); } } -void XGUI_ActionsMgr::saveCommandsState() +void XGUI_ActionsMgr::updateCheckState() { - myActionsState.clear(); - QStringList anActionIdsList = myActions.keys(); - foreach(QString eachKey, anActionIdsList) { - myActionsState.insert(eachKey, myActions[eachKey]->isEnabled()); + QString eachCommand = QString(); + foreach(eachCommand, myActions.keys()) { + setActionChecked(eachCommand, false); + } + QStringList ltActiveCommands = myOperationMgr->operationList(); + foreach(eachCommand, ltActiveCommands) { + setActionChecked(eachCommand, true); } +} +QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const +{ + if (myNestedActions.contains(theId)) + return myNestedActions[theId]; + return QStringList(); } -void XGUI_ActionsMgr::restoreCommandState() +bool XGUI_ActionsMgr::isNested(const QString& theId) const { - QStringList anActionIdsList = myActions.keys(); - foreach(QString eachKey, anActionIdsList) { - myActions[eachKey]->setEnabled(myActionsState[eachKey]); - myActions[eachKey]->setChecked(false); + foreach(QString aId, myNestedActions.keys()) { + QStringList aList = myNestedActions[aId]; + if (aList.contains(theId)) + return true; + } + return false; +} + +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; }