#include "XGUI_Selection.h"
#include "XGUI_SalomeConnector.h"
#include "XGUI_DataModel.h"
+#include "XGUI_OperationMgr.h"
+#include "XGUI_Tools.h"
#include <AppElements_MainWindow.h>
#include <ModuleBase_IModule.h>
#include <ModuleBase_Tools.h>
+#include <ModuleBase_OperationAction.h>
#include <QAction>
#include <QContextMenuEvent>
void XGUI_ContextMenuMgr::onRename()
{
+ ModuleBase_OperationAction* anAction = new ModuleBase_OperationAction("Rename", this);
+ XGUI_OperationMgr* anOpMgr = myWorkshop->operationMgr();
+ anOpMgr->startOperation(anAction);
myWorkshop->objectBrowser()->onEditItem();
+ anOpMgr->commitOperation();
}
#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Tools.h>
+#include <Events_Error.h>
#include <ModuleBase_Tools.h>
void XGUI_DataTree::commitData(QWidget* theEditor)
{
- QLineEdit* aEditor = dynamic_cast<QLineEdit*>(theEditor);
- if (aEditor) {
- QString aName = aEditor->text();
- QModelIndexList aIndexList = selectionModel()->selectedIndexes();
- XGUI_DataModel* aModel = dataModel();
- ObjectPtr aObj = aModel->object(aIndexList.first());
- SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation("Rename");
+ static int aEntrance = 0;
+ if (aEntrance == 0) {
+ // We have to check number of enter and exit of this function because it can be called recursively by Qt
+ // in order to avoid double modifying of a data
+ aEntrance = 1;
+ QLineEdit* aEditor = dynamic_cast<QLineEdit*>(theEditor);
+ if (aEditor) {
+ QString aName = aEditor->text();
+ QModelIndexList aIndexList = selectionModel()->selectedIndexes();
+ XGUI_DataModel* aModel = dataModel();
+ ObjectPtr aObj = aModel->object(aIndexList.first());
- if (!XGUI_Tools::canRename(this, aObj, aName)) {
- aMgr->abortOperation();
- return;
+ if (XGUI_Tools::canRename(aObj, aName))
+ aObj->data()->setName(qPrintable(aName));
}
-
- aObj->data()->setName(qPrintable(aName));
- aMgr->finishOperation();
}
+ aEntrance = 0;
}
void XGUI_DataTree::clear()
#include <ModelAPI_ResultPart.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Tools.h>
+#include <Events_Error.h>
#include <GeomAPI_Shape.h>
}
//******************************************************************
-bool canRename(QWidget* theParent, const ObjectPtr& theObject, const QString& theName)
+bool canRename(const ObjectPtr& theObject, const QString& theName)
{
if (std::dynamic_pointer_cast<ModelAPI_ResultParameter>(theObject).get()) {
double aValue;
ResultParameterPtr aParam;
if (ModelAPI_Tools::findVariable(theObject->document(), qPrintable(theName), aValue, aParam)) {
- QMessageBox::information(theParent, QObject::tr("Rename parameter"),
- QString(QObject::tr("Selected parameter can not be renamed to: %1. \
-There is a parameter with the same name. Its value is: %2.")).arg(qPrintable(theName)).arg(aValue));
+ QString aErrMsg(QObject::tr("Selected parameter can not be renamed to: %1. \
+ There is a parameter with the same name. Its value is: %2.").arg(qPrintable(theName)).arg(aValue));
+ // We can not use here a dialog box for message - it will crash editing process in ObjectBrowser
+ Events_Error::send(aErrMsg.toStdString());
return false;
}
}
/*!
Check possibility to rename object
- \param theParent a parent widget
\param theObject an object to rename
\param theName a name
*/
-bool canRename(QWidget* theParent, const ObjectPtr& theObject, const QString& theName);
+bool canRename(const ObjectPtr& theObject, const QString& theName);
/*!
Returns true if there are no parts in the document, which are not activated