2 using System
.Collections
;
3 using System
.Runtime
.InteropServices
;
8 namespace Search
.Tiles
{
10 public class OpenWithMenu
: Gtk
.Menu
{
12 public delegate void OpenWithHandler (MimeApplication app
);
13 public event OpenWithHandler ApplicationActivated
;
15 private ArrayList list
= null;
17 private bool show_icons
= true;
18 public bool ShowIcons
{
19 get { return show_icons; }
20 set { show_icons = value; }
23 static OpenWithMenu ()
25 Gnome
.Vfs
.Vfs
.Initialize ();
28 public OpenWithMenu (string mime
)
30 list
= GetApplications (mime
);
35 foreach (MimeApplication app
in list
) {
36 ApplicationMenuItem i
= new ApplicationMenuItem (this, app
);
37 i
.Activated
+= HandleItemActivated
;
42 public void AppendToMenu (Gtk
.Menu menu
)
44 if (list
== null || list
.Count
== 0)
47 Gtk
.MenuItem open_with
= new Gtk
.MenuItem (Mono
.Unix
.Catalog
.GetString ("Open With"));
48 open_with
.Submenu
= this;
50 menu
.Append (open_with
);
53 private ArrayList
GetApplications (string mime
)
55 if (mime
== null || mime
== "")
58 ArrayList list
= new ArrayList ();
60 MimeApplication
[] apps
= Gnome
.Vfs
.Mime
.GetAllApplications (mime
);
62 foreach (MimeApplication app
in apps
) {
63 // Skip apps that don't take URIs
64 if (! app
.SupportsUris ())
67 if (! list
.Contains (app
))
74 private void HandleItemActivated (object sender
, EventArgs args
)
76 if (ApplicationActivated
!= null)
77 ApplicationActivated ((sender
as ApplicationMenuItem
).Application
);
80 private class ApplicationMenuItem
: ImageMenuItem
{
82 private MimeApplication application
;
83 public MimeApplication Application
{
84 get { return application; }
85 set { application = value; }
88 public ApplicationMenuItem (OpenWithMenu menu
, MimeApplication ma
) : base (ma
.Name
)
90 this.application
= ma
;
98 Gdk
.Pixbuf pixbuf
= null;
101 if (ma
.Icon
.StartsWith ("/"))
102 pixbuf
= new Gdk
.Pixbuf (ma
.Icon
, 16, 16);
104 pixbuf
= IconTheme
.Default
.LoadIcon (ma
.Icon
, 16,
111 Image
= new Gtk
.Image (pixbuf
);