r23380 by jghali - #15886: Scripter: add function to revert doc to last saved state (ale)

scribus-commit scribus-commit at lists.scribus.net
Tue Nov 26 11:50:13 UTC 2019


Author: jghali
Date: Tue Nov 26 11:50:13 2019
New Revision: 23380

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23380
Log:
#15886: Scripter: add function to revert doc to last saved state (ale)

Modified:
    trunk/Scribus/doc/de/scripterapi-doc.html
    trunk/Scribus/doc/en/scripterapi-doc.html
    trunk/Scribus/doc/fr/scripterapi-doc.html
    trunk/Scribus/doc/it/scripterapi-doc.html
    trunk/Scribus/doc/ru/scripterapi-doc.html
    trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.h
    trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
    trunk/Scribus/scribus/scribus.cpp

Modified: trunk/Scribus/doc/de/scripterapi-doc.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/doc/de/scripterapi-doc.html
==============================================================================
--- trunk/Scribus/doc/de/scripterapi-doc.html	(original)
+++ trunk/Scribus/doc/de/scripterapi-doc.html	Tue Nov 26 11:50:13 2019
@@ -30,11 +30,17 @@
 
 <dt><a name="-getUnit"><strong>getUnit</strong></a>(...)</dt>
 <dd><code>getUnit() -> integer (Scribus unit constant)</code>
-<p>Returns the measurement units of the document. The returned value will be one of the UNIT_* constants: UNIT_INCHES, UNIT_MILLIMETERS, UNIT_PICAS, UNIT_POINTS.</p></dd>
+<p>Returns the measurement units of the document. The returned value will be one of the UNIT_* constants: UNIT_INCHES, UNIT_MILLIMETERS, UNIT_PICAS, UNIT_POINTS.</p>
+<p>Typically you may use this command so that you can change the measurement units to something else, for which you are creating or modifying objects based some particular units, like points, after which you want to return to whatever the original units were.</p><p><b>original = getUnit()</b></p>
+<p><i>do some operations...then later</i></p>
+<p><b>setUnit(original)</b></p>
+</dd>
 
 <dt><a name="-haveDoc"><strong>haveDoc</strong></a>(...)</dt>
 <dd><code>haveDoc() -> bool</code>
-<p>Returns true if there is a document open.</p></dd>
+<p>Returns true if there is a document open. Since this returns a boolean, typically this will be used in a conditional clause:</p>
+<p><b>if haveDoc():</b></p>
+<p>so that you can deal with the situation where no document exists with an <b>else:</b> clause.</p></dd>
 
 <!--<dt><a name="-importSVG"><strong>importSVG</strong>(...)</a></dt>
 <dd><code>importSVG("string")</code>
@@ -50,7 +56,7 @@
 
 <dt><a name="-newDoc"><strong>newDoc</strong></a>(...)</dt>
 <dd><code>newDoc(size, margins, orientation, firstPageNumber, unit, facingPages, firstSideLeft) -> bool</code>
-<p>WARNING: Obsolete procedure! Use <a href="#-newDocument">newDocument</a> instead.</p>
+<p>WARNING: Obsolete procedure! Use <a href="#-newDocument">newDocument</a> instead. Also note that this commands requires 7 parameters, whereas the preferred <b>newDocument()</b> command requires 8.</p>
 <p>Creates a new document and returns true if successful. The parameters have the
 following meaning:</p>
 <ul>
@@ -62,12 +68,13 @@
 	<li>facingPages = FACINGPAGES, NOFACINGPAGES</li>
 	<li>firstSideLeft = FIRSTPAGELEFT, FIRSTPAGERIGHT</li>
 	</ul>
-<p>The values for width, height and the margins are expressed in the given unit for the document. PAPER_* constants are expressed in points. If your document is not in points, make sure to account for this.</p>
+<p>The values for width, height and the margins are expressed in the given unit for the document. PAPER_* constants are a series of tuples specific to the document size, with the values corresponding to points. Therefore, if you are creating a document and using UNIT_MILLIMETERS for example, DO NOT USE the PAPER_* constants. A workaround can be to use the PAPER_* constant along with UNIT_POINTS, then follow the command with another command, setUnit(UNIT_MILLIMETERS).</p>
 <p>example: <a href="#-newDoc">newDoc</a>(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 1, UNIT_POINTS, FACINGPAGES, FIRSTPAGERIGHT)</p></dd>
 
 <dt><a name="-newDocument"><strong>newDocument</strong>(...)</a></dt>
 <dd><code>newDocument(size, margins, orientation, firstPageNumber,
                         unit, pagesType, firstPageOrder, numPages) -> bool</code>
+<p>Note that this commands requires 8 parameters, whereas the obsolete <b>newDoc()</b> command required 7. The additional parameter indicates how many pages to create.</p>
 <p>Creates a new document and returns true if successful. The parameters have the
 following meaning:
 <ul>
@@ -90,10 +97,11 @@
 <li>numPage = Number of pages to be created.</li>
 </ul>
 <p>The values for width, height and the margins are expressed in the given unit
-for the document. PAPER_* constants are expressed in points. If your document
-is not in points, make sure to account for this.</p>
-<p>example: newDocument(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 7, UNIT_POINTS,
-PAGE_4, 3, 1)</p>
+for the document. PAPER_* constants are a series of tuples specific to the document size, with the values corresponding to points. Therefore, if you are creating a document and using UNIT_MILLIMETERS for example, DO NOT USE the PAPER_* constants.</p>
+<p>For A and B paper formats there are now new constants to use with UNIT_MILLIMETERS, named for example, PAPER_A4_MM, or PAPER_B6_MM.</p>
+<p>Examples:</p>
+<p><b>newDocument(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 7, UNIT_POINTS, PAGE_4, 3, 1)</b></p>
+<p><b>newDocument(PAPER_A4_MM, (10, 10, 20, 20), LANDSCAPE, 7, UNIT_MILLIMETERS, PAGE_4, 3, 1)</b></p>
 <p>May raise ScribusError if is firstPageOrder bigger than allowed by pagesType.</p>
 </dd>
 
@@ -103,32 +111,38 @@
 <p>May raise ScribusError if the document could not be opened.</p></dd>
 
 <dt><a name="-placeEPS"><strong>placeEPS</strong>(...)</a></dt>
-<dd><code></code>
-<p>placeEPS("filename", x, y) Places the EPS "filename" onto the current
-page, x and y specify the coordinate of the topleft corner of the EPS
-placed on the page If loading was successful, the selection contains
-the imported EPS</p></dd>
+<dd><code>placeEPS("filename", x, y)</code>
+<p>Places the EPS "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the EPS placed on the page.</p>
+<p>If loading was successful, the selection contains the imported EPS.</p></dd>
 
 <dt><a name="-placeODG"><strong>placeODG</strong>(...)</a></dt>
-<dd><code></code>
-<p>placeODG("filename", x, y) Places the ODG "filename" onto the current
-page, x and y specify the coordinate of the topleft corner of the ODG
-placed on the page If loading was successful, the selection contains
-the imported ODG</p></dd>
+<dd><code>placeODG("filename", x, y)</code>
+<p>Places the ODG "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the ODG placed on the page.</p>
+<p>If loading was successful, the selection contains the imported ODG.</p></dd>
 
 <dt><a name="-placeSVG"><strong>placeSVG</strong>(...)</a></dt>
-<dd><code></code>
-<p>placeSVG("filename", x, y) Places the SVG "filename" onto the current
-page, x and y specify the coordinate of the topleft corner of the SVG
-placed on the page If loading was successful, the selection contains
-the imported SVG</p></dd>
+<dd><code>placeSVG("filename", x, y)</code>
+<p>Places the SVG "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the SVG placed on the page.</p>
+<p>If loading was successful, the selection contains the imported SVG.</p></dd>
 
 <dt><a name="-placeSXD"><strong>placeSXD</strong>(...)</a></dt>
-<dd><code></code>
-<p>placeSXD("filename", x, y) Places the SXD "filename" onto the current
-page, x and y specify the coordinate of the topleft corner of the SXD
-placed on the page If loading was successful, the selection contains
-the imported SXD</p></dd>
+<dd><code>placeSXD("filename", x, y)</code>
+<p>Places the SXD "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the SXD placed on the page.</p>
+<p>If loading was successful, the selection contains the imported SXD.</p></dd>
+
+<dt><a name="-placeVectorFile"><strong>placeVectorFile</strong>(...)</a></dt>
+<dd><code>placeVectorFile("filename", x, y)</code>
+<p>Places the vector graphics "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the graphic placed on the page.</p>
+<p>If loading was successful, the selection contains the imported graphic.</p></dd>
+
+<dt><a name="-revertDoc"><strong>revertDoc</strong></a>(...)</dt>
+<dd><code>revertDoc()</code>
+<p>Revert the current document to its last saved state.</p></dd>
 
 <dt><a name="-saveDoc"><strong>saveDoc</strong></a>(...)</dt>
 <dd><code>saveDoc()</code>
@@ -155,7 +169,10 @@
 <dt><a name="-setUnit"><strong>setUnit</strong></a>(...)</dt>
 <dd><code>setUnit(type)</code>
 <p>Changes the measurement unit of the document. Possible values for "unit" are defined as constants UNIT_<type>.</p>
-<p>May raise ValueError if an invalid unit is passed.</p></dd>
+<p>May raise ValueError if an invalid unit is passed.</p>
+<p>As noted above, typically you may use this command so that you can change the measurement units to something else, for which you are creating or modifying objects based some particular units, like points, after which you want to return to whatever the original units were.</p><p><b>original = getUnit()</b></p>
+<p><i>do some operations...then later</i></p>
+<p><b>setUnit(original)</b></p></dd>
 
 <dt><a name="-setBaseLine"><strong>setBaseLine</strong></a>(...)</dt>
 <dd><code>setBaseLine(grid, offset)</code>

Modified: trunk/Scribus/doc/en/scripterapi-doc.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/doc/en/scripterapi-doc.html
==============================================================================
--- trunk/Scribus/doc/en/scripterapi-doc.html	(original)
+++ trunk/Scribus/doc/en/scripterapi-doc.html	Tue Nov 26 11:50:13 2019
@@ -140,6 +140,10 @@
 of the topleft corner of the graphic placed on the page.</p>
 <p>If loading was successful, the selection contains the imported graphic.</p></dd>
 
+<dt><a name="-revertDoc"><strong>revertDoc</strong></a>(...)</dt>
+<dd><code>revertDoc()</code>
+<p>Revert the current document to its last saved state.</p></dd>
+
 <dt><a name="-saveDoc"><strong>saveDoc</strong></a>(...)</dt>
 <dd><code>saveDoc()</code>
 <p>Saves the current document with its current name, returns true if successful. If the document has not already been saved, this may bring up an interactive save file dialog. If the save fails, there is currently no way to tell.</p></dd>

Modified: trunk/Scribus/doc/fr/scripterapi-doc.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/doc/fr/scripterapi-doc.html
==============================================================================
--- trunk/Scribus/doc/fr/scripterapi-doc.html	(original)
+++ trunk/Scribus/doc/fr/scripterapi-doc.html	Tue Nov 26 11:50:13 2019
@@ -78,7 +78,41 @@
 <dd><code>openDoc("nom")</code>
 <p>Ouvre le document "nom".</p>
 <p>Peut générer ScribusError si le document ne peut pas être ouvert.</p></dd>
-	
+
+<dt><a name="-placeEPS"><strong>placeEPS</strong>(...)</a></dt>
+<dd><code>placeEPS("nomFichier", x, y)</code>
+<p>Importe le fichier EPS "nomFichier" vers la page courante, x et y étant les coordonnées du bord supérieure gauche
+du fichier EPS une fois placé sur la page.</p>
+<p>Si l'opération se termine avec succès, la sélection contiendra le fichier EPS importé.</p></dd>
+
+<dt><a name="-placeODG"><strong>placeODG</strong>(...)</a></dt>
+<dd><code>placeODG("nomFichier", x, y)</code>
+<p>Importe le fichier ODG "nomFichier" vers la page courante, x et y étant les coordonnées du bord supérieure gauche
+du fichier ODG une fois placé sur la page.</p>
+<p>Si l'opération se termine avec succès, la sélection contiendra le fichier ODG importé.</p></dd>
+
+<dt><a name="-placeSVG"><strong>placeSVG</strong>(...)</a></dt>
+<dd><code>placeSVG("nomFichier", x, y)</code>
+<p>Importe le fichier SVG "nomFichier" vers la page courante, x et y étant les coordonnées du bord supérieure gauche
+du fichier SVG une fois placé sur la page.</p>
+<p>Si l'opération se termine avec succès, la sélection contiendra le fichier SVG importé.</p></dd>
+
+<dt><a name="-placeSXD"><strong>placeSXD</strong>(...)</a></dt>
+<dd><code>placeSXD("nomFichier", x, y)</code>
+<p>Importe le fichier SXD "nomFichier" vers la page courante, x et y étant les coordonnées du bord supérieure gauche
+du fichier SXD une fois placé sur la page.</p>
+<p>Si l'opération se termine avec succès, la sélection contiendra le fichier SXD importé.</p></dd>
+
+<dt><a name="-placeVectorFile"><strong>placeVectorFile</strong>(...)</a></dt>
+<dd><code>placeVectorFile("nomFichier", x, y)</code>
+<p>Importe le fichier vectoriel "nomFichier" vers la page courante, x et y étant les coordonnées du bord supérieure gauche
+du fichier vectoriel une fois placé sur la page.</p>
+<p>Si l'opération se termine avec succès, la sélection contiendra le fichier vectoriel importé.</p></dd>
+
+<dt><a name="-revertDoc"><strong>revertDoc</strong></a>(...)</dt>
+<dd><code>revertDoc()</code>
+<p>Restaure le document à l'état de sa dernière sauvergarde.</p></dd>
+
 <dt><a name="-saveDoc"><strong>saveDoc</strong></a>(...)</dt>
 <dd><code>saveDoc()</code>
 <p>Enregistre le document ouvert sous son nom courant, et retourne la valeur True si l'opération réussit. Si le document n'a pas déjà été enregistré, le système peut afficher le dialogue interactif Enregistrer sous.Si l'enregistrement échoue, il n'y a actuellement aucun moyen de le savoir.</p></dd>

Modified: trunk/Scribus/doc/it/scripterapi-doc.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/doc/it/scripterapi-doc.html
==============================================================================
--- trunk/Scribus/doc/it/scripterapi-doc.html	(original)
+++ trunk/Scribus/doc/it/scripterapi-doc.html	Tue Nov 26 11:50:13 2019
@@ -1,162 +1,192 @@
-<html>
-<head>
-	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
-	<title>Document related Commands</title>
-</head>
-<body>
-<h2>Document related Commands</h2>
-
-<dl>
-
-<dt><a name="-closeDoc"><strong>closeDoc</strong></a>(...)</dt>
-<dd><code>closeDoc()</code>
-<p>Closes the current document without prompting to save.</p>
-<p>May throw <a href="#NoDocOpenError">NoDocOpenError</a> if there is no document to close</p></dd>
-
-<dt><a name="-docChanged"><strong>docChanged</strong></a>(...)</dt>
-<dd><code>docChanged(bool)</code>
-<p>Enable/disable save icon in the Scribus icon bar and the Save menu item. It's
-useful to call this procedure when you're changing the document, because Scribus
-won't automatically notice when you change the document using a script.</p></dd>
-
-<dt><a name="-getUnit"><strong>getUnit</strong></a>(...)</dt>
-<dd><code>getUnit() -> integer (Scribus unit constant)</code>
-<p>Returns the measurement units of the document. The returned value will be one of the UNIT_* constants: UNIT_INCHES, UNIT_MILLIMETERS, UNIT_PICAS, UNIT_POINTS.</p></dd>
-
-<dt><a name="-haveDoc"><strong>haveDoc</strong></a>(...)</dt>
-<dd><code>haveDoc() -> bool</code>
-<p>Returns true if there is a document open.</p></dd>
-
-<!--<dt><a name="-importSVG"><strong>importSVG</strong>(...)</a></dt>
-<dd><code>importSVG("string")</code>
-<p>The "string" must be a valid filename for a SVG image. The text must be UTF8 encoded or 'unicode' string(recommended).</p></dd> -->
-
-<dt><a name="-loadStylesFromFile"><strong>loadStylesFromFile</strong></a>(...)</dt>
-<dd><code>loadStylesFromFile("filename")</code>
-<p>Loads paragraph styles from the Scribus document at "filename" into the current document.</p></dd>
-
-<dt><a name="-masterPageNames"><strong>masterPageNames</strong>(...)</a></dt>
-<dd><code>masterPageNames()</code>
-<p>Returns a list of the names of all master pages in the document.</p></dd>
-
-<dt><a name="-newDoc"><strong>newDoc</strong></a>(...)</dt>
-<dd><code>newDoc(size, margins, orientation, firstPageNumber, unit, facingPages, firstSideLeft) -> bool</code>
-<p>WARNING: Obsolete procedure! Use <a href="#-newDocument">newDocument</a> instead.</p>
-<p>Creates a new document and returns true if successful. The parameters have the
-following meaning:</p>
-<ul>
-	<li>size = A tuple (width, height) describing the size of the document. You can use predefined constants named PAPER_<paper_type> e.g. PAPER_A4 etc.</li>
-	<li>margins = A tuple (left, right, top, bottom) describing the document margins</li>
-	<li>orientation = the page orientation - constants PORTRAIT, LANDSCAPE</li>
-	<li>firstPageNumber = is the number of the first page in the document used for page numbering. While you'll usually want 1, it's useful to have higher numbers if you're creating a document in several parts.</li>
-	<li>unit: this value sets the measurement units used by the document. Use a predefined constant for this, one of: UNIT_INCHES, UNIT_MILLIMETERS, UNIT_PICAS, UNIT_POINTS.</li>
-	<li>facingPages = FACINGPAGES, NOFACINGPAGES</li>
-	<li>firstSideLeft = FIRSTPAGELEFT, FIRSTPAGERIGHT</li>
-	</ul>
-<p>The values for width, height and the margins are expressed in the given unit for the document. PAPER_* constants are expressed in points. If your document is not in points, make sure to account for this.</p>
-<p>example: <a href="#-newDoc">newDoc</a>(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 1, UNIT_POINTS, FACINGPAGES, FIRSTPAGERIGHT)</p></dd>
-
-<dt><a name="-newDocument"><strong>newDocument</strong>(...)</a></dt>
-<dd><code>newDocument(size, margins, orientation, firstPageNumber,
-                        unit, pagesType, firstPageOrder, numPages) -> bool</code>
-<p>Creates a new document and returns true if successful. The parameters have the
-following meaning:
-<ul>
-<li>size = A tuple (width, height) describing the size of the document. You can
-use predefined constants named PAPER_<paper_type> e.g. PAPER_A4 etc.</li>
-<li>margins = A tuple (left, right, top, bottom) describing the document
-margins</li>
-<li>orientation = the page orientation - constants PORTRAIT, LANDSCAPE</li>
-<li>firstPageNumer = is the number of the first page in the document used for
-pagenumbering. While you'll usually want 1, it's useful to have higher
-numbers if you're creating a document in several parts.</li>
-<li>unit: this value sets the measurement units used by the document. Use a
-predefined constant for this, one of: UNIT_INCHES, UNIT_MILLIMETERS,
-UNIT_PICAS, UNIT_POINTS.</li>
-<li>pagesType = One of the predefined constants PAGE_n. PAGE_1 is single page,
-PAGE_2 is for double sided documents, PAGE_3 is for 3 pages fold and
-PAGE_4 is 4-fold.</li>
-<li>firstPageOrder = What is position of first page in the document.
-Indexed from 0 (0 = first).</li>
-<li>numPage = Number of pages to be created.</li>
-</ul>
-<p>The values for width, height and the margins are expressed in the given unit
-for the document. PAPER_* constants are expressed in points. If your document
-is not in points, make sure to account for this.</p>
-<p>example: newDocument(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 7, UNIT_POINTS,
-PAGE_4, 3, 1)</p>
-<p>May raise ScribusError if is firstPageOrder bigger than allowed by pagesType.</p>
-</dd>
-
-<dt><a name="-openDoc"><strong>openDoc</strong></a>(...)</dt>
-<dd><code>openDoc("name")</code>
-<p>Opens the document "name".</p>
-<p>May raise ScribusError if the document could not be opened.</p></dd>
-
-<dt><a name="-placeEPS"><strong>placeEPS</strong>(...)</a></dt>
-<dd><code></code>
-<p>placeEPS("filename", x, y) Places the EPS "filename" onto the current
-page, x and y specify the coordinate of the topleft corner of the EPS
-placed on the page If loading was successful, the selection contains
-the imported EPS</p></dd>
-
-<dt><a name="-placeODG"><strong>placeODG</strong>(...)</a></dt>
-<dd><code></code>
-<p>placeODG("filename", x, y) Places the ODG "filename" onto the current
-page, x and y specify the coordinate of the topleft corner of the ODG
-placed on the page If loading was successful, the selection contains
-the imported ODG</p></dd>
-
-<dt><a name="-placeSVG"><strong>placeSVG</strong>(...)</a></dt>
-<dd><code></code>
-<p>placeSVG("filename", x, y) Places the SVG "filename" onto the current
-page, x and y specify the coordinate of the topleft corner of the SVG
-placed on the page If loading was successful, the selection contains
-the imported SVG</p></dd>
-
-<dt><a name="-placeSXD"><strong>placeSXD</strong>(...)</a></dt>
-<dd><code></code>
-<p>placeSXD("filename", x, y) Places the SXD "filename" onto the current
-page, x and y specify the coordinate of the topleft corner of the SXD
-placed on the page If loading was successful, the selection contains
-the imported SXD</p></dd>
-
-<dt><a name="-saveDoc"><strong>saveDoc</strong></a>(...)</dt>
-<dd><code>saveDoc()</code>
-<p>Saves the current document with its current name, returns true if successful. If the document has not already been saved, this may bring up an interactive save file dialog. If the save fails, there is currently no way to tell.</p></dd>
-
-<dt><a name="-saveDocAs"><strong>saveDocAs</strong></a>(...)</dt>
-<dd><code>saveDocAs("name")</code>
-<p>Saves the current document under the new name "name" (which may be a full or
-relative path).</p>
-<p>May raise ScribusError if the save fails.</p></dd>
-
-<dt><a name="-setInfo"><strong>setInfo</strong></a>(...)</dt>
-<dd><code>setInfo("author", "info", "description") -> bool</code>
-<p>Sets the document information. "Author", "Info", "Description" are strings.</p></dd>
-
-<dt><a name="-setMargins"><strong>setMargins</strong></a>(...)</dt>
-<dd><code>setMargins(lr, rr, tr, br)</code>
-<p>Sets the margins of the document, Left(lr), Right(rr), Top(tr) and Bottom(br) margins are given in the measurement units of the document - see UNIT_<type> constants.</p></dd>
-
-<dt><a name="-setDocType"><strong>setDocType</strong></a>(...)</dt>
-<dd><code>setDocType(facingPages, firstPageLeft)</code>
-<p>Sets the document type. To get facing pages set the first parameter to FACINGPAGES, to switch facingPages off use NOFACINGPAGES instead. If you want to be the first page a left side set the second parameter to FIRSTPAGELEFT, for a right page use FIRSTPAGERIGHT.</p></dd>
-
-<dt><a name="-setUnit"><strong>setUnit</strong></a>(...)</dt>
-<dd><code>setUnit(type)</code>
-<p>Changes the measurement unit of the document. Possible values for "unit" are defined as constants UNIT_<type>.</p>
-<p>May raise ValueError if an invalid unit is passed.</p></dd>
-
-<dt><a name="-scrollDocument"><strong>scrollDocument</strong>(...)</a></dt>
-<dd><code>scrollDocument(x,y)</code>
-<p>Scroll the document in main GUI window by x and y.</p></dd>
-
-<dt><a name="-zoomDocument"><strong>zoomDocument</strong>(...)</a></dt>
-<dd><code>zoomDocument(double)</code>
-<p>Zoom the document in main GUI window. Actions have whole number
-values like 20.0, 100.0, etc. Zoom to Fit uses -100 as a marker.</p></dd>
-
-</dl>
-</body>
-</html>
+<html>
+<head>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+	<title>Document related Commands</title>
+</head>
+<style>
+ at import "manual.css";
+</style>
+<body>
+<h2>Document related Commands</h2>
+
+<dl>
+
+<dt><a name="-closeDoc"><strong>closeDoc</strong></a>(...)</dt>
+<dd><code>closeDoc()</code>
+<p>Closes the current document without prompting to save.</p>
+<p>May throw <a href="#NoDocOpenError">NoDocOpenError</a> if there is no document to close</p></dd>
+
+<dt><a name="-docChanged"><strong>docChanged</strong></a>(...)</dt>
+<dd><code>docChanged(bool)</code>
+<p>Enable/disable save icon in the Scribus icon bar and the Save menu item. It's
+useful to call this procedure when you're changing the document, because Scribus
+won't automatically notice when you change the document using a script.</p></dd>
+
+<dt><a name="-getDocName"><strong>getDocName</strong>(...)</dt>
+<dd><code>getDocName() -> string</code>
+<p>Returns the name of current file</p>
+</dd>
+</dt>
+
+<dt><a name="-getUnit"><strong>getUnit</strong></a>(...)</dt>
+<dd><code>getUnit() -> integer (Scribus unit constant)</code>
+<p>Returns the measurement units of the document. The returned value will be one of the UNIT_* constants: UNIT_INCHES, UNIT_MILLIMETERS, UNIT_PICAS, UNIT_POINTS.</p>
+<p>Typically you may use this command so that you can change the measurement units to something else, for which you are creating or modifying objects based some particular units, like points, after which you want to return to whatever the original units were.</p><p><b>original = getUnit()</b></p>
+<p><i>do some operations...then later</i></p>
+<p><b>setUnit(original)</b></p>
+</dd>
+
+<dt><a name="-haveDoc"><strong>haveDoc</strong></a>(...)</dt>
+<dd><code>haveDoc() -> bool</code>
+<p>Returns true if there is a document open. Since this returns a boolean, typically this will be used in a conditional clause:</p>
+<p><b>if haveDoc():</b></p>
+<p>so that you can deal with the situation where no document exists with an <b>else:</b> clause.</p></dd>
+
+<!--<dt><a name="-importSVG"><strong>importSVG</strong>(...)</a></dt>
+<dd><code>importSVG("string")</code>
+<p>The "string" must be a valid filename for a SVG image. The text must be UTF8 encoded or 'unicode' string(recommended).</p></dd> -->
+
+<dt><a name="-loadStylesFromFile"><strong>loadStylesFromFile</strong></a>(...)</dt>
+<dd><code>loadStylesFromFile("filename")</code>
+<p>Loads paragraph styles from the Scribus document at "filename" into the current document.</p></dd>
+
+<dt><a name="-masterPageNames"><strong>masterPageNames</strong>(...)</a></dt>
+<dd><code>masterPageNames()</code>
+<p>Returns a list of the names of all master pages in the document.</p></dd>
+
+<dt><a name="-newDoc"><strong>newDoc</strong></a>(...)</dt>
+<dd><code>newDoc(size, margins, orientation, firstPageNumber, unit, facingPages, firstSideLeft) -> bool</code>
+<p>WARNING: Obsolete procedure! Use <a href="#-newDocument">newDocument</a> instead. Also note that this commands requires 7 parameters, whereas the preferred <b>newDocument()</b> command requires 8.</p>
+<p>Creates a new document and returns true if successful. The parameters have the
+following meaning:</p>
+<ul>
+	<li>size = A tuple (width, height) describing the size of the document. You can use predefined constants named PAPER_<paper_type> e.g. PAPER_A4 etc.</li>
+	<li>margins = A tuple (left, right, top, bottom) describing the document margins</li>
+	<li>orientation = the page orientation - constants PORTRAIT, LANDSCAPE</li>
+	<li>firstPageNumber = is the number of the first page in the document used for page numbering. While you'll usually want 1, it's useful to have higher numbers if you're creating a document in several parts.</li>
+	<li>unit: this value sets the measurement units used by the document. Use a predefined constant for this, one of: UNIT_INCHES, UNIT_MILLIMETERS, UNIT_PICAS, UNIT_POINTS.</li>
+	<li>facingPages = FACINGPAGES, NOFACINGPAGES</li>
+	<li>firstSideLeft = FIRSTPAGELEFT, FIRSTPAGERIGHT</li>
+	</ul>
+<p>The values for width, height and the margins are expressed in the given unit for the document. PAPER_* constants are a series of tuples specific to the document size, with the values corresponding to points. Therefore, if you are creating a document and using UNIT_MILLIMETERS for example, DO NOT USE the PAPER_* constants. A workaround can be to use the PAPER_* constant along with UNIT_POINTS, then follow the command with another command, setUnit(UNIT_MILLIMETERS).</p>
+<p>example: <a href="#-newDoc">newDoc</a>(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 1, UNIT_POINTS, FACINGPAGES, FIRSTPAGERIGHT)</p></dd>
+
+<dt><a name="-newDocument"><strong>newDocument</strong>(...)</a></dt>
+<dd><code>newDocument(size, margins, orientation, firstPageNumber,
+                        unit, pagesType, firstPageOrder, numPages) -> bool</code>
+<p>Note that this commands requires 8 parameters, whereas the obsolete <b>newDoc()</b> command required 7. The additional parameter indicates how many pages to create.</p>
+<p>Creates a new document and returns true if successful. The parameters have the
+following meaning:
+<ul>
+<li>size = A tuple (width, height) describing the size of the document. You can
+use predefined constants named PAPER_<paper_type> e.g. PAPER_A4 etc.</li>
+<li>margins = A tuple (left, right, top, bottom) describing the document
+margins</li>
+<li>orientation = the page orientation - constants PORTRAIT, LANDSCAPE</li>
+<li>firstPageNumer = is the number of the first page in the document used for
+pagenumbering. While you'll usually want 1, it's useful to have higher
+numbers if you're creating a document in several parts.</li>
+<li>unit: this value sets the measurement units used by the document. Use a
+predefined constant for this, one of: UNIT_INCHES, UNIT_MILLIMETERS,
+UNIT_PICAS, UNIT_POINTS.</li>
+<li>pagesType = One of the predefined constants PAGE_n. PAGE_1 is single page,
+PAGE_2 is for double sided documents, PAGE_3 is for 3 pages fold and
+PAGE_4 is 4-fold.</li>
+<li>firstPageOrder = What is position of first page in the document.
+Indexed from 0 (0 = first).</li>
+<li>numPage = Number of pages to be created.</li>
+</ul>
+<p>The values for width, height and the margins are expressed in the given unit
+for the document. PAPER_* constants are a series of tuples specific to the document size, with the values corresponding to points. Therefore, if you are creating a document and using UNIT_MILLIMETERS for example, DO NOT USE the PAPER_* constants.</p>
+<p>For A and B paper formats there are now new constants to use with UNIT_MILLIMETERS, named for example, PAPER_A4_MM, or PAPER_B6_MM.</p>
+<p>Examples:</p>
+<p><b>newDocument(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 7, UNIT_POINTS, PAGE_4, 3, 1)</b></p>
+<p><b>newDocument(PAPER_A4_MM, (10, 10, 20, 20), LANDSCAPE, 7, UNIT_MILLIMETERS, PAGE_4, 3, 1)</b></p>
+<p>May raise ScribusError if is firstPageOrder bigger than allowed by pagesType.</p>
+</dd>
+
+<dt><a name="-openDoc"><strong>openDoc</strong></a>(...)</dt>
+<dd><code>openDoc("name")</code>
+<p>Opens the document "name".</p>
+<p>May raise ScribusError if the document could not be opened.</p></dd>
+
+<dt><a name="-placeEPS"><strong>placeEPS</strong>(...)</a></dt>
+<dd><code>placeEPS("filename", x, y)</code>
+<p>Places the EPS "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the EPS placed on the page.</p>
+<p>If loading was successful, the selection contains the imported EPS.</p></dd>
+
+<dt><a name="-placeODG"><strong>placeODG</strong>(...)</a></dt>
+<dd><code>placeODG("filename", x, y)</code>
+<p>Places the ODG "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the ODG placed on the page.</p>
+<p>If loading was successful, the selection contains the imported ODG.</p></dd>
+
+<dt><a name="-placeSVG"><strong>placeSVG</strong>(...)</a></dt>
+<dd><code>placeSVG("filename", x, y)</code>
+<p>Places the SVG "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the SVG placed on the page.</p>
+<p>If loading was successful, the selection contains the imported SVG.</p></dd>
+
+<dt><a name="-placeSXD"><strong>placeSXD</strong>(...)</a></dt>
+<dd><code>placeSXD("filename", x, y)</code>
+<p>Places the SXD "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the SXD placed on the page.</p>
+<p>If loading was successful, the selection contains the imported SXD.</p></dd>
+
+<dt><a name="-placeVectorFile"><strong>placeVectorFile</strong>(...)</a></dt>
+<dd><code>placeVectorFile("filename", x, y)</code>
+<p>Places the vector graphics "filename" onto the current page, x and y specify the coordinate 
+of the topleft corner of the graphic placed on the page.</p>
+<p>If loading was successful, the selection contains the imported graphic.</p></dd>
+
+<dt><a name="-revertDoc"><strong>revertDoc</strong></a>(...)</dt>
+<dd><code>revertDoc()</code>
+<p>Revert the current document to its last saved state.</p></dd>
+
+<dt><a name="-saveDoc"><strong>saveDoc</strong></a>(...)</dt>
+<dd><code>saveDoc()</code>
+<p>Saves the current document with its current name, returns true if successful. If the document has not already been saved, this may bring up an interactive save file dialog. If the save fails, there is currently no way to tell.</p></dd>
+
+<dt><a name="-saveDocAs"><strong>saveDocAs</strong></a>(...)</dt>
+<dd><code>saveDocAs("name")</code>
+<p>Saves the current document under the new name "name" (which may be a full or
+relative path).</p>
+<p>May raise ScribusError if the save fails.</p></dd>
+
+<dt><a name="-setInfo"><strong>setInfo</strong></a>(...)</dt>
+<dd><code>setInfo("author", "info", "description") -> bool</code>
+<p>Sets the document information. "Author", "Info", "Description" are strings.</p></dd>
+
+<dt><a name="-setMargins"><strong>setMargins</strong></a>(...)</dt>
+<dd><code>setMargins(lr, rr, tr, br)</code>
+<p>Sets the margins of the document, Left(lr), Right(rr), Top(tr) and Bottom(br) margins are given in the measurement units of the document - see UNIT_<type> constants.</p></dd>
+
+<dt><a name="-setDocType"><strong>setDocType</strong></a>(...)</dt>
+<dd><code>setDocType(facingPages, firstPageLeft)</code>
+<p>Sets the document type. To get facing pages set the first parameter to FACINGPAGES, to switch facingPages off use NOFACINGPAGES instead. If you want to be the first page a left side set the second parameter to FIRSTPAGELEFT, for a right page use FIRSTPAGERIGHT.</p></dd>
+
+<dt><a name="-setUnit"><strong>setUnit</strong></a>(...)</dt>
+<dd><code>setUnit(type)</code>
+<p>Changes the measurement unit of the document. Possible values for "unit" are defined as constants UNIT_<type>.</p>
+<p>May raise ValueError if an invalid unit is passed.</p>
+<p>As noted above, typically you may use this command so that you can change the measurement units to something else, for which you are creating or modifying objects based some particular units, like points, after which you want to return to whatever the original units were.</p><p><b>original = getUnit()</b></p>
+<p><i>do some operations...then later</i></p>
+<p><b>setUnit(original)</b></p></dd>
+
+<dt><a name="-setBaseLine"><strong>setBaseLine</strong></a>(...)</dt>
+<dd><code>setBaseLine(grid, offset)</code>
+<p>Sets the base line settings of the document, grid spacing(grid), grid offset(offset). Values are given in the measurement units of the document - see UNIT_<type> constants.</p></dd>
+
+<dt><a name="-scrollDocument"><strong>scrollDocument</strong>(...)</a></dt>
+<dd><code>scrollDocument(x,y)</code>
+<p>Scroll the document in main GUI window by x and y.</p></dd>
+
+<dt><a name="-zoomDocument"><strong>zoomDocument</strong>(...)</a></dt>
+<dd><code>zoomDocument(double)</code>
+<p>Zoom the document in main GUI window. Actions have whole number
+values like 20.0, 100.0, etc. Zoom to Fit uses -100 as a marker.</p></dd>
+
+</dl>
+</body>
+</html>

Modified: trunk/Scribus/doc/ru/scripterapi-doc.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/doc/ru/scripterapi-doc.html
==============================================================================
--- trunk/Scribus/doc/ru/scripterapi-doc.html	(original)
+++ trunk/Scribus/doc/ru/scripterapi-doc.html	Tue Nov 26 11:50:13 2019
@@ -140,6 +140,10 @@
 of the topleft corner of the graphic placed on the page.</p>
 <p>If loading was successful, the selection contains the imported graphic.</p></dd>
 
+<dt><a name="-revertDoc"><strong>revertDoc</strong></a>(...)</dt>
+<dd><code>revertDoc()</code>
+<p>Revert the current document to its last saved state.</p></dd>
+
 <dt><a name="-saveDoc"><strong>saveDoc</strong></a>(...)</dt>
 <dd><code>saveDoc()</code>
 <p>Saves the current document with its current name, returns true if successful. If the document has not already been saved, this may bring up an interactive save file dialog. If the save fails, there is currently no way to tell.</p></dd>

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp	Tue Nov 26 11:50:13 2019
@@ -193,6 +193,14 @@
 	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 @@
 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__;
+}

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.h	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.h	Tue Nov 26 11:50:13 2019
@@ -142,6 +142,14 @@
 PyObject *scribus_savedoc(PyObject * /*self*/);
 
 /*! docstring */
+PyDoc_STRVAR(scribus_revertdoc__doc__,
+QT_TR_NOOP("revertDoc()\n\
+\n\
+Revert the current document to its last saved state.\n\
+"));
+PyObject *scribus_revertdoc(PyObject * /*self*/);
+
+/*! docstring */
 PyDoc_STRVAR(scribus_getdocname__doc__,
 QT_TR_NOOP("getDocName() -> string\n\
 \n\

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	Tue Nov 26 11:50:13 2019
@@ -460,11 +460,12 @@
 	{const_cast<char*>("replaceColor"), scribus_replcolor, METH_VARARGS, tr(scribus_replcolor__doc__)},
 	{const_cast<char*>("resizeTableColumn"), scribus_resizetablecolumn, METH_VARARGS, tr(scribus_resizetablecolumn__doc__)},
 	{const_cast<char*>("resizeTableRow"), scribus_resizetablerow, METH_VARARGS, tr(scribus_resizetablerow__doc__)},
+	{const_cast<char*>("revertDoc"), (PyCFunction)scribus_revertdoc, METH_NOARGS, tr(scribus_revertdoc__doc__)},
 	{const_cast<char*>("rotateObjectAbs"), scribus_rotobjabs, METH_VARARGS, tr(scribus_rotobjabs__doc__)},
 	{const_cast<char*>("rotateObject"), scribus_rotobjrel, METH_VARARGS, tr(scribus_rotobjrel__doc__)},
 	{const_cast<char*>("getDocName"), (PyCFunction)scribus_getdocname, METH_NOARGS, tr(scribus_getdocname__doc__)},
+	{const_cast<char*>("saveDoc"), (PyCFunction)scribus_savedoc, METH_NOARGS, tr(scribus_savedoc__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*>("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__)},

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23380&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Tue Nov 26 11:50:13 2019
@@ -4136,13 +4136,16 @@
 	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;




More information about the scribus-commit mailing list