[blam/gtk3] Theme: refactor loading



commit 049b523610154fab19942692b965eab28f58e539
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Wed Dec 11 21:03:31 2013 +0100

    Theme: refactor loading

 src/Theme.cs |   33 +++++++++++++--------------------
 1 files changed, 13 insertions(+), 20 deletions(-)
---
diff --git a/src/Theme.cs b/src/Theme.cs
index 6331107..cb426b4 100644
--- a/src/Theme.cs
+++ b/src/Theme.cs
@@ -42,49 +42,42 @@ namespace Blam
 
        public class Theme : ITheme
        {
-               private string mName = "";
-               private string mPath = "";
-
-               private string mThemeHtml = "";
+               readonly string name;
+               readonly string path;
+               readonly string themeContent;
 
                public Theme (string path)
                {
-                       mPath = path;
+                       this.path = path;
+                       this.name = path.Substring(path.LastIndexOf('/') + 1);
 
-            Load ();
+                       var filename = System.IO.Path.Combine(path, Defines.THEME_INDEX_NAME);
+                       using (var r = File.OpenText(filename))
+                       {
+                               themeContent = r.ReadToEnd();
+                       }
                }
 
                public string Name {
                        get {
-                               return mName;
+                               return name;
                        }
                }
 
                public string Path {
                        get {
-                               return mPath;
+                               return path;
                        }
                }
 
                public string Render(IDictionary<string,string> replaces)
                {
-                       string str = mThemeHtml;
+                       string str = themeContent;
 
                        foreach (var k in replaces.Keys)
                                str = str.Replace("${" + k + "}", replaces[k]);
 
                        return str;
                }
-
-               private void Load () 
-               {
-            string fileName = mPath + "/" + Defines.THEME_INDEX_NAME;
-            TextReader r = File.OpenText (fileName);
-            mThemeHtml = r.ReadToEnd ();
-            r.Close ();
-
-            // TODO: Add better error handling here
-            mName = mPath.Substring (mPath.LastIndexOf ("/") + 1);
-               }
        }
 }


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