public static void OnButtonPressEvent(Gdk.EventButton evnt, Item item) { if (evnt.Button == 1) { item.open(); } else if (evnt.Button == 3) { Menu popup_menu = new Menu(); MenuItem open_item = new MenuItem(Mono.Unix.Catalog.GetString("Open")); open_item.Activated += delegate { item.open(); }; popup_menu.Add(open_item); MenuItem open_with_item = new MenuItem(Mono.Unix.Catalog.GetString("Open with")); Gnome.Vfs.MimeApplication[] application_handlers = Gnome.Vfs.Mime.GetAllApplications(item.mime_type); if (application_handlers.Length > 0) { Menu handlers_menu = new Menu(); foreach (Gnome.Vfs.MimeApplication m in application_handlers) { MenuItem handlers_menu_item = new MenuItem(m.Name); GLib.List tmp = new GLib.List(typeof(System.String)); // fixme, use better name tmp.Append(Gnome.Vfs.Uri.GetUriFromLocalPath(item.path)); Gnome.Vfs.MimeApplication tmp_m = m; // go lambda bug, go handlers_menu_item.Activated += delegate { tmp_m.Launch(tmp); }; handlers_menu.Add(handlers_menu_item); } open_with_item.Submenu = handlers_menu; } popup_menu.Add(open_with_item); MenuItem open_folder = new MenuItem(Mono.Unix.Catalog.GetString("Open dir containing file")); open_folder.Activated += delegate { string path = item.path; int index = -1; if ((index = path.LastIndexOf('/')) != -1) { Gnome.Vfs.MimeApplication[] folder_handlers = Gnome.Vfs.Mime.GetAllApplications("inode/directory"); GLib.List tmp = new GLib.List(typeof(System.String)); // fixme, use better name tmp.Append(Gnome.Vfs.Uri.GetUriFromLocalPath(path.Substring(0, index+1))); folder_handlers[0].Launch(tmp); } }; popup_menu.Add(open_folder); MenuItem clipboard_item = new MenuItem(Mono.Unix.Catalog.GetString("Copy path to clipboard")); clipboard_item.Activated += delegate { Gtk.Clipboard clipboard_x = Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", true)); clipboard_x.Text = item.path; Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true)); clipboard.Text = item.path; }; popup_menu.Add(clipboard_item); MenuItem labels_item = new MenuItem(Mono.Unix.Catalog.GetString("Labels")); Menu categories_menu = new Menu(); bool first_category = true; foreach (Category cat in Singleton<Categories>.Instance.categories) { if (cat.labels.Count > 0 || Singleton<Categories>.Instance.categories.Count == 1) { if (first_category) first_category = false; else categories_menu.Add(new Gtk.SeparatorMenuItem()); MenuItem cat_item = new MenuItem(cat.metalabel.label); categories_menu.Add(cat_item); foreach (UserLabel tmp_label in cat.labels) { UserLabel label = tmp_label; // go lambda bug, go if (!item.contains_label(label)) { ImageMenuItem label_item = new ImageMenuItem(); Gtk.Label l = new Gtk.Label(label.metalabel.label); l.SetAlignment(0f, 0.5f); GtkCommon.set_foreground_color(l, new Gdk.Color(label.metalabel.color.r, label.metalabel.color.g, label.metalabel.color.b)); label_item.Add(l); label_item.Image = CairoDrawing.create_dot_image(0, 0, 0, 0, 14, 14); label_item.Activated += delegate { item.make_label(label); }; categories_menu.Add(label_item); } else { ImageMenuItem label_item = new ImageMenuItem(); Gtk.Label l = new Gtk.Label(label.metalabel.label); l.SetAlignment(0f, 0.5f); GtkCommon.set_foreground_color(l, new Gdk.Color(label.metalabel.color.r, label.metalabel.color.g, label.metalabel.color.b)); label_item.Add(l); label_item.Image = label.dot(); label_item.Activated += delegate { item.remove_label(label); }; categories_menu.Add(label_item); } } } } labels_item.Submenu = categories_menu; popup_menu.Add(labels_item); popup_menu.Add(new Gtk.SeparatorMenuItem()); string starred_text = Mono.Unix.Catalog.GetString("Add star"); if (item.file.starred) starred_text = Mono.Unix.Catalog.GetString("Remove star"); ImageMenuItem starred_item = new ImageMenuItem(starred_text); starred_item.Image = new Gtk.Image(new Gdk.Pixbuf(null, "stock_about.png")); starred_item.Activated += delegate { item.update_starred(); }; popup_menu.Add(starred_item); popup_menu.ShowAll(); popup_menu.Popup(null, null, null, evnt.Button, evnt.Time); } }
static MenuItem LabelItem (Gtk.Widget widget) { ImageMenuItem item; Label label; label = new Label (widget is Placeholder ? Catalog.GetString ("Placeholder") : widget.Name); label.UseUnderline = false; label.SetAlignment (0.0f, 0.5f); item = new ImageMenuItem (); item.Add (label); Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup (widget); if (wrapper != null) { ClassDescriptor klass = wrapper.ClassDescriptor; if (klass != null) { Gdk.Pixbuf pixbuf = klass.Icon; int width, height; Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out width, out height); item.Image = new Gtk.Image (pixbuf.ScaleSimple (width, height, Gdk.InterpType.Bilinear)); } } return item; }