SciNotes: add autosaving 78/7578/2
Calixte DENIZET [Mon, 18 Jun 2012 20:06:47 +0000 (22:06 +0200)]
Change-Id: Id74e5973f5dce0617e916b03dc1f598eacd14c0d

scilab/modules/scinotes/etc/XConfiguration-scinotes.xml
scilab/modules/scinotes/etc/XConfiguration-scinotes.xsl
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotes.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesAutosave.java [new file with mode: 0644]
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesOptions.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabDocument.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/SaveFile.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/SciNotesMessages.java

index 92f3fc9..8f07508 100644 (file)
@@ -10,7 +10,7 @@
   </display>
   <autosave title="Autosave">
     <body>
-      <scinotes-autosave enable="true" save-every="5" automatic-delete="true" append-with="~" replace-with="tmp" source-flag="true" single-directory=""/>
+      <scinotes-autosave enable="true" save-every="5" automatic-delete="true" append-filename="true" append-with="~" replace-with="tmp" source-flag="true" single-directory=""/>
     </body>
   </autosave>
 </scinotes>
index 14b003a..cea137e 100644 (file)
           </xsl:choose>\r
         </xsl:variable>\r
         <Grid>\r
-         <Radiobutton value="{@external-cmd}" expected-value="true" listener="ActionListener" text="External editor: " gridx="1" gridy="1" fill="none" weightx="0" anchor="west" enable="{$enable}">\r
-           <actionPerformed choose="external-cmd">\r
-             <xsl:call-template name="context"/>\r
-           </actionPerformed>\r
-         </Radiobutton>\r
+          <Radiobutton value="{@external-cmd}" expected-value="true" listener="ActionListener" text="External editor: " gridx="1" gridy="1" fill="none" weightx="0" anchor="west" enable="{$enable}">\r
+            <actionPerformed choose="external-cmd">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+          </Radiobutton>\r
           <FileSelector gridx="2" gridy="1" weightx="1" anchor="above_baseline"\r
                         listener="EntryListener"\r
                         href="{@cmd}"\r
                         dir-selection="false">\r
-           <xsl:attribute name="enable">\r
-             <xsl:if test="@scinotes='false' and @external-cmd='true'">\r
-               <xsl:text>true</xsl:text>\r
-             </xsl:if>\r
-           </xsl:attribute>\r
-           <entryChanged choose="cmd">\r
+            <xsl:attribute name="enable">\r
+              <xsl:if test="@scinotes='false' and @external-cmd='true'">\r
+                <xsl:text>true</xsl:text>\r
+              </xsl:if>\r
+            </xsl:attribute>\r
+            <entryChanged choose="cmd">\r
               <xsl:call-template name="context"/>\r
             </entryChanged>\r
           </FileSelector>\r
-         <Radiobutton value="{@external-cmd}" expected-value="false" listener="ActionListener" text="Scilab command: " gridx="1" gridy="2" fill="none" weightx="0" anchor="west" enable="{$enable}">\r
-           <actionPerformed choose="external-cmd">\r
-             <xsl:call-template name="context"/>\r
-           </actionPerformed>\r
-         </Radiobutton>\r
+          <Radiobutton value="{@external-cmd}" expected-value="false" listener="ActionListener" text="Scilab command: " gridx="1" gridy="2" fill="none" weightx="0" anchor="west" enable="{$enable}">\r
+            <actionPerformed choose="external-cmd">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+          </Radiobutton>\r
           <Entry gridx="2" gridy="2" weightx="1" anchor="above_baseline"\r
-                        listener="EntryListener"\r
-                        text="{@cmd}">\r
-           <xsl:attribute name="enable">\r
-             <xsl:if test="@scinotes='false' and @external-cmd='false'">\r
-               <xsl:text>true</xsl:text>\r
-             </xsl:if>\r
-           </xsl:attribute>\r
+                 listener="EntryListener"\r
+                 text="{@cmd}">\r
+            <xsl:attribute name="enable">\r
+              <xsl:if test="@scinotes='false' and @external-cmd='false'">\r
+                <xsl:text>true</xsl:text>\r
+              </xsl:if>\r
+            </xsl:attribute>\r
             <entryChanged choose="macro">\r
               <xsl:call-template name="context"/>\r
             </entryChanged>\r
           </Entry>\r
-       </Grid>\r
+        </Grid>\r
       </VBox>\r
     </Title>\r
     <VSpace height="10"/>\r
   <xsl:template match="scinotes-display">\r
     <Title text="General display options">\r
       <Grid>\r
-       <Checkbox checked="{@highlight-current-line}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight current line: " gridx="1" gridy="1" fill="none" weightx="0" anchor="west">\r
-         <actionPerformed choose="highlight-current-line">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Checkbox>\r
-       <Panel gridx="2" gridy="1" weightx="1"/>\r
-       <Panel gridx="3" gridy="1" weightx="1"/>\r
-       <Color color="{@current-line-color}" listener="ActionListener" gridx="4" gridy="1" weightx="0" enable="{@highlight-current-line}">\r
-         <actionPerformed choose="current-line-color">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Color>\r
-       <Checkbox checked="{@show-line-numbers}" selected-value="true" unselected-value="false" listener="ActionListener" text="Show line numbers: " gridx="1" gridy="2" fill="none" weightx="0" anchor="west">\r
-         <actionPerformed choose="show-line-numbers">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Checkbox>\r
-       <Radiobutton value="{@whereami}" expected-value="true" listener="ActionListener" text="Whereami compatible" gridx="2" gridy="2" fill="none" weightx="0" anchor="west" enable="{@show-line-numbers}">\r
-         <actionPerformed choose="whereami">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Radiobutton>\r
-       <Radiobutton value="{@whereami}" expected-value="false" listener="ActionListener" text="Normal" gridx="3" gridy="2" gridwidth="2" fill="none" weightx="0" anchor="west" enable="{@show-line-numbers}">\r
-         <actionPerformed choose="whereami">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Radiobutton>\r
-       <Checkbox checked="{@wrap-lines}" selected-value="true" unselected-value="false" listener="ActionListener" text="Wrap lines" gridx="1" gridy="3" fill="none" weightx="0" anchor="west">\r
-         <actionPerformed choose="wrap-lines">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Checkbox>\r
+        <Checkbox checked="{@highlight-current-line}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight current line: " gridx="1" gridy="1" fill="none" weightx="0" anchor="west">\r
+          <actionPerformed choose="highlight-current-line">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Checkbox>\r
+        <Panel gridx="2" gridy="1" weightx="1"/>\r
+        <Panel gridx="3" gridy="1" weightx="1"/>\r
+        <Color color="{@current-line-color}" listener="ActionListener" gridx="4" gridy="1" weightx="0" enable="{@highlight-current-line}">\r
+          <actionPerformed choose="current-line-color">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Color>\r
+        <Checkbox checked="{@show-line-numbers}" selected-value="true" unselected-value="false" listener="ActionListener" text="Show line numbers: " gridx="1" gridy="2" fill="none" weightx="0" anchor="west">\r
+          <actionPerformed choose="show-line-numbers">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Checkbox>\r
+        <Radiobutton value="{@whereami}" expected-value="true" listener="ActionListener" text="Whereami compatible" gridx="2" gridy="2" fill="none" weightx="0" anchor="west" enable="{@show-line-numbers}">\r
+          <actionPerformed choose="whereami">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
+        <Radiobutton value="{@whereami}" expected-value="false" listener="ActionListener" text="Normal" gridx="3" gridy="2" gridwidth="2" fill="none" weightx="0" anchor="west" enable="{@show-line-numbers}">\r
+          <actionPerformed choose="whereami">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
+        <Checkbox checked="{@wrap-lines}" selected-value="true" unselected-value="false" listener="ActionListener" text="Wrap lines" gridx="1" gridy="3" fill="none" weightx="0" anchor="west">\r
+          <actionPerformed choose="wrap-lines">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Checkbox>\r
       </Grid>\r
     </Title>\r
     <VSpace height="10"/>\r
     <Title text="Keywords">\r
-        <Grid>\r
-         <Checkbox checked="{@keywords-colorization}" selected-value="true" unselected-value="false" listener="ActionListener" text="Enable keywords colorization" gridx="1" gridy="1" fill="none" weightx="0" anchor="west">\r
-           <actionPerformed choose="keywords-colorization">\r
-             <xsl:call-template name="context"/>\r
-           </actionPerformed>\r
-         </Checkbox>\r
-         <Panel gridx="2" gridy="1" weightx="1"/>\r
-         <Link gridx="3" gridy="1" weightx="0" listener="MouseListener" text="Set syntax Colors" enable="{@keywords-colorization}">\r
-           <mouseClicked set="path" value="3/" context="/" enable="{@keywords-colorization}"/>\r
-         </Link>\r
-         <Checkbox checked="{@highlight-brackets}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight corresponding brackets" gridx="1" gridy="2" fill="none" weightx="0" anchor="west">\r
-           <actionPerformed choose="highlight-brackets">\r
-             <xsl:call-template name="context"/>\r
-           </actionPerformed>\r
-         </Checkbox>\r
-         <Grid gridx="1" gridy="3" gridwidth="3" ipadx="10">\r
-           <Label gridx="1" gridy="1" weightx="0" text="Color: " enable="{@highlight-brackets}"/>        \r
-           <Color color="{@brackets-color}" listener="ActionListener" gridx="2" gridy="1" weightx="0" enable="{@highlight-brackets}">\r
-             <actionPerformed choose="brackets-color">\r
-               <xsl:call-template name="context"/>\r
-             </actionPerformed>\r
-           </Color>\r
-           <Panel gridx="3" gridy="1" weightx="1"/>\r
-           <Checkbox checked="{@brackets-onmouseover}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight on mouse over" gridx="4" gridy="1" fill="none" weightx="0" anchor="west" enable="{@highlight-brackets}">\r
-             <actionPerformed choose="brackets-onmouseover">\r
-               <xsl:call-template name="context"/>\r
-             </actionPerformed>\r
-           </Checkbox>\r
-           <Panel gridx="5" gridy="1" weightx="1"/>\r
-           <Label gridx="6" gridy="1" weightx="0" text="Style: " enable="{@highlight-brackets}"/>        \r
-           <Panel gridx="7" gridy="1" weightx="0">\r
-             <xsl:call-template name="Select">\r
-               <xsl:with-param name="among">\r
-                 <option brackets-highlightment="Filled"/>\r
-                 <option brackets-highlightment="Framed"/>\r
-                 <option brackets-highlightment="Underlined"/>\r
-               </xsl:with-param>\r
-               <xsl:with-param name="enable" select="@highlight-brackets" />\r
-             </xsl:call-template>\r
-           </Panel>\r
-         </Grid>\r
-         <Checkbox checked="{@highlight-keywords}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight corresponding keywords (e.g. if ... end)" gridx="1" gridy="4" fill="none" weightx="0" anchor="west">\r
-           <actionPerformed choose="highlight-keywords">\r
-             <xsl:call-template name="context"/>\r
-           </actionPerformed>\r
-         </Checkbox>\r
-         <Grid gridx="1" gridy="5" gridwidth="3" ipadx="10">\r
-           <Label gridx="1" gridy="1" weightx="0" text="Color: " enable="{@highlight-keywords}"/>        \r
-           <Color color="{@keywords-color}" listener="ActionListener" gridx="2" gridy="1" weightx="0" enable="{@highlight-keywords}">\r
-             <actionPerformed choose="keywords-color">\r
-               <xsl:call-template name="context"/>\r
-             </actionPerformed>\r
-           </Color>\r
-           <Panel gridx="3" gridy="1" weightx="1"/>\r
-           <Checkbox checked="{@keywords-onmouseover}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight on mouse over" gridx="4" gridy="1" fill="none" weightx="0" anchor="west" enable="{@highlight-keywords}">\r
-             <actionPerformed choose="keywords-onmouseover">\r
-               <xsl:call-template name="context"/>\r
-             </actionPerformed>\r
-           </Checkbox>\r
-           <Panel gridx="5" gridy="1" weightx="1"/>\r
-           <Label gridx="6" gridy="1" weightx="0" text="Style: " enable="{@highlight-keywords}"/>        \r
-           <Panel gridx="7" gridy="1" weightx="0">\r
-             <xsl:call-template name="Select">\r
-               <xsl:with-param name="among">\r
-                 <option keywords-highlightment="Filled"/>\r
-                 <option keywords-highlightment="Framed"/>\r
-               </xsl:with-param>\r
-               <xsl:with-param name="enable" select="@highlight-keywords" />\r
-             </xsl:call-template>\r
-           </Panel>\r
-         </Grid>\r
-       </Grid>\r
+      <Grid>\r
+        <Checkbox checked="{@keywords-colorization}" selected-value="true" unselected-value="false" listener="ActionListener" text="Enable keywords colorization" gridx="1" gridy="1" fill="none" weightx="0" anchor="west">\r
+          <actionPerformed choose="keywords-colorization">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Checkbox>\r
+        <Panel gridx="2" gridy="1" weightx="1"/>\r
+        <Link gridx="3" gridy="1" weightx="0" listener="MouseListener" text="Set syntax Colors" enable="{@keywords-colorization}">\r
+          <mouseClicked set="path" value="3/" context="/" enable="{@keywords-colorization}"/>\r
+        </Link>\r
+        <Checkbox checked="{@highlight-brackets}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight corresponding brackets" gridx="1" gridy="2" fill="none" weightx="0" anchor="west">\r
+          <actionPerformed choose="highlight-brackets">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Checkbox>\r
+        <Grid gridx="1" gridy="3" gridwidth="3" ipadx="10">\r
+          <Label gridx="1" gridy="1" weightx="0" text="Color: " enable="{@highlight-brackets}"/>\r
+          <Color color="{@brackets-color}" listener="ActionListener" gridx="2" gridy="1" weightx="0" enable="{@highlight-brackets}">\r
+            <actionPerformed choose="brackets-color">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+          </Color>\r
+          <Panel gridx="3" gridy="1" weightx="1"/>\r
+          <Checkbox checked="{@brackets-onmouseover}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight on mouse over" gridx="4" gridy="1" fill="none" weightx="0" anchor="west" enable="{@highlight-brackets}">\r
+            <actionPerformed choose="brackets-onmouseover">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+          </Checkbox>\r
+          <Panel gridx="5" gridy="1" weightx="1"/>\r
+          <Label gridx="6" gridy="1" weightx="0" text="Style: " enable="{@highlight-brackets}"/>\r
+          <Panel gridx="7" gridy="1" weightx="0">\r
+            <xsl:call-template name="Select">\r
+              <xsl:with-param name="among">\r
+                <option brackets-highlightment="Filled"/>\r
+                <option brackets-highlightment="Framed"/>\r
+                <option brackets-highlightment="Underlined"/>\r
+              </xsl:with-param>\r
+              <xsl:with-param name="enable" select="@highlight-brackets" />\r
+            </xsl:call-template>\r
+          </Panel>\r
+        </Grid>\r
+        <Checkbox checked="{@highlight-keywords}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight corresponding keywords (e.g. if ... end)" gridx="1" gridy="4" fill="none" weightx="0" anchor="west">\r
+          <actionPerformed choose="highlight-keywords">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Checkbox>\r
+        <Grid gridx="1" gridy="5" gridwidth="3" ipadx="10">\r
+          <Label gridx="1" gridy="1" weightx="0" text="Color: " enable="{@highlight-keywords}"/>\r
+          <Color color="{@keywords-color}" listener="ActionListener" gridx="2" gridy="1" weightx="0" enable="{@highlight-keywords}">\r
+            <actionPerformed choose="keywords-color">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+          </Color>\r
+          <Panel gridx="3" gridy="1" weightx="1"/>\r
+          <Checkbox checked="{@keywords-onmouseover}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight on mouse over" gridx="4" gridy="1" fill="none" weightx="0" anchor="west" enable="{@highlight-keywords}">\r
+            <actionPerformed choose="keywords-onmouseover">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+          </Checkbox>\r
+          <Panel gridx="5" gridy="1" weightx="1"/>\r
+          <Label gridx="6" gridy="1" weightx="0" text="Style: " enable="{@highlight-keywords}"/>\r
+          <Panel gridx="7" gridy="1" weightx="0">\r
+            <xsl:call-template name="Select">\r
+              <xsl:with-param name="among">\r
+                <option keywords-highlightment="Filled"/>\r
+                <option keywords-highlightment="Framed"/>\r
+              </xsl:with-param>\r
+              <xsl:with-param name="enable" select="@highlight-keywords" />\r
+            </xsl:call-template>\r
+          </Panel>\r
+        </Grid>\r
+      </Grid>\r
     </Title>\r
     <VSpace height="10"/>\r
     <Title text="Tabulation &amp; Indentation">\r
       <Grid>\r
         <Label text="Tabulation size:" gridx="1" gridy="1" weightx="0"/>\r
-       <NumericalSpinner gridx="2"\r
+        <NumericalSpinner gridx="2"\r
                           gridy="1"\r
-                         weightx="0"\r
+                          weightx="0"\r
                           min-value = "1"\r
                           increment = "1"\r
                           length = "3"\r
           </actionPerformed>\r
         </NumericalSpinner>\r
         <Panel gridx="3" gridy="1" weightx="1"/>\r
-       <Checkbox checked="{@use-spaces}" selected-value="true" unselected-value="false" listener="ActionListener" text="Use space" gridx="4" gridy="1" fill="none" weightx="0" anchor="west">\r
-         <actionPerformed choose="use-spaces">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Checkbox>\r
+        <Checkbox checked="{@use-spaces}" selected-value="true" unselected-value="false" listener="ActionListener" text="Use space" gridx="4" gridy="1" fill="none" weightx="0" anchor="west">\r
+          <actionPerformed choose="use-spaces">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Checkbox>\r
 \r
-       <Label text="Representation:" gridx="1" gridy="2" weightx="0"/>\r
-       <Radiobutton value="{@tab-representation}" expected-value="chevrons" listener="ActionListener" text="Chevrons" gridx="2" gridy="2" fill="none" weightx="0" anchor="west" enable="true">\r
-         <actionPerformed choose="tab-representation">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Radiobutton>\r
-       <Radiobutton value="{@tab-representation}" expected-value="hrule" listener="ActionListener" text="Horizontal rule" gridx="3" gridy="2" fill="none" weightx="0" anchor="west" enable="true">\r
-         <actionPerformed choose="tab-representation">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Radiobutton>\r
-       <Radiobutton value="{@tab-representation}" expected-value="vrule" listener="ActionListener" text="Vertical rule" gridx="4" gridy="2" fill="none" weightx="0" anchor="west" enable="true">\r
-         <actionPerformed choose="tab-representation">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Radiobutton>\r
+        <Label text="Representation:" gridx="1" gridy="2" weightx="0"/>\r
+        <Radiobutton value="{@tab-representation}" expected-value="chevrons" listener="ActionListener" text="Chevrons" gridx="2" gridy="2" fill="none" weightx="0" anchor="west" enable="true">\r
+          <actionPerformed choose="tab-representation">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
+        <Radiobutton value="{@tab-representation}" expected-value="hrule" listener="ActionListener" text="Horizontal rule" gridx="3" gridy="2" fill="none" weightx="0" anchor="west" enable="true">\r
+          <actionPerformed choose="tab-representation">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
+        <Radiobutton value="{@tab-representation}" expected-value="vrule" listener="ActionListener" text="Vertical rule" gridx="4" gridy="2" fill="none" weightx="0" anchor="west" enable="true">\r
+          <actionPerformed choose="tab-representation">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
 \r
-       <Checkbox checked="{@automatic-indent}" selected-value="true" unselected-value="false" listener="ActionListener" text="Enable auto indentation" gridx="1" gridy="3" fill="none" weightx="0" anchor="west">\r
-         <actionPerformed choose="use-spaces">\r
-           <xsl:call-template name="context"/>\r
-         </actionPerformed>\r
-       </Checkbox>\r
+        <Checkbox checked="{@automatic-indent}" selected-value="true" unselected-value="false" listener="ActionListener" text="Enable auto indentation" gridx="1" gridy="3" fill="none" weightx="0" anchor="west">\r
+          <actionPerformed choose="use-spaces">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Checkbox>\r
         <Label gridy="4" text="Indent size:"/>\r
         <Panel gridy="4" gridx="2" >\r
           <xsl:call-template name="Select">\r
     </Title>\r
   </xsl:template>\r
 \r
-  <!--xsl:template match="scinotes-syntax">\r
-    <VSpace height="20"/>\r
-    <Title text="Tabs &amp; Indents">\r
-      <Grid ipady="30" insets="large">\r
-        <Label text="Tab size:"/>\r
-        <Panel gridx="2" >\r
-          <xsl:call-template name="Select">\r
-            <xsl:with-param name="among">\r
-              <option tab-size="2"/>\r
-              <option tab-size="4"/>\r
-              <option tab-size="8"/>\r
-            </xsl:with-param>\r
-          </xsl:call-template>\r
-        </Panel>\r
-        <Panel gridx="3">\r
-          <xsl:call-template name="BooleanCheckBox">\r
-            <xsl:with-param name="attr-name" select="'use-spaces'"/>\r
-            <xsl:with-param name="text" select="'Tab key insert spaces'"/>\r
-          </xsl:call-template>\r
-        </Panel>\r
-        <HBox gridy="2" gridwidth="3">\r
-          View\r
-          <HSpace width="2"/>\r
-          <Link listener="MouseListener" text="Scinotes tab keys preferences">\r
-            <mouseClicked callback="customScinotesColors"/>\r
-          </Link>\r
-        </HBox>\r
-        <Label gridy="3" text="Indent size:"/>\r
-        <Panel gridy="3" gridx="2" >\r
-          <xsl:call-template name="Select">\r
-            <xsl:with-param name="among">\r
-              <option indent-size="2"/>\r
-              <option indent-size="4"/>\r
-              <option indent-size="8"/>\r
-            </xsl:with-param>\r
-          </xsl:call-template>\r
-        </Panel>\r
-        <HBox gridy="4" gridwidth="3">\r
-          <xsl:call-template name="BooleanCheckBox">\r
-            <xsl:with-param name="attr-name" select="'automatic-indent'"/>\r
-            <xsl:with-param name="text" select="' Enable automatic indenting'"/>\r
-          </xsl:call-template>\r
-          <Glue/>\r
-        </HBox>\r
+  <xsl:template match="scinotes-autosave">\r
+    <Checkbox checked="{@enable}" selected-value="true" unselected-value="false" listener="ActionListener" text="Enable autosave in Scinotes">\r
+      <actionPerformed choose="enable">\r
+       <xsl:call-template name="context"/>\r
+      </actionPerformed>\r
+    </Checkbox>   \r
+    <VSpace height="10"/>\r
+    <Title text="Save options">\r
+      <Grid>\r
+       <Label gridx="1" gridy="1" weightx="0" anchor="west" text="Save every " enable="{@enable}"/>\r
+        <NumericalSpinner gridx="2"\r
+                          gridy="1"\r
+                          weightx="0"\r
+                          min-value = "1"\r
+                          increment = "1"\r
+                          length = "4"\r
+                          listener = "ActionListener"\r
+                         enable = "{@enable}"\r
+                          value = "{@save-every}">\r
+          <actionPerformed choose="save-every">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </NumericalSpinner>\r
+       <Label gridx="3" gridy="1" weightx="0" anchor="west" text=" minutes " enable="{@enable}"/>\r
+        <Panel gridx="4" gridy="1" gridheight="1" fill="both"/>\r
+       </Grid>\r
+    </Title>\r
+    <VSpace height="10"/>\r
+    <Title text="Close options">\r
+      <Checkbox checked="{@automatic-delete}" selected-value="true" unselected-value="false" listener="ActionListener" text="Delete automatically saved files" enable="{@enable}">\r
+       <actionPerformed choose="automatic-delete">\r
+         <xsl:call-template name="context"/>\r
+       </actionPerformed>\r
+      </Checkbox>\r
+    </Title>\r
+    <VSpace height="10"/>\r
+    <Title text="Filename">\r
+      <Grid>\r
+        <Radiobutton value="{@append-filename}" expected-value="true" listener="ActionListener" text="Append filename with: " gridx="1" gridy="1" fill="none" weightx="0" anchor="west" enable="{@enable}">\r
+          <actionPerformed choose="append-filename">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
+        <Panel gridx="2" gridy="1" gridheight="1" fill="both"/>\r
+        <Entry gridx="3" gridy="1" weightx="1" anchor="above_baseline"\r
+               listener="EntryListener"\r
+               text="{@append-with}">\r
+          <xsl:attribute name="enable">\r
+            <xsl:if test="@enable='true' and @append-filename='true'">\r
+              <xsl:text>true</xsl:text>\r
+            </xsl:if>\r
+          </xsl:attribute>\r
+          <entryChanged choose="append-with">\r
+            <xsl:call-template name="context"/>\r
+          </entryChanged>\r
+        </Entry>\r
+        <Radiobutton value="{@append-filename}" expected-value="false" listener="ActionListener" text="Replace extension with: " gridx="1" gridy="2" fill="none" weightx="0" anchor="west" enable="{@enable}">\r
+          <actionPerformed choose="append-filename">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
+        <Entry gridx="3" gridy="2" weightx="1" anchor="above_baseline"\r
+               listener="EntryListener"\r
+               text="{@replace-with}">\r
+          <xsl:attribute name="enable">\r
+            <xsl:if test="@enable='true' and @append-filename='false'">\r
+              <xsl:text>true</xsl:text>\r
+            </xsl:if>\r
+          </xsl:attribute>\r
+          <entryChanged choose="replace-with">\r
+            <xsl:call-template name="context"/>\r
+          </entryChanged>\r
+        </Entry>\r
+      </Grid>\r
+    </Title>\r
+    <VSpace height="10"/>\r
+    <Title text="Location">\r
+      <Grid>\r
+        <Radiobutton value="{@source-flag}" expected-value="true" listener="ActionListener" text="Source file directory" gridx="1" gridy="1" fill="none" weightx="0" anchor="west" enable="{@enable}">\r
+          <actionPerformed choose="source-flag">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
+        <Radiobutton value="{@source-flag}" expected-value="false" listener="ActionListener" text="Single directory" gridx="1" gridy="2" fill="none" weightx="0" anchor="west" enable="{@enable}">\r
+          <actionPerformed choose="source-flag">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </Radiobutton>\r
+        <Panel gridx="2" gridy="2" gridheight="1" fill="both"/>\r
+        <FileSelector gridx="3" gridy="2" href="{@single-directory}" mask="*"\r
+                      desc="Choose an autosave directory"\r
+                      dir-selection = "true"\r
+                      listener="EntryListener">\r
+          <xsl:attribute name="enable">\r
+            <xsl:if test="@enable='true' and @source-flag='false'">\r
+              <xsl:text>true</xsl:text>\r
+            </xsl:if>\r
+          </xsl:attribute>\r
+          <entryChanged choose="single-directory">\r
+            <xsl:call-template name="context"/>\r
+          </entryChanged>\r
+        </FileSelector>\r
       </Grid>\r
     </Title>\r
-  </xsl:template-->\r
-\r
-  <xsl:template match="scinotes-autosave">\r
-    <HBox>\r
-      <xsl:call-template name="BooleanCheckBox">\r
-        <xsl:with-param name="attr-name" select="'enable'"/>\r
-      </xsl:call-template>\r
-      Enable autosave in Scinotes\r
-      <Glue/>\r
-    </HBox>\r
-    <xsl:choose>\r
-      <xsl:when test="@enable='true'">\r
-        <Title text="Save options">\r
-          <HBox>\r
-            Save every\r
-            <xsl:call-template name="Select">\r
-              <xsl:with-param name="among">\r
-                <option save-every="2"/>\r
-                <option save-every="3"/>\r
-                <option save-every="5"/>\r
-                <option save-every="7"/>\r
-                <option save-every="11"/>\r
-                <option save-every="13"/>\r
-              </xsl:with-param>\r
-            </xsl:call-template>\r
-            minutes\r
-            <Glue/>\r
-            <xsl:call-template name="BooleanCheckBox">\r
-              <xsl:with-param name="attr-name" select="'save-untitled'"/>\r
-            </xsl:call-template>\r
-            Save untitled files\r
-          </HBox>\r
-        </Title>\r
-        <Title text="Close options">\r
-          <HBox>\r
-            <xsl:call-template name="BooleanCheckBox">\r
-              <xsl:with-param name="attr-name" select="'automatic-delete'"/>\r
-            </xsl:call-template>\r
-            Delete automatically saved files\r
-            <Glue/>\r
-          </HBox>\r
-        </Title>\r
-        <Title text="Filename">\r
-          <Grid>\r
-            <Panel>\r
-              <xsl:call-template name="BooleanRadio">\r
-                <xsl:with-param name="attr-name" select="'append-flag'"/>\r
-                <xsl:with-param name="text" select="'Append filename with'"/>\r
-              </xsl:call-template>\r
-            </Panel>\r
-            <Entry gridx="2" enable="{@append-flag='true'}" text="{@append-with}" listener="ActionListener">\r
-              <actionPerformed choose="append-with">\r
-                <xsl:call-template name="context"/>\r
-              </actionPerformed>\r
-            </Entry>\r
-            <Panel gridy="2">\r
-              <xsl:call-template name="InvertedRadio">\r
-                <xsl:with-param name="attr-name" select="'append-flag'"/>\r
-                <xsl:with-param name="text" select="'Replace extension with'"/>\r
-              </xsl:call-template>\r
-            </Panel>\r
-            <Entry gridy="2" gridx="2" enable="{@append-flag='false'}" text="{@replace-with}" listener="ActionListener">\r
-              <actionPerformed choose="replace-with">\r
-                <xsl:call-template name="context"/>\r
-              </actionPerformed>\r
-            </Entry>\r
-          </Grid>\r
-        </Title>\r
-        <Title text="Location">\r
-          <Grid>\r
-            <Panel>\r
-              <xsl:call-template name="BooleanRadio">\r
-                <xsl:with-param name="attr-name" select="'source-flag'"/>\r
-                <xsl:with-param name="text" select="'Source file directory'"/>\r
-              </xsl:call-template>\r
-            </Panel>\r
-            <Panel gridy="2" >\r
-              <xsl:call-template name="InvertedRadio">\r
-                <xsl:with-param name="attr-name" select="'source-flag'"/>\r
-                <xsl:with-param name="text" select="'Single directory:'"/>\r
-              </xsl:call-template>\r
-            </Panel>\r
-            <FileSelector gridx="2" gridy="2" enable="{@source-flag='false'}" href="{@single-directory}" mask="*"\r
-                          desc="Choose an autosave directory"\r
-                          dir-selection = "true"\r
-                          listener="DocumentListener">\r
-              <actionPerformed choose="single-directory">\r
-                <xsl:call-template name="context"/>\r
-              </actionPerformed>\r
-            </FileSelector>\r
-          </Grid>\r
-        </Title>\r
-      </xsl:when>\r
-      <xsl:otherwise>\r
-        <VSpace height="350"/>\r
-      </xsl:otherwise>\r
-    </xsl:choose>\r
   </xsl:template>\r
 </xsl:stylesheet>\r
 \r
index 2b1635c..dc533be 100644 (file)
@@ -175,6 +175,7 @@ public class SciNotes extends SwingScilabTab {
         Document doc = ScilabXMLUtilities.readDocument(System.getenv("SCI") + "/modules/console/etc/Actions-Configuration.xml");
         actionToName = XConfiguration.get(doc, "name", String.class, "action", String.class, XPATH_SCINOTES_ACTION);
         XConfiguration.addXConfigurationListener(new SciNotesConfiguration());
+        SciNotesAutosave.autosave();
     }
 
     /**
@@ -230,6 +231,9 @@ public class SciNotes extends SwingScilabTab {
             setKeyStrokeActions();
             setAllMenus();
         }
+        if (conf.autosave) {
+            SciNotesAutosave.autosave();
+        }
         updatePanes(conf);
     }
 
@@ -646,7 +650,7 @@ public class SciNotes extends SwingScilabTab {
      */
     public void restorePreviousSession() {
         restored = true;
-        if (!ConfigSciNotesManager.getRestoreOpenedFiles() || ConfigSciNotesManager.countExistingOpenFiles(getUUID()) == 0) {
+        if (!SciNotesOptions.getSciNotesPreferences().restartOpen || !ConfigSciNotesManager.getRestoreOpenedFiles() || ConfigSciNotesManager.countExistingOpenFiles(getUUID()) == 0) {
             if (getTabPane().getTabCount() != 1 || getTextPane(0).getName() != null) {
                 openFile(null, 0, null);
             }
@@ -791,6 +795,10 @@ public class SciNotes extends SwingScilabTab {
          */
 
         scinotesList.remove(this);
+        if (scinotesList.size() == 0) {
+            SciNotesAutosave.stopAutosave();
+        }
+
         editor = null;
         ConfigSciNotesManager.resetDocument();
     }
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesAutosave.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesAutosave.java
new file mode 100644 (file)
index 0000000..95c5fed
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2012 - Scilab Enterprises -Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.scinotes;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.swing.Timer;
+
+import org.scilab.modules.core.Scilab;
+import org.scilab.modules.scinotes.utils.SaveFile;
+import org.scilab.modules.scinotes.utils.SciNotesMessages;
+
+public class SciNotesAutosave implements ActionListener {
+
+    private static SciNotesAutosave instance;
+    private static Set<File> toRemove = new HashSet<File>();
+
+    static {
+        Scilab.registerFinalHook(new Runnable() {
+            public void run() {
+                for (File f : toRemove) {
+                    if (f.exists()) {
+                        try {
+                            f.delete();
+                        } catch (Exception e) { }
+                    }
+                }
+            }
+        });
+    }
+
+    private Timer timer;
+
+    private SciNotesAutosave() {
+        timer = new Timer(SciNotesOptions.getSciNotesAutosave().saveEvery * 60 * 1000, this);
+        timer.setRepeats(true);
+        timer.start();
+    }
+
+    public static void autosave() {
+        if (SciNotesOptions.getSciNotesAutosave().autoSave) {
+            startAutosave();
+        } else {
+            stopAutosave();
+        }
+    }
+
+    static void startAutosave() {
+        if (instance == null && SciNotesOptions.getSciNotesAutosave().autoSave) {
+            instance = new SciNotesAutosave();
+        }
+    }
+
+    static void stopAutosave() {
+        if (instance != null) {
+            instance.timer.stop();
+            instance = null;
+        }
+    }
+
+    public void actionPerformed(ActionEvent e) {
+        SciNotesOptions.Autosave as = SciNotesOptions.getSciNotesAutosave();
+        if (as.autoSave) {
+            for (SciNotes ed : SciNotes.getSciNotesList()) {
+                int n = ed.getTabPane().getTabCount();
+                for (int i = 0; i < n; i++) {
+                    ScilabEditorPane sep = ed.getTextPane(i);
+                    if (sep.getName() != null && !sep.getName().isEmpty() && !sep.checkExternalModif() && ((ScilabDocument) sep.getDocument()).isContentModified() && ((ScilabDocument) sep.getDocument()).isContentModifiedSinceBackup()) {
+                        String name = sep.getName();
+                        if (as.appendFilename) {
+                            name += as.appendWith;
+                        } else {
+                            int dotpos = name.lastIndexOf('.');
+                            if (dotpos != -1) {
+                                name = name.substring(0, dotpos + 1) + as.replaceWith;
+                            }
+                        }
+                        File file = new File(name);
+                        String filename = file.getName();
+                        if (!as.sourceFlag) {
+                            file = new File(as.singleDirectory, filename);
+                        }
+                        boolean different = new File(sep.getName()).equals(file);
+
+                        boolean success = SaveFile.doSave(sep, i, file, ed.getEditorKit(), false, true);
+                        if (!success) {
+                            ed.getInfoBar().setText(String.format(SciNotesMessages.AUTOSAVE_ERROR, filename));
+                            return;
+                        } else {
+                            if (!different) {
+                                ((ScilabDocument) sep.getDocument()).setContentModified(false);
+                                sep.setLastModified(file.lastModified());
+                            } else {
+                                ((ScilabDocument) sep.getDocument()).setContentModifiedSinceBackup(false);
+                                if (as.automaticDelete) {
+                                    toRemove.add(file);
+                                }
+                            }
+                        }
+                    }
+                }
+                ed.getInfoBar().setText(SciNotesMessages.AUTOSAVE_FINISHED);
+            }
+        }
+    }
+}
index 6bf4f4f..29ffb69 100644 (file)
@@ -157,6 +157,7 @@ public class SciNotesOptions {
         public boolean autoSave;
         public int saveEvery;
         public boolean automaticDelete;
+        public boolean appendFilename;
         public String appendWith;
         public String replaceWith;
         public boolean sourceFlag;
@@ -164,11 +165,12 @@ public class SciNotesOptions {
 
         private Autosave() { }
 
-        @XConfAttribute(tag = "scinotes-autosave", attributes = {"enable", "save-every", "automatic-delete", "append-with", "replace-with", "source-flag", "single-directory"})
-        private void set(boolean autoSave, int saveEvery, boolean automaticDelete, String appendWith, String replaceWith, boolean sourceFlag, String singleDirectory) {
+        @XConfAttribute(tag = "scinotes-autosave", attributes = {"enable", "save-every", "automatic-delete", "append-filename", "append-with", "replace-with", "source-flag", "single-directory"})
+        private void set(boolean autoSave, int saveEvery, boolean automaticDelete, boolean appendFilename, String appendWith, String replaceWith, boolean sourceFlag, String singleDirectory) {
             this.autoSave = autoSave;
             this.saveEvery = saveEvery;
             this.automaticDelete = automaticDelete;
+            this.appendFilename = appendFilename;
             this.appendWith = appendWith;
             this.replaceWith = replaceWith;
             this.sourceFlag = sourceFlag;
index a71ba66..1af42ca 100644 (file)
@@ -73,6 +73,7 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
     private Set<String> functions = new HashSet<String>(INITFUNCTIONSNUMBER);
 
     private boolean contentModified;
+    private boolean contentModifiedSinceBackup;
     private boolean alphaOrder;
 
     // Editor's default encoding is UTF-8
@@ -105,6 +106,7 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
         undoManagerEnabled = true;
 
         contentModified = false;
+        contentModifiedSinceBackup = false;
     }
 
     /**
@@ -260,6 +262,29 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
         }
     }
 
+    public void addEOL() {
+        if (SciNotesOptions.getSciNotesPreferences().addLineTermination) {
+            int len = getLength();
+            int lenEOL = getEOL().length();
+            if (getLength() >= lenEOL) {
+                try {
+                    String end = getText(len - lenEOL, lenEOL);
+                    if (!end.equals(getEOL())) {
+                        insertString(len, getEOL(), null);
+                    }
+                } catch (BadLocationException e) {
+                    System.err.println(e);
+                }
+            } else {
+                try {
+                    insertString(len, getEOL(), null);
+                } catch (BadLocationException e) {
+                    System.err.println(e);
+                }
+            }
+        }
+    }
+
     /**
      * Begins a compound edit (for the undo)
      */
@@ -312,6 +337,22 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
     }
 
     /**
+     * isContentModifiedSinceBackup
+     * @return boolean
+     */
+    public boolean isContentModifiedSinceBackup() {
+        return contentModifiedSinceBackup;
+    }
+
+    /**
+     * setContentModified
+     * @param contentModified boolean
+     */
+    public void setContentModifiedSinceBackup(boolean contentModified) {
+        this.contentModifiedSinceBackup = contentModified;
+    }
+
+    /**
      * setContentModified
      * @param contentModified boolean
      */
@@ -320,6 +361,8 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
         if (!contentModified) {
             undo.setReference();
             pane.updateTitle();
+        } else {
+            this.contentModifiedSinceBackup = true;
         }
     }
 
@@ -696,6 +739,7 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
             contentModified = true;
             pane.updateTitle();
         }
+        contentModifiedSinceBackup = true;
 
         DocumentEvent.ElementChange chg = ev.getChange(getDefaultRootElement());
         if (chg != null) {
index cf46ace..9032e37 100644 (file)
@@ -31,6 +31,7 @@ import org.scilab.modules.gui.messagebox.ScilabModalDialog.ButtonType;
 import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
 import org.scilab.modules.scinotes.ScilabDocument;
 import org.scilab.modules.scinotes.ScilabEditorPane;
+import org.scilab.modules.scinotes.SciNotesOptions;
 
 /**
  * Save File utility class
@@ -54,14 +55,29 @@ public final class SaveFile {
      * @return true if saved
      */
     public static boolean doSave(ScilabEditorPane textPane, int index, File fOut, EditorKit editorKit) {
+        return doSave(textPane, index, fOut, editorKit, true, false);
+    }
+
+    /**
+     * save text in JEditorPane
+     * @param textPane JEditorPane
+     * @param fOut File
+     * @param editorKit EditorKit
+     * @return true if saved
+     */
+    public static boolean doSave(ScilabEditorPane textPane, int index, File fOut, EditorKit editorKit, boolean addEOL, boolean silent) {
         ScilabDocument styledDocument = (ScilabDocument) textPane.getDocument();
         boolean enc = false;
-        if (!styledDocument.getEncoding().equalsIgnoreCase(ConfigSciNotesManager.getDefaultEncoding())) {
-            String msg = String.format(SciNotesMessages.DIFFERENT_ENCODINGS, styledDocument.getEncoding(), ConfigSciNotesManager.getDefaultEncoding());
-            if (ScilabModalDialog.show(textPane.getEditor(), msg, SciNotesMessages.DIFFERENT_ENCODINGS_TITLE, IconType.QUESTION_ICON, ButtonType.YES_NO) == AnswerOption.NO_OPTION) {
+        if (!styledDocument.getEncoding().equalsIgnoreCase(SciNotesOptions.getSciNotesPreferences().encoding)) {
+            if (!silent) {
+                String msg = String.format(SciNotesMessages.DIFFERENT_ENCODINGS, styledDocument.getEncoding(), SciNotesOptions.getSciNotesPreferences().encoding);
+                if (ScilabModalDialog.show(textPane.getEditor(), msg, SciNotesMessages.DIFFERENT_ENCODINGS_TITLE, IconType.QUESTION_ICON, ButtonType.YES_NO) == AnswerOption.NO_OPTION) {
+                    return false;
+                }
+                enc = true;
+            } else {
                 return false;
             }
-            enc = true;
         }
 
         try {
@@ -71,7 +87,9 @@ public final class SaveFile {
         }
 
         if (!fOut.canWrite()) {
-            ScilabModalDialog.show(textPane.getEditor(), SciNotesMessages.NOTWRITABLE, SciNotesMessages.SCINOTES_ERROR, IconType.ERROR_ICON);
+            if (!silent) {
+                ScilabModalDialog.show(textPane.getEditor(), SciNotesMessages.NOTWRITABLE, SciNotesMessages.SCINOTES_ERROR, IconType.ERROR_ICON);
+            }
             return false;
         }
 
@@ -82,6 +100,10 @@ public final class SaveFile {
         if (styledDocument.getEOL().compareTo(defaultEol) != 0) {
             System.setProperty(LINE_SEPARATOR, styledDocument.getEOL());
         }
+        if (addEOL) {
+            styledDocument.addEOL();
+        }
+
         boolean bReturn = false;
 
         BufferedWriter bw = null;
index 20b3941..1af2c9e 100644 (file)
@@ -227,6 +227,9 @@ public class SciNotesMessages {
     public static final String DIFFERENT_ENCODINGS_TITLE = Messages.gettext("Encoding problems");
     public static final String CANNOT_GUESS_ENCODING = Messages.gettext("Cannot guess the file encoding.");
 
+    public static final String AUTOSAVE_ERROR = Messages.gettext("Cannot save the file %s... stop the backup process");
+    public static final String AUTOSAVE_FINISHED = Messages.gettext("Backup finsihed...");
+
     /**
      * "Change Colors" message
      */