Add loadGui and saveGui help pages. 25/14225/4
Adeline CARNIS [Fri, 28 Mar 2014 17:29:40 +0000 (18:29 +0100)]
Change-Id: I832fe64c94189648ed256c279047094629a689f7

scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/XMLDomLoader.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/XmlLoader.java
scilab/modules/gui/help/en_US/loadGui.xml [new file with mode: 0644]
scilab/modules/gui/help/en_US/saveGui.xml [new file with mode: 0644]
scilab/modules/gui/sci_gateway/cpp/sci_loadGui.cpp
scilab/modules/gui/sci_gateway/cpp/sci_saveGui.cpp

index 382af42..fab20b7 100644 (file)
@@ -236,8 +236,9 @@ public class XMLDomLoader {
 
                     currentPath = initialDirectoryPath + File.separator + filePath;
                     FindIconHelper.addThemePath(currentPath);
+                    FindIconHelper.addThemePath(initialDirectoryPath);
 
-                    f = new File(currentPath + File.separator + filename);
+                    f = new File(initialDirectoryPath, filename);
                 }
             } else {
                 //try to find file in currentPath
index 3c77fa2..19c68ff 100644 (file)
@@ -154,6 +154,9 @@ public class XmlLoader extends DefaultHandler {
                 }
                 currentPath = initialDirectoryPath + File.separator + filePath;
                 FindIconHelper.addThemePath(currentPath);
+                FindIconHelper.addThemePath(initialDirectoryPath);
+
+                f = new File(initialDirectoryPath, filename);
             }
         } else {
             //try to find file in currentPath
diff --git a/scilab/modules/gui/help/en_US/loadGui.xml b/scilab/modules/gui/help/en_US/loadGui.xml
new file mode 100644 (file)
index 0000000..606b86e
--- /dev/null
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="loadGui" xml:lang="en">
+    <refnamediv>
+        <refname>loadGui</refname>
+        <refpurpose>Load a graphic user interface from a saved file</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>loadGui(filename)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>filename</term>
+                <listitem>
+                    <para>character string containing the path of the file</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            The <literal>loadGui</literal> function can be used to load in the
+            Scilab session a graphic user interface previously saved in a file with the
+            <literal>
+                <link linkend="saveGui">saveGui</link>
+            </literal>
+            function.
+        </para>
+        <para>
+            <literal>loadGui(filename)</literal> loads an interface saved in file
+            given by its path <literal>filename</literal>.
+        </para>
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[ 
+// First example
+f = figure("background", -2);
+h = uicontrol(f, "style", "text", ...
+              "string", "This is a figure", ...
+              "position", [210 180 300 100], ...
+              "fontsize", 24, ...
+              "backgroundcolor", [1 1 1]);
+
+saveGui(f, fullfile(TMPDIR, "foo"))
+close(f)
+loadGui(fullfile(TMPDIR, "foo"));
+
+// Second example
+f = figure("default_axes", "off", ...
+           "dockable", "off", ...
+           "figure_name", "Sélection", ...
+           "axes_size", [200 200], ...
+           "infobar_visible", "off", ...
+           "menubar_visible", "off", ...
+           "toolbar", "none", ...
+           "toolbar_visible", "off", ...
+           "layout", "gridbag");
+           
+h1 = uicontrol(f, "style", "text", ...
+                "string", "Following List :", ...
+                "fontsize", 15, ...
+                "constraints", createConstraints("gridbag", [1 1 2 1], [1 0], "both"));
+                
+h2 = uicontrol(f, "style", "popupmenu", ...
+                "string", ["item1"; "item2"; "item3"], ...
+                "value", 1, ...
+                "fontsize", 15, ...
+                "constraints", createConstraints("gridbag", [1 2 2 1], [1 0], "both"), ...
+                "tag", "selection");
+                
+h3 = uicontrol(f, "style", "pushbutton", ...
+                "string", "OK", ...
+                "callback", "obj = findobj(""tag"", ""selection""); mprintf(""La valeur sélectionnée est : %s.\n"", obj.string(obj.value)); close(gcf())", ...
+                "fontsize", 15, ...
+                "constraints", createConstraints("gridbag", [1 3 1 1], [1 0], "both", "left"));
+                
+h4 = uicontrol(f, "style", "pushbutton", ...
+                "string", "CANCEL", ...
+                "callback", "close(gcf())", ...
+                "fontsize", 15, ...
+                "constraints", createConstraints("gridbag", [2 3 1 1], [1 0], "both", "right"));
+                
+saveGui(f, "TMPDIR/foo2.xml");
+close(f)
+loadGui("TMPDIR/foo2.xml")
+
+
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="saveGui">saveGui</link>
+            </member>
+            <member>
+                <link linkend="load">load</link>
+            </member>
+            <member>
+                <link linkend="save">save</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.5.0</revnumber>
+                <revremark>
+                    Function <function>loadGui</function> introduced.
+                </revremark>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
diff --git a/scilab/modules/gui/help/en_US/saveGui.xml b/scilab/modules/gui/help/en_US/saveGui.xml
new file mode 100644 (file)
index 0000000..5e22400
--- /dev/null
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="saveGui" xml:lang="en">
+    <refnamediv>
+        <refname>saveGui</refname>
+        <refpurpose>Save a graphic user interface in a file</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>saveGui(fig, filename)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>fig</term>
+                <listitem>
+                    <para>handle, the handle of the current figure</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>filename</term>
+                <listitem>
+                    <para>character string containing the path of the file</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            The <literal>saveGui</literal> function can be used to save a graphic user interface in a file and reloaded by the
+            <literal>
+                <link linkend="loadGui">loadGui</link>
+            </literal>
+            function.
+        </para>
+        <para>
+            <literal>saveGui(f, filename)</literal> save a current graphic handle f in file
+            defined by <literal>filename</literal>.
+        </para>
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[ 
+// First example
+f = figure("background", -2);
+h = uicontrol(f, "style", "text", ...
+              "string", "This is a figure", ...
+              "position", [210 180 300 100], ...
+              "fontsize", 24, ...
+              "backgroundcolor", [1 1 1]);
+
+saveGui(f, fullfile(TMPDIR, "foo"))
+close(f)
+loadGui(fullfile(TMPDIR, "foo"));
+
+// Second example
+f = figure("default_axes", "off", ...
+           "dockable", "off", ...
+           "figure_name", "Sélection", ...
+           "axes_size", [200 200], ...
+           "infobar_visible", "off", ...
+           "menubar_visible", "off", ...
+           "toolbar", "none", ...
+           "toolbar_visible", "off", ...
+           "layout", "gridbag");
+           
+h1 = uicontrol(f, "style", "text", ...
+                "string", "Following List :", ...
+                "fontsize", 15, ...
+                "constraints", createConstraints("gridbag", [1 1 2 1], [1 0], "both"));
+                
+h2 = uicontrol(f, "style", "popupmenu", ...
+                "string", ["item1"; "item2"; "item3"], ...
+                "value", 1, ...
+                "fontsize", 15, ...
+                "constraints", createConstraints("gridbag", [1 2 2 1], [1 0], "both"), ...
+                "tag", "selection");
+                
+h3 = uicontrol(f, "style", "pushbutton", ...
+                "string", "OK", ...
+                "callback", "obj = findobj(""tag"", ""selection""); mprintf(""La valeur sélectionnée est : %s.\n"", obj.string(obj.value)); close(gcf())", ...
+                "fontsize", 15, ...
+                "constraints", createConstraints("gridbag", [1 3 1 1], [1 0], "both", "left"));
+                
+h4 = uicontrol(f, "style", "pushbutton", ...
+                "string", "CANCEL", ...
+                "callback", "close(gcf())", ...
+                "fontsize", 15, ...
+                "constraints", createConstraints("gridbag", [2 3 1 1], [1 0], "both", "right"));
+                
+saveGui(f, "TMPDIR/foo2.xml");
+close(f)
+loadGui("TMPDIR/foo2.xml")
+
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="loadGui">loadGui</link>
+            </member>
+            <member>
+                <link linkend="load">load</link>
+            </member>
+            <member>
+                <link linkend="save">save</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.5.0</revnumber>
+                <revremark>
+                    Function <function>saveGui</function> introduced.
+                </revremark>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
index 22323e3..ce37752 100644 (file)
@@ -19,6 +19,8 @@ extern "C" {
 #include "getGraphicObjectProperty.h"
 #include "graphicObjectProperties.h"
 #include "HandleManagement.h"
+#include "FileExist.h"
+#include "expandPathVariable.h"
 }
 
 int sci_loadGui(char *fname, unsigned long fname_len)
@@ -26,6 +28,7 @@ int sci_loadGui(char *fname, unsigned long fname_len)
     SciErr sciErr;
     int* piAddr = NULL;
     char* pstFile = NULL;
+    char* pstFullFile = NULL;
 
     int iRhs = nbInputArgument(pvApiCtx);
 
@@ -39,13 +42,6 @@ int sci_loadGui(char *fname, unsigned long fname_len)
         return 1;
     }
 
-    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return 1;
-    }
-
     if (isStringType(pvApiCtx, piAddr) == 0 || isScalar(pvApiCtx, piAddr) == 0)
     {
         Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
@@ -60,15 +56,25 @@ int sci_loadGui(char *fname, unsigned long fname_len)
             freeAllocatedSingleString(pstFile);
         }
 
-        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2);
+        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
         return 1;
     }
 
-    int iFig = xmldomload(pstFile);
+    pstFullFile = expandPathVariable(pstFile);
+    if (!FileExist(pstFullFile))
+    {
+        Scierror(999, _("%s: This file %s does not exist.\n"), fname, pstFile);
+        freeAllocatedSingleString(pstFile);
+        freeAllocatedSingleString(pstFullFile);
+        return 0;
+    }
+
+    int iFig = xmldomload(pstFullFile);
     if (iFig < 1)
     {
         Scierror(999, _("%s: can not read file %s.\n"), fname, pstFile);
         freeAllocatedSingleString(pstFile);
+        freeAllocatedSingleString(pstFullFile);
         return 0;
     }
 
index 62247ca..fc8869a 100644 (file)
@@ -20,6 +20,7 @@ extern "C" {
 #include "graphicObjectProperties.h"
 #include "HandleManagement.h"
 #include "BOOL.h"
+#include "expandPathVariable.h"
 }
 
 int sci_saveGui(char *fname, unsigned long fname_len)
@@ -33,6 +34,7 @@ int sci_saveGui(char *fname, unsigned long fname_len)
     int* piType = &iType;
     int* piAddr2 = NULL;
     char* pstFile = NULL;
+    char* pstFullFile = NULL;
 
     int* piAddr3 = NULL;
     int bReserve = 0;
@@ -122,8 +124,11 @@ int sci_saveGui(char *fname, unsigned long fname_len)
         }
     }
 
-    char* ret = xmlsave(iFig, pstFile, (BOOL) bReserve);
+    pstFullFile = expandPathVariable(pstFile);
+
+    char* ret = xmlsave(iFig, pstFullFile, (BOOL) bReserve);
     freeAllocatedSingleString(pstFile);
+    freeAllocatedSingleString(pstFullFile);
 
     if (ret[0] != '\0')
     {