5 #include "XGUI_ActionsMgr.h"
6 #include "XGUI_Command.h"
7 #include "XGUI_Workshop.h"
8 #include "XGUI_OperationMgr.h"
9 #include "XGUI_SalomeConnector.h"
11 #include <ModuleBase_Operation.h>
12 #include <Events_Error.h>
21 XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
23 myWorkshop(theParent),
24 myOperationMgr(theParent->operationMgr())
27 myShortcuts << QKeySequence::Save;
28 myShortcuts << QKeySequence::Undo;
29 myShortcuts << QKeySequence::Redo;
30 myShortcuts << QKeySequence::Open;
31 myShortcuts << QKeySequence::Close;
34 XGUI_ActionsMgr::~XGUI_ActionsMgr()
38 void XGUI_ActionsMgr::addCommand(QAction* theCmd)
40 QString aId = theCmd->data().toString();
44 myActions.insert(aId, theCmd);
45 XGUI_Command* aXCmd = dynamic_cast<XGUI_Command*>(theCmd);
47 myNestedActions[aId] = aXCmd->nestedCommands();
49 XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
50 myNestedActions[aId] = aWorkshop->salomeConnector()->nestedActions(aId);
54 void XGUI_ActionsMgr::addNestedCommands(const QString& theId, const QStringList& theCommands)
56 myNestedActions[theId] = theCommands;
59 void XGUI_ActionsMgr::update()
61 if (myOperationMgr->hasOperation()) {
63 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
64 FeaturePtr aFeature = anOperation->feature();
65 QString aFeatureId = QString::fromStdString(aFeature->getKind());
66 setActionEnabled(aFeatureId, true);
67 setNestedStackEnabled(anOperation);
70 setNestedCommandsEnabled(false);
75 void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
77 foreach(QString eachAction, myActions.keys())
79 setActionEnabled(eachAction, isEnabled);
83 void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
85 if(theOperation == NULL)
87 FeaturePtr aFeature = theOperation->feature();
88 QString aFeatureId = QString::fromStdString(aFeature->getKind());
89 bool isNestedEnabled = theOperation->isNestedOperationsEnabled();
90 setNestedCommandsEnabled(isNestedEnabled, aFeatureId);
92 setNestedStackEnabled(myOperationMgr->previousOperation(theOperation));
96 void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
98 QStringList ltNestedActions;
99 if (theParent.isEmpty()) { //Disable ALL nested
100 foreach(QString eachParent, myNestedActions.keys()) {
101 ltNestedActions << myNestedActions[eachParent];
104 ltNestedActions << myNestedActions[theParent];
106 foreach(QString eachNested, ltNestedActions) {
107 setActionEnabled(eachNested, theEnabled);
111 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
113 QAction* anAction = myActions[theId];
114 if (anAction && anAction->isCheckable()) {
115 anAction->setChecked(theChecked);
119 void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
121 QAction* anAction = myActions[theId];
123 anAction->setEnabled(theEnabled);
127 void XGUI_ActionsMgr::updateCheckState()
129 QString eachCommand = QString();
130 foreach(eachCommand, myActions.keys()) {
131 setActionChecked(eachCommand, false);
133 QStringList ltActiveCommands = myOperationMgr->operationList();
134 foreach(eachCommand, ltActiveCommands) {
135 setActionChecked(eachCommand, true);
139 QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const
141 if (myNestedActions.contains(theId))
142 return myNestedActions[theId];
143 return QStringList();
146 bool XGUI_ActionsMgr::isNested(const QString& theId) const
148 foreach(QString aId, myNestedActions.keys())
150 QStringList aList = myNestedActions[aId];
151 if (aList.contains(theId))
157 QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
159 if (theKeySequence.isEmpty()) {
160 return QKeySequence();
162 QKeySequence aResult(theKeySequence);
163 if (myShortcuts.contains(aResult)) {
164 QString aMessage = tr("Shortcut %1 is already defined. Ignore.").arg(theKeySequence);
165 Events_Error::send(aMessage.toStdString());
166 return QKeySequence();
168 myShortcuts.append(aResult);