Skip to content

Commit

Permalink
+ when trying to close a document then do it even if a task dialog is…
Browse files Browse the repository at this point in the history
… open
  • Loading branch information
wwmayer committed Nov 9, 2015
1 parent 9d856fb commit d3280a0
Showing 1 changed file with 46 additions and 33 deletions.
79 changes: 46 additions & 33 deletions src/Gui/Document.cpp
Expand Up @@ -1139,42 +1139,55 @@ bool Document::canClose ()
QObject::tr("The document is not closable for the moment."));
return false;
}
else if (!Gui::Control().isAllowedAlterDocument()) {
std::string name = Gui::Control().activeDialog()->getDocumentName();
if (name == this->getDocument()->getName()) {
QMessageBox::warning(getActiveView(),
QObject::tr("Document not closable"),
QObject::tr("The document is in editing mode and thus cannot be closed for the moment.\n"
"You either have to finish or cancel the editing in the task panel."));
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
if (dlg) Gui::Control().showDialog(dlg);
return false;
//else if (!Gui::Control().isAllowedAlterDocument()) {
// std::string name = Gui::Control().activeDialog()->getDocumentName();
// if (name == this->getDocument()->getName()) {
// QMessageBox::warning(getActiveView(),
// QObject::tr("Document not closable"),
// QObject::tr("The document is in editing mode and thus cannot be closed for the moment.\n"
// "You either have to finish or cancel the editing in the task panel."));
// Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
// if (dlg) Gui::Control().showDialog(dlg);
// return false;
// }
//}

bool ok = true;
if (isModified()) {
QMessageBox box(getActiveView());
box.setIcon(QMessageBox::Question);
box.setWindowTitle(QObject::tr("Unsaved document"));
box.setText(QObject::tr("Do you want to save your changes to document '%1' before closing?")
.arg(QString::fromUtf8(getDocument()->Label.getValue())));
box.setInformativeText(QObject::tr("If you don't save, your changes will be lost."));
box.setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel | QMessageBox::Save);
box.setDefaultButton(QMessageBox::Save);

switch (box.exec())
{
case QMessageBox::Save:
ok = save();
break;
case QMessageBox::Discard:
ok = true;
break;
case QMessageBox::Cancel:
ok = false;
break;
}
}

if (!isModified())
return true;
bool ok = true;
QMessageBox box(getActiveView());
box.setIcon(QMessageBox::Question);
box.setWindowTitle(QObject::tr("Unsaved document"));
box.setText(QObject::tr("Do you want to save your changes to document '%1' before closing?")
.arg(QString::fromUtf8(getDocument()->Label.getValue())));
box.setInformativeText(QObject::tr("If you don't save, your changes will be lost."));
box.setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel | QMessageBox::Save);
box.setDefaultButton(QMessageBox::Save);

switch (box.exec())
{
case QMessageBox::Save:
ok = save();
break;
case QMessageBox::Discard:
ok = true;
break;
case QMessageBox::Cancel:
ok = false;
break;
if (ok) {
// If a tsk dialog is open that doesn't allow other commands to modify
// the document it must be closed by resetting the edit mode of the
// corresponding view provider.
if (!Gui::Control().isAllowedAlterDocument()) {
std::string name = Gui::Control().activeDialog()->getDocumentName();
if (name == this->getDocument()->getName()) {
if (this->getInEdit())
this->resetEdit();
}
}
}

return ok;
Expand Down

0 comments on commit d3280a0

Please sign in to comment.