Skip to content

Commit

Permalink
Command: disable auto transaction if triggering editing
Browse files Browse the repository at this point in the history
Each command will create an App::AutoTransaction to auto create and
commit a transaction for proper undo/redo. But if the command starts
editing, the current transaction may be required to out live the current
command.

Note that the command can only detect editing if the code calls
Gui::Document::setEdit(). There are objects that starts editing by
calling its own ViewProvider::setEdit(), e.g. various TechDraw
ViewProviders. In this case, to avoid auto committing, one can call
App::Application::setActiveTransaction() with the second argument set to
true, or call App::AutoTransaction::setEnable(false).
  • Loading branch information
realthunder authored and wwmayer committed Aug 17, 2019
1 parent 78ce18a commit d0ca893
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/App/Application.cpp
Expand Up @@ -938,8 +938,11 @@ int Application::setActiveTransaction(const char *name, bool persist) {
FC_LOG("transaction rename to '" << name << "'");
for(auto &v : DocMap)
v.second->renameTransaction(name,_activeTransactionID);
}else
} else {
if(persist)
AutoTransaction::setEnable(false);
return 0;
}
}else{
FC_LOG("set active transaction '" << name << "'");
_activeTransactionID = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/Gui/Command.cpp
Expand Up @@ -394,6 +394,7 @@ void Command::invoke(int i, TriggerSource trigger)
// check if it really works NOW (could be a delay between click deactivation of the button)
if (isActive()) {
auto manager = getGuiApplication()->macroManager();
auto editDoc = getGuiApplication()->editDocument();
if(!disabler)
activated( i );
else {
Expand Down Expand Up @@ -426,6 +427,10 @@ void Command::invoke(int i, TriggerSource trigger)
}
}
getMainWindow()->updateActions();

// If this command starts an editing, let the transaction persist
if(!editDoc && getGuiApplication()->editDocument())
committer.setEnable(false);
}
}
catch (const Base::SystemExitException&) {
Expand Down
5 changes: 5 additions & 0 deletions src/Gui/Tree.cpp
Expand Up @@ -1304,6 +1304,7 @@ void TreeWidget::mouseDoubleClickEvent (QMouseEvent * event)
objitem->getOwnerDocument()->document()->setActiveView(objitem->object());
auto manager = Application::Instance->macroManager();
auto lines = manager->getLines();
auto editDoc = Application::Instance->editDocument();
App::AutoTransaction committer("Double click", true);
std::ostringstream ss;
ss << Command::getObjectCmd(objitem->object()->getObject())
Expand All @@ -1312,6 +1313,10 @@ void TreeWidget::mouseDoubleClickEvent (QMouseEvent * event)
QTreeWidget::mouseDoubleClickEvent(event);
else if(lines == manager->getLines())
manager->addLine(MacroManager::Gui,ss.str().c_str());

// If the double click starts an editing, let the transaction persist
if(!editDoc && Application::Instance->editDocument())
committer.setEnable(false);
}
}

Expand Down

0 comments on commit d0ca893

Please sign in to comment.