~ubuntu-branches/debian/squeeze/f-spot/squeeze

« back to all changes in this revision

Viewing changes to src/TagMenu.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane, Mirco Bauer, Iain Lane
  • Date: 2009-02-07 20:23:32 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090207202332-oc93rfjo1st0571s
Tags: 0.5.0.3-2
[ Mirco Bauer]
* Upload to unstable.
* debian/control:
  + Lowered GNOME# build-deps to 2.0 ABI as that transition didn't happen
    yet in unstable.

[ Iain Lane ]
* debian/patches/svn-r4545_locales-import.dpatch: Patch backported from SVN
  trunk revision 4545 - initialize the translation catalog earlier (LP: #293305)
  (Closes: #514457). Thanks to Florian Heinle for finding the patch and to
  Chris Coulson for preparing the update.
* debian/control: Build-depend on libmono-dev (>= 1.2.4) to match configure
  checks.
* debian/rules: Pass CSC=/usr/bin/csc to configure for gio-sharp to fix FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using Gtk;
2
 
using System;
3
 
using FSpot;
4
 
using FSpot.Utils;
5
 
 
6
 
public class TagMenu : Menu {
7
 
        private TagStore tag_store;
8
 
        private MenuItem parent_item;
9
 
 
10
 
        public delegate void TagSelectedHandler (Tag t);
11
 
        public event TagSelectedHandler TagSelected;
12
 
        
13
 
        private EventHandler new_tag_handler = null;
14
 
        public EventHandler NewTagHandler {
15
 
                get { return new_tag_handler; }
16
 
                set { new_tag_handler = value; }
17
 
        }
18
 
 
19
 
        public class TagMenuItem : Gtk.ImageMenuItem {
20
 
                public Tag Value;
21
 
 
22
 
                public TagMenuItem (Tag t) : this (t, t.Name) { }
23
 
                
24
 
                public TagMenuItem (Tag t, string name) : base (name.Replace ("_", "__"))
25
 
                {
26
 
                        Value = t;
27
 
                        if (t.Icon != null)
28
 
                                this.Image = new Gtk.Image (t.SizedIcon);
29
 
                }
30
 
 
31
 
                public static TagMenuItem IndentedItem (Tag t)
32
 
                {
33
 
                        System.Text.StringBuilder label_builder = new System.Text.StringBuilder ();
34
 
                        
35
 
                        for (Category parent = t.Category; 
36
 
                             parent != null && parent.Category != null;
37
 
                             parent = parent.Category)
38
 
                                label_builder.Append ("  ");
39
 
                        
40
 
                        label_builder.Append (t.Name);
41
 
                        return new TagMenuItem (t, label_builder.ToString ());
42
 
                }
43
 
 
44
 
                protected TagMenuItem (IntPtr raw) : base (raw) {}
45
 
        }
46
 
 
47
 
        public TagMenu (MenuItem item, TagStore store) 
48
 
        {
49
 
                if (item != null) {
50
 
                        item.Submenu = this;
51
 
                        item.Activated += HandlePopulate;
52
 
                        parent_item = item;
53
 
                }
54
 
 
55
 
                tag_store = store;
56
 
        }
57
 
 
58
 
        protected TagMenu (IntPtr raw) : base (raw) {}
59
 
 
60
 
        public void Populate ()
61
 
        {
62
 
                Populate (false);
63
 
        }
64
 
 
65
 
        public int GetPosition (Tag t)
66
 
        {
67
 
                // FIXME right now this only works on flat menus
68
 
 
69
 
                int i = 0;
70
 
                foreach (Widget w in this.Children) {
71
 
                        TagMenuItem item = w as TagMenuItem;
72
 
                        if (item != null) {
73
 
                                if (t == item.Value)
74
 
                                        return i;
75
 
                        }
76
 
                        i++;
77
 
                }
78
 
                
79
 
                return -1;
80
 
        }
81
 
 
82
 
        public void Populate (bool flat)
83
 
        { 
84
 
                if (flat)
85
 
                        PopulateFlat (tag_store.RootCategory, this);
86
 
                else
87
 
                        Populate (tag_store.RootCategory, this);
88
 
 
89
 
                if (NewTagHandler != null) {
90
 
                        GtkUtil.MakeMenuSeparator (this);
91
 
                        GtkUtil.MakeMenuItem (this, Mono.Unix.Catalog.GetString ("Create New Tag..."),
92
 
                                        "tag-new", NewTagHandler, true);
93
 
                }
94
 
        }
95
 
 
96
 
        public void PopulateFlat (Category cat, Gtk.Menu parent)
97
 
        {
98
 
                foreach (Tag t in cat.Children) {
99
 
                        TagMenuItem item = TagMenuItem.IndentedItem (t);
100
 
                        parent.Append (item);
101
 
                        item.ShowAll ();
102
 
 
103
 
                        Category subcat = t as Category;
104
 
                        if (subcat != null && subcat.Children.Length != 0) {
105
 
                                PopulateFlat (t as Category, parent);
106
 
                        } else {
107
 
                                item.Activated += HandleActivate;
108
 
                        }
109
 
                } 
110
 
        }
111
 
 
112
 
        public void Populate (Category cat, Gtk.Menu parent)
113
 
        {
114
 
                Widget [] dead_pool = parent.Children;
115
 
                for (int i = 0; i < dead_pool.Length; i++)
116
 
                        dead_pool [i].Destroy ();
117
 
 
118
 
                foreach (Tag t in cat.Children) {
119
 
                        TagMenuItem item = new TagMenuItem (t);
120
 
                        parent.Append (item);
121
 
                        item.ShowAll ();
122
 
 
123
 
                        Category subcat = t as Category;
124
 
                        if (subcat != null && subcat.Children.Length != 0) {
125
 
                                Gtk.Menu submenu = new Menu ();
126
 
                                Populate (t as Category, submenu);
127
 
 
128
 
                                Gtk.SeparatorMenuItem sep = new Gtk.SeparatorMenuItem ();
129
 
                                submenu.Prepend (sep);
130
 
                                sep.ShowAll ();
131
 
 
132
 
                                TagMenuItem subitem = new TagMenuItem (t);
133
 
                                subitem.Activated += HandleActivate;
134
 
                                submenu.Prepend (subitem);
135
 
                                subitem.ShowAll ();
136
 
 
137
 
                                item.Submenu = submenu;
138
 
                        } else {
139
 
                                item.Activated += HandleActivate;
140
 
                        }
141
 
                } 
142
 
        }
143
 
        
144
 
        private void HandlePopulate (object obj, EventArgs args)
145
 
        {
146
 
                this.Populate ();
147
 
        }
148
 
        
149
 
        void HandleActivate (object obj, EventArgs args)
150
 
        {
151
 
                if (TagSelected != null) {
152
 
                        TagMenuItem t = obj as TagMenuItem;
153
 
                        if (t != null)
154
 
                                TagSelected (t.Value);
155
 
                        else 
156
 
                                Console.WriteLine ("Item was not a TagMenuItem");
157
 
                }
158
 
        }
159
 
}