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 anOperationId = QString::fromStdString(aFeature->getKind()); //anOperation->id();
66 setActionEnabled(anOperationId, true);
67 bool isNestedEnabled = anOperation->isNestedOperationsEnabled();
68 setNestedCommandsEnabled(isNestedEnabled, anOperationId);
71 setNestedCommandsEnabled(false);
76 void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
78 foreach(QString eachAction, myActions.keys())
80 setActionEnabled(eachAction, isEnabled);
85 void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
87 QStringList ltNestedActions;
88 if (theParent.isEmpty()) { //Disable ALL nested
89 foreach(QString eachParent, myNestedActions.keys()) {
90 ltNestedActions << myNestedActions[eachParent];
93 ltNestedActions << myNestedActions[theParent];
95 foreach(QString eachNested, ltNestedActions) {
96 setActionEnabled(eachNested, theEnabled);
100 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
102 QAction* anAction = myActions[theId];
103 if (anAction && anAction->isCheckable()) {
104 anAction->setChecked(theChecked);
108 void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
110 QAction* anAction = myActions[theId];
112 anAction->setEnabled(theEnabled);
116 void XGUI_ActionsMgr::updateCheckState()
118 QString eachCommand = QString();
119 foreach(eachCommand, myActions.keys()) {
120 setActionChecked(eachCommand, false);
122 QStringList ltActiveCommands = myOperationMgr->operationList();
123 foreach(eachCommand, ltActiveCommands) {
124 setActionChecked(eachCommand, true);
128 QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const
130 if (myNestedActions.contains(theId))
131 return myNestedActions[theId];
132 return QStringList();
135 bool XGUI_ActionsMgr::isNested(const QString& theId) const
137 foreach(QString aId, myNestedActions.keys())
139 QStringList aList = myNestedActions[aId];
140 if (aList.contains(theId))
146 QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
148 if (theKeySequence.isEmpty()) {
149 return QKeySequence();
151 QKeySequence aResult(theKeySequence);
152 if (myShortcuts.contains(aResult)) {
153 QString aMessage = tr("Shortcut %1 is already defined. Ignore.").arg(theKeySequence);
154 Events_Error::send(aMessage.toStdString());
155 return QKeySequence();
157 myShortcuts.append(aResult);