Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hutchinson <mhutchinson@novell.com>2010-11-03 03:13:28 +0300
committerMichael Hutchinson <mhutchinson@novell.com>2010-11-03 21:20:05 +0300
commit228d93d422e81c1b4c0c04a15081b16431830e41 (patch)
tree6121fb83970174c6959f043aad9dd5da9d01b87e /main/src/addins/GnomePlatform
parentfc5cc48f066062bfbf7b61ac882ca6fda6f98976 (diff)
[Mac] Native Open With and file icons (fixed)
Diffstat (limited to 'main/src/addins/GnomePlatform')
-rw-r--r--main/src/addins/GnomePlatform/Gio.cs20
-rw-r--r--main/src/addins/GnomePlatform/GnomePlatform.cs73
2 files changed, 71 insertions, 22 deletions
diff --git a/main/src/addins/GnomePlatform/Gio.cs b/main/src/addins/GnomePlatform/Gio.cs
index 89eed2f66b..e2dcb42aed 100644
--- a/main/src/addins/GnomePlatform/Gio.cs
+++ b/main/src/addins/GnomePlatform/Gio.cs
@@ -70,12 +70,14 @@ namespace MonoDevelop.Platform {
public IntPtr prev;
}
- static DesktopApplication AppFromAppInfoPtr (IntPtr handle)
+ static GnomeDesktopApplication AppFromAppInfoPtr (IntPtr handle, DesktopApplication defaultApp)
{
string id = GLib.Marshaller.Utf8PtrToString (g_app_info_get_id (handle));
string name = GLib.Marshaller.Utf8PtrToString (g_app_info_get_name (handle));
string executable = GLib.Marshaller.Utf8PtrToString (g_app_info_get_executable (handle));
- return new DesktopApplication (id, name, executable);
+
+ if (!string.IsNullOrEmpty (name) && !string.IsNullOrEmpty (executable) && !executable.Contains ("monodevelop "))
+ return new GnomeDesktopApplication (executable, name, defaultApp != null && defaultApp.Id == id);
}
static IntPtr ContentTypeFromMimeType (string mime_type)
@@ -91,29 +93,31 @@ namespace MonoDevelop.Platform {
return content_type;
}
- public static DesktopApplication GetDefaultForType (string mime_type)
+ static DesktopApplication GetDefaultForType (string mime_type)
{
IntPtr content_type = ContentTypeFromMimeType (mime_type);
IntPtr ret = g_app_info_get_default_for_type (content_type, false);
GLib.Marshaller.Free (content_type);
- return ret == IntPtr.Zero ? new DesktopApplication () : AppFromAppInfoPtr (ret);
+ return ret == IntPtr.Zero ? null : AppFromAppInfoPtr (ret, null);
}
- public static DesktopApplication[] GetAllForType (string mime_type)
+ public static System.Collections.IList<DesktopApplication> GetAllForType (string mime_type)
{
+ var def = GetDefaultForType (mime_type);
+
IntPtr content_type = ContentTypeFromMimeType (mime_type);
IntPtr ret = g_app_info_get_all_for_type (content_type);
GLib.Marshaller.Free (content_type);
IntPtr l = ret;
- ArrayList apps = new ArrayList ();
+ var apps = new System.Collections.Generic.List<DesktopApplication> ();
while (l != IntPtr.Zero) {
GList node = (GList) Marshal.PtrToStructure (l, typeof (GList));
if (node.data != IntPtr.Zero)
- apps.Add (AppFromAppInfoPtr (node.data));
+ apps.Add (AppFromAppInfoPtr (node.data, def));
l = node.next;
}
g_list_free (ret);
- return (DesktopApplication[]) apps.ToArray (typeof (DesktopApplication));
+ return apps;
}
public static string GetMimeTypeDescription (string mime_type)
diff --git a/main/src/addins/GnomePlatform/GnomePlatform.cs b/main/src/addins/GnomePlatform/GnomePlatform.cs
index af4e3bcee7..a87658a5d7 100644
--- a/main/src/addins/GnomePlatform/GnomePlatform.cs
+++ b/main/src/addins/GnomePlatform/GnomePlatform.cs
@@ -55,32 +55,43 @@ namespace MonoDevelop.Platform
//apparently Gnome.Icon needs GnomeVFS initialized even when we're using GIO.
Gnome.Vfs.Vfs.Initialize ();
}
-
-
- public override DesktopApplication GetDefaultApplication (string mimeType)
+
+ DesktopApplication GetGnomeVfsDefaultApplication (string mimeType)
{
- if (useGio)
- return Gio.GetDefaultForType (mimeType);
-
var app = Gnome.Vfs.Mime.GetDefaultApplication (mimeType);
if (app != null)
return (DesktopApplication) Marshal.PtrToStructure (app.Handle, typeof(DesktopApplication));
else
- return new DesktopApplication ();
+ return null;
}
- public override DesktopApplication [] GetAllApplications (string mimeType)
+ IEnumerable<DesktopApplication> GetGnomeVfsApplications ()
{
- if (useGio)
- return Gio.GetAllForType (mimeType);
-
+ var def = GetGnomeVfsDefaultApplication (mimeType);
var list = new List<DesktopApplication> ();
var apps = Gnome.Vfs.Mime.GetAllApplications (mimeType);
foreach (var app in apps) {
- var dap = (DesktopApplication) Marshal.PtrToStructure (app.Handle, typeof(DesktopApplication));
- list.Add (dap);
+ var dap = (GnomeVfsApp) Marshal.PtrToStructure (app.Handle, typeof(GnomeVfsApp));
+ if (!string.IsNullOrEmpty (dap.Command) && !string.IsNullOrEmpty (dap.DisplayName) && !dap.Command.Contains ("monodevelop ")) {
+ var isDefault = def != null && def.Id == dap.Command;
+ list.Add (new GnomeDesktopApplication (dap.Command, dap.DisplayName, isDefault));
+ }
}
- return list.ToArray ();
+ return list;
+ }
+
+ public override IEnumerable<DesktopApplication> GetApplications (string filename)
+ {
+ var mimeType = DesktopService.GetMimeTypeForUri (fileName);
+
+ if (useGio)
+ return Gio.GetAllForType (mimeType);
+ else
+ return GetGnomeVfsApplications (mimeType);
+ }
+
+ struct GnomeVfsApp {
+ public string Id, DisplayName, Command;
}
protected override string OnGetMimeTypeDescription (string mt)
@@ -333,4 +344,38 @@ namespace MonoDevelop.Platform
Runtime.ProcessService.StartProcess (TerminalCommand, "", directory, null);
}
}
+
+ class GnomeDesktopApplication : DesktopApplication
+ {
+ public GnomeDesktopApplication (string command, string displayName) : base (command, displayName)
+ {
+ }
+
+ string Command {
+ get { return Id; }
+ }
+
+ public abstract void Launch (params string[] files)
+ {
+ // TODO: implement all other cases
+ if (Command.IndexOf ("%f") != -1) {
+ foreach (string s in files) {
+ string cmd = Command.Replace ("%f", "\"" + s + "\"");
+ Process.Start (cmd);
+ }
+ }
+ else if (Command.IndexOf ("%F") != -1) {
+ string[] fs = new string [files.Length];
+ for (int n=0; n<files.Length; n++) {
+ fs [n] = "\"" + files [n] + "\"";
+ }
+ string cmd = Command.Replace ("%F", string.Join (" ", fs));
+ Process.Start (cmd);
+ } else {
+ foreach (string s in files) {
+ Process.Start (Command, "\"" + s + "\"");
+ }
+ }
+ }
+ }
}