View Issue Details

IDProjectCategoryView StatusLast Update
0015886ScribusScripterpublic2019-12-08 21:24
Reporterale Assigned Toale  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version1.5.6.svn 
Target VersionFixed in Version1.5.6.svn 
Summary0015886: Scripter: Add function to revert doc to last saved state
Descriptionfor a "simple" mail merge script i would need access from the scripter to "file > revert to saved"
TagsNo tags attached.
PatchYes

Activities

ale

2019-10-29 21:25

manager  

script-revert-doc.diff (4,933 bytes)
diff --git a/scribus/plugins/scriptplugin/cmddoc.cpp b/scribus/plugins/scriptplugin/cmddoc.cpp
index 8e2eeedc8..4da95c8eb 100644
--- a/scribus/plugins/scriptplugin/cmddoc.cpp
+++ b/scribus/plugins/scriptplugin/cmddoc.cpp
@@ -193,6 +193,14 @@ PyObject *scribus_savedoc(PyObject* /* self */)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_revertdoc(PyObject* /* self */)
+{
+	if (!checkHaveDocument())
+		return nullptr;
+	ScCore->primaryMainWindow()->slotFileRevert();
+	Py_RETURN_NONE;
+}
+
 PyObject *scribus_getdocname(PyObject* /* self */)
 {
 	if (!checkHaveDocument())
@@ -450,5 +458,5 @@ PV */
 void cmddocdocwarnings()
 {
 	QStringList s;
-	s << scribus_newdocument__doc__ << scribus_newdoc__doc__ <<  scribus_closedoc__doc__ << scribus_havedoc__doc__ << scribus_opendoc__doc__ << scribus_savedoc__doc__ << scribus_getdocname__doc__ << scribus_savedocas__doc__ << scribus_setinfo__doc__ <<scribus_setmargins__doc__ <<scribus_setunit__doc__ <<scribus_getunit__doc__ <<scribus_loadstylesfromfile__doc__ <<scribus_setdoctype__doc__ <<scribus_closemasterpage__doc__ <<scribus_masterpagenames__doc__ <<scribus_editmasterpage__doc__ <<scribus_createmasterpage__doc__ <<scribus_deletemasterpage__doc__ << scribus_setbaseline__doc__ << scribus_getmasterpage__doc__  << scribus_applymasterpage__doc__;
+	s << scribus_newdocument__doc__ << scribus_newdoc__doc__ <<  scribus_closedoc__doc__ << scribus_havedoc__doc__ << scribus_opendoc__doc__ << scribus_savedoc__doc__ << scribus_revertdoc__doc__ << scribus_getdocname__doc__ << scribus_savedocas__doc__ << scribus_setinfo__doc__ <<scribus_setmargins__doc__ <<scribus_setunit__doc__ <<scribus_getunit__doc__ <<scribus_loadstylesfromfile__doc__ <<scribus_setdoctype__doc__ <<scribus_closemasterpage__doc__ <<scribus_masterpagenames__doc__ <<scribus_editmasterpage__doc__ <<scribus_createmasterpage__doc__ <<scribus_deletemasterpage__doc__ << scribus_setbaseline__doc__ << scribus_getmasterpage__doc__  << scribus_applymasterpage__doc__;
 }
diff --git a/scribus/plugins/scriptplugin/cmddoc.h b/scribus/plugins/scriptplugin/cmddoc.h
index a4946fc8c..25207ab0c 100644
--- a/scribus/plugins/scriptplugin/cmddoc.h
+++ b/scribus/plugins/scriptplugin/cmddoc.h
@@ -141,6 +141,14 @@ If the save fails, there is currently no way to tell.\n\
 "));
 PyObject *scribus_savedoc(PyObject * /*self*/);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_revertdoc__doc__,
+QT_TR_NOOP("revertDoc()\n\
+\n\
+Revert the current document to its saved state.\n\
+"));
+PyObject *scribus_revertdoc(PyObject * /*self*/);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_getdocname__doc__,
 QT_TR_NOOP("getDocName() -> string\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 87461a5b9..12d29ff67 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -462,6 +462,7 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("getDocName"), (PyCFunction)scribus_getdocname, METH_NOARGS, tr(scribus_getdocname__doc__)},
 	{const_cast<char*>("saveDocAs"), scribus_savedocas, METH_VARARGS, tr(scribus_savedocas__doc__)},
 	{const_cast<char*>("saveDoc"), (PyCFunction)scribus_savedoc, METH_NOARGS, tr(scribus_savedoc__doc__)},
+	{const_cast<char*>("revertDoc"), (PyCFunction)scribus_revertdoc, METH_NOARGS, tr(scribus_revertdoc__doc__)},
 	{const_cast<char*>("savePageAsEPS"), scribus_savepageeps, METH_VARARGS, tr(scribus_savepageeps__doc__)},
 	{const_cast<char*>("savePDFOptions"), (PyCFunction)scribus_savepdfoptions, METH_VARARGS, tr(scribus_savepdfoptions__doc__)},
 	{const_cast<char*>("scaleGroup"), scribus_scalegroup, METH_VARARGS, tr(scribus_scalegroup__doc__)},
diff --git a/scribus/scribus.cpp b/scribus/scribus.cpp
index 0aab3ad00..e9f5c71fa 100644
--- a/scribus/scribus.cpp
+++ b/scribus/scribus.cpp
@@ -4137,13 +4137,16 @@ void ScribusMainWindow::slotFileRevert()
 	if ((doc->hasName) && (doc->isModified()) && (!doc->masterPageMode()) && (!doc->isConverted))
 	{
 		ScribusWin* tw = ActWin;
-		int t = ScMessageBox::warning(this, CommonStrings::trWarning, "<qt>" +
-								 QObject::tr("The changes to your document have not been saved and you have requested to revert them. Do you wish to continue?") + "</qt>",
-								 QMessageBox::Yes | QMessageBox::No,
-								 QMessageBox::No,	// GUI default
-								 QMessageBox::Yes);	// batch default
-		if (t == QMessageBox::No)
-			return;
+		if (!scriptIsRunning())
+		{
+			int t = ScMessageBox::warning(this, CommonStrings::trWarning, "<qt>" +
+									 QObject::tr("The changes to your document have not been saved and you have requested to revert them. Do you wish to continue?") + "</qt>",
+									 QMessageBox::Yes | QMessageBox::No,
+									 QMessageBox::No,	// GUI default
+									 QMessageBox::Yes);	// batch default
+			if (t == QMessageBox::No)
+				return;
+		}
 
 		mdiArea->setActiveSubWindow(tw->getSubWin());
 		ActWin = tw;
script-revert-doc.diff (4,933 bytes)

ale

2019-11-12 07:28

manager   ~0047050

any news?

Issue History

Date Modified Username Field Change
2019-10-29 21:10 ale New Issue
2019-10-29 21:25 ale Summary Scripter: revert to saved => [PATCH] Scripter: revert to saved
2019-10-29 21:25 ale Patch No => Yes
2019-10-29 21:25 ale File Added: script-revert-doc.diff
2019-11-12 07:28 ale Note Added: 0047050
2019-11-26 11:48 jghali Summary [PATCH] Scripter: revert to saved => Scripter: Add function to revert doc to last saved state
2019-11-26 14:11 jghali Assigned To => ale
2019-11-26 14:11 jghali Status new => resolved
2019-11-26 14:11 jghali Resolution open => fixed
2019-11-26 14:11 jghali Fixed in Version => 1.5.6.svn
2019-12-08 21:24 cbradney Status resolved => closed