6
public class TagMenu : Menu {
7
private TagStore tag_store;
8
private MenuItem parent_item;
10
public delegate void TagSelectedHandler (Tag t);
11
public event TagSelectedHandler TagSelected;
13
private EventHandler new_tag_handler = null;
14
public EventHandler NewTagHandler {
15
get { return new_tag_handler; }
16
set { new_tag_handler = value; }
19
public class TagMenuItem : Gtk.ImageMenuItem {
22
public TagMenuItem (Tag t) : this (t, t.Name) { }
24
public TagMenuItem (Tag t, string name) : base (name.Replace ("_", "__"))
28
this.Image = new Gtk.Image (t.SizedIcon);
31
public static TagMenuItem IndentedItem (Tag t)
33
System.Text.StringBuilder label_builder = new System.Text.StringBuilder ();
35
for (Category parent = t.Category;
36
parent != null && parent.Category != null;
37
parent = parent.Category)
38
label_builder.Append (" ");
40
label_builder.Append (t.Name);
41
return new TagMenuItem (t, label_builder.ToString ());
44
protected TagMenuItem (IntPtr raw) : base (raw) {}
47
public TagMenu (MenuItem item, TagStore store)
51
item.Activated += HandlePopulate;
58
protected TagMenu (IntPtr raw) : base (raw) {}
60
public void Populate ()
65
public int GetPosition (Tag t)
67
// FIXME right now this only works on flat menus
70
foreach (Widget w in this.Children) {
71
TagMenuItem item = w as TagMenuItem;
82
public void Populate (bool flat)
85
PopulateFlat (tag_store.RootCategory, this);
87
Populate (tag_store.RootCategory, this);
89
if (NewTagHandler != null) {
90
GtkUtil.MakeMenuSeparator (this);
91
GtkUtil.MakeMenuItem (this, Mono.Unix.Catalog.GetString ("Create New Tag..."),
92
"tag-new", NewTagHandler, true);
96
public void PopulateFlat (Category cat, Gtk.Menu parent)
98
foreach (Tag t in cat.Children) {
99
TagMenuItem item = TagMenuItem.IndentedItem (t);
100
parent.Append (item);
103
Category subcat = t as Category;
104
if (subcat != null && subcat.Children.Length != 0) {
105
PopulateFlat (t as Category, parent);
107
item.Activated += HandleActivate;
112
public void Populate (Category cat, Gtk.Menu parent)
114
Widget [] dead_pool = parent.Children;
115
for (int i = 0; i < dead_pool.Length; i++)
116
dead_pool [i].Destroy ();
118
foreach (Tag t in cat.Children) {
119
TagMenuItem item = new TagMenuItem (t);
120
parent.Append (item);
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);
128
Gtk.SeparatorMenuItem sep = new Gtk.SeparatorMenuItem ();
129
submenu.Prepend (sep);
132
TagMenuItem subitem = new TagMenuItem (t);
133
subitem.Activated += HandleActivate;
134
submenu.Prepend (subitem);
137
item.Submenu = submenu;
139
item.Activated += HandleActivate;
144
private void HandlePopulate (object obj, EventArgs args)
149
void HandleActivate (object obj, EventArgs args)
151
if (TagSelected != null) {
152
TagMenuItem t = obj as TagMenuItem;
154
TagSelected (t.Value);
156
Console.WriteLine ("Item was not a TagMenuItem");