Preferences: continue to connect SciNotes 66/7566/3
Calixte DENIZET [Mon, 18 Jun 2012 10:14:34 +0000 (12:14 +0200)]
Change-Id: I546f9f564b70e173def00eec4bfa4a78bfa7b1f6

29 files changed:
scilab/modules/commons/src/java/org/scilab/modules/commons/xml/XConfiguration.java
scilab/modules/console/etc/Actions-Configuration.xml
scilab/modules/console/etc/XConfiguration-general.xml
scilab/modules/core/macros/edit.sci
scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/Select.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/XCommonManager.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/XConfigManager.java
scilab/modules/scinotes/etc/XConfiguration-scinotes.xml
scilab/modules/scinotes/etc/XConfiguration-scinotes.xsl
scilab/modules/scinotes/etc/scinotesGUIConfiguration.xml
scilab/modules/scinotes/help/en_US/editor.xml
scilab/modules/scinotes/help/en_US/scinotes.xml [new file with mode: 0644]
scilab/modules/scinotes/macros/editor.sci [new file with mode: 0644]
scilab/modules/scinotes/sci_gateway/scinotes_gateway.xml
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/HelpOnTypingManager.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotes.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesConfiguration.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesGUI.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesLineNumberPanel.java
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/ScilabEditorKit.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabEditorPane.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabPlainView.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabView.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/TabManager.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ConfigTabulationsAction.java [deleted file]
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/DefaultEncodingAction.java [deleted file]
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/HorizontalWrapAction.java [deleted file]

index a680c3f..615246a 100644 (file)
@@ -292,19 +292,20 @@ public class XConfiguration {
     }
 
     public static void fireXConfigurationEvent() {
-        XConfigurationEvent event = null;
-        Object[] listeners = listenerList.getListenerList();
-        for (int i = listeners.length - 2; i >= 0; i -= 2) {
-            if (listeners[i] == XConfigurationListener.class) {
-                if (event == null) {
-                    event = new XConfigurationEvent(modifiedPaths);
+        if (!modifiedPaths.isEmpty()) {
+            XConfigurationEvent event = null;
+            Object[] listeners = listenerList.getListenerList();
+            for (int i = listeners.length - 2; i >= 0; i -= 2) {
+                if (listeners[i] == XConfigurationListener.class) {
+                    if (event == null) {
+                        event = new XConfigurationEvent(modifiedPaths);
+                    }
+                    ((XConfigurationListener) listeners[i + 1]).configurationChanged(event);
                 }
-
-                ((XConfigurationListener) listeners[i + 1]).configurationChanged(event);
             }
-        }
 
-        modifiedPaths.clear();
+            modifiedPaths.clear();
+        }
     }
 
     /**
index 190b9ac..303901e 100644 (file)
@@ -76,7 +76,6 @@
     <entry type="java" action="RestoreOpenedFilesAction" name="scinotes-restore-startup"/>
     <entry type="java" action="ExportAction" name="scinotes-export"/>
     <entry type="java" action="EncodingAction" name="scinotes-encoding"/>
-    <entry type="java" action="DefaultEncodingAction" name="scinotes-default-encoding"/>
     <entry type="java" action="EndOfLineAction" name="scinotes-eof"/>
     <entry type="java" action="CopySelectionInNewTabAction" name="scinotes-selection-new-tab"/>
     <entry type="java" action="SplitAction" name="scinotes-split"/>
index 095ade3..8f251bd 100644 (file)
@@ -16,7 +16,7 @@
   <shortcuts title="Shortcuts">
     <body>
       <actions active="scilab" name="Console" item="1" browse="--choose a file --" filter="">
-        <action-folder name="Console">
+        <action-folder name="Console" xconf-uid="console">
           <action key="OSSCKEY E" description="Execute" name="console-execute"/>
           <action key="OSSCKEY O" description="Open a file" name="console-open"/>
           <action key="OSSCKEY L" description="Load environment" name="console-load"/>
@@ -57,7 +57,7 @@
           <action key="" description="Open Bugzilla" name="console-bugzilla-website"/>
           <action key="Shift F1" description="About Scilab" name="console-about"/>
         </action-folder>
-        <action-folder name="Scinotes">
+        <action-folder name="Scinotes" xconf-uid="scinotes">
           <action key="OSSCKEY H" description="Auto complete (, [,..." name="scinotes-autocomplete-openers"/>
           <action key="OSSCKEY Shift H" description="Auto complete keyword" name="scinotes-autocomplete-keyword"/>
           <action key="OSSCKEY Shift G" description="Generate Help prototype" name="scinotes-help-prototype"/>
           <action key="" description="Convert quote to double quote" name="scinotes-double-quote"/>
           <action key="" description="Line numbering" name="scinotes-line-numbering"/>
         </action-folder>
-        <action-folder name="Xcos">
+        <action-folder name="Xcos" xconf-uid="xcos">
           <action key="OSSCKEY S" description="Save diagramm" name="xcos-save"/>
         </action-folder>
-        <action-folder name="Variable Browser">
+        <action-folder name="Variable Browser" xconf-uid="browsevar">
           <action key="OSSCKEY S" description="Save" name="variablebrowser-save"/>
         </action-folder>
-        <action-folder name="Variable Editor">
+        <action-folder name="Variable Editor" xconf-uid="editvar">
           <action key="OSSCKEY S" description="Save variable" name="editvar-save"/>
         </action-folder>
-        <action-folder name="History Browser">
+        <action-folder name="History Browser" xconf-uid="historybrowser">
           <action key="OSSCKEY S" description="Save history" name="historybrowser-save"/>
         </action-folder>
-        <action-folder name="File Browser">
+        <action-folder name="File Browser" xconf-uid="filebrowser">
           <action key="OSSCKEY S" description="Save file" name="filebrowser-save"/>
         </action-folder>
       </actions>
index 550bb95..3fccc44 100644 (file)
@@ -13,11 +13,6 @@ function edit(macroname,linenumber)
     // macroname : character string giving a macroname
     // linenumber : line number
 
-    if (~isdef("editor") & (funptr("editor")==0))  then
-        warning(sprintf(gettext("%s: Requires scilab editor.\n"), "edit"));
-        return
-    end
-
     [lhs,rhs] = argn(0);
     if (rhs > 2) then
         error(sprintf(gettext("%s: Wrong number of input argument(s): At least %d expected.\n"), "edit", 1));
index 687d149..3bd89a7 100644 (file)
@@ -58,10 +58,8 @@ public class Select extends JComboBox implements XComponent, XChooser {
         for (int i = 0; i < nodelist.getLength(); i++) {
             Node node = nodelist.item(i);
             if (node.getNodeName().equals("option")) {
-                String value = XConfigManager.getAttribute(node , "value");
-                String selected = XConfigManager.getAttribute(
-                        node ,
-                        "selected");
+                String value = XConfigManager.getAttribute(node, "value");
+                String selected = XConfigManager.getAttribute(node, "selected");
                 addItem(value);
                 if (selected.equals("selected")) {
                     select = index;
@@ -82,7 +80,7 @@ public class Select extends JComboBox implements XComponent, XChooser {
         for (int i = 0; i < nodelist.getLength(); i++) {
             Node node = nodelist.item(i);
             if (node.getNodeName().equals("option")) {
-                String selected = XConfigManager.getAttribute(node ,"selected");
+                String selected = XConfigManager.getAttribute(node , "selected");
                 if (selected.equals("selected")) {
                     select = index;
                 }
@@ -93,7 +91,7 @@ public class Select extends JComboBox implements XComponent, XChooser {
             setEnabled(false);
             setSelectedIndex(select);
         }
-        String enable     = XConfigManager.getAttribute(peer , "enable", "true");
+        String enable = XConfigManager.getAttribute(peer , "enable", "true");
         setEnabled(enable.equals("true"));
     }
 
index 84e28d0..82b134b 100644 (file)
@@ -568,7 +568,15 @@ public abstract class XCommonManager {
         Node n = node;
 
         while (n != null) {
-            stack.push(n.getNodeName());
+            String nname = n.getNodeName();
+            NamedNodeMap attrs = n.getAttributes();
+            if (attrs != null && attrs.getLength() != 0) {
+                Node attr = attrs.getNamedItem("xconf-uid");
+                if (attr != null) {
+                    nname += "[@xconf-uid=\"" + attr.getNodeValue() + "\"]";
+                }
+            }
+            stack.push(nname);
             n = n.getParentNode();
         }
 
index d08ea93..0db636d 100644 (file)
@@ -265,6 +265,7 @@ public final class XConfigManager extends XCommonManager {
         }
         if (callback.equals("Default")) {
             XConfiguration.invalidate();
+            XConfiguration.addModifiedPath("ALL");
             reloadTransformer(SCILAB_CONFIG_XSL);
             document = XConfiguration.createDocument();
             writeDocument(USER_CONFIG_FILE, document);
index ea06e26..92f3fc9 100644 (file)
@@ -1,11 +1,11 @@
 <?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="" external-cmd="true"/>
+    <scinotes-preferences restart-reopen="true" add-line-termination="true" number-of-recently-open="5" encoding="utf-8" eol="Unix (LF)" scinotes="true" cmd="" external-cmd="true"/>
   </body>
   <display title="Display">
     <body>
-      <scinotes-display highlight-current-line="true" current-line-color="#FACADE" show-line-numbers="true" wrap-lines="true" keywords-colorization="true" highlight-brackets="true" brackets-color="#E40087" brackets-highlightment="Framed" brackets-onmouseover="true" highlight-keywords="true" keywords-color="#FFF3D2" keywords-highlightment="Filled" keywords-onmouseover="true" whereami="false" tab-size="4" use-spaces="true" indent-size="4" automatic-indent="true"/>
+      <scinotes-display highlight-current-line="true" current-line-color="#FACADE" show-line-numbers="true" wrap-lines="true" keywords-colorization="true" highlight-brackets="true" brackets-color="#E40087" brackets-highlightment="Framed" brackets-onmouseover="true" highlight-keywords="true" keywords-color="#FFF3D2" keywords-highlightment="Filled" keywords-onmouseover="true" whereami="false" tab-size="4" tab-representation="chevrons" use-spaces="true" indent-size="4" automatic-indent="true" auto-complete-openers="true" auto-complete-keywords="true"/>
     </body>
   </display>
   <autosave title="Autosave">
index 36d09c2..14b003a 100644 (file)
@@ -41,7 +41,7 @@
               <xsl:call-template name="context"/>\r
             </entryChanged>\r
           </FileSelector>\r
-         <Radiobutton value="{@external-cmd}" expected-value="false" listener="ActionListener" text="Scilab macro: " gridx="1" gridy="2" fill="none" weightx="0" anchor="west" enable="{$enable}">\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
@@ -96,6 +96,7 @@
             <xsl:with-param name="among">\r
               <option encoding="utf-8"/>\r
               <option encoding="iso-8859-1"/>\r
+              <option encoding="windows-1252"/>\r
             </xsl:with-param>\r
           </xsl:call-template>\r
         </Panel>\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="2" fill="none" weightx="0" anchor="west">\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
+\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="3" text="Indent size:"/>\r
-        <Panel gridy="3" gridx="2" >\r
+        <Label gridy="4" text="Indent size:"/>\r
+        <Panel gridy="4" gridx="2" >\r
           <xsl:call-template name="Select">\r
             <xsl:with-param name="among">\r
               <option indent-size="2"/>\r
index 4f38148..2d218ce 100644 (file)
@@ -75,9 +75,6 @@
     <menu label="Format" mnemonic="P">
       <menuitem action="scinotes-tabify" label="Shift Right"/>
       <menuitem action="scinotes-untabify" label="Shift Left"/>
-      <!--menuitem action="ConfigTabulationsAction" label="Configure Tabulation"/-->
-      <separator/>
-      <!--menuitem action="HorizontalWrapAction" label="Horizontal wrapping"/-->
       <separator/>
       <menuitem action="scinotes-indent" label="Correct Indentation"/>
       <menuitem action="scinotes-remove-whites" label="Remove trailing spaces"/>
     
     <menu label="Options">
       <menuitem action="scinotes-encoding" label="Current file encoding"/>
-      <menuitem action="scinotes-default-encoding" label="Default SciNotes file encoding;UTF-8;Windows 1252 (ANSI);ISO-8859-1"/>
       <menuitem action="scinotes-eof" label="Line Endings"/>
       <separator/>
+      <menu label="Auto-completion on">
+        <menuitem action="scinotes-autocomplete-openers" label="(, [, ..."/>
+        <menuitem action="scinotes-autocomplete-keyword" label="if, function, ..."/>
+      </menu>
       <menuitem action="scinotes-line-numbering" label="Line numbering;Off;Normal;Whereami compatible"/>
       <!--menuitem action="HighlightCurrentLineAction" label="Highlight current line"/>
       <menuitem action="AutoIndentAction" label="Enable Auto Reformat"/>
index fc8d198..4cd9ee8 100644 (file)
     <pubdate>$LastChangedDate$</pubdate>
   </info>
   <refnamediv>
-    <refname>Editor</refname>
-    <refpurpose>Scinotes: Embedded Scilab text editor</refpurpose>
+    <refname>editor</refname>
+    <refpurpose>Call a the text editor as defined in the preferences</refpurpose>
   </refnamediv>
   <refsynopsisdiv>
     <title>Calling Sequence</title>
     <synopsis>
-      editor()
-      editor(file)
-      editor([file1, file2])
-      editor(file, line_number)
-      editor(file, line_number, macro_name)
-      editor([file1, file2], [line_number1, line_number2])
-      editor(file, 'readonly')
-      editor([file1, file2], 'readonly')
-      
+      editor(...)
     </synopsis>
   </refsynopsisdiv>
   <refsection>
-    <title>Arguments</title>
-    <variablelist>
-      <varlistentry>
-        <term>file</term>
-        <listitem>
-          <para>a string, the file to be opened.</para>
-        </listitem>
-      </varlistentry>
-      <varlistentry>
-        <term>[file1, file2]</term>
-        <listitem>
-          <para>a matrix of string, files to be opened.</para>
-        </listitem>
-      </varlistentry>
-    </variablelist>
-    <variablelist>
-      <varlistentry>
-        <term>line_number</term>
-        <listitem>
-          <para>An integer, the number of the line to be highlighted at the
-            opening of the file.
-          </para>
-        </listitem>
-      </varlistentry>
-    </variablelist>
-    <variablelist>
-      <varlistentry>
-        <term>macro_name</term>
-        <listitem>
-          <para>a string, the line number would be relative to the definition of the function macro_name</para>
-        </listitem>
-      </varlistentry>
-    </variablelist>
-    <variablelist>
-      <varlistentry>
-        <term>[line_number1, line_number2]</term>
-        <listitem>
-          <para>a matrix of integer, each opened file will have its corresponding
-            line highlighted.
-          </para>
-        </listitem>
-      </varlistentry>
-    </variablelist>
-  </refsection>
-  <refsection>
     <title>Description</title>
     <para>
-      <literal>Scinotes</literal> is an embedded Scilab text editor.
-    </para>
-    <para>It can be started with a fresh text buffer pressing the "Editor"
-      button on top of the main Scilab window, or from Scilab command line with
-      the instruction <literal>editor()</literal>, or it can open specific files
-      if invoked with any of the calling sequences above (whithout any
-      parameters, it opens editor with a blank file).
-    </para>
-    <para>The same invocation adds further files to an already opened
-      Editor.
-    </para>
-    <para>With the option 'readonly', files are opened in read-only mode so
-      they cannot be modified.
-    </para>
-    <para>Keyboard shortcuts are defined for most possible editing actions and
-      reported by the menu entries.
+      An external text editor can be used with Scilab.
     </para>
-    <para/>
-    <para>editor can be started in the following ways :</para>
-    <itemizedlist>
-      <listitem>
-        <para>By the menu Applications. Choose Applications =&gt;
-          Editor
-        </para>
-      </listitem>
-      <listitem>
-        <para>From the command line:</para>
-        <itemizedlist>
-          <listitem>
-            <para>editor()</para>
-          </listitem>
-          <listitem>
-            <para>editor(file)</para>
-          </listitem>
-          <listitem>
-            <para>editor([file1, file2])</para>
-          </listitem>
-          <listitem>
-            <para>editor(file, line_number)</para>
-          </listitem>
-          <listitem>
-            <para>editor([file1, file2], [line_number1, line_number2])</para>
-          </listitem>
-        </itemizedlist>
-      </listitem>
-    </itemizedlist>
   </refsection>
-  <refsection>
-    <title>Menus and Shortcuts</title>
-    <itemizedlist>
-      <listitem>
-        <para>Menu File</para>
-        <informaltable border="1">
-          <tr>
-            <td>
-              <para>Commande</para>
-            </td>
-            <td>
-              <para>Shortcut</para>
-            </td>
-            <td>
-              <para>Description</para>
-            </td>
-          </tr>
-          <tr>
-            <td>New...</td>
-            <td>&lt;CTRL-N&gt;</td>
-            <td>
-              <para>Open a new file</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Open...</td>
-            <td>&lt;CTRL-O&gt;</td>
-            <td>
-              <para>Open an existing file</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Recent Files</td>
-            <td/>
-            <td>
-              <para>Display files recently opened</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Save</td>
-            <td>&lt;CTRL-S&gt;</td>
-            <td>
-              <para>Save a file</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Save as...</td>
-            <td>&lt;CTRL-MAJ-S&gt;</td>
-            <td>
-              <para>Save a file as</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Page Setup</td>
-            <td/>
-            <td>
-              <para>Setup page for printing</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Print Preview</td>
-            <td>&lt;CTRL-MAJ-P&gt;</td>
-            <td>
-              <para>Open a print preview window</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Print...</td>
-            <td>&lt;CTRL-P&gt;</td>
-            <td>
-              <para>Print a file</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Close</td>
-            <td>&lt;CTRL-W&gt;</td>
-            <td>
-              <para>Close a file</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Quit</td>
-            <td>&lt;CTRL-Q&gt;</td>
-            <td>
-              <para>Close Editor</para>
-            </td>
-          </tr>
-        </informaltable>
-      </listitem>
-      <listitem>
-        <para>Menu Edit</para>
-        <informaltable border="1">
-          <tr>
-            <td>
-              <para>Commande</para>
-            </td>
-            <td>
-              <para>Shortcut</para>
-            </td>
-            <td>
-              <para>Description</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Undo</td>
-            <td>&lt;CTRL-Z&gt;</td>
-            <td>
-              <para>Undo action</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Redo</td>
-            <td>&lt;CTRL-Y&gt;</td>
-            <td>
-              <para>Redo action</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Cut</td>
-            <td>&lt;CTRL-X&gt;</td>
-            <td>
-              <para>Cut the selection</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Copy</td>
-            <td>&lt;CTRL-C&gt;</td>
-            <td>
-              <para>Copy the selection</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Paste</td>
-            <td>&lt;CTRL-V&gt;</td>
-            <td>
-              <para>Paste the selection</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Select All</td>
-            <td>&lt;CTRL-A&gt;</td>
-            <td>
-              <para>Select the entire document</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Delete</td>
-            <td/>
-            <td>
-              <para>Delete the selection</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Comment Selection</td>
-            <td>&lt;CTRL-D&gt;</td>
-            <td>
-              <para>Comment selected lines</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Uncomment Selection</td>
-            <td>&lt;CTRL-MAJ-D&gt;</td>
-            <td>
-              <para>Uncomment selected lines</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Tabify Selection</td>
-            <td>&lt;TAB&gt;</td>
-            <td>
-              <para>Tabify selected lines</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Untabify Selection</td>
-            <td>&lt;MAJ-TAB&gt;</td>
-            <td>
-              <para>Untabify selected lines</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Indent</td>
-            <td>&lt;CTRL-I&gt;</td>
-            <td>
-              <para>Indent selected lines</para>
-            </td>
-          </tr>
-        </informaltable>
-      </listitem>
-      <listitem>
-        <para>Menu Search</para>
-        <informaltable border="1">
-          <tr>
-            <td>
-              <para>Commande</para>
-            </td>
-            <td>
-              <para>Shortcut</para>
-            </td>
-            <td>
-              <para>Description</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Find/Replace</td>
-            <td>&lt;CTRL-F&gt;</td>
-            <td>
-              <para>Find and/or Replace an element</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Goto line</td>
-            <td>&lt;CTRL-G&gt;</td>
-            <td>
-              <para>Goto line</para>
-            </td>
-          </tr>
-        </informaltable>
-      </listitem>
-      <listitem>
-        <para>Menu View</para>
-        <informaltable border="1">
-          <tr>
-            <td>
-              <para>Commande</para>
-            </td>
-            <td>
-              <para>Shortcut</para>
-            </td>
-            <td>
-              <para>Description</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Show/Hide Toolbar</td>
-            <td/>
-            <td>
-              <para>Option to show or hide the toolbar</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Highlight current line</td>
-            <td>&lt;CTRL-J&gt;</td>
-            <td>
-              <para>Highlight the current line</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Line Numbers</td>
-            <td>&lt;CTRL-B&gt;</td>
-            <td>
-              <para>Display document's line numbers</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Set Colors...</td>
-            <td/>
-            <td>
-              <para>Color settings for documents</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Set Fonts...</td>
-            <td/>
-            <td>
-              <para>Font settings for documents</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Reset default font</td>
-            <td/>
-            <td>
-              <para>Reset default font settings for documents</para>
-            </td>
-          </tr>
-        </informaltable>
-      </listitem>
-      <listitem>
-        <para>Menu Document</para>
-        <informaltable border="1">
-          <tr>
-            <td>
-              <para>Commande</para>
-            </td>
-            <td>
-              <para>Shortcut</para>
-            </td>
-            <td>
-              <para>Description</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Syntax Type</td>
-            <td/>
-            <td>
-              <para>Syntax type settings (default type is Scilab)</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Encoding</td>
-            <td/>
-            <td>
-              <para>Encoding settings (default type is UTF-8
-                Encoding)
-              </para>
-            </td>
-          </tr>
-          <tr>
-            <td>Colorize</td>
-            <td/>
-            <td>
-              <para>Colorize the document</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Auto Indent</td>
-            <td/>
-            <td>
-              <para>Activate the automatic indentation</para>
-            </td>
-          </tr>
-        </informaltable>
-      </listitem>
-      <listitem>
-        <para>Menu Execute</para>
-        <informaltable border="1">
-          <tr>
-            <td>
-              <para>Commande</para>
-            </td>
-            <td>
-              <para>Shortcut</para>
-            </td>
-            <td>
-              <para>Description</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Load Into Scilab</td>
-            <td>&lt;CTRL-L&gt;</td>
-            <td>
-              <para>Load the entire document into the Scilab console</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Evaluate Selection</td>
-            <td/>
-            <td>
-              <para>Load the selection into the Scilab console</para>
-            </td>
-          </tr>
-          <tr>
-            <td>Execute Into Scilab</td>
-            <td>&lt;CTRL-E&gt;</td>
-            <td>
-              <para>If the file exist, execute the content of the file</para>
-            </td>
-          </tr>
-        </informaltable>
-      </listitem>
-    </itemizedlist>
-  </refsection>
-  <refsection>
-    <title>Remarks</title>
-    <variablelist>
-      <varlistentry>
-        <term>Document :</term>
-        <listitem>
-          <para>The default text colorization is the Scilab's syntax
-            colorization.
-          </para>
-          <para>
-            The <literal>auto-indent</literal> mode indent a line
-            according to Scilab's syntax (after a return action).
-          </para>
-          <para/>
-        </listitem>
-      </varlistentry>
-    </variablelist>
-  </refsection>
-  <refsection>
-    <title>Examples</title>
-    <programlisting role="example"><![CDATA[ 
-// editor without parameters
-editor();
-    
-// editor with a file name
-editor('SCI/modules/time/macros/datenum.sci');
-    
-// editor with a matrix of files name
-editor(['SCI/modules/time/macros/datenum.sci','SCI/modules/time/macros/datevec.sci']);
-    
-// editor with a file name and the line number to highlight
-editor('SCI/modules/time/macros/datenum.sci', 5);
-
-// editor with a file name and the line number to highlight
-editor('SCI/modules/time/macros/datenum.sci', 8, 'datenum');
-
-// editor with a matrix of files name and the corresponding matrix of lines to highlight
-// the files name matrix and the lines to highlight matrix should have the same size
-editor(['SCI/modules/time/macros/datenum.sci','SCI/modules/time/macros/datevec.sci'], [5,10]);
- ]]></programlisting>
+  <refsection role="see also">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="scinotes">scinotes</link>
+      </member>
+    </simplelist>
   </refsection>
 </refentry>
diff --git a/scilab/modules/scinotes/help/en_US/scinotes.xml b/scilab/modules/scinotes/help/en_US/scinotes.xml
new file mode 100644 (file)
index 0000000..6ae0e25
--- /dev/null
@@ -0,0 +1,533 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2009 - DIGITEO - Sylvestre KOUMAR
+ *
+ * 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
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="scinotes" xml:lang="en">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+  <refnamediv>
+    <refname>scinotes</refname>
+    <refpurpose>Scinotes: Embedded Scilab text editor</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>
+      scinotes()
+      scinotes(file)
+      scinotes([file1, file2])
+      scinotes(file, line_number)
+      scinotes(file, line_number, macro_name)
+      scinotes([file1, file2], [line_number1, line_number2])
+      scinotes(file, 'readonly')
+      scinotes([file1, file2], 'readonly')
+      
+    </synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Arguments</title>
+    <variablelist>
+      <varlistentry>
+        <term>file</term>
+        <listitem>
+          <para>a string, the file to be opened.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>[file1, file2]</term>
+        <listitem>
+          <para>a matrix of string, files to be opened.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+    <variablelist>
+      <varlistentry>
+        <term>line_number</term>
+        <listitem>
+          <para>An integer, the number of the line to be highlighted at the
+            opening of the file.
+          </para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+    <variablelist>
+      <varlistentry>
+        <term>macro_name</term>
+        <listitem>
+          <para>a string, the line number would be relative to the definition of the function macro_name</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+    <variablelist>
+      <varlistentry>
+        <term>[line_number1, line_number2]</term>
+        <listitem>
+          <para>a matrix of integer, each opened file will have its corresponding
+            line highlighted.
+          </para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Description</title>
+    <para>
+      <literal>Scinotes</literal> is an embedded Scilab text editor.
+    </para>
+    <para>It can be started with a fresh text buffer pressing the "Editor"
+      button on top of the main Scilab window, or from Scilab command line with
+      the instruction <literal>editor()</literal>, or it can open specific files
+      if invoked with any of the calling sequences above (whithout any
+      parameters, it opens editor with a blank file).
+    </para>
+    <para>The same invocation adds further files to an already opened
+      Editor.
+    </para>
+    <para>With the option 'readonly', files are opened in read-only mode so
+      they cannot be modified.
+    </para>
+    <para>Keyboard shortcuts are defined for most possible editing actions and
+      reported by the menu entries.
+    </para>
+    <para/>
+    <para>SciNotes can be started in the following ways :</para>
+    <itemizedlist>
+      <listitem>
+        <para>By the menu Applications. Choose Applications =&gt;
+          Editor
+        </para>
+      </listitem>
+      <listitem>
+        <para>From the command line:</para>
+        <itemizedlist>
+          <listitem>
+            <para>scinotes()</para>
+          </listitem>
+          <listitem>
+            <para>scinotes(file)</para>
+          </listitem>
+          <listitem>
+            <para>scinotes([file1, file2])</para>
+          </listitem>
+          <listitem>
+            <para>scinotes(file, line_number)</para>
+          </listitem>
+          <listitem>
+            <para>scinotes([file1, file2], [line_number1, line_number2])</para>
+          </listitem>
+        </itemizedlist>
+      </listitem>
+    </itemizedlist>
+  </refsection>
+  <refsection>
+    <title>Menus and Shortcuts</title>
+    <itemizedlist>
+      <listitem>
+        <para>Menu File</para>
+        <informaltable border="1">
+          <tr>
+            <td>
+              <para>Commande</para>
+            </td>
+            <td>
+              <para>Shortcut</para>
+            </td>
+            <td>
+              <para>Description</para>
+            </td>
+          </tr>
+          <tr>
+            <td>New...</td>
+            <td>&lt;CTRL-N&gt;</td>
+            <td>
+              <para>Open a new file</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Open...</td>
+            <td>&lt;CTRL-O&gt;</td>
+            <td>
+              <para>Open an existing file</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Recent Files</td>
+            <td/>
+            <td>
+              <para>Display files recently opened</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Save</td>
+            <td>&lt;CTRL-S&gt;</td>
+            <td>
+              <para>Save a file</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Save as...</td>
+            <td>&lt;CTRL-MAJ-S&gt;</td>
+            <td>
+              <para>Save a file as</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Page Setup</td>
+            <td/>
+            <td>
+              <para>Setup page for printing</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Print Preview</td>
+            <td>&lt;CTRL-MAJ-P&gt;</td>
+            <td>
+              <para>Open a print preview window</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Print...</td>
+            <td>&lt;CTRL-P&gt;</td>
+            <td>
+              <para>Print a file</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Close</td>
+            <td>&lt;CTRL-W&gt;</td>
+            <td>
+              <para>Close a file</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Quit</td>
+            <td>&lt;CTRL-Q&gt;</td>
+            <td>
+              <para>Close Editor</para>
+            </td>
+          </tr>
+        </informaltable>
+      </listitem>
+      <listitem>
+        <para>Menu Edit</para>
+        <informaltable border="1">
+          <tr>
+            <td>
+              <para>Commande</para>
+            </td>
+            <td>
+              <para>Shortcut</para>
+            </td>
+            <td>
+              <para>Description</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Undo</td>
+            <td>&lt;CTRL-Z&gt;</td>
+            <td>
+              <para>Undo action</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Redo</td>
+            <td>&lt;CTRL-Y&gt;</td>
+            <td>
+              <para>Redo action</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Cut</td>
+            <td>&lt;CTRL-X&gt;</td>
+            <td>
+              <para>Cut the selection</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Copy</td>
+            <td>&lt;CTRL-C&gt;</td>
+            <td>
+              <para>Copy the selection</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Paste</td>
+            <td>&lt;CTRL-V&gt;</td>
+            <td>
+              <para>Paste the selection</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Select All</td>
+            <td>&lt;CTRL-A&gt;</td>
+            <td>
+              <para>Select the entire document</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Delete</td>
+            <td/>
+            <td>
+              <para>Delete the selection</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Comment Selection</td>
+            <td>&lt;CTRL-D&gt;</td>
+            <td>
+              <para>Comment selected lines</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Uncomment Selection</td>
+            <td>&lt;CTRL-MAJ-D&gt;</td>
+            <td>
+              <para>Uncomment selected lines</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Tabify Selection</td>
+            <td>&lt;TAB&gt;</td>
+            <td>
+              <para>Tabify selected lines</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Untabify Selection</td>
+            <td>&lt;MAJ-TAB&gt;</td>
+            <td>
+              <para>Untabify selected lines</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Indent</td>
+            <td>&lt;CTRL-I&gt;</td>
+            <td>
+              <para>Indent selected lines</para>
+            </td>
+          </tr>
+        </informaltable>
+      </listitem>
+      <listitem>
+        <para>Menu Search</para>
+        <informaltable border="1">
+          <tr>
+            <td>
+              <para>Commande</para>
+            </td>
+            <td>
+              <para>Shortcut</para>
+            </td>
+            <td>
+              <para>Description</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Find/Replace</td>
+            <td>&lt;CTRL-F&gt;</td>
+            <td>
+              <para>Find and/or Replace an element</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Goto line</td>
+            <td>&lt;CTRL-G&gt;</td>
+            <td>
+              <para>Goto line</para>
+            </td>
+          </tr>
+        </informaltable>
+      </listitem>
+      <listitem>
+        <para>Menu View</para>
+        <informaltable border="1">
+          <tr>
+            <td>
+              <para>Commande</para>
+            </td>
+            <td>
+              <para>Shortcut</para>
+            </td>
+            <td>
+              <para>Description</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Show/Hide Toolbar</td>
+            <td/>
+            <td>
+              <para>Option to show or hide the toolbar</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Highlight current line</td>
+            <td>&lt;CTRL-J&gt;</td>
+            <td>
+              <para>Highlight the current line</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Line Numbers</td>
+            <td>&lt;CTRL-B&gt;</td>
+            <td>
+              <para>Display document's line numbers</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Set Colors...</td>
+            <td/>
+            <td>
+              <para>Color settings for documents</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Set Fonts...</td>
+            <td/>
+            <td>
+              <para>Font settings for documents</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Reset default font</td>
+            <td/>
+            <td>
+              <para>Reset default font settings for documents</para>
+            </td>
+          </tr>
+        </informaltable>
+      </listitem>
+      <listitem>
+        <para>Menu Document</para>
+        <informaltable border="1">
+          <tr>
+            <td>
+              <para>Commande</para>
+            </td>
+            <td>
+              <para>Shortcut</para>
+            </td>
+            <td>
+              <para>Description</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Syntax Type</td>
+            <td/>
+            <td>
+              <para>Syntax type settings (default type is Scilab)</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Encoding</td>
+            <td/>
+            <td>
+              <para>Encoding settings (default type is UTF-8
+                Encoding)
+              </para>
+            </td>
+          </tr>
+          <tr>
+            <td>Colorize</td>
+            <td/>
+            <td>
+              <para>Colorize the document</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Auto Indent</td>
+            <td/>
+            <td>
+              <para>Activate the automatic indentation</para>
+            </td>
+          </tr>
+        </informaltable>
+      </listitem>
+      <listitem>
+        <para>Menu Execute</para>
+        <informaltable border="1">
+          <tr>
+            <td>
+              <para>Commande</para>
+            </td>
+            <td>
+              <para>Shortcut</para>
+            </td>
+            <td>
+              <para>Description</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Load Into Scilab</td>
+            <td>&lt;CTRL-L&gt;</td>
+            <td>
+              <para>Load the entire document into the Scilab console</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Evaluate Selection</td>
+            <td/>
+            <td>
+              <para>Load the selection into the Scilab console</para>
+            </td>
+          </tr>
+          <tr>
+            <td>Execute Into Scilab</td>
+            <td>&lt;CTRL-E&gt;</td>
+            <td>
+              <para>If the file exist, execute the content of the file</para>
+            </td>
+          </tr>
+        </informaltable>
+      </listitem>
+    </itemizedlist>
+  </refsection>
+  <refsection>
+    <title>Remarks</title>
+    <variablelist>
+      <varlistentry>
+        <term>Document :</term>
+        <listitem>
+          <para>The default text colorization is the Scilab's syntax
+            colorization.
+          </para>
+          <para>
+            The <literal>auto-indent</literal> mode indent a line
+            according to Scilab's syntax (after a return action).
+          </para>
+          <para/>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[ 
+// editor without parameters
+scinotes();
+    
+// editor with a file name
+scinotes('SCI/modules/time/macros/datenum.sci');
+    
+// editor with a matrix of files name
+scinotes(['SCI/modules/time/macros/datenum.sci','SCI/modules/time/macros/datevec.sci']);
+    
+// editor with a file name and the line number to highlight
+scinotes('SCI/modules/time/macros/datenum.sci', 5);
+
+// editor with a file name and the line number to highlight
+scinotes('SCI/modules/time/macros/datenum.sci', 8, 'datenum');
+
+// editor with a matrix of files name and the corresponding matrix of lines to highlight
+// the files name matrix and the lines to highlight matrix should have the same size
+scinotes(['SCI/modules/time/macros/datenum.sci','SCI/modules/time/macros/datevec.sci'], [5,10]);
+ ]]></programlisting>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/scinotes/macros/editor.sci b/scilab/modules/scinotes/macros/editor.sci
new file mode 100644 (file)
index 0000000..0af1dc6
--- /dev/null
@@ -0,0 +1,61 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab\r
+// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET\r
+//\r
+// This file must be used under the terms of the CeCILL.\r
+// This source file is licensed as described in the file COPYING, which\r
+// you should have received as part of this distribution.  The terms\r
+// are also available at\r
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\r
+\r
+// This function is designed to call the godd "editor" according the values in\r
+// the preferences file.\r
+// This function can take any type of arguments.\r
+function editor(varargin)\r
+    doc = xmlRead(SCIHOME + "/XConfiguration.xml");\r
+    prefsNode = xmlXPath(doc, "//scinotes/body/scinotes-preferences");\r
+    prefsNode = prefsNode(1);\r
+    if prefsNode.attributes.scinotes == "true" then\r
+        xmlDelete(doc);\r
+        cmd = makeCommand("scinotes", varargin);\r
+        execstr(cmd);\r
+    elseif prefsNode.attributes("external-cmd") == "true" then\r
+        cmd = prefsNode.attributes.cmd;\r
+        xmlDelete(doc);\r
+        for item=varargin\r
+            cmd = cmd + " " + string(item); \r
+        end\r
+        unix_w(cmd);\r
+    else\r
+        cmd = makeCommand(prefsNode.attributes.cmd, varargin);\r
+        xmlDelete(doc);\r
+        execstr(cmd);\r
+    end\r
+endfunction\r
+\r
+// Private function\r
+// Params:\r
+//   - name: the command name\r
+//   - args: a list of arguments\r
+// Return:\r
+//   - cmd: the complete command to call with execstr\r
+//\r
+function cmd = makeCommand(name, args)\r
+    cmd = name + "(";\r
+    N = size(args);\r
+    if N ~= 0 then\r
+        for i=1:(N-1)\r
+            arg = string(args(i));\r
+            if type(args(i)) == 10 then\r
+                arg = """" + arg + """";\r
+            end\r
+            cmd = cmd + arg + ","; \r
+        end\r
+\r
+        arg = string(args(N));\r
+        if type(args(N)) == 10 then\r
+            arg = """" + arg + """";\r
+        end\r
+        cmd = cmd + arg\r
+    end\r
+    cmd = cmd + ")";\r
+endfunction
\ No newline at end of file
index 7cf2023..a465801 100644 (file)
@@ -2,8 +2,8 @@
 
 <!DOCTYPE GATEWAY SYSTEM "../../functions/xml/gateway.dtd">
 <GATEWAY name="scinotes">
-<!-- =================== -->
-<!--
+  <!-- =================== -->
+  <!--
  Scilab
  Interface description. In this file, we define the list of the function which
  will be available into Scilab and the link to the "native" function.
@@ -21,8 +21,7 @@
  ===================
  Don't touch if you do not know what you are doing
 -->
-<!-- =================== -->
-<PRIMITIVE gatewayId="63" primitiveId="1" primitiveName="scinotes" />
-<PRIMITIVE gatewayId="63" primitiveId="1" primitiveName="editor" />
-<PRIMITIVE gatewayId="63" primitiveId="2" primitiveName="closeEditor" />
+  <!-- =================== -->
+  <PRIMITIVE gatewayId="63" primitiveId="1" primitiveName="scinotes" />
+  <PRIMITIVE gatewayId="63" primitiveId="2" primitiveName="closeEditor" />
 </GATEWAY>
index 005a036..cedd989 100644 (file)
@@ -17,7 +17,7 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.text.BadLocationException;
 
-import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
+import org.scilab.modules.commons.xml.XConfiguration;
 
 /**
  * This class handles the help on typing
@@ -25,9 +25,6 @@ import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
  */
 public final class HelpOnTypingManager implements KeyListener {
 
-    private static final String OPENERS = "Openers";
-    private static final String KEYWORDS = "Keywords";
-
     private static HelpOnTypingManager instance = new HelpOnTypingManager();
     private static boolean openers;
     private static boolean keywords;
@@ -38,8 +35,8 @@ public final class HelpOnTypingManager implements KeyListener {
     private HelpOnTypingManager() {
         super();
         instance = this;
-        openers = ConfigSciNotesManager.getHelpOnTyping(OPENERS);
-        keywords = ConfigSciNotesManager.getHelpOnTyping(KEYWORDS);
+        openers = SciNotesOptions.getSciNotesDisplay().autoCompleteOpeners;
+        keywords = SciNotesOptions.getSciNotesDisplay().autoCompleteKeywords;
     }
 
     /**
@@ -54,7 +51,8 @@ public final class HelpOnTypingManager implements KeyListener {
      */
     public static void enableOpeners(boolean b) {
         openers = b;
-        ConfigSciNotesManager.saveHelpOnTyping(OPENERS, b);
+        SciNotesOptions.getSciNotesDisplay().autoCompleteOpeners = b;
+        XConfiguration.set(XConfiguration.getXConfigurationDocument(), SciNotesOptions.DISPLAYPATH + "/@auto-complete-openers", Boolean.toString(b));
     }
 
     /**
@@ -62,7 +60,8 @@ public final class HelpOnTypingManager implements KeyListener {
      */
     public static void enableKeywords(boolean b) {
         keywords = b;
-        ConfigSciNotesManager.saveHelpOnTyping(KEYWORDS, b);
+        SciNotesOptions.getSciNotesDisplay().autoCompleteKeywords = b;
+        XConfiguration.set(XConfiguration.getXConfigurationDocument(), SciNotesOptions.DISPLAYPATH + "/@auto-complete-keywords", Boolean.toString(b));
     }
 
     /**
@@ -106,7 +105,7 @@ public final class HelpOnTypingManager implements KeyListener {
         char c = e.getKeyChar();
         ScilabEditorPane textPane = ScilabEditorPane.getFocusedPane();
         ScilabDocument doc = (ScilabDocument) textPane.getDocument();
-        if (keywords && c != KeyEvent.CHAR_UNDEFINED && textPane.getSelectionStart() == textPane.getSelectionEnd()) {
+        if (isActive() && c != KeyEvent.CHAR_UNDEFINED && textPane.getSelectionStart() == textPane.getSelectionEnd()) {
             int pos = textPane.getCaretPosition();
             if (c == ' ' && e.getModifiers() == 0) {
                 int end = doc.getDefaultRootElement().getElement(doc.getDefaultRootElement().getElementIndex(pos)).getEndOffset() - 1;
@@ -119,34 +118,34 @@ public final class HelpOnTypingManager implements KeyListener {
                         int[] ret;
                         String kw;
                         switch (kwe.getType()) {
-                        case ScilabLexerConstants.OSKEYWORD :
-                            kw = doc.getText(kwe.getStart(), kwe.getLength());
-                            if ("if".equals(kw)) {
-                                doc.insertString(pos + 1, " then\nend", null);
-                                ret = textPane.getIndentManager().indentDoc(pos + 1, pos + 9);
-                                textPane.setCaretPosition(ret[0]);
-                            } else if (!"end".equals(kw)) {
-                                doc.insertString(pos + 1, "\nend", null);
-                                ret = textPane.getIndentManager().indentDoc(pos + 1, pos + 4);
-                                textPane.setCaretPosition(ret[0]);
-                            }
-                            break;
-                        case ScilabLexerConstants.SKEYWORD :
-                            kw = doc.getText(kwe.getStart(), kwe.getLength());
-                            if ("elseif".equals(kw)) {
-                                doc.insertString(pos + 1, " then", null);
-                                textPane.setCaretPosition(pos + 1);
-                            }
-                            break;
-                        case ScilabLexerConstants.FKEYWORD :
-                            /* We have 'function' or 'endfunction' */
-                            if ("f".equals(doc.getText(kwe.getStart(), 1))) {
-                                doc.insertString(pos + 1, "()\nendfunction", null);
-                                textPane.getIndentManager().indentDoc(pos + 3, pos + 14);
-                                textPane.setCaretPosition(pos + 1);
-                            }
-                            break;
-                        default :
+                            case ScilabLexerConstants.OSKEYWORD :
+                                kw = doc.getText(kwe.getStart(), kwe.getLength());
+                                if ("if".equals(kw)) {
+                                    doc.insertString(pos + 1, " then\nend", null);
+                                    ret = textPane.getIndentManager().indentDoc(pos + 1, pos + 9);
+                                    textPane.setCaretPosition(ret[0]);
+                                } else if (!"end".equals(kw)) {
+                                    doc.insertString(pos + 1, "\nend", null);
+                                    ret = textPane.getIndentManager().indentDoc(pos + 1, pos + 4);
+                                    textPane.setCaretPosition(ret[0]);
+                                }
+                                break;
+                            case ScilabLexerConstants.SKEYWORD :
+                                kw = doc.getText(kwe.getStart(), kwe.getLength());
+                                if ("elseif".equals(kw)) {
+                                    doc.insertString(pos + 1, " then", null);
+                                    textPane.setCaretPosition(pos + 1);
+                                }
+                                break;
+                            case ScilabLexerConstants.FKEYWORD :
+                                /* We have 'function' or 'endfunction' */
+                                if ("f".equals(doc.getText(kwe.getStart(), 1))) {
+                                    doc.insertString(pos + 1, "()\nendfunction", null);
+                                    textPane.getIndentManager().indentDoc(pos + 3, pos + 14);
+                                    textPane.setCaretPosition(pos + 1);
+                                }
+                                break;
+                            default :
                         }
                     } catch (BadLocationException exc) {
                         System.err.println(exc);
@@ -166,19 +165,19 @@ public final class HelpOnTypingManager implements KeyListener {
 
                 String str = null;
                 switch (c) {
-                case '(' :
-                    str = "()";
-                    break;
-                case '[' :
-                    str = "[]";
-                    break;
-                case '{' :
-                    str = "{}";
-                    break;
-                case '\"' :
-                    str = "\"\"";
-                    break;
-                default :
+                    case '(' :
+                        str = "()";
+                        break;
+                    case '[' :
+                        str = "[]";
+                        break;
+                    case '{' :
+                        str = "{}";
+                        break;
+                    case '\"' :
+                        str = "\"\"";
+                        break;
+                    default :
                 }
 
                 if (str != null) {
index d0044af..2b1635c 100644 (file)
@@ -77,7 +77,6 @@ import org.scilab.modules.gui.utils.Position;
 import org.scilab.modules.gui.utils.SciFileFilter;
 import org.scilab.modules.gui.utils.Size;
 import org.scilab.modules.gui.utils.WindowsConfigurationManager;
-import org.scilab.modules.scinotes.actions.ConfigTabulationsAction;
 import org.scilab.modules.scinotes.actions.EncodingAction;
 import org.scilab.modules.scinotes.actions.EndOfLineAction;
 import org.scilab.modules.scinotes.actions.ExitAction;
@@ -141,6 +140,7 @@ public class SciNotes extends SwingScilabTab {
 
     private static List<SciNotes> scinotesList = new ArrayList<SciNotes>();
     private static SciNotes editor;
+    private static boolean mustWrapLines;
 
     private SwingScilabWindow parentWindow;
     private UUID uuid;
@@ -187,7 +187,8 @@ public class SciNotes extends SwingScilabTab {
         editor = this;
         scinotesList.add(this);
         numberOfUntitled = 0;
-        editorKit = new ScilabEditorKit(!ConfigSciNotesManager.getHorizontalWrap());
+        mustWrapLines = SciNotesOptions.getSciNotesDisplay().wrapLines;
+        editorKit = new ScilabEditorKit(!mustWrapLines);
         protectOpenFileList = false;
         contentPane = new SciNotesContents(this);
         tabPane = contentPane.getScilabTabbedPane();
@@ -222,6 +223,13 @@ public class SciNotes extends SwingScilabTab {
     public static void configurationChanged(SciNotesConfiguration.Conf conf) {
         setWhereamiLineNumbering();
         setAutoIndent();
+        setHorizontalWrap();
+        setDefaultTabulation();
+        if (conf.keymap) {
+            actionKeys = null;
+            setKeyStrokeActions();
+            setAllMenus();
+        }
         updatePanes(conf);
     }
 
@@ -775,7 +783,6 @@ public class SciNotes extends SwingScilabTab {
         FindAction.close();
         IncrementalSearchAction.close(this);
         OpenSourceFileOnKeywordAction.closeOpenSourceWindow();
-        ConfigTabulationsAction.closeConfTabWindow();
         SearchWordInFilesAction.closeWindow();
 
         /*
@@ -1358,7 +1365,7 @@ public class SciNotes extends SwingScilabTab {
      *            the pane to init
      */
     public void initPane(ScilabEditorPane pane) {
-        initPane(pane, !ConfigSciNotesManager.getHorizontalWrap());
+        initPane(pane, !SciNotesOptions.getSciNotesDisplay().wrapLines);
     }
 
     /**
@@ -1768,6 +1775,39 @@ public class SciNotes extends SwingScilabTab {
     }
 
     /**
+     * Set the keystroke actions
+     */
+    public static void setAllMenus() {
+        for (SciNotes ed : scinotesList) {
+            SciNotesGUI.reinitMenus(ed);
+            int n = ed.getTabPane().getTabCount();
+            for (int i = 0; i < n; i++) {
+                ScilabEditorPane sep = ed.getTextPane(i);
+                sep.setComponentPopupMenu(SciNotesGUI.generateRightClickPopup(ed));
+                if (sep.getOtherPaneInSplit() != null) {
+                    sep.getOtherPaneInSplit().setComponentPopupMenu(SciNotesGUI.generateRightClickPopup(ed));
+                }
+            }
+        }
+    }
+
+    /**
+     * Set the keystroke actions
+     */
+    public static void setKeyStrokeActions() {
+        for (SciNotes ed : scinotesList) {
+            int n = ed.getTabPane().getTabCount();
+            for (int i = 0; i < n; i++) {
+                ScilabEditorPane sep = ed.getTextPane(i);
+                ed.initInputMap(sep);
+                if (sep.getOtherPaneInSplit() != null) {
+                    ed.initInputMap(sep.getOtherPaneInSplit());
+                }
+            }
+        }
+    }
+
+    /**
      * Enable the whereami-line numbering
      *
      * @param state
@@ -1831,34 +1871,37 @@ public class SciNotes extends SwingScilabTab {
      * @param b
      *            true to activate horizontal wrapping mode
      */
-    public static void setHorizontalWrap(boolean b) {
-        for (SciNotes ed : scinotesList) {
-            int n = ed.getTabPane().getTabCount();
-            for (int i = 0; i < n; i++) {
-                ScilabEditorPane sep = ed.getTextPane(i);
-                if (sep.getOtherPaneInSplit() == null) {
-                    ScilabEditorPane pane = new ScilabEditorPane(editor);
-                    ed.initPane(pane, !b);
-                    sep.copyProps(pane);
-                    pane.setDocument(sep.getDocument());
-                    pane.setCaretPosition(sep.getCaretPosition());
-                    pane.getXln().setWhereamiLineNumbering(SciNotesOptions.getSciNotesDisplay().showLineNumbers, SciNotesOptions.getSciNotesDisplay().whereami);
-                    ed.tabPane.setComponentAt(i, pane.getEditorComponent());
-                    ed.activateHelpOnTyping(pane);
-                    ed.initInputMap(pane);
-                    if (((ScilabDocument) sep.getDocument()).getBinary()) {
-                        pane.setBinary(true);
+    public static void setHorizontalWrap() {
+        if (SciNotesOptions.getSciNotesDisplay().wrapLines != mustWrapLines) {
+            mustWrapLines = SciNotesOptions.getSciNotesDisplay().wrapLines;
+            for (SciNotes ed : scinotesList) {
+                int n = ed.getTabPane().getTabCount();
+                for (int i = 0; i < n; i++) {
+                    ScilabEditorPane sep = ed.getTextPane(i);
+                    if (sep.getOtherPaneInSplit() == null) {
+                        ScilabEditorPane pane = new ScilabEditorPane(editor);
+                        ed.initPane(pane, !mustWrapLines);
+                        sep.copyProps(pane);
+                        pane.setDocument(sep.getDocument());
+                        pane.setCaretPosition(sep.getCaretPosition());
+                        pane.getXln().setWhereamiLineNumbering(SciNotesOptions.getSciNotesDisplay().showLineNumbers, SciNotesOptions.getSciNotesDisplay().whereami);
+                        ed.tabPane.setComponentAt(i, pane.getEditorComponent());
+                        ed.activateHelpOnTyping(pane);
+                        ed.initInputMap(pane);
+                        if (((ScilabDocument) sep.getDocument()).getBinary()) {
+                            pane.setBinary(true);
+                        }
+                        ed.getInfoBar().setText(pane.getInfoBarText());
                     }
-                    ed.getInfoBar().setText(pane.getInfoBarText());
                 }
             }
         }
     }
 
     /**
-         * Set a line numbering compatible with the whereami function
-         * @param state 0 for nothing, 1 for normal and 2 for whereami
-         */
+     * Set a line numbering compatible with the whereami function
+     * @param state 0 for nothing, 1 for normal and 2 for whereami
+     */
 
     /**
      * Enable the highlighted line in this editor
@@ -1871,9 +1914,9 @@ public class SciNotes extends SwingScilabTab {
             int n = ed.getTabPane().getTabCount();
             for (int i = 0; i < n; i++) {
                 ScilabEditorPane sep = ed.getTextPane(i);
-                sep.enableHighlightedLine(b);
+                sep.enableHighlightedLine(SciNotesOptions.getSciNotesDisplay().highlightCurrentLine);
                 if (sep.getOtherPaneInSplit() != null) {
-                    sep.getOtherPaneInSplit().enableHighlightedLine(b);
+                    sep.getOtherPaneInSplit().enableHighlightedLine(SciNotesOptions.getSciNotesDisplay().highlightCurrentLine);
                 }
             }
         }
@@ -1911,7 +1954,8 @@ public class SciNotes extends SwingScilabTab {
      * @param c
      *            Color
      */
-    public static void setDefaultTabulation(TabManager.Tabulation tab) {
+    public static void setDefaultTabulation() {
+        TabManager.Tabulation tab = new TabManager.Tabulation();
         for (SciNotes ed : scinotesList) {
             int n = ed.getTabPane().getTabCount();
             for (int i = 0; i < n; i++) {
@@ -1957,14 +2001,14 @@ public class SciNotes extends SwingScilabTab {
      * @param c
      *            Color
      */
-    public static void setHighlightedLineColor(Color c) {
+    public static void setHighlightedLineColor() {
         for (SciNotes ed : scinotesList) {
             int n = ed.getTabPane().getTabCount();
             for (int i = 0; i < n; i++) {
                 ScilabEditorPane sep = ed.getTextPane(i);
-                sep.setHighlightedLineColor(c);
+                sep.setHighlightedLineColor(SciNotesOptions.getSciNotesDisplay().currentLineColor);
                 if (sep.getOtherPaneInSplit() != null) {
-                    sep.getOtherPaneInSplit().setHighlightedLineColor(c);
+                    sep.getOtherPaneInSplit().setHighlightedLineColor(SciNotesOptions.getSciNotesDisplay().currentLineColor);
                 }
             }
         }
@@ -1976,14 +2020,14 @@ public class SciNotes extends SwingScilabTab {
      * @param c
      *            Color
      */
-    public static void setHighlightedContourColor(Color c) {
+    public static void setHighlightedContourColor() {
         for (SciNotes ed : scinotesList) {
             int n = ed.getTabPane().getTabCount();
             for (int i = 0; i < n; i++) {
                 ScilabEditorPane sep = ed.getTextPane(i);
-                sep.setHighlightedContourColor(c);
+                sep.setHighlightedContourColor(null);
                 if (sep.getOtherPaneInSplit() != null) {
-                    sep.getOtherPaneInSplit().setHighlightedContourColor(c);
+                    sep.getOtherPaneInSplit().setHighlightedContourColor(null);
                 }
             }
         }
@@ -1996,10 +2040,9 @@ public class SciNotes extends SwingScilabTab {
      *            ScilabEditorPane
      */
     public static void setHighlight(ScilabEditorPane sep) {
-        sep.enableHighlightedLine(ConfigSciNotesManager.getHighlightState());
-        Color[] arr = ConfigSciNotesManager.getHighlightColors();
-        sep.setHighlightedLineColor(arr[0]);
-        sep.setHighlightedContourColor(arr[1]);
+        sep.enableHighlightedLine(SciNotesOptions.getSciNotesDisplay().highlightCurrentLine);
+        sep.setHighlightedLineColor(SciNotesOptions.getSciNotesDisplay().currentLineColor);
+        sep.setHighlightedContourColor(null);
     }
 
     /**
index ceb3001..fd4a8a7 100644 (file)
@@ -42,18 +42,30 @@ public class SciNotesConfiguration implements XConfigurationListener {
         public boolean colors;
         public boolean systemfont;
         public boolean font;
+        public boolean keymap;
 
         public Conf(Set<String> path) {
-            preferences = path.contains(SciNotesOptions.PREFERENCESPATH);
-            display = path.contains(SciNotesOptions.DISPLAYPATH);
-            autosave = path.contains(SciNotesOptions.AUTOSAVEPATH);
-            colors = path.contains(ScilabContext.COLORSPATH);
-            systemfont = path.contains(ScilabContext.SYSTEMFONTPATH);
-            font = path.contains(ScilabContext.FONTPATH);
+            if (path.contains("ALL")) {
+                preferences = true;
+                display = true;
+                autosave = true;
+                colors = true;
+                systemfont = true;
+                font = true;
+                keymap = true;
+            } else {
+                preferences = path.contains(SciNotesOptions.PREFERENCESPATH);
+                display = path.contains(SciNotesOptions.DISPLAYPATH);
+                autosave = path.contains(SciNotesOptions.AUTOSAVEPATH);
+                colors = path.contains(ScilabContext.COLORSPATH);
+                systemfont = path.contains(ScilabContext.SYSTEMFONTPATH);
+                font = path.contains(ScilabContext.FONTPATH);
+                keymap = path.contains(SciNotesOptions.KEYMAPPATH);
+            }
         }
 
         public boolean changed() {
-            return preferences || display || autosave || colors || systemfont || font;
+            return preferences || display || autosave || colors || systemfont || font || keymap;
         }
     }
 }
index 3fc383d..b754f9f 100644 (file)
@@ -91,8 +91,6 @@ public final class SciNotesGUI {
         mainWindow.addTab(editorInstance);
 
         // Set SciNotes Window position /size
-        mainWindow.setPosition(ConfigSciNotesManager.getMainWindowPosition());
-        mainWindow.setDims(ConfigSciNotesManager.getMainWindowSize());
         mainWindow.setTitle(title);
         mainWindow.setVisible(true);
 
@@ -110,6 +108,16 @@ public final class SciNotesGUI {
     }
 
     /**
+     * Initialize SciNotes
+     * @param editorInstance SciNotes
+     */
+    public static void reinitMenus(SciNotes editorInstance) {
+        mapMenuBar.remove(editorInstance);
+        mapPopup.remove(editorInstance);
+        editorInstance.setMenuBar(generateMenuBar(editorInstance));
+    }
+
+    /**
      * @param editor the editor
      * @return the infobar of the editor
      */
index 5b0bccd..097f882 100644 (file)
@@ -104,18 +104,20 @@ public class SciNotesLineNumberPanel extends JPanel implements CaretListener, Do
      * @param state 0 for nothing, 1 for normal and 2 for whereami
      */
     public void setWhereamiLineNumbering(int state) {
-        if (state != 0) {
-            if (!display) {
-                textPane.getScrollPane().setRowHeaderView(this);
+        if (state != this.state) {
+            if (state != 0) {
+                if (!display) {
+                    textPane.getScrollPane().setRowHeaderView(this);
+                }
+                whereami = state == 2;
+                display = true;
+            } else {
+                textPane.getScrollPane().setRowHeaderView(null);
+                display = false;
             }
-            whereami = state == 2;
-            display = true;
-        } else {
-            textPane.getScrollPane().setRowHeaderView(null);
-            display = false;
+            updateLineNumber();
+            this.state = state;
         }
-        updateLineNumber();
-        this.state = state;
     }
 
     public static int getState(boolean showLinesNumber, boolean whereami) {
index 34a86e0..6bf4f4f 100644 (file)
@@ -28,6 +28,7 @@ public class SciNotesOptions {
     public static final String PREFERENCESPATH = "//scinotes/body/scinotes-preferences";
     public static final String DISPLAYPATH = "//scinotes/display/body/scinotes-display";
     public static final String AUTOSAVEPATH = "//scinotes/autosave/body/scinotes-autosave";
+    public static final String KEYMAPPATH = "//general/shortcuts/body/actions/action-folder[@xconf-uid=\"scinotes\"]/action";
 
     private static SciNotesOptions.Preferences prefs;
     private static SciNotesOptions.Display display;
@@ -44,18 +45,28 @@ public class SciNotesOptions {
         public int numberOfRecentlyOpen;
         public String encoding;
         public String eol;
+        public boolean useScinotes;
         public boolean externalCmd;
         public String cmd;
 
         private Preferences() { }
 
         @XConfAttribute(tag = "scinotes-preferences", attributes = {"restart-reopen", "add-line-termination", "number-of-recently-open", "encoding", "eol", "scinotes", "cmd", "external-cmd"})
-        private void set(boolean restartOpen, boolean addLineTermination, int numberOfRecentlyOpen, String encoding, String eol, boolean externalCmd, String cmd) {
+        private void set(boolean restartOpen, boolean addLineTermination, int numberOfRecentlyOpen, String encoding, String eol, boolean useScinotes, boolean externalCmd, String cmd) {
             this.restartOpen = restartOpen;
             this.addLineTermination = addLineTermination;
             this.numberOfRecentlyOpen = numberOfRecentlyOpen;
-            this.encoding = encoding;
-            this.eol = eol;
+            this.encoding = encoding.toLowerCase();
+
+            if (eol.startsWith("Windows")) {
+                this.eol = ScilabDocument.EOLWIN;
+            } else if (eol.startsWith("Mac")) {
+                this.eol = ScilabDocument.EOLMAC;
+            } else {
+                this.eol = ScilabDocument.EOLUNIX;
+            }
+
+            this.useScinotes = useScinotes;
             this.externalCmd = externalCmd;
             this.cmd = cmd;
         }
@@ -80,19 +91,23 @@ public class SciNotesOptions {
         public boolean keywordsOnmouseover;
         public boolean whereami;
         public int tabSize;
+        public int tabRepresentation;
         public boolean useSpaces;
         public int indentSize;
         public boolean automaticIndent;
+        public boolean autoCompleteOpeners;
+        public boolean autoCompleteKeywords;
 
         private Display() { }
 
-        @XConfAttribute(tag = "scinotes-display", attributes = {"highlight-current-line", "current-line-color", "show-line-numbers", "wrap-lines", "keywordsColorization", "highlight-brackets", "brackets-color", "brackets-highlightment", "brackets-onmouseover", "highlight-keywords", "keywords-color", "keywords-highlightment", "keywords-onmouseover", "whereami", "tab-size", "use-spaces", "indent-size", "automatic-indent"})
-        private void set(boolean highlightCurrentLine, Color currentLineColor, boolean showLineNumbers, boolean wrapLines, boolean keywordsColorization, boolean highlightBrackets, Color bracketsColor, String bracketsHighlightment, boolean bracketsOnmouseover, boolean highlightKeywords, Color keywordsColor, String keywordsHighlightment, boolean keywordsOnmouseover, boolean whereami, int tabSize, boolean useSpaces, int indentSize, boolean automaticIndent) {
+        @XConfAttribute(tag = "scinotes-display", attributes = {"highlight-current-line", "current-line-color", "show-line-numbers", "wrap-lines", "keywords-colorization", "highlight-brackets", "brackets-color", "brackets-highlightment", "brackets-onmouseover", "highlight-keywords", "keywords-color", "keywords-highlightment", "keywords-onmouseover", "whereami", "tab-size", "tab-representation", "use-spaces", "indent-size", "automatic-indent", "auto-complete-openers", "auto-complete-keywords"})
+        private void set(boolean highlightCurrentLine, Color currentLineColor, boolean showLineNumbers, boolean wrapLines, boolean keywordsColorization, boolean highlightBrackets, Color bracketsColor, String bracketsHighlightment, boolean bracketsOnmouseover, boolean highlightKeywords, Color keywordsColor, String keywordsHighlightment, boolean keywordsOnmouseover, boolean whereami, int tabSize, String tabRepresentation, boolean useSpaces, int indentSize, boolean automaticIndent, boolean autoCompleteOpeners, boolean autoCompleteKeywords) {
             this.highlightCurrentLine = highlightCurrentLine;
             this.currentLineColor = currentLineColor;
             this.showLineNumbers = showLineNumbers;
             this.wrapLines = wrapLines;
             this.keywordsColorization = keywordsColorization;
+
             this.highlightBrackets = highlightBrackets;
             this.bracketsColor = bracketsColor;
             this.bracketsOnmouseover = bracketsOnmouseover;
@@ -101,6 +116,15 @@ public class SciNotesOptions {
             this.keywordsOnmouseover = keywordsOnmouseover;
             this.whereami = whereami;
             this.tabSize = tabSize;
+            if (tabRepresentation.equalsIgnoreCase("chevrons")) {
+                this.tabRepresentation = ScilabView.TABDOUBLECHEVRONS;
+            } else if (tabRepresentation.equalsIgnoreCase("hrule")) {
+                this.tabRepresentation = ScilabView.TABHORIZONTAL;
+            } else if (tabRepresentation.equalsIgnoreCase("vrule")) {
+                this.tabRepresentation = ScilabView.TABVERTICAL;
+            } else {
+                this.tabRepresentation = ScilabView.TABNOTHING;
+            }
             this.useSpaces = useSpaces;
             this.indentSize = indentSize;
             this.automaticIndent = automaticIndent;
@@ -120,6 +144,9 @@ public class SciNotesOptions {
             } else {
                 this.keywordsHighlightment = MatchingBlockManager.ScilabKeywordsPainter.UNDERLINED;
             }
+
+            this.autoCompleteOpeners = autoCompleteOpeners;
+            this.autoCompleteKeywords = autoCompleteKeywords;
         }
     }
 
@@ -153,10 +180,12 @@ public class SciNotesOptions {
         if (conf.preferences) {
             prefs = null;
             doc = null;
-        } else if (conf.display) {
+        }
+        if (conf.display) {
             display = null;
             doc = null;
-        } else if (conf.autosave) {
+        }
+        if (conf.autosave) {
             autosave = null;
             doc = null;
         }
index fbd5f28..a71ba66 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.scilab.modules.scinotes;
 
+import java.nio.charset.Charset;
+
 import java.util.Vector;
 import java.util.ArrayList;
 import java.util.List;
@@ -74,7 +76,7 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
     private boolean alphaOrder;
 
     // Editor's default encoding is UTF-8
-    private String encoding = "utf-8";
+    private String encoding;
     private boolean updater = true;
     private boolean binary;
     private boolean autoIndent;
@@ -85,7 +87,7 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
     private ScilabEditorPane pane;
     private boolean focused;
 
-    private String eolStyle = System.getProperty(LINE_SEPARATOR);
+    private String eolStyle;
 
     /**
      * Constructor
@@ -94,8 +96,9 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
         super(new GapContent(GAPBUFFERCAPACITY));
         setAsynchronousLoadPriority(2);
 
-        autoIndent = ConfigSciNotesManager.getAutoIndent();
-        encoding = ConfigSciNotesManager.getDefaultEncoding();
+        autoIndent = SciNotesOptions.getSciNotesDisplay().automaticIndent;
+        encoding = Charset.forName(SciNotesOptions.getSciNotesPreferences().encoding).toString();
+        eolStyle = SciNotesOptions.getSciNotesPreferences().eol;
 
         undo = new CompoundUndoManager(this);
         addUndoableEditListener(undo);
@@ -396,48 +399,48 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
                 if (elem instanceof ScilabDocument.ScilabLeafElement) {
                     int type = ((ScilabDocument.ScilabLeafElement) elem).getType();
                     switch (type) {
-                    case ScilabDocument.ScilabLeafElement.NOTHING :
-                        break;
-                    case ScilabDocument.ScilabLeafElement.FUN :
-                        base.add(new DefaultMutableTreeNode(elem));
-                        break;
-                    case ScilabDocument.ScilabLeafElement.ENDFUN :
-                        break;
-                    default :
-                        break;
+                        case ScilabDocument.ScilabLeafElement.NOTHING :
+                            break;
+                        case ScilabDocument.ScilabLeafElement.FUN :
+                            base.add(new DefaultMutableTreeNode(elem));
+                            break;
+                        case ScilabDocument.ScilabLeafElement.ENDFUN :
+                            break;
+                        default :
+                            break;
                     }
                 }
             }
         } else {
             Set<DefaultMutableTreeNode> set = new TreeSet<DefaultMutableTreeNode>(new Comparator<DefaultMutableTreeNode>() {
-                    public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
-                        ScilabLeafElement l1 = (ScilabLeafElement) o1.getUserObject();
-                        ScilabLeafElement l2 = (ScilabLeafElement) o2.getUserObject();
-                        int n = l1.getFunctionName().compareTo(l2.getFunctionName());
-                        if (n != 0) {
-                            return n;
-                        }
-                        return l1.getStartOffset() - l2.getStartOffset();
+                public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
+                    ScilabLeafElement l1 = (ScilabLeafElement) o1.getUserObject();
+                    ScilabLeafElement l2 = (ScilabLeafElement) o2.getUserObject();
+                    int n = l1.getFunctionName().compareTo(l2.getFunctionName());
+                    if (n != 0) {
+                        return n;
                     }
+                    return l1.getStartOffset() - l2.getStartOffset();
+                }
 
-                    public boolean equals(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
-                        return false;
-                    }
-                });
+                public boolean equals(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
+                    return false;
+                }
+            });
             for (int i = 0; i < nlines; i++) {
                 Element elem = root.getElement(i);
                 if (elem instanceof ScilabDocument.ScilabLeafElement) {
                     int type = ((ScilabDocument.ScilabLeafElement) elem).getType();
                     switch (type) {
-                    case ScilabDocument.ScilabLeafElement.NOTHING :
-                        break;
-                    case ScilabDocument.ScilabLeafElement.FUN :
-                        set.add(new DefaultMutableTreeNode(elem));
-                        break;
-                    case ScilabDocument.ScilabLeafElement.ENDFUN :
-                        break;
-                    default :
-                        break;
+                        case ScilabDocument.ScilabLeafElement.NOTHING :
+                            break;
+                        case ScilabDocument.ScilabLeafElement.FUN :
+                            set.add(new DefaultMutableTreeNode(elem));
+                            break;
+                        case ScilabDocument.ScilabLeafElement.ENDFUN :
+                            break;
+                        default :
+                            break;
                     }
                 }
             }
@@ -464,20 +467,20 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
             }
         } else {
             Set<DefaultMutableTreeNode> set = new TreeSet<DefaultMutableTreeNode>(new Comparator<DefaultMutableTreeNode>() {
-                    public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
-                        ScilabLeafElement l1 = (ScilabLeafElement) o1.getUserObject();
-                        ScilabLeafElement l2 = (ScilabLeafElement) o2.getUserObject();
-                        int n = l1.getAnchorName().compareTo(l2.getAnchorName());
-                        if (n != 0) {
-                            return n;
-                        }
-                        return l1.getStartOffset() - l2.getStartOffset();
+                public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
+                    ScilabLeafElement l1 = (ScilabLeafElement) o1.getUserObject();
+                    ScilabLeafElement l2 = (ScilabLeafElement) o2.getUserObject();
+                    int n = l1.getAnchorName().compareTo(l2.getAnchorName());
+                    if (n != 0) {
+                        return n;
                     }
+                    return l1.getStartOffset() - l2.getStartOffset();
+                }
 
-                    public boolean equals(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
-                        return false;
-                    }
-                });
+                public boolean equals(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
+                    return false;
+                }
+            });
             for (int i = 0; i < nlines; i++) {
                 ScilabLeafElement elem = (ScilabLeafElement) root.getElement(i);
                 if (elem.isAnchor()) {
@@ -586,20 +589,20 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
         while (index != -1) {
             ScilabLeafElement e = (ScilabLeafElement) root.getElement(index--);
             switch (e.getType()) {
-            case ScilabLeafElement.NOTHING :
-                break;
-            case ScilabLeafElement.FUN :
-                if (compt == 0) {
-                    FunctionScanner.FunctionInfo info = e.getFunctionInfo();
-                    return new List[]{info.returnValues, info.argsValues};
-                } else {
-                    compt++;
-                }
-                break;
-            case ScilabLeafElement.ENDFUN :
-                compt--;
-                break;
-            default :
+                case ScilabLeafElement.NOTHING :
+                    break;
+                case ScilabLeafElement.FUN :
+                    if (compt == 0) {
+                        FunctionScanner.FunctionInfo info = e.getFunctionInfo();
+                        return new List[] {info.returnValues, info.argsValues};
+                    } else {
+                        compt++;
+                    }
+                    break;
+                case ScilabLeafElement.ENDFUN :
+                    compt--;
+                    break;
+                default :
             }
         }
         return null;
@@ -618,23 +621,23 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
         while (index != -1) {
             ScilabLeafElement e = (ScilabLeafElement) root.getElement(index--);
             switch (e.getType()) {
-            case ScilabLeafElement.NOTHING :
-                break;
-            case ScilabLeafElement.FUN :
-                if (compt == 0) {
-                    String str = e.getFunctionInfo().functionName;
-                    if (str == null) {
-                        str = SciNotesMessages.UNKNOWN_FUNCTION;
+                case ScilabLeafElement.NOTHING :
+                    break;
+                case ScilabLeafElement.FUN :
+                    if (compt == 0) {
+                        String str = e.getFunctionInfo().functionName;
+                        if (str == null) {
+                            str = SciNotesMessages.UNKNOWN_FUNCTION;
+                        }
+                        return String.format(SciNotesMessages.POSFUN_IN_DOC, line + 1, pos - root.getElement(line).getStartOffset(), str, line - index);
+                    } else {
+                        compt++;
                     }
-                    return String.format(SciNotesMessages.POSFUN_IN_DOC, line + 1, pos - root.getElement(line).getStartOffset(), str, line - index);
-                } else {
-                    compt++;
-                }
-                break;
-            case ScilabLeafElement.ENDFUN :
-                compt--;
-                break;
-            default :
+                    break;
+                case ScilabLeafElement.ENDFUN :
+                    compt--;
+                    break;
+                default :
             }
         }
         return String.format(SciNotesMessages.POS_IN_DOC, line + 1, pos - root.getElement(line).getStartOffset());
@@ -721,7 +724,7 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
             ScilabLeafElement line = (ScilabLeafElement) root.getElement(index);
             boolean broken = line.isBroken();
             if (line.resetType() == ScilabLeafElement.FUN || broken != line.isBroken()
-                || (index > 0 && ((ScilabLeafElement) root.getElement(index - 1)).isBroken())) {
+                    || (index > 0 && ((ScilabLeafElement) root.getElement(index - 1)).isBroken())) {
                 pane.repaint();
             }
         }
@@ -746,7 +749,7 @@ public class ScilabDocument extends PlainDocument implements DocumentListener {
         funScanner = new FunctionScanner(this);
         BranchElement map = (BranchElement) createBranchElement(null, null);
         Element line = createLeafElement(map, null, 0, 1);
-        map.replace(0, 0, new Element[]{line});
+        map.replace(0, 0, new Element[] {line});
         return map;
     }
 
index 6e78055..36ff9d5 100644 (file)
@@ -21,6 +21,10 @@ import java.io.Reader;
 import java.nio.CharBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.swing.text.BadLocationException;
 import javax.swing.text.DefaultEditorKit;
@@ -29,7 +33,6 @@ import javax.swing.text.ViewFactory;
 
 import org.scilab.modules.gui.messagebox.ScilabModalDialog;
 import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
-import org.scilab.modules.scinotes.actions.DefaultEncodingAction;
 import org.scilab.modules.scinotes.actions.EncodingAction;
 import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
 import org.scilab.modules.scinotes.utils.SciNotesMessages;
@@ -47,8 +50,16 @@ public class ScilabEditorKit extends DefaultEditorKit {
      * The mimetype for a scilab code
      */
     public static final String MIMETYPE = "text/scilab";
-
     private static final int BUFFERCAPACITY = 8192;
+    public static final String[] ENCODINGS = new String[] {"utf-8", "windows-1252", "iso-8859-1"};
+    private static final Map<String, Integer> encPos = new HashMap<String, Integer>(ENCODINGS.length);
+
+    static {
+        for (int i = 0; i < ENCODINGS.length; i++) {
+            encPos.put(ENCODINGS[i], i);
+        }
+    }
+
     private final char[] buffer = new char[BUFFERCAPACITY];
 
     private ScilabContext preferences;
@@ -70,6 +81,10 @@ public class ScilabEditorKit extends DefaultEditorKit {
         this.plain = plain;
     }
 
+    public boolean isPlain() {
+        return plain;
+    }
+
     /**
      * @return the mime type
      */
@@ -111,6 +126,45 @@ public class ScilabEditorKit extends DefaultEditorKit {
     }
 
     /**
+     * @param file the file to test
+     * @return the corresponding charset if exists
+     * @throws IOExecption if I/O problems are met
+     * @throws CharacterCodingException if no charset is found
+     */
+    public static Charset tryToGuessEncoding(File file) throws IOException, CharacterCodingException {
+        for (int i = 0; i < ENCODINGS.length; i++) {
+            if (tryToGuessEncoding(file, Charset.forName(ENCODINGS[i]))) {
+                return Charset.forName(ENCODINGS[i]);
+            }
+        }
+
+        throw new CharacterCodingException();
+    }
+
+    /**
+     * @param file the file to test
+     * @param charset the charset to test
+     * @return true if the file can be decoded with the charset
+     * @throws IOExecption if I/O problems are met
+     */
+    public static boolean tryToGuessEncoding(File file, Charset charset) throws IOException {
+        char[] cbuf = new char[BUFFERCAPACITY];
+        CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
+        FileInputStream fis = new FileInputStream(file);
+        InputStreamReader inReader = new InputStreamReader(fis, decoder);
+        BufferedReader bufReader = new BufferedReader(inReader);
+        try {
+            while (bufReader.read(cbuf) != -1);
+            fis.close();
+            inReader.close();
+            bufReader.close();
+            return true;
+        } catch (Exception e) { }
+
+        return false;
+    }
+
+    /**
      * The read method is used to read the file and to write its contents
      * in the document at position pos
      * @param file the file to read
@@ -121,9 +175,9 @@ public class ScilabEditorKit extends DefaultEditorKit {
      * @throws BadLocationException if the pos is invalid
      */
     public void read(SciNotes editor, File file, Document doc, int pos) throws IOException, BadLocationException {
-        Charset charset = Charset.forName(ConfigSciNotesManager.getDefaultEncoding());
+        Charset charset = Charset.forName(SciNotesOptions.getSciNotesPreferences().encoding);
         try {
-            charset = DefaultEncodingAction.tryToGuessEncoding(file);
+            charset = tryToGuessEncoding(file);
         } catch (CharacterCodingException e) {
             ScilabModalDialog.show(editor, SciNotesMessages.CANNOT_GUESS_ENCODING, SciNotesMessages.SCINOTES_ERROR, IconType.ERROR_ICON);
         }
index 793ad30..b142486 100644 (file)
@@ -258,10 +258,25 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         setTransferHandler(new CopyAsHTMLAction.HTMLTransferHandler());
     }
 
+    public void enableColorization(boolean b) {
+        View view = ((ScilabDocument) getDocument()).getView();
+        if (view != null) {
+            if (view instanceof ScilabView) {
+                ((ScilabView) view).enable(b);
+            } else {
+                ((ScilabPlainView) view).enable(b);
+            }
+        }
+    }
+
     public void configurationChanged(SciNotesConfiguration.Conf conf) {
         ((ScilabEditorKit) getEditorKit()).getStylePreferences().configurationChanged(conf);
 
         if (conf.display) {
+            enableHighlightedLine(SciNotesOptions.getSciNotesDisplay().highlightCurrentLine);
+            setHighlightedLineColor(SciNotesOptions.getSciNotesDisplay().currentLineColor);
+            enableColorization(SciNotesOptions.getSciNotesDisplay().keywordsColorization);
+
             boolean kw = SciNotesOptions.getSciNotesDisplay().highlightKeywords;
             boolean op = SciNotesOptions.getSciNotesDisplay().highlightBrackets;
 
index 83fd756..c7a6005 100644 (file)
@@ -50,7 +50,7 @@ public class ScilabPlainView extends PlainView {
     private Segment text = new Segment();
     private boolean isTabViewable = true;
     private boolean isWhiteViewable = true;
-    private boolean enable = true;
+    private boolean enable = SciNotesOptions.getSciNotesDisplay().keywordsColorization;
 
     private int tabType;
     private String tabCharacter = " ";
@@ -117,6 +117,13 @@ public class ScilabPlainView extends PlainView {
     }
 
     /**
+     * Enable this view
+     */
+    public void enable(boolean b) {
+        enable = b;
+    }
+
+    /**
      * If n > 0, then a line will be drawn to see the maximum of chars recommanded in a line
      * (80 by default).
      * @param n the maximum of column recommanded in this view
@@ -279,37 +286,37 @@ public class ScilabPlainView extends PlainView {
                 }
 
                 switch (tok) {
-                case ScilabLexerConstants.WHITE :
-                case ScilabLexerConstants.WHITE_COMMENT :
-                case ScilabLexerConstants.WHITE_STRING :
-                    if (isWhiteViewable) {
+                    case ScilabLexerConstants.WHITE :
+                    case ScilabLexerConstants.WHITE_COMMENT :
+                    case ScilabLexerConstants.WHITE_STRING :
+                        if (isWhiteViewable) {
+                            w = Utilities.getTabbedTextWidth(text, g.getFontMetrics(), x, this, mark);
+                            g.drawLine(x + (w - 1) / 2, y - whiteHeight, x + (w + 1) / 2, y - whiteHeight);
+                        }
+                        break;
+                    case ScilabLexerConstants.TAB :
+                    case ScilabLexerConstants.TAB_COMMENT :
+                    case ScilabLexerConstants.TAB_STRING :
+                        if (isTabViewable) {
+                            paintTab(text, x, y, g, mark);
+                        }
+                        break;
+                    case ScilabLexerConstants.ERROR :
+                        if (unselected) {
+                            g.setColor(Color.RED);
+                        } else {
+                            g.setColor(Color.WHITE);
+                        }
                         w = Utilities.getTabbedTextWidth(text, g.getFontMetrics(), x, this, mark);
-                        g.drawLine(x + (w - 1) / 2, y - whiteHeight, x + (w + 1) / 2, y - whiteHeight);
-                    }
-                    break;
-                case ScilabLexerConstants.TAB :
-                case ScilabLexerConstants.TAB_COMMENT :
-                case ScilabLexerConstants.TAB_STRING :
-                    if (isTabViewable) {
-                        paintTab(text, x, y, g, mark);
-                    }
-                    break;
-                case ScilabLexerConstants.ERROR :
-                    if (unselected) {
-                        g.setColor(Color.RED);
-                    } else {
-                        g.setColor(Color.WHITE);
-                    }
-                    w = Utilities.getTabbedTextWidth(text, g.getFontMetrics(), x, this, mark);
-                    for (int i = 0; i < w; i +=4) {
-                        g.drawLine(x + i, y + 2, x + i + 1, y + 2);
-                    }
-                    for (int i = 2; i < w; i +=4) {
-                        g.drawLine(x + i, y + 1, x + i + 1, y + 1);
-                    }
-                    break;
-                default :
-                    break;
+                        for (int i = 0; i < w; i += 4) {
+                            g.drawLine(x + i, y + 2, x + i + 1, y + 2);
+                        }
+                        for (int i = 2; i < w; i += 4) {
+                            g.drawLine(x + i, y + 1, x + i + 1, y + 1);
+                        }
+                        break;
+                    default :
+                        break;
                 }
 
                 x = Utilities.drawTabbedText(text, x, y, g, this, mark);
@@ -420,7 +427,7 @@ public class ScilabPlainView extends PlainView {
      * Used to represent the default tabulation got with ConfigSciNotesManager
      */
     public void setDefaultTabRepresentation() {
-        setTabRepresentation(ConfigSciNotesManager.getDefaultTabulation());
+        setTabRepresentation(new TabManager.Tabulation());
     }
 
     /**
index cae6cd0..ff1dd09 100644 (file)
@@ -75,7 +75,7 @@ public class ScilabView extends WrappedPlainView {
     private Segment text = new Segment();
     private boolean isTabViewable = true;
     private boolean isWhiteViewable = true;
-    private boolean enable = true;
+    private boolean enable = SciNotesOptions.getSciNotesDisplay().keywordsColorization;
 
     private int tabType;
     private String tabCharacter = " ";
@@ -142,6 +142,13 @@ public class ScilabView extends WrappedPlainView {
     }
 
     /**
+     * Enable this view
+     */
+    public void enable(boolean b) {
+        enable = b;
+    }
+
+    /**
      * If n > 0, then a line will be drawn to see the maximum of chars recommanded in a line
      * (80 by default).
      * @param n the maximum of column recommanded in this view
@@ -312,37 +319,37 @@ public class ScilabView extends WrappedPlainView {
                 }
 
                 switch (tok) {
-                case ScilabLexerConstants.WHITE :
-                case ScilabLexerConstants.WHITE_COMMENT :
-                case ScilabLexerConstants.WHITE_STRING :
-                    if (isWhiteViewable) {
+                    case ScilabLexerConstants.WHITE :
+                    case ScilabLexerConstants.WHITE_COMMENT :
+                    case ScilabLexerConstants.WHITE_STRING :
+                        if (isWhiteViewable) {
+                            w = Utilities.getTabbedTextWidth(text, g.getFontMetrics(), x, this, mark);
+                            g.drawLine(x + (w - 1) / 2, y - whiteHeight, x + (w + 1) / 2, y - whiteHeight);
+                        }
+                        break;
+                    case ScilabLexerConstants.TAB :
+                    case ScilabLexerConstants.TAB_COMMENT :
+                    case ScilabLexerConstants.TAB_STRING :
+                        if (isTabViewable) {
+                            paintTab(text, x, y, g, mark);
+                        }
+                        break;
+                    case ScilabLexerConstants.ERROR :
+                        if (unselected) {
+                            g.setColor(Color.RED);
+                        } else {
+                            g.setColor(Color.WHITE);
+                        }
                         w = Utilities.getTabbedTextWidth(text, g.getFontMetrics(), x, this, mark);
-                        g.drawLine(x + (w - 1) / 2, y - whiteHeight, x + (w + 1) / 2, y - whiteHeight);
-                    }
-                    break;
-                case ScilabLexerConstants.TAB :
-                case ScilabLexerConstants.TAB_COMMENT :
-                case ScilabLexerConstants.TAB_STRING :
-                    if (isTabViewable) {
-                        paintTab(text, x, y, g, mark);
-                    }
-                    break;
-                case ScilabLexerConstants.ERROR :
-                    if (unselected) {
-                        g.setColor(Color.RED);
-                    } else {
-                        g.setColor(Color.WHITE);
-                    }
-                    w = Utilities.getTabbedTextWidth(text, g.getFontMetrics(), x, this, mark);
-                    for (int i = 0; i < w; i +=4) {
-                        g.drawLine(x + i, y + 2, x + i + 1, y + 2);
-                    }
-                    for (int i = 2; i < w; i +=4) {
-                        g.drawLine(x + i, y + 1, x + i + 1, y + 1);
-                    }
-                    break;
-                default :
-                    break;
+                        for (int i = 0; i < w; i += 4) {
+                            g.drawLine(x + i, y + 2, x + i + 1, y + 2);
+                        }
+                        for (int i = 2; i < w; i += 4) {
+                            g.drawLine(x + i, y + 1, x + i + 1, y + 1);
+                        }
+                        break;
+                    default :
+                        break;
                 }
 
                 x = Utilities.drawTabbedText(text, x, y, g, this, mark);
@@ -451,7 +458,7 @@ public class ScilabView extends WrappedPlainView {
      * Used to represent the default tabulation got with ConfigSciNotesManager
      */
     public void setDefaultTabRepresentation() {
-        setTabRepresentation(ConfigSciNotesManager.getDefaultTabulation());
+        setTabRepresentation(new TabManager.Tabulation());
     }
 
     /**
index 3808935..ba47937 100644 (file)
@@ -15,8 +15,6 @@ package org.scilab.modules.scinotes;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Element;
 
-import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-
 /**
  * This class handles the tabulation
  * @author Calixte DENIZET
@@ -76,10 +74,10 @@ public class TabManager {
     }
 
     /**
-     * Set the type and the size of a tabulation in using ConfigSciNotesManager
+     * Set the type and the size of a tabulation
      */
     public void setDefaultTabulation() {
-        setTabulation(ConfigSciNotesManager.getDefaultTabulation());
+        setTabulation(new Tabulation());
     }
 
     /**
@@ -125,7 +123,7 @@ public class TabManager {
     public int[] tabifyLines(int start, int end) {
         Element startL = elem.getElement(elem.getElementIndex(start));
         int sstart = startL.getStartOffset();
-        int[] ret = new int[]{0, 0};
+        int[] ret = new int[] {0, 0};
         int send = end;
 
         try {
@@ -262,5 +260,12 @@ public class TabManager {
             this.type = type;
             this.rep = rep;
         }
+
+        public Tabulation() {
+            this.tab = SciNotesOptions.getSciNotesDisplay().useSpaces ? ' ' : '\t';
+            this.number = SciNotesOptions.getSciNotesDisplay().tabSize;
+            this.type = SciNotesOptions.getSciNotesDisplay().tabRepresentation;
+            this.rep = ' ';
+        }
     }
 }
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ConfigTabulationsAction.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ConfigTabulationsAction.java
deleted file mode 100644 (file)
index 2557b95..0000000
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2010 - 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.actions;
-
-import java.awt.Component;
-import java.awt.FlowLayout;
-import java.awt.GridLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.AbstractAction;
-import javax.swing.BorderFactory;
-import javax.swing.BoxLayout;
-import javax.swing.ButtonGroup;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-import javax.swing.JScrollBar;
-import javax.swing.JSpinner;
-import javax.swing.KeyStroke;
-import javax.swing.SpinnerNumberModel;
-
-import org.scilab.modules.commons.ScilabConstants;
-import org.scilab.modules.gui.menuitem.MenuItem;
-import org.scilab.modules.gui.utils.ScilabSwingUtilities;
-import org.scilab.modules.scinotes.IndentManager;
-import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.ScilabDocument;
-import org.scilab.modules.scinotes.ScilabEditorPane;
-import org.scilab.modules.scinotes.ScilabView;
-import org.scilab.modules.scinotes.TabManager;
-import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
-/**
- * ConfigTabulationsAction Class
- * @author Calixte DENIZET
- */
-public class ConfigTabulationsAction extends DefaultAction {
-
-    private static final long serialVersionUID = 1L;
-    private static final int GAP = 5;
-    private static final String ESCAPE = "escape";
-    private static final String SCI = ScilabConstants.SCI.getPath();
-
-    private static boolean windowAlreadyExist;
-    private static JFrame mainFrame;
-
-    private JButton okButton;
-    private JButton cancelButton;
-    private JButton applyButton;
-    private JRadioButton tabHRule;
-    private JRadioButton tabVRule;
-    private JRadioButton tabDbleChev;
-    private JCheckBox useWhitesCheckBox;
-    private JSpinner tabLengthSpinner;
-
-    /**
-     * Constructor
-     * @param name the name of the action
-     * @param editor SciNotes
-     */
-    public ConfigTabulationsAction(String name, SciNotes editor) {
-        super(name, editor);
-    }
-
-    /**
-     * doAction
-     */
-    @Override
-    public void doAction() {
-        ScilabEditorPane sep = getEditor().getTextPane();
-        openConfTabWindow();
-    }
-
-    /**
-     * createMenu
-     * @param label label of the menu
-     * @param editor SciNotes
-     * @param key Keystroke
-     * @return MenuItem
-     */
-    public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
-        return createMenu(label, null, new ConfigTabulationsAction(label, editor), key);
-    }
-
-    /**
-     * Close the window
-     */
-    public static void closeConfTabWindow() {
-        if (windowAlreadyExist) {
-            mainFrame.dispose();
-            mainFrame = null;
-            windowAlreadyExist = false;
-        }
-    }
-
-    /**
-     * Open a window
-     */
-    public void openConfTabWindow() {
-        if (windowAlreadyExist) {
-            mainFrame.setVisible(true);
-            return;
-        }
-
-        TabManager.Tabulation tabProps = ConfigSciNotesManager.getDefaultTabulation();
-
-        mainFrame = new JFrame();
-        mainFrame.setIconImage(new ImageIcon(ScilabSwingUtilities.findIcon("scilab")).getImage());
-        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-        mainFrame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE , 0), ESCAPE);
-        mainFrame.getRootPane().getActionMap().put(ESCAPE, new AbstractAction() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    closeConfTabWindow();
-                }
-            });
-
-        windowAlreadyExist = true;
-
-        cancelButton = new JButton(SciNotesMessages.CANCEL);
-        okButton = new JButton(SciNotesMessages.OK);
-        okButton.setPreferredSize(cancelButton.getPreferredSize());
-        applyButton = new JButton(SciNotesMessages.APPLYREINDENT);
-
-        JPanel panelButton = new JPanel();
-        panelButton.setLayout(new GridLayout(1, 4, GAP, GAP));
-        panelButton.setBorder(BorderFactory.createEmptyBorder(GAP, 0, 0, 0));
-        panelButton.add(new JLabel());
-        panelButton.add(okButton);
-        panelButton.add(applyButton);
-        panelButton.add(cancelButton);
-
-        /* Main content pane */
-        JPanel contentPanel = new JPanel(new GridLayout(1, 2, GAP, GAP));
-        contentPanel.setBorder(BorderFactory.createEmptyBorder(2 * GAP, 2 * GAP, 2 * GAP, 2 * GAP));
-
-        /* Style */
-        JPanel stylePanel = new JPanel(new GridLayout(2, 1, GAP, GAP));
-        stylePanel.setBorder(BorderFactory.createTitledBorder(SciNotesMessages.TABSTYLE));
-
-        useWhitesCheckBox = new JCheckBox(SciNotesMessages.TABUSEWHITES, tabProps.tab == ' ');
-        stylePanel.add(useWhitesCheckBox);
-
-        JPanel tabLengthPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
-        tabLengthSpinner = new JSpinner(new SpinnerNumberModel(tabProps.number, 0, 16, 1));
-
-        tabLengthPanel.add(new JLabel(SciNotesMessages.TABLENGTH));
-        tabLengthPanel.add(tabLengthSpinner);
-
-        stylePanel.add(tabLengthPanel);
-
-        contentPanel.add(stylePanel);
-
-        /* Representation */
-        final JPanel panelRepresentation = new JPanel(new GridLayout(3, 1, GAP, GAP));
-        panelRepresentation.setBorder(BorderFactory.createTitledBorder(SciNotesMessages.TABREPRESENTATION));
-        tabHRule = new JRadioButton(SciNotesMessages.TABHRULE, tabProps.type == ScilabView.TABHORIZONTAL);
-        panelRepresentation.add(tabHRule);
-        tabVRule = new JRadioButton(SciNotesMessages.TABVRULE, tabProps.type == ScilabView.TABVERTICAL);
-        panelRepresentation.add(tabVRule);
-        tabDbleChev = new JRadioButton(SciNotesMessages.TABDOUBLECHEVRONS, tabProps.type == ScilabView.TABDOUBLECHEVRONS);
-        panelRepresentation.add(tabDbleChev);
-        ButtonGroup repGroup = new ButtonGroup();
-        repGroup.add(tabHRule);
-        repGroup.add(tabVRule);
-        repGroup.add(tabDbleChev);
-
-        contentPanel.add(panelRepresentation);
-        useWhitesCheckBox.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    boolean b = !useWhitesCheckBox.isSelected();
-                    for (Component c : panelRepresentation.getComponents()) {
-                        c.setEnabled(b);
-                    }
-                }
-            });
-
-        boolean b = !useWhitesCheckBox.isSelected();
-        for (Component c : panelRepresentation.getComponents()) {
-            c.setEnabled(b);
-        }
-
-        JPanel framePanel = new JPanel();
-        framePanel.setLayout(new BoxLayout(framePanel, BoxLayout.PAGE_AXIS));
-        framePanel.add(contentPanel);
-        framePanel.add(panelButton);
-
-        mainFrame.setContentPane(framePanel);
-
-        cancelButton.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    ConfigTabulationsAction.windowAlreadyExist = false;
-                    mainFrame.dispose();
-                }
-            });
-
-        okButton.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    ConfigTabulationsAction.windowAlreadyExist = false;
-                    refreshPane();
-                    mainFrame.dispose();
-                }
-            });
-
-        applyButton.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    ScilabEditorPane sep = getEditor().getTextPane();
-                    IndentManager indent = sep.getIndentManager();
-                    ScilabDocument doc = (ScilabDocument) sep.getDocument();
-                    JScrollBar sb = sep.getScrollPane().getHorizontalScrollBar();
-                    int val = -1;
-                    if (sb != null) {
-                        val = sb.getValue();
-                    }
-                    refreshPane();
-                    indent.indentDoc(0, doc.getLength() - 1);
-                    if (val != -1) {
-                        sb.setValue(val);
-                    }
-                }
-            });
-
-        mainFrame.addWindowListener(new WindowListener() {
-                @Override
-                public void windowClosed(WindowEvent arg0) { }
-                @Override
-                public void windowDeiconified(WindowEvent arg0) { }
-                @Override
-                public void windowActivated(WindowEvent arg0) { }
-
-                @Override
-                public void windowClosing(WindowEvent arg0) {
-                    closeConfTabWindow();
-                }
-
-                @Override
-                public void windowDeactivated(WindowEvent arg0) { }
-                @Override
-                public void windowIconified(WindowEvent arg0) { };
-                @Override
-                public void windowOpened(WindowEvent arg0) { }
-            });
-
-        mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
-        mainFrame.setTitle(SciNotesMessages.CONFIGTAB);
-        mainFrame.pack();
-        mainFrame.setLocationRelativeTo(getEditor());
-        mainFrame.setVisible(true);
-    }
-
-    /**
-     * Refresh the pane
-     */
-    private void refreshPane() {
-        char tab = ' ';
-        if (!useWhitesCheckBox.isSelected()) {
-            tab = '\t';
-        }
-        int len = ((Integer) tabLengthSpinner.getValue()).intValue();
-        int type = ScilabView.TABNOTHING;
-        if (tab == '\t' && tabVRule.isSelected()) {
-            type = ScilabView.TABVERTICAL;
-        } else if (tabHRule.isSelected()) {
-            type = ScilabView.TABHORIZONTAL;
-        } else if (tabDbleChev.isSelected()) {
-            type = ScilabView.TABDOUBLECHEVRONS;
-        }
-        TabManager.Tabulation cfg = new TabManager.Tabulation(tab, len, type, ' ');
-        ConfigSciNotesManager.saveDefaultTabulation(cfg);
-        SciNotes.setDefaultTabulation(cfg);
-    }
-}
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/DefaultEncodingAction.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/DefaultEncodingAction.java
deleted file mode 100644 (file)
index 749aec5..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2010 - 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.actions;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CodingErrorAction;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JMenu;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.KeyStroke;
-
-import org.scilab.modules.gui.menu.Menu;
-import org.scilab.modules.gui.menu.ScilabMenu;
-import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-
-/**
- * DefaultEncodingAction Class
- * @author Calixte DENIZET
- *
- */
-public class DefaultEncodingAction extends DefaultCheckAction {
-
-    private static final long serialVersionUID = 455217357242331617L;
-
-    /**
-     * Default encoding to test
-     */
-    public static final String[] ENCODINGS = new String[]{"utf-8", "windows-1252", "iso-8859-1"};
-
-    private static final Map<String, Integer> encPos = new HashMap<String, Integer>(ENCODINGS.length);
-
-    static {
-        for (int i = 0; i < ENCODINGS.length; i++) {
-            encPos.put(ENCODINGS[i], i);
-        }
-    }
-
-    private static final int BUFFERCAPACITY = 8192;
-    private String encoding;
-
-    /**
-     * Construtor
-     * @param name the name of the action
-     * @param editor SciNotes
-     */
-    public DefaultEncodingAction(String name, SciNotes editor) {
-        super(name, editor);
-        encoding = ConfigSciNotesManager.getDefaultEncoding();
-    }
-
-    /**
-     * doAction
-     */
-    public void doAction() {
-        ConfigSciNotesManager.saveDefaultEncoding(encoding);
-    }
-
-    /**
-     * createMenu
-     * @param label label of the menu
-     * @param editor SciNotes
-     * @param key KeyStroke
-     * @return createMenu
-     */
-    public static Menu createMenu(String label, SciNotes editor, KeyStroke key) {
-        StringTokenizer tokens = new StringTokenizer(label, ";");
-        String labelDefaultEnc = tokens.nextToken();
-        String labelUTF8 = tokens.nextToken();
-        String labelANSI = tokens.nextToken();
-        String labelISO88591 = tokens.nextToken();
-
-        DefaultEncodingAction de = new DefaultEncodingAction(labelDefaultEnc, editor);
-        final JRadioButtonMenuItem[] arr = new JRadioButtonMenuItem[3];
-        String[] labels = new String[]{labelUTF8, labelANSI, labelISO88591};
-
-        final Menu menu = ScilabMenu.createMenu();
-        menu.setText(labelDefaultEnc);
-
-        ButtonGroup group = new ButtonGroup();
-        JRadioButtonMenuItem radio;
-
-        for (int i = 0; i < labels.length; i++) {
-            radio = createRadioButtonMenuItem(de, labels[i], ENCODINGS[i]);
-            group.add(radio);
-            ((JMenu) menu.getAsSimpleMenu()).add(radio);
-            arr[i] = radio;
-        }
-
-        arr[encPos.get(de.encoding)].setSelected(true);
-
-        return menu;
-    }
-
-    /**
-     * @param file the file to test
-     * @return the corresponding charset if exists
-     * @throws IOExecption if I/O problems are met
-     * @throws CharacterCodingException if no charset is found
-     */
-    public static Charset tryToGuessEncoding(File file) throws IOException, CharacterCodingException {
-        for (int i = 0; i < ENCODINGS.length; i++) {
-            if (tryToGuessEncoding(file, Charset.forName(ENCODINGS[i]))) {
-                return Charset.forName(ENCODINGS[i]);
-            }
-        }
-
-        throw new CharacterCodingException();
-    }
-
-    /**
-     * @param file the file to test
-     * @param charset the charset to test
-     * @return true if the file can be decoded with the charset
-     * @throws IOExecption if I/O problems are met
-     */
-    public static boolean tryToGuessEncoding(File file, Charset charset) throws IOException {
-        char[] cbuf = new char[BUFFERCAPACITY];
-        CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
-        FileInputStream fis = new FileInputStream(file);
-        InputStreamReader inReader = new InputStreamReader(fis, decoder);
-        BufferedReader bufReader = new BufferedReader(inReader);
-        try {
-            while (bufReader.read(cbuf) != -1);
-            fis.close();
-            inReader.close();
-            bufReader.close();
-            return true;
-        } catch (Exception e) { }
-
-        return false;
-    }
-
-    /**
-     * createRadioButtonMenuItem
-     * @param ln the LineNumbersAction
-     * @param title the label of the menuitem
-     * @param state the state associated with the menuitem
-     * @return JRadioButtonMenuItem
-     */
-    private static JRadioButtonMenuItem createRadioButtonMenuItem(final DefaultEncodingAction de, String title, final String encoding) {
-        JRadioButtonMenuItem radio = new JRadioButtonMenuItem(title);
-        radio.addActionListener(new ActionListener() {
-                public void actionPerformed(ActionEvent arg0) {
-                    de.encoding = encoding;
-                    de.doAction();
-                }
-            });
-
-        return radio;
-    }
-}
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/HorizontalWrapAction.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/HorizontalWrapAction.java
deleted file mode 100644 (file)
index 373ed3f..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2010 - 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.actions;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.KeyStroke;
-import javax.swing.SwingUtilities;
-
-import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
-import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-
-/**
- * AutoIndentAction Class
- * @author Calixte DENIZET
- *
- */
-public final class HorizontalWrapAction extends DefaultCheckAction  {
-
-    /**
-     * serialVersionUID
-     */
-    private static final long serialVersionUID = -1L;
-
-    /**
-     * Constructor
-     * @param name the name of the action
-     * @param editor SciNotes
-     */
-    public HorizontalWrapAction(String name, SciNotes editor) {
-        super(name, editor);
-    }
-
-    /**
-     * doAction
-     */
-    public void doAction() {
-        SwingUtilities.invokeLater(new Runnable() {
-                public void run() {
-                    SciNotes.setHorizontalWrap(HorizontalWrapAction.this.getState());
-                    ConfigSciNotesManager.saveHorizontalWrap(HorizontalWrapAction.this.getState());
-                }
-            });
-    }
-
-    /**
-     * createCheckBoxMenu
-     * @param label label of the menu
-     * @param editor SciNotes
-     * @param key KeyStroke
-     * @return CheckBoxMenuItem
-     */
-    public static CheckBoxMenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
-        final CheckBoxMenuItem horizontalWrap = createCheckBoxMenu(label, null, new HorizontalWrapAction(label, editor), key);
-        horizontalWrap.setChecked(ConfigSciNotesManager.getHorizontalWrap());
-        ((JCheckBoxMenuItem) horizontalWrap.getAsSimpleCheckBoxMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
-                public void propertyChange(PropertyChangeEvent e) {
-                    horizontalWrap.setChecked(ConfigSciNotesManager.getHorizontalWrap());
-                }
-            });
-
-        return horizontalWrap;
-    }
-}