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); } }
private Gtk.HBox create_element(Item item, string search_text, string snippet_text, VoidFunction update) { Gtk.HBox element = new Gtk.HBox(); Gtk.VBox lines = new Gtk.VBox(); Gtk.HBox title_date = new Gtk.HBox(); Gtk.EventBox title_wrapper = new Gtk.EventBox(); Gtk.Label title = new Gtk.Label(); string str_title = item.name(40); string capitalized = search_text.Substring(0, 1).ToUpper() + search_text.Substring(1); if (str_title.Contains(search_text)) { int index = str_title.IndexOf(search_text); str_title = str_title.Substring(0, index) + "<b>" + search_text + "</b>" + str_title.Substring(index+search_text.Length); } else if (str_title.Contains(capitalized)) { int index = str_title.IndexOf(capitalized); str_title = str_title.Substring(0, index) + "<b>" + capitalized + "</b>" + str_title.Substring(index+capitalized.Length); } title.Markup = "<big>" + str_title + "</big>"; title.UseUnderline = false; title.SetAlignment(0, 0); // left aligned title_wrapper.ButtonPressEvent += delegate(object sender, Gtk.ButtonPressEventArgs args) { if (args.Event.Button == 1) item.open(); }; title_wrapper.Add(title); GtkCommon.set_background_color(title_wrapper, "white"); GtkCommon.show_hand_and_tooltip(title_wrapper, String.Format(Mono.Unix.Catalog.GetString("Open: {0}"), item.long_name)); GtkCommon.create_preview(item, lines, title_wrapper); title_date.PackStart(title_wrapper, true, true, 0); Gtk.Alignment date_alignment = new Gtk.Alignment(1, 0, 0, 0); Gtk.Label date = new Gtk.Label(); date.Markup = "<big>" + String.Format("{0:dd/MM/yy}", item.last_modify) + "</big>"; date_alignment.Add(date); date_alignment.LeftPadding = 10; title_date.PackStart(date_alignment, true, true, 0); lines.PackStart(title_date, true, true, 0); try { DocumentItem doc_item = item as DocumentItem; if (doc_item != null) { doc_item.on_snippet_callback = delegate (string snippet) { if (!String.IsNullOrEmpty(snippet)) { System.Console.WriteLine("got snippet: {0}", snippet); Gtk.Label snippet_label = new Gtk.Label(); snippet_label.SetAlignment(0, 0); // left aligned snippet_label.Markup = snippet; lines.PackStart(snippet_label, true, true, 2); lines.ReorderChild(snippet_label, 1); update(); } }; if (!String.IsNullOrEmpty(doc_item.snippet)) doc_item.on_snippet_callback(doc_item.snippet); } } catch (Exception) { // not document item } Gtk.HBox label_links = new Gtk.HBox(); Gtk.HBox bubbles = new Gtk.HBox(); foreach (UserLabel label in item.labels) bubbles.Add(label.dot()); label_links.PackStart(bubbles, false, false, 0); item.on_labels_callback = delegate() { foreach (Widget w in bubbles) w.Destroy(); foreach (UserLabel label in item.labels) bubbles.Add(label.dot()); element.ShowAll(); }; Gtk.Alignment links_alignment = new Gtk.Alignment(1,1,0,0); Gtk.HBox links = new Gtk.HBox(); add_link(Mono.Unix.Catalog.GetString("Go to week"), CalendarDriver.View.Week, item.last_modify, links); add_link(Mono.Unix.Catalog.GetString("Go to month"), CalendarDriver.View.Month, item.last_modify, links); add_link(Mono.Unix.Catalog.GetString("Go to year"), CalendarDriver.View.Year, item.last_modify, links); links_alignment.Add(links); label_links.PackStart(links_alignment, true, true, 0); lines.PackStart(label_links, true, true, 2); string image = String.Empty; if (item.file != null) image = Singleton<Types>.Instance.get_type((int)item.file.type.category).icon; Gtk.Alignment img_alignment = new Gtk.Alignment(0, (float)0.05, 0,0); if (!String.IsNullOrEmpty(image)) { Gtk.Image img; if (item.file.starred) img = CairoDrawing.create_small_starred_image(image); else img = new Gtk.Image(null, image); item.register_small_starred_change(delegate(bool starred) { foreach (Widget w in img_alignment) w.Destroy(); if (starred) img = CairoDrawing.create_small_starred_image(image); else img = new Gtk.Image(null, image); img_alignment.Add(img); img_alignment.ShowAll(); }); img_alignment.Add(img); img_alignment.ShowAll(); } element.PackStart(img_alignment, false, false, 5); element.PackStart(lines, true, true, 0); return element; }