[latexila] BuildTool struct: getter/setter for the description



commit 6298c7f84c0a70aa212f61f914f2d80aa0aa63ca
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Fri Jul 13 04:23:37 2012 +0200

    BuildTool struct: getter/setter for the description
    
    If the description is empty, take the label. This behavior is now
    centralized.

 src/build_tool_dialog.vala       |   10 ++--------
 src/build_tools.vala             |   27 ++++++++++++++++++---------
 src/build_tools_preferences.vala |    4 +++-
 src/main_window.vala             |    2 +-
 4 files changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/src/build_tool_dialog.vala b/src/build_tool_dialog.vala
index ea146ec..69e7161 100644
--- a/src/build_tool_dialog.vala
+++ b/src/build_tool_dialog.vala
@@ -434,7 +434,7 @@ private class BuildToolDialog : Dialog
         /* Text entries */
 
         _entry_label.text = build_tool.label;
-        _entry_desc.text = build_tool.description;
+        _entry_desc.text = build_tool.get_description ();
         _entry_extensions.text = build_tool.extensions;
         _entry_files_to_open.text = build_tool.files_to_open;
 
@@ -478,13 +478,7 @@ private class BuildToolDialog : Dialog
         /* Text entries */
 
         tool.label = _entry_label.text.strip ();
-
-        string desc = _entry_desc.text.strip ();
-        if (desc == "")
-            tool.description = tool.label;
-        else
-            tool.description = desc;
-
+        tool.set_description (_entry_desc.text.strip ());
         tool.extensions = _entry_extensions.text.strip ();
         tool.files_to_open = _entry_files_to_open.text.strip ();
 
diff --git a/src/build_tools.vala b/src/build_tools.vala
index 533f139..4b2c882 100644
--- a/src/build_tools.vala
+++ b/src/build_tools.vala
@@ -37,7 +37,7 @@ public struct BuildJob
 
 public struct BuildTool
 {
-    string description;
+    private string _description;
     string extensions;
     string label;
     string icon;
@@ -47,7 +47,7 @@ public struct BuildTool
 
     public BuildTool ()
     {
-        description = "";
+        _description = "";
         extensions = "";
         label = "";
         icon = "";
@@ -60,6 +60,19 @@ public struct BuildTool
     {
         return jobs.size > 0;
     }
+
+    public void set_description (string description)
+    {
+        _description = description;
+    }
+
+    public string get_description ()
+    {
+        if (_description == null || _description == "")
+            return label;
+
+        return _description;
+    }
 }
 
 public class BuildTools : GLib.Object
@@ -190,7 +203,7 @@ public class BuildTools : GLib.Object
     {
         if (tool1.enabled != tool2.enabled
             || tool1.label != tool2.label
-            || tool1.description != tool2.description
+            || tool1.get_description () != tool2.get_description ()
             || tool1.extensions != tool2.extensions
             || tool1.icon != tool2.icon
             || tool1.files_to_open != tool2.files_to_open
@@ -335,10 +348,6 @@ public class BuildTools : GLib.Object
                 return;
 
             case "tool":
-                // the description is optional
-                if (_cur_tool.description == "")
-                    _cur_tool.description = _cur_tool.label;
-
                 _build_tools.add (_cur_tool);
                 break;
 
@@ -366,7 +375,7 @@ public class BuildTools : GLib.Object
                 break;
 
             case "description":
-                _cur_tool.description = text.strip ();
+                _cur_tool.set_description (text.strip ());
                 break;
 
             case "open":
@@ -390,7 +399,7 @@ public class BuildTools : GLib.Object
 
             content += Markup.printf_escaped ("    <label>%s</label>\n", tool.label);
             content += Markup.printf_escaped ("    <description>%s</description>\n",
-                tool.description);
+                tool.get_description ());
 
             foreach (BuildJob job in tool.jobs)
             {
diff --git a/src/build_tools_preferences.vala b/src/build_tools_preferences.vala
index 9d7b8ce..f397402 100644
--- a/src/build_tools_preferences.vala
+++ b/src/build_tools_preferences.vala
@@ -401,13 +401,15 @@ public class BuildToolsPreferences : Grid
 
         foreach (BuildTool tool in BuildTools.get_default ())
         {
+            string description = Markup.escape_text (tool.get_description ());
+
             TreeIter iter;
             _list_store.append (out iter);
             _list_store.set (iter,
                 BuildToolColumn.ENABLED, tool.enabled,
                 BuildToolColumn.PIXBUF, tool.icon,
                 BuildToolColumn.LABEL, tool.label,
-                BuildToolColumn.DESCRIPTION, Markup.escape_text (tool.description)
+                BuildToolColumn.DESCRIPTION, description
             );
         }
     }
diff --git a/src/main_window.vala b/src/main_window.vala
index dde4735..bfde072 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -1181,7 +1181,7 @@ public class MainWindow : Window
 
             string action_name = @"BuildTool_$i";
             Gtk.Action action = new Gtk.Action (action_name, build_tool.label,
-                build_tool.description, build_tool.icon);
+                build_tool.get_description (), build_tool.icon);
 
             // F2 -> F11
             // (F1 = help, F12 = stop execution)



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