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
path: root/main/src
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo.moya@xamarin.com>2019-07-18 14:41:28 +0300
committerRodrigo Moya <rodrigo.moya@xamarin.com>2019-07-25 12:31:12 +0300
commit4740ce100bad0328d90bdbae638a61d34816e292 (patch)
tree4ed6c7e201d167ceda0cd92e3c050c1bebf83efc /main/src
parentc6af3e627a728356c3ae44d2c35806862feaf583 (diff)
[MacPlatform] Fix retrieval of installed applications
Also, remove some old CoreFoundation bindings which are not needed anymore, as same code is available in Xamarin.Mac already.
Diffstat (limited to 'main/src')
-rw-r--r--main/src/addins/MacPlatform/MacInterop/CoreFoundation.cs70
-rw-r--r--main/src/addins/MacPlatform/MacPlatform.cs26
2 files changed, 15 insertions, 81 deletions
diff --git a/main/src/addins/MacPlatform/MacInterop/CoreFoundation.cs b/main/src/addins/MacPlatform/MacInterop/CoreFoundation.cs
index e2d4ab8949..8fbdcd6814 100644
--- a/main/src/addins/MacPlatform/MacInterop/CoreFoundation.cs
+++ b/main/src/addins/MacPlatform/MacInterop/CoreFoundation.cs
@@ -150,75 +150,5 @@ namespace MonoDevelop.MacInterop
Shell = 0x00000008,
All = 0xFFFFFFFF
}
-
- public static IntPtr CreatePathUrl (string path)
- {
- IntPtr str = IntPtr.Zero;
- IntPtr url = IntPtr.Zero;
- try {
- str = CreateString (path);
- if (str == IntPtr.Zero)
- throw new Exception ("CreateString failed");
- url = CFURLCreateWithFileSystemPath (IntPtr.Zero, str, CFUrlPathStyle.Posix, false);
- if (url == IntPtr.Zero)
- throw new Exception ("CFURLCreateWithFileSystemPath failed");
- return url;
- } finally {
- if (str != IntPtr.Zero)
- Release (str);
- }
- }
-
- public static string UrlToPath (IntPtr url)
- {
- IntPtr str = IntPtr.Zero;
- try {
- str = CFURLCopyFileSystemPath (url, CFUrlPathStyle.Posix);
- return str == IntPtr.Zero? null : FetchString (str);
- } finally {
- if (str != IntPtr.Zero)
- Release (str);
- }
- }
-
- public static string GetApplicationUrl (string filePath, LSRolesMask roles)
- {
- IntPtr url = IntPtr.Zero;
- try {
- url = CreatePathUrl (filePath);
- IntPtr appUrl = IntPtr.Zero;
- if (LSGetApplicationForURL (url, roles, IntPtr.Zero, ref appUrl) == 0 && appUrl != IntPtr.Zero)
- return UrlToPath (appUrl);
- return null;
- } finally {
- if (url != IntPtr.Zero)
- Release (url);
- }
- }
-
- public static string[] GetApplicationUrls (string filePath, LSRolesMask roles)
- {
- IntPtr url = IntPtr.Zero;
- IntPtr arr = IntPtr.Zero;
- try {
- url = CreatePathUrl (filePath);
- arr = LSCopyApplicationURLsForURL (url, roles);
- if (arr == IntPtr.Zero)
- return new string[0];
- int count = CFArrayGetCount (arr);
- string[] values = new string [count];
- for (int i = 0; i < values.Length; i++ ) {
- var u = CFArrayGetValueAtIndex (arr, i);
- if (u != IntPtr.Zero)
- values[i] = UrlToPath (u);
- }
- return values;
- } finally {
- if (url != IntPtr.Zero)
- Release (url);
- if (arr != IntPtr.Zero)
- Release (arr);
- }
- }
}
}
diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs
index 49cadaa103..aa7eea5109 100644
--- a/main/src/addins/MacPlatform/MacPlatform.cs
+++ b/main/src/addins/MacPlatform/MacPlatform.cs
@@ -980,18 +980,19 @@ namespace MonoDevelop.MacIntegration
checkUniqueName.Add ("MonoDevelop");
checkUniqueName.Add (BrandingService.ApplicationName);
- string def = MonoDevelop.MacInterop.CoreFoundation.GetApplicationUrl (filename,
- MonoDevelop.MacInterop.CoreFoundation.LSRolesMask.All);
+ var def = global::CoreServices.LaunchServices.GetDefaultApplicationUrlForUrl (NSUrl.FromString (filename));
var apps = new List<DesktopApplication> ();
- foreach (var app in MonoDevelop.MacInterop.CoreFoundation.GetApplicationUrls (filename,
- MonoDevelop.MacInterop.CoreFoundation.LSRolesMask.All)) {
- if (string.IsNullOrEmpty (app) || !checkUniquePath.Add (app))
- continue;
- var name = NSFileManager.DefaultManager.DisplayName (app);
- if (checkUniqueName.Add (name))
- apps.Add (new MacDesktopApplication (app, name, def != null && def == app));
+ var retrievedApps = global::CoreServices.LaunchServices.GetApplicationUrlsForUrl (NSUrl.FromString (filename), global::CoreServices.LSRoles.All);
+ if (retrievedApps != null) {
+ foreach (var app in retrievedApps) {
+ if (string.IsNullOrEmpty (app.Path) || !checkUniquePath.Add (app.Path))
+ continue;
+ if (checkUniqueName.Add (app.LastPathComponent)) {
+ apps.Add (new MacDesktopApplication (app.Path, app.LastPathComponent, def != null && def == app));
+ }
+ }
}
apps.Sort ((DesktopApplication a, DesktopApplication b) => {
@@ -1012,8 +1013,11 @@ namespace MonoDevelop.MacIntegration
public override void Launch (params string[] files)
{
- foreach (var file in files)
- NSWorkspace.SharedWorkspace.OpenFile (file, Id);
+ NSWorkspace.SharedWorkspace.OpenUrls (
+ files.Select (NSUrl.FromString).ToArray (),
+ NSBundle.FromPath (Id).BundleIdentifier,
+ NSWorkspaceLaunchOptions.Default,
+ NSAppleEventDescriptor.DescriptorWithBoolean (true));
}
}