SciNotes Prefs: choose the eol according to the OS 41/8441/3
Calixte DENIZET [Tue, 31 Jul 2012 10:51:54 +0000 (12:51 +0200)]
Change-Id: If930417cee7f35fad702066fb4ad07a339a198d8

scilab/modules/preferences/etc/XConfiguration.xml
scilab/modules/scinotes/etc/XConfiguration-scinotes.xml
scilab/modules/scinotes/etc/XConfiguration-scinotes.xsl
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesOptions.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/SaveFile.java

index 19de192..cdb39e9 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<interface version="0.04" path="1/" width="800" height="550">
+<interface version="0.05" path="1/" width="800" height="550">
   <general/>
   <web/>
   <preference/>
index fbf502b..f879ac6 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <scinotes title="SciNotes">
   <body>
-    <scinotes-preferences restart-reopen="true" add-line-termination="true" number-of-recently-open="5" encoding="utf-8" eol="Unix (LF)" scinotes="true" cmd="" macro="" external-cmd="true"/>
+    <scinotes-preferences restart-reopen="true" add-line-termination="true" number-of-recently-open="5" encoding="utf-8" eol="" scinotes="true" cmd="" macro="" external-cmd="true"/>
   </body>
   <display title="_(Display)">
     <body>
index 0a21154..16e4c8c 100644 (file)
           </xsl:call-template>\r
         </Panel>\r
         <Label gridx="1" gridy="5" weightx="0" text="_(Default End-Of-Line: )"/>\r
-        <Panel gridx="3" gridy="5">\r
-          <xsl:call-template name="Select">\r
-            <xsl:with-param name="among">\r
-              <option eol="Unix (LF)"/>\r
-              <option eol="Windows (CR+LF)"/>\r
-              <option eol="Mac OS (CR)"/>\r
-            </xsl:with-param>\r
-          </xsl:call-template>\r
-        </Panel>\r
+        <Select gridx="3" gridy="5" listener="ActionListener">\r
+          <actionPerformed choose="eol">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+          <xsl:variable name="eol">\r
+            <xsl:choose>\r
+              <xsl:when test="@eol=''">\r
+                <xsl:choose>\r
+                  <xsl:when test="$OS='Windows'">\r
+                    <xsl:text>Windows (CR+LF)</xsl:text>\r
+                  </xsl:when>\r
+                  <xsl:when test="$OS='Mac'">\r
+                    <xsl:text>Mac OS (CR)</xsl:text>\r
+                  </xsl:when>\r
+                  <xsl:otherwise>\r
+                    <xsl:text>Unix (LF)</xsl:text>\r
+                  </xsl:otherwise>\r
+                </xsl:choose>\r
+              </xsl:when>\r
+              <xsl:otherwise>\r
+                <xsl:value-of select="@eol"/>\r
+              </xsl:otherwise>\r
+            </xsl:choose>\r
+          </xsl:variable>\r
+          <option value="Unix (LF)">\r
+            <xsl:if test="$eol='Unix (LF)'">\r
+              <xsl:attribute name="selected">selected</xsl:attribute>\r
+            </xsl:if>\r
+          </option>\r
+          <option value="Windows (CR+LF)">\r
+            <xsl:if test="$eol='Windows (CR+LF)'">\r
+              <xsl:attribute name="selected">selected</xsl:attribute>\r
+            </xsl:if>\r
+          </option>\r
+          <option value="Mac OS (CR)">\r
+            <xsl:if test="$eol='Mac OS (CR)'">\r
+              <xsl:attribute name="selected">selected</xsl:attribute>\r
+            </xsl:if>\r
+          </option>\r
+        </Select>\r
       </Grid>\r
     </Title>\r
   </xsl:template>\r
           </Checkbox>\r
           <Panel gridx="5" gridy="1" weightx="1"/>\r
           <Label gridx="6" gridy="1" weightx="0" text="_(Style: )" enable="{@highlight-brackets}"/>\r
-         <Select gridx="7" gridy="1" listener="ActionListener" enable="{@highlight-brackets}">\r
-           <actionPerformed choose="brackets-highlightment">\r
-             <xsl:call-template name="context"/>\r
-           </actionPerformed>\r
-           <option value="_(Filled)" key="Filled"/>\r
-           <option value="_(Framed)" key="Framed"/>\r
-           <option value="_(Underlined)" key="Underlined"/>\r
-         </Select>\r
+          <Select gridx="7" gridy="1" listener="ActionListener" enable="{@highlight-brackets}">\r
+            <actionPerformed choose="brackets-highlightment">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+            <option value="_(Filled)" key="Filled"/>\r
+            <option value="_(Framed)" key="Framed"/>\r
+            <option value="_(Underlined)" key="Underlined"/>\r
+          </Select>\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
           </Checkbox>\r
           <Panel gridx="5" gridy="1" weightx="1"/>\r
           <Label gridx="6" gridy="1" weightx="0" text="_(Style: )" enable="{@highlight-keywords}"/>\r
-         <Select gridx="7" gridy="1" listener="ActionListener" enable="{@highlight-keywords}">\r
-           <actionPerformed choose="keywords-highlightment">\r
-             <xsl:call-template name="context"/>\r
-           </actionPerformed>\r
-           <option value="_(Filled)" key="Filled"/>\r
-           <option value="_(Framed)" key="Framed"/>\r
-         </Select>\r
+          <Select gridx="7" gridy="1" listener="ActionListener" enable="{@highlight-keywords}">\r
+            <actionPerformed choose="keywords-highlightment">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+            <option value="_(Filled)" key="Filled"/>\r
+            <option value="_(Framed)" key="Framed"/>\r
+          </Select>\r
         </Grid>\r
       </Grid>\r
     </Title>\r
           </actionPerformed>\r
         </Checkbox>\r
         <Panel gridx="2" gridy="1" gridheight="1" fill="both"/>\r
-       <TextArea gridx="1" gridy="2" weightx="1" gridwidth="2" weighty="0" anchor="west"\r
-                 editable="true"\r
-                 rows="15"\r
-                 scroll="true"\r
-                 listener="EntryListener"\r
-                 enable="{@enable}">\r
-         <xsl:attribute name="text">\r
-           <xsl:value-of select="string(child::node()[1])" disable-output-escaping="yes"/>\r
-         </xsl:attribute>\r
-         <entryChanged choose-child="1">\r
+        <TextArea gridx="1" gridy="2" weightx="1" gridwidth="2" weighty="0" anchor="west"\r
+                  editable="true"\r
+                  rows="15"\r
+                  scroll="true"\r
+                  listener="EntryListener"\r
+                  enable="{@enable}">\r
+          <xsl:attribute name="text">\r
+            <xsl:value-of select="string(child::node()[1])" disable-output-escaping="yes"/>\r
+          </xsl:attribute>\r
+          <entryChanged choose-child="1">\r
             <xsl:call-template name="context"/>\r
           </entryChanged>\r
-       </TextArea>\r
+        </TextArea>\r
       </Grid>\r
-      </Title>\r
-    </xsl:template> \r
+    </Title>\r
+  </xsl:template>\r
 </xsl:stylesheet>\r
index 913b32e..bacaa26 100644 (file)
@@ -23,6 +23,7 @@ import javax.xml.xpath.XPathFactory;
 
 import org.w3c.dom.Document;
 
+import org.scilab.modules.commons.OS;
 import static org.scilab.modules.commons.xml.XConfiguration.XConfAttribute;
 import org.scilab.modules.commons.xml.XConfiguration;
 
@@ -67,7 +68,19 @@ public class SciNotesOptions {
             this.numberOfRecentlyOpen = numberOfRecentlyOpen;
             this.encoding = encoding.toLowerCase();
 
-            if (eol.startsWith("Windows")) {
+           if (eol.equals("")) {
+               switch (OS.get()) {
+               case WINDOWS:
+                   this.eol = ScilabDocument.EOLWIN;
+                   break;
+               case MAC:
+                   this.eol = ScilabDocument.EOLMAC;
+                   break;
+               default:
+                   this.eol = ScilabDocument.EOLUNIX;
+                   break;
+               }
+            } else if (eol.startsWith("Windows")) {
                 this.eol = ScilabDocument.EOLWIN;
             } else if (eol.startsWith("Mac")) {
                 this.eol = ScilabDocument.EOLMAC;
index 9032e37..8d9fd84 100644 (file)
@@ -112,7 +112,7 @@ public final class SaveFile {
 
         try {
             fos = new FileOutputStream(fOut);
-            osw = new OutputStreamWriter(fos, ConfigSciNotesManager.getDefaultEncoding());
+            osw = new OutputStreamWriter(fos, SciNotesOptions.getSciNotesPreferences().encoding);
             bw = new BufferedWriter(osw);
             editorKit.write(bw, styledDocument, 0, styledDocument.getLength());
             bw.flush();