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>
22 XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
24 myWorkshop(theParent),
25 myOperationMgr(theParent->operationMgr())
28 myShortcuts << QKeySequence::Save;
29 myShortcuts << QKeySequence::Undo;
30 myShortcuts << QKeySequence::Redo;
31 myShortcuts << QKeySequence::Open;
32 myShortcuts << QKeySequence::Close;
35 XGUI_ActionsMgr::~XGUI_ActionsMgr()
40 void XGUI_ActionsMgr::addCommand(QAction* theCmd)
42 QString aId = theCmd->data().toString();
46 myActions.insert(aId, theCmd);
47 XGUI_Command* aXCmd = dynamic_cast<XGUI_Command*>(theCmd);
49 myNestedActions[aId] = aXCmd->nestedCommands();
51 XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
52 myNestedActions[aId] = aWorkshop->salomeConnector()->nestedActions(aId);
56 void XGUI_ActionsMgr::addNestedCommands(const QString& theId, const QStringList& theCommands)
58 myNestedActions[theId] = theCommands;
61 void XGUI_ActionsMgr::update()
63 if(myOperationMgr->hasOperation()) {
65 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
66 QString anOperationId = anOperation->id();
67 setActionEnabled(anOperationId, true);
68 bool isNestedEnabled = anOperation->isNestedOperationsEnabled();
69 setNestedCommandsEnabled(isNestedEnabled, anOperationId);
72 setNestedCommandsEnabled(false);
77 void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
79 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);
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()) {
121 setActionChecked(eachCommand, false);
123 QStringList ltActiveCommands = myOperationMgr->operationList();
124 foreach(eachCommand, ltActiveCommands) {
125 setActionChecked(eachCommand, true);
129 QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const
131 if (myNestedActions.contains(theId))
132 return myNestedActions[theId];
133 return QStringList();
136 bool XGUI_ActionsMgr::isNested(const QString& theId) const
138 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);