Open transaction when start editing with context-menu
This commit is contained in:
parent
2c8009cb74
commit
dd67c22837
|
@ -255,7 +255,12 @@ void TreeWidget::onStartEditing()
|
||||||
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
|
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
|
||||||
MDIView *view = doc->getActiveView();
|
MDIView *view = doc->getActiveView();
|
||||||
if (view) getMainWindow()->setActiveWindow(view);
|
if (view) getMainWindow()->setActiveWindow(view);
|
||||||
doc->setEdit(objitem->object(), edit);
|
// open a transaction before starting edit mode
|
||||||
|
std::string cmd("Edit ");
|
||||||
|
cmd += obj->Label.getValue();
|
||||||
|
doc->openCommand(cmd.c_str());
|
||||||
|
bool ok = doc->setEdit(objitem->object(), edit);
|
||||||
|
if (!ok) doc->abortCommand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,6 +273,7 @@ void TreeWidget::onFinishEditing()
|
||||||
App::DocumentObject* obj = objitem->object()->getObject();
|
App::DocumentObject* obj = objitem->object()->getObject();
|
||||||
if (!obj) return;
|
if (!obj) return;
|
||||||
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
|
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
|
||||||
|
doc->commitCommand();
|
||||||
doc->resetEdit();
|
doc->resetEdit();
|
||||||
doc->getDocument()->recompute();
|
doc->getDocument()->recompute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,6 @@ public:
|
||||||
OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent)
|
OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent)
|
||||||
: d(new Private())
|
: d(new Private())
|
||||||
{
|
{
|
||||||
if (!Gui::Command::hasPendingCommand())
|
|
||||||
Gui::Command::openCommand("Edit offset");
|
|
||||||
Gui::Application::Instance->runPythonCode("from FreeCAD import Base");
|
Gui::Application::Instance->runPythonCode("from FreeCAD import Base");
|
||||||
Gui::Application::Instance->runPythonCode("import Part");
|
Gui::Application::Instance->runPythonCode("import Part");
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,7 @@ public:
|
||||||
QString text;
|
QString text;
|
||||||
std::string selection;
|
std::string selection;
|
||||||
Part::Thickness* thickness;
|
Part::Thickness* thickness;
|
||||||
bool edit;
|
Private()
|
||||||
Private() : edit(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~Private()
|
~Private()
|
||||||
|
@ -91,10 +90,6 @@ public:
|
||||||
ThicknessWidget::ThicknessWidget(Part::Thickness* thickness, QWidget* parent)
|
ThicknessWidget::ThicknessWidget(Part::Thickness* thickness, QWidget* parent)
|
||||||
: d(new Private())
|
: d(new Private())
|
||||||
{
|
{
|
||||||
if (!Gui::Command::hasPendingCommand()) {
|
|
||||||
d->edit = true;
|
|
||||||
Gui::Command::openCommand("Edit thickness");
|
|
||||||
}
|
|
||||||
Gui::Application::Instance->runPythonCode("from FreeCAD import Base");
|
Gui::Application::Instance->runPythonCode("from FreeCAD import Base");
|
||||||
Gui::Application::Instance->runPythonCode("import Part");
|
Gui::Application::Instance->runPythonCode("import Part");
|
||||||
|
|
||||||
|
@ -244,19 +239,22 @@ bool ThicknessWidget::reject()
|
||||||
{
|
{
|
||||||
if (d->loop.isRunning())
|
if (d->loop.isRunning())
|
||||||
return false;
|
return false;
|
||||||
// object has been created right before opening this panel
|
|
||||||
if (d->edit == false) {
|
// save this and check if the object is still there after the
|
||||||
App::DocumentObject* source = d->thickness->Faces.getValue();
|
// transaction is aborted
|
||||||
if (source){
|
std::string objname = d->thickness->getNameInDocument();
|
||||||
Gui::Application::Instance->getViewProvider(source)->show();
|
App::DocumentObject* source = d->thickness->Faces.getValue();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// roll back the done things
|
// roll back the done things
|
||||||
Gui::Command::abortCommand();
|
Gui::Command::abortCommand();
|
||||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||||
Gui::Command::updateActive();
|
Gui::Command::updateActive();
|
||||||
|
|
||||||
|
// Thickness object was deleted
|
||||||
|
if (source && !source->getDocument()->getObject(objname.c_str())) {
|
||||||
|
Gui::Application::Instance->getViewProvider(source)->show();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
#include <Base/Exception.h>
|
#include <Base/Exception.h>
|
||||||
#include <App/Application.h>
|
#include <App/Application.h>
|
||||||
#include <App/Document.h>
|
#include <App/Document.h>
|
||||||
|
#include <Gui/Command.h>
|
||||||
#include <Gui/SoFCSelection.h>
|
#include <Gui/SoFCSelection.h>
|
||||||
#include <Gui/Selection.h>
|
#include <Gui/Selection.h>
|
||||||
#include <Gui/View3DInventorViewer.h>
|
#include <Gui/View3DInventorViewer.h>
|
||||||
|
@ -107,6 +108,17 @@ ViewProviderPart::ViewProviderPart()
|
||||||
ViewProviderPart::~ViewProviderPart()
|
ViewProviderPart::~ViewProviderPart()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ViewProviderPart::doubleClicked(void)
|
||||||
|
{
|
||||||
|
std::string Msg("Edit ");
|
||||||
|
Msg += this->pcObject->Label.getValue();
|
||||||
|
Gui::Command::openCommand(Msg.c_str());
|
||||||
|
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.setEdit('%s',0)",
|
||||||
|
this->pcObject->getNameInDocument());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
PROPERTY_SOURCE(PartGui::ViewProviderPart, PartGui::ViewProviderPartBase)
|
PROPERTY_SOURCE(PartGui::ViewProviderPart, PartGui::ViewProviderPartBase)
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,7 @@ public:
|
||||||
ViewProviderPart();
|
ViewProviderPart();
|
||||||
/// destructor
|
/// destructor
|
||||||
virtual ~ViewProviderPart();
|
virtual ~ViewProviderPart();
|
||||||
|
virtual bool doubleClicked(void);
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
class PartGuiExport ViewProviderPart : public ViewProviderPartBase
|
class PartGuiExport ViewProviderPart : public ViewProviderPartBase
|
||||||
|
|
|
@ -45,8 +45,8 @@ ViewProvider::~ViewProvider()
|
||||||
|
|
||||||
bool ViewProvider::doubleClicked(void)
|
bool ViewProvider::doubleClicked(void)
|
||||||
{
|
{
|
||||||
std::string Msg("Change ");
|
std::string Msg("Edit ");
|
||||||
Msg += this->pcObject->getNameInDocument();
|
Msg += this->pcObject->Label.getValue();
|
||||||
Gui::Command::openCommand(Msg.c_str());
|
Gui::Command::openCommand(Msg.c_str());
|
||||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s',0)",this->pcObject->getNameInDocument());
|
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s',0)",this->pcObject->getNameInDocument());
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user