#include "XGUI_SalomeConnector.h"
#include <ModuleBase_Operation.h>
+#include <Events_Error.h>
#include <QAction>
#ifdef _DEBUG
+#include <iostream>
#include <QDebug>
#endif
XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
- : QObject(theParent), myOperationMgr(theParent->operationMgr())
+ : 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()
return true;
}
return false;
-}
\ No newline at end of file
+}
+
+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;
+}
#include <QObject>
#include <QMap>
+#include <QList>
#include <QStringList>
+#include <QKeySequence>
class XGUI_Command;
class XGUI_Workshop;
bool isNested(const QString& theId) const;
+ QKeySequence registerShortcut(const QString& theKeySequence);
+
public slots:
//! Update workbench actions according to OperationMgr state:
//! No active operations: all actions but nested are available
private:
QMap<QString, QAction*> myActions;
QMap<QString, QStringList> myNestedActions;
+ QList<QKeySequence> myShortcuts;
+ XGUI_Workshop* myWorkshop;
XGUI_OperationMgr* myOperationMgr;
};
QString aWchName = QString::fromStdString(theMessage->workbenchId());
QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
bool isUsePropPanel = theMessage->isUseInput();
- QString aId = QString::fromStdString(theMessage->id());
+ QString aFeatureId = QString::fromStdString(theMessage->id());
if (isSalomeMode()) {
QAction* aAction = salomeConnector()->addFeature(aWchName,
- aId,
+ aFeatureId,
QString::fromStdString(theMessage->text()),
QString::fromStdString(theMessage->tooltip()),
QIcon(theMessage->icon().c_str()),
QKeySequence(), isUsePropPanel);
- salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
+ salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" "));
myActionsMgr->addCommand(aAction);
myModule->featureCreated(aAction);
} else {
if (!aGroup) {
aGroup = aPage->addGroup(aGroupName);
}
- //Create feature...
- XGUI_Command* aCommand = aGroup->addFeature(aId,
+ // Check if hotkey sequence is already defined:
+ QKeySequence aHotKey = myActionsMgr->registerShortcut(
+ QString::fromStdString(theMessage->keysequence()));
+ // Create feature...
+ XGUI_Command* aCommand = aGroup->addFeature(aFeatureId,
QString::fromStdString(theMessage->text()),
QString::fromStdString(theMessage->tooltip()),
QIcon(theMessage->icon().c_str()),
- QKeySequence(), isUsePropPanel);
+ aHotKey, isUsePropPanel);
aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
myActionsMgr->addCommand(aCommand);
myModule->featureCreated(aCommand);
{
for (int i = 0; i < theDoc->size(theGroup); i++)
myDisplayer->display(theDoc->object(theGroup, i), false);
-}
\ No newline at end of file
+}