[latexila] Load and save enabled/disabled state of default build tools



commit 36ac2cf8ff23301fdee6a69a9978d9814819a1cb
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Wed Jul 18 02:02:21 2012 +0200

    Load and save enabled/disabled state of default build tools

 data/org.gnome.latexila.gschema.xml |   10 ++++
 src/build_tools.vala                |   82 +++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.latexila.gschema.xml b/data/org.gnome.latexila.gschema.xml
index f42860c..6f6adc6 100644
--- a/data/org.gnome.latexila.gschema.xml
+++ b/data/org.gnome.latexila.gschema.xml
@@ -148,6 +148,16 @@
       <summary>File extensions for clean-up</summary>
       <description>The file extensions for the clean-up are separated by spaces</description>
     </key>
+    <key name="enabled-default-build-tools" type="ai">
+      <default>[]</default>
+      <summary>Enabled default build tools</summary>
+      <description>The list of the default build tools that are enabled</description>
+    </key>
+    <key name="disabled-default-build-tools" type="ai">
+      <default>[]</default>
+      <summary>Disabled default build tools</summary>
+      <description>The list of the default build tools that are disabled</description>
+    </key>
   </schema>
 
   <schema id="org.gnome.latexila.preferences.file-browser" path="/org/gnome/latexila/preferences/file-browser/">
diff --git a/src/build_tools.vala b/src/build_tools.vala
index 8aba455..6c00cde 100644
--- a/src/build_tools.vala
+++ b/src/build_tools.vala
@@ -323,6 +323,8 @@ public class DefaultBuildTools : BuildTools
         }
 
         load ();
+        load_enable_setting ();
+        modified.connect (save_enable_setting);
     }
 
     public static DefaultBuildTools get_default ()
@@ -332,6 +334,86 @@ public class DefaultBuildTools : BuildTools
 
         return _instance;
     }
+
+    // Enable or disable the build tools.
+    // There are two lists: the enabled build tools IDs, and the disabled build tools IDs.
+    // By default, the two lists are empty. If an ID is in a list, it will erase the
+    // default value found in the XML file. So when a new default build tool is added,
+    // it is not present in the lists, and it automatically gets the default value from
+    // the XML file.
+    private void load_enable_setting ()
+    {
+        GLib.Settings settings =
+            new GLib.Settings ("org.gnome.latexila.preferences.latex");
+
+        /* Get the enabled build tool IDs */
+
+        int[] enabled_tool_ids = {};
+
+        Variant enabled_tools = settings.get_value ("enabled-default-build-tools");
+        VariantIter iter;
+        enabled_tools.get ("ai", out iter);
+
+        int enabled_tool_id;
+        while (iter.next ("i", out enabled_tool_id))
+            enabled_tool_ids += enabled_tool_id;
+
+        /* Enable the build tools to enable */
+
+        int tool_num = 0;
+        foreach (BuildTool build_tool in _build_tools)
+        {
+            if (build_tool.id in enabled_tool_ids)
+                set_enabled (tool_num, true);
+
+            tool_num++;
+        }
+
+        /* Get the disabled build tool IDs */
+
+        int[] disabled_tool_ids = {};
+
+        Variant disabled_tools = settings.get_value ("disabled-default-build-tools");
+        disabled_tools.get ("ai", out iter);
+
+        int disabled_tool_id;
+        while (iter.next ("i", out disabled_tool_id))
+            disabled_tool_ids += disabled_tool_id;
+
+        /* Disable the build tools to disable */
+
+        tool_num = 0;
+        foreach (BuildTool build_tool in _build_tools)
+        {
+            if (build_tool.id in disabled_tool_ids)
+                set_enabled (tool_num, false);
+
+            tool_num++;
+        }
+    }
+
+    private void save_enable_setting ()
+    {
+        VariantBuilder builder_enabled = new VariantBuilder (VariantType.ARRAY);
+        VariantBuilder builder_disabled = new VariantBuilder (VariantType.ARRAY);
+
+        foreach (BuildTool build_tool in _build_tools)
+        {
+            if (build_tool.enabled)
+                builder_enabled.add ("i", build_tool.id);
+            else
+                builder_disabled.add ("i", build_tool.id);
+        }
+
+        Variant enabled_tools = builder_enabled.end ();
+        Variant disabled_tools = builder_disabled.end ();
+
+        GLib.Settings settings =
+            new GLib.Settings ("org.gnome.latexila.preferences.latex");
+
+        settings.set_value ("enabled-default-build-tools", enabled_tools);
+        settings.set_value ("disabled-default-build-tools", disabled_tools);
+    }
 }
 
 public class PersonalBuildTools : BuildTools



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]