[blam/gtk3: 3/3] Fill the theme list in the preferences



commit a4d057cea3017c6a9d005b5ba6b67c44f9d67762
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Sun Oct 13 04:05:49 2013 +0200

    Fill the theme list in the preferences

 blam.csproj              |    1 -
 src/Blam.cs              |    6 ++++--
 src/Dialogs.cs           |   29 ++++++++++++++++++++++++++++-
 src/PreferencesDialog.cs |   39 ---------------------------------------
 src/Theme.cs             |    7 +++++++
 src/ThemeManager.cs      |    9 +++++++--
 6 files changed, 46 insertions(+), 45 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index 5f51159..f6c248e 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -86,7 +86,6 @@
     <Compile Include="src\ItemStore.cs" />
     <Compile Include="src\ItemView.cs" />
     <Compile Include="src\Opml.cs" />
-    <Compile Include="src\PreferencesDialog.cs" />
     <Compile Include="src\Proxy.cs" />
     <Compile Include="src\Theme.cs" />
     <Compile Include="src\ThemeManager.cs" />
diff --git a/src/Blam.cs b/src/Blam.cs
index 0055eb3..c46d435 100644
--- a/src/Blam.cs
+++ b/src/Blam.cs
@@ -31,6 +31,7 @@ namespace Blam
                ScrolledWindow ItemViewSw;
 
                ChannelCollection channels;
+               ThemeManager themeManager;
 
                public BlamApplication()
                {
@@ -50,6 +51,7 @@ namespace Blam
 
                        trayIcon.ObserveClick.Subscribe(_ => toggleVisible());
 
+                       themeManager = new ThemeManager();
 
                        FeedListSw = bld.GetObject<ScrolledWindow>("feed-list-scroll");
                        FeedList = new FeedList(channels.ObservableChannels, channels.ObservableGroups);
@@ -60,7 +62,7 @@ namespace Blam
                        ItemListSw = bld.GetObject<ScrolledWindow>("item-list-scroll");
                        ItemListSw.Child = ItemList;
 
-                       ItemView = new ItemView();
+                       ItemView = new ItemView(themeManager);
                        ItemViewSw = bld.GetObject<ScrolledWindow>("item-view-scroll");
                        ItemViewSw.Child = ItemView;
 
@@ -105,7 +107,7 @@ namespace Blam
 
                        item = bld.GetObject<MenuItem>("menu-preferences");
                        item.ObserveActivated().Subscribe(obj => {
-                               using (var dialog = new PreferencesDialog(MainWindow)) {
+                               using (var dialog = new PreferencesDialog(MainWindow, themeManager)) {
                                        dialog.Run();
                                }
                        });
diff --git a/src/Dialogs.cs b/src/Dialogs.cs
index 62e3f72..2e5960b 100644
--- a/src/Dialogs.cs
+++ b/src/Dialogs.cs
@@ -251,7 +251,9 @@ namespace Blam
                Togglable markReadDelay;
                Spinnable markReadDelayTime;
 
-               public PreferencesDialog(Gtk.Window parent)
+               ThemeManager themeManager;
+
+               public PreferencesDialog(Gtk.Window parent, ThemeManager themeManager)
                        : base(parent, "preferences")
                {
                        reverseEntries = new Togglable(bld, "reverse-entries", "reverse-entries");
@@ -261,10 +263,35 @@ namespace Blam
                        refreshOnStartup = new Togglable(bld, "refresh-on-startup", "refresh-on-startup");
                        markReadDelay = new Togglable(bld, "mark-read-delay", "mark-read-delay");
                        markReadDelayTime = new Spinnable(bld,"mark-read-delay-time", "mark-read-delay-time");
+                       theme = bld.GetObject<ComboBox>("theme");
+
+                       this.themeManager = themeManager;
+               }
+
+               void fillThemes()
+               {
+                       theme.Clear();
+
+                       CellRendererText cell = new CellRendererText();
+                       theme.PackStart(cell, false);
+                       theme.AddAttribute(cell, "text", 0);
+                       ListStore store = new ListStore(typeof(string));
+                       theme.Model = store;
+
+                       var current = themeManager.Current;
+                       var list = themeManager.Themes;
+
+                       foreach (var t in list) {
+                               var iter = store.AppendValues(t.Name);
+                               if (t == current)
+                                       theme.SetActiveIter(iter);
+                       }
                }
 
                public new void Run()
                {
+                       fillThemes();
+
                        var toggles = Observable.Merge(
                                reverseEntries.Toggle,
                                autoRefresh.Toggle,
diff --git a/src/Theme.cs b/src/Theme.cs
index 12b456a..df6510d 100644
--- a/src/Theme.cs
+++ b/src/Theme.cs
@@ -16,6 +16,7 @@ namespace Blam
        {
                string Render(IDictionary<string,string> replaces);
                string Path { get; }
+               string Name { get; }
        }
 
 
@@ -27,6 +28,12 @@ namespace Blam
                        }
                }
 
+               public string Name {
+                       get {
+                               return "None";
+                       }
+               }
+
                public string Render(IDictionary<string,string> replaces)
                {
                        return replaces["text"];
diff --git a/src/ThemeManager.cs b/src/ThemeManager.cs
index f307d70..c03b72a 100644
--- a/src/ThemeManager.cs
+++ b/src/ThemeManager.cs
@@ -24,6 +24,11 @@ namespace Blam
                public event PropertyChangedEventHandler PropertyChanged;
 
                List<ITheme> themes;
+               public IEnumerable<ITheme> Themes {
+                       get {
+                               return themes;
+                       }
+               }
 
                ITheme current;
                public ITheme Current {
@@ -43,8 +48,8 @@ namespace Blam
                        loadThemes(Defines.PERSONAL_THEME_DIR);
                        loadThemes(Defines.THEME_DIR);
 
-                       var themePath = Conf.Preferences.GetString("theme");
-                       var theme = themes.Find(t => t.Path.Equals(themePath));
+                       var wanted = Conf.Preferences.GetString("theme");
+                       var theme = themes.Find(t => t.Name.Equals(wanted));
                        // if the user's theme isn't found, take the first of the list and fallback
                        // to an empty theme if the list is empty
                        theme = theme ?? themes.FirstOrDefault() ?? new EmptyTheme();


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