[blam] Use a Dictionary for the theme variables
- From: Carlos MartÃn Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam] Use a Dictionary for the theme variables
- Date: Mon, 6 Aug 2012 03:18:27 +0000 (UTC)
commit 4e962dd1784e235a540a731d1b85d0d32153f5ea
Author: Carlos MartÃn Nieto <carlos cmartin tk>
Date: Sat Aug 4 21:23:30 2012 +0200
Use a Dictionary for the theme variables
src/ItemView.cs | 17 +++++++++--------
src/Theme.cs | 19 ++++++-------------
2 files changed, 15 insertions(+), 21 deletions(-)
---
diff --git a/src/ItemView.cs b/src/ItemView.cs
index 8ba963a..27721ee 100644
--- a/src/ItemView.cs
+++ b/src/ItemView.cs
@@ -13,6 +13,7 @@ using GtkSharp;
using WebKit;
using Mono.Unix;
using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
using System.IO;
using System.Net;
@@ -121,14 +122,14 @@ namespace Imendio.Blam {
baseDir = "file://" + theme.Path;
- string[] replaces = {
- "author", author,
- "link", link,
- "pubdate", pubdate,
- "text", text,
- "title", title,
- "url", url,
- "localbase", baseDir
+ var replaces = new Dictionary<string, string> {
+ {"author", author},
+ {"link", link},
+ {"pubdate", pubdate},
+ {"text", text},
+ {"title", title},
+ {"url", url},
+ {"localbase", baseDir},
};
webView.LoadString(theme.Render(replaces), null, null, baseDir);
diff --git a/src/Theme.cs b/src/Theme.cs
index fe6a31d..6ad3942 100644
--- a/src/Theme.cs
+++ b/src/Theme.cs
@@ -6,6 +6,7 @@
// (C) 2005 Michael Ostermeier
using System.IO;
+using System.Collections.Generic;
namespace Imendio.Blam {
public class Theme {
@@ -33,22 +34,14 @@ namespace Imendio.Blam {
}
}
- public string Render(string[] args)
+ public string Render(Dictionary<string,string> replaces)
{
- int off = 0;
- int max = args.Length;
- string str = mThemeHtml;
+ string str = mThemeHtml;
- /*
- * We take pairs of the keyword to replace and the text
- * to replace it with.
- */
+ foreach (var k in replaces.Keys)
+ str = str.Replace("${" + k + "}", replaces[k]);
- for(; off + 1 < max; off += 2) {
- str = str.Replace("${" + args[off] + "}", args[off + 1]);
- }
-
- return str;
+ return str;
}
private void Load ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]