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 QString anOperationId = anOperation->id();
65 setActionEnabled(anOperationId, true);
66 bool isNestedEnabled = anOperation->isNestedOperationsEnabled();
67 setNestedCommandsEnabled(isNestedEnabled, anOperationId);
70 setNestedCommandsEnabled(false);
75 void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
77 foreach(QString eachAction, myActions.keys())
79 setActionEnabled(eachAction, isEnabled);
84 void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
86 QStringList ltNestedActions;
87 if (theParent.isEmpty()) { //Disable ALL nested
88 foreach(QString eachParent, myNestedActions.keys())
90 ltNestedActions << myNestedActions[eachParent];
93 ltNestedActions << myNestedActions[theParent];
95 foreach(QString eachNested, ltNestedActions)
97 setActionEnabled(eachNested, theEnabled);
101 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
103 QAction* anAction = myActions[theId];
104 if (anAction && anAction->isCheckable()) {
105 anAction->setChecked(theChecked);
109 void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
111 QAction* anAction = myActions[theId];
113 anAction->setEnabled(theEnabled);
117 void XGUI_ActionsMgr::updateCheckState()
119 QString eachCommand = QString();
120 foreach(eachCommand, myActions.keys())
122 setActionChecked(eachCommand, false);
124 QStringList ltActiveCommands = myOperationMgr->operationList();
125 foreach(eachCommand, ltActiveCommands)
127 setActionChecked(eachCommand, true);
131 QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const
133 if (myNestedActions.contains(theId))
134 return myNestedActions[theId];
135 return QStringList();
138 bool XGUI_ActionsMgr::isNested(const QString& theId) const
140 foreach(QString aId, myNestedActions.keys())
142 QStringList aList = myNestedActions[aId];
143 if (aList.contains(theId))
149 QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
151 if (theKeySequence.isEmpty()) {
152 return QKeySequence();
154 QKeySequence aResult(theKeySequence);
155 if (myShortcuts.contains(aResult)) {
156 QString aMessage = tr("Shortcut %1 is already defined. Ignore.").arg(theKeySequence);
157 Events_Error::send(aMessage.toStdString());
158 return QKeySequence();
160 myShortcuts.append(aResult);