--- /dev/null
+/*
+ * XGUI_HistoryMenu.cpp
+ *
+ * Created on: Feb 2, 2015
+ * Author: sbh
+ */
+
+#include <XGUI_HistoryMenu.h>
+
+#include <ModelAPI_Session.h>
+
+#include <QListWidget>
+#include <QWidgetAction>
+#include <QToolButton>
+
+//! Extends given feature with previously created context menu.
+//! \param theId - Id of the feature to add \a theMenu
+//! \param theMenu - Enables or disables menu feature
+XGUI_HistoryMenu::XGUI_HistoryMenu(QToolButton* theParent)
+ : QMenu(theParent),
+ myHistoryList(new QListWidget(this))
+{
+ theParent->setMenu(this);
+ theParent->setPopupMode(QToolButton::MenuButtonPopup);
+
+ QWidgetAction* aListAction = new QWidgetAction(this);
+ aListAction->setDefaultWidget(myHistoryList);
+ this->addAction(aListAction);
+
+ myHistoryList->setMouseTracking(true); // track mouse hover
+ myHistoryList->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ connect(myHistoryList, SIGNAL(itemEntered(QListWidgetItem *)),
+ this, SLOT(setStackSelectedTo(QListWidgetItem *)));
+ connect(myHistoryList, SIGNAL(itemClicked(QListWidgetItem *)),
+ this, SLOT(onItemPressed(QListWidgetItem *)));
+}
+
+XGUI_HistoryMenu::~XGUI_HistoryMenu()
+{
+}
+
+void XGUI_HistoryMenu::setHistory(const QList<QAction*>& theActions)
+{
+ myHistoryList->clear();
+ foreach(QAction* anAct, theActions) {
+ QListWidgetItem* anItem = new QListWidgetItem(anAct->icon(),
+ anAct->text(),
+ myHistoryList);
+ anAct->deleteLater();
+ }
+}
+
+
+void XGUI_HistoryMenu::setStackSelectedTo(QListWidgetItem * theItem)
+{
+ if (!theItem)
+ return;
+
+ QListWidgetItem* eachItem = NULL;
+ bool isSelect = true;
+ for(int aRow = 0; aRow < myHistoryList->count(); ++aRow) {
+ eachItem = myHistoryList->item(aRow);
+ myHistoryList->setItemSelected(eachItem, isSelect);
+ // Deselect items below hovered
+ if (eachItem == theItem) {
+ isSelect = false;
+ }
+ }
+}
+
+void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
+{
+ int selectedSize = myHistoryList->row(theItem) + 1;
+ emit actionsSelected(selectedSize);
+ hide();
+ myHistoryList->clear();
+}
#include "XGUI_ContextMenuMgr.h"
#include "XGUI_ModuleConnector.h"
#include <XGUI_QtEvents.h>
+#include <XGUI_HistoryMenu.h>
#include <AppElements_Workbench.h>
#include <AppElements_Viewer.h>
#include <QLayout>
#include <QThread>
#include <QObject>
+#include <QMenu>
+#include <QToolButton>
+#include <QAction>
#ifdef _DEBUG
#include <QDebug>
aCommand->connectTo(this, SLOT(onSave()));
//aCommand->disable();
- aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
+ QString aUndoId = "UNDO_CMD";
+ aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
QIcon(":pictures/undo.png"), QKeySequence::Undo);
aCommand->connectTo(this, SLOT(onUndo()));
- aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
+ QToolButton* aToolBtn = qobject_cast<QToolButton*>(aGroup->widget(aUndoId));
+ XGUI_HistoryMenu* aUndoMenu = new XGUI_HistoryMenu(aToolBtn);
+ connect(this, SIGNAL(updateUndoHistory(const QList<QAction*>&)),
+ aUndoMenu, SLOT(setHistory(const QList<QAction*>&)));
+ connect(aUndoMenu, SIGNAL(actionsSelected(int)),
+ this, SLOT(onUndo(int)));
+
+ QString aRedoId = "REDO_CMD";
+ aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
QIcon(":pictures/redo.png"), QKeySequence::Redo);
aCommand->connectTo(this, SLOT(onRedo()));
+ aToolBtn = qobject_cast<QToolButton*>(aGroup->widget(aRedoId));
+ XGUI_HistoryMenu* aRedoMenu = new XGUI_HistoryMenu(aToolBtn);
+ connect(this, SIGNAL(updateUndoHistory(const QList<QAction*>&)),
+ aRedoMenu, SLOT(setHistory(const QList<QAction*>&)));
+ connect(aRedoMenu, SIGNAL(actionsSelected(int)),
+ this, SLOT(onUndo(int)));
+
aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
QIcon(":pictures/rebuild.png"), QKeySequence());
aCommand->connectTo(this, SLOT(onRebuild()));
// Remember features icons
myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
- //Find or create Workbench
QString aWchName = QString::fromStdString(theMessage->workbenchId());
QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
bool isUsePropPanel = theMessage->isUseInput();
QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
QString::fromStdString(theMessage->text()),
QString::fromStdString(theMessage->tooltip()),
- QIcon(theMessage->icon().c_str()),
+ QIcon(QString::fromStdString(theMessage->icon())),
QKeySequence(),
isUsePropPanel);
salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
myActionsMgr->addCommand(aAction);
myModule->actionCreated(aAction);
} else {
-
+ //Find or create Workbench
AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
if (!aPage) {
}
//******************************************************
-void XGUI_Workshop::onUndo()
+void XGUI_Workshop::onUndo(int theTimes)
{
objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
SessionPtr aMgr = ModelAPI_Session::get();
if (aMgr->isOperation())
operationMgr()->onAbortOperation();
- aMgr->undo();
+ for (int i = 0; i < theTimes; ++i) {
+ aMgr->undo();
+ }
updateCommandStatus();
}
//******************************************************
-void XGUI_Workshop::onRedo()
+void XGUI_Workshop::onRedo(int theTimes)
{
objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
SessionPtr aMgr = ModelAPI_Session::get();
if (aMgr->isOperation())
operationMgr()->onAbortOperation();
- aMgr->redo();
+ for (int i = 0; i < theTimes; ++i) {
+ aMgr->redo();
+ }
updateCommandStatus();
}
SessionPtr aMgr = ModelAPI_Session::get();
bool aWasOperation = aMgr->isOperation(); // keep this value
if (!aWasOperation) {
- aMgr->startOperation();
+ aMgr->startOperation("Rebuild");
}
static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
}
aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation());
aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation());
+
+ updateHistory();
+
} else {
foreach(QAction* aCmd, aCommands) {
QString aId = aCmd->data().toString();
emit commandStatusUpdated();
}
+void XGUI_Workshop::updateHistory()
+{
+ std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
+ std::list<std::string>::iterator it = aUndoList.begin();
+ QList<QAction*> aUndoRes;
+ for ( ; it != aUndoList.end(); it++) {
+ QString anId = QString::fromStdString(*it);
+ QIcon aIcon;
+ if (myIcons.contains(anId))
+ aIcon = QIcon(myIcons[anId]);
+ aUndoRes << new QAction(aIcon, anId, NULL);
+ }
+ emit updateUndoHistory(aUndoRes);
+
+ std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
+ it = aRedoList.begin();
+ QList<QAction*> aRedoRes;
+ for ( ; it != aRedoList.end(); it++) {
+ QString anId = QString::fromStdString(*it);
+ QIcon aIcon;
+ if (myIcons.contains(anId))
+ aIcon = QIcon(myIcons[anId]);
+ aRedoRes << new QAction(aIcon, anId, NULL);
+ }
+ emit updateRedoHistory(aUndoRes);
+}
+
//******************************************************
QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
{
}
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation();
+ aMgr->startOperation("DeleteObjects");
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
aLast = aRefFeatures.end();
for (; anIt != aLast; anIt++) {