~cszikszoy/docky/mmv3

« back to all changes in this revision

Viewing changes to Docky.StandardPlugins/Clock/ClockThemeSelector.cs

  • Committer: Chris S.
  • Date: 2009-10-22 03:23:13 UTC
  • mfrom: (284.1.7 testaddins)
  • Revision ID: chris@szikszoy.com-20091022032313-2s9kikljologdsyt
enable lazy loading of addins

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  
2
 
//  Copyright (C) 2009 Robert Dyer
3
 
// 
4
 
//  This program is free software: you can redistribute it and/or modify
5
 
//  it under the terms of the GNU General Public License as published by
6
 
//  the Free Software Foundation, either version 3 of the License, or
7
 
//  (at your option) any later version.
8
 
// 
9
 
//  This program is distributed in the hope that it will be useful,
10
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
//  GNU General Public License for more details.
13
 
// 
14
 
//  You should have received a copy of the GNU General Public License
15
 
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
// 
17
 
 
18
 
using System;
19
 
using System.Collections.Generic;
20
 
using System.Collections.ObjectModel;
21
 
using System.IO;
22
 
using System.Linq;
23
 
using System.Text;
24
 
 
25
 
using Mono.Unix;
26
 
using Gtk;
27
 
 
28
 
using Docky.CairoHelper;
29
 
using Docky.Items;
30
 
using Docky.Menus;
31
 
using Docky.Services;
32
 
 
33
 
namespace Clock
34
 
{
35
 
        public class ClockThemeSelector : Gtk.Dialog
36
 
        {
37
 
                TreeStore labelTreeStore = new TreeStore (typeof (string));
38
 
                TreeView labelTreeView = new TreeView ();
39
 
                
40
 
                ClockDockItem DockItem { get; set; }
41
 
                
42
 
                public ClockThemeSelector (ClockDockItem dockItem)
43
 
                {
44
 
                        DockItem = dockItem;
45
 
                        Title = Catalog.GetString ("Themes");
46
 
                        
47
 
                        labelTreeView.Model = labelTreeStore;
48
 
                        labelTreeView.HeadersVisible = false;
49
 
                        labelTreeView.Selection.Changed += OnLabelSelectionChanged;
50
 
                        labelTreeView.AppendColumn (Catalog.GetString ("Theme"), new CellRendererText (), "text", 0);
51
 
                        
52
 
                        ScrolledWindow win = new ScrolledWindow ();
53
 
                        win.Add (labelTreeView);
54
 
                        win.SetSizeRequest (200, 300);
55
 
                        win.Show ();
56
 
                        VBox.PackEnd (win);
57
 
                        VBox.ShowAll ();
58
 
                        AddButton ("Close", ResponseType.Close);
59
 
 
60
 
                        UpdateThemeList ();
61
 
                }
62
 
                
63
 
                public void UpdateThemeList ()
64
 
                {
65
 
                        List<string> themes = new List<string> ();
66
 
                        
67
 
                        foreach (string path in DockItem.ThemeURIs)
68
 
                                if (Directory.Exists (path))
69
 
                                        foreach (DirectoryInfo p in new DirectoryInfo (path).GetDirectories ())
70
 
                                                themes.Add (p.Name);
71
 
                        
72
 
                        labelTreeStore.Clear ();
73
 
                        
74
 
                        themes.Sort ();
75
 
                        
76
 
                        int i = 0, selected = -1;
77
 
                        foreach (string p in themes.Distinct ()) {
78
 
                                if (p == DockItem.CurrentTheme)
79
 
                                        selected = i;
80
 
                                labelTreeStore.AppendValues (p);
81
 
                                i++;
82
 
                        }
83
 
                        
84
 
                        labelTreeView.Selection.SelectPath (new TreePath ("" + selected));
85
 
                        labelTreeView.ScrollToCell (new TreePath ("" + selected), null, false, 0, 0);
86
 
                }
87
 
                
88
 
                protected virtual void OnLabelSelectionChanged (object o, System.EventArgs args)
89
 
                {
90
 
                        TreeIter iter;
91
 
                        TreeModel model;
92
 
                        
93
 
                        if (((TreeSelection)o).GetSelected (out model, out iter))
94
 
                                DockItem.SetTheme ((string) model.GetValue (iter, 0));
95
 
                }
96
 
                
97
 
                protected override void OnResponse (ResponseType response_id)
98
 
                {
99
 
                        Destroy ();
100
 
                }
101
 
        }
102
 
}