瀏覽代碼

working dialog callbacks

Dan Walmsley 7 年之前
父節點
當前提交
9cb9c1fef1

+ 4 - 0
src/Avalonia.Native.OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj

@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		37C09D8821580FE4006A6758 /* SystemDialogs.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C09D8721580FE4006A6758 /* SystemDialogs.mm */; };
 		AB00E4F72147CA920032A60A /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB00E4F62147CA920032A60A /* main.mm */; };
 		AB661C1E2148230F00291242 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB661C1D2148230F00291242 /* AppKit.framework */; };
 		AB661C202148286E00291242 /* window.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB661C1F2148286E00291242 /* window.mm */; };
@@ -15,6 +16,7 @@
 
 /* Begin PBXFileReference section */
 		379A4506214D0F6500CC143D /* headers */ = {isa = PBXFileReference; lastKnownFileType = folder; name = headers; path = ../headers; sourceTree = "<group>"; };
+		37C09D8721580FE4006A6758 /* SystemDialogs.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemDialogs.mm; sourceTree = "<group>"; };
 		AB00E4F62147CA920032A60A /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = "<group>"; };
 		AB661C1D2148230F00291242 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
 		AB661C1F2148286E00291242 /* window.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = window.mm; sourceTree = "<group>"; };
@@ -51,6 +53,7 @@
 				AB661C212148288600291242 /* common.h */,
 				AB661C1F2148286E00291242 /* window.mm */,
 				AB00E4F62147CA920032A60A /* main.mm */,
+				37C09D8721580FE4006A6758 /* SystemDialogs.mm */,
 				AB7A61F02147C815003C5833 /* Products */,
 				AB661C1C2148230E00291242 /* Frameworks */,
 			);
@@ -133,6 +136,7 @@
 			files = (
 				AB8F7D6B21482D7F0057DBA5 /* platformthreading.mm in Sources */,
 				AB00E4F72147CA920032A60A /* main.mm in Sources */,
+				37C09D8821580FE4006A6758 /* SystemDialogs.mm in Sources */,
 				AB661C202148286E00291242 /* window.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 36 - 0
src/Avalonia.Native.OSX/SystemDialogs.mm

@@ -0,0 +1,36 @@
+#include "common.h"
+
+class SystemDialogs : public ComSingleObject<IAvnSystemDialogs, &IID_IAvnSystemDialogs>
+{
+    virtual void SelectFolderDialog (IAvnSystemDialogEvents* events,
+                                     const char* title,
+                                     const char* initialPath)
+    {
+        
+    }
+    
+    virtual void OpenFileDialog (IAvnSystemDialogEvents* events,
+                                 bool allowMultiple,
+                                 const char* title,
+                                 const char* initialDirectory,
+                                 const char* intialFile,
+                                 const char* filters)
+    {
+        events->OnCompleted(0, nullptr);
+    }
+    
+    virtual void SaveFileDialog (IAvnSystemDialogEvents* events,
+                                 const char* title,
+                                 const char* initialDirectory,
+                                 const char* intialFile,
+                                 const char* filters)
+    {
+        
+    }
+
+};
+
+extern IAvnSystemDialogs* CreateSystemDialogs()
+{
+    return new SystemDialogs();
+}

+ 1 - 0
src/Avalonia.Native.OSX/common.h

@@ -10,6 +10,7 @@
 extern IAvnPlatformThreadingInterface* CreatePlatformThreading();
 extern IAvnWindow* CreateAvnWindow(IAvnWindowEvents*events);
 extern IAvnPopup* CreateAvnPopup(IAvnWindowEvents*events);
+extern IAvnSystemDialogs* CreateSystemDialogs();
 
 extern NSPoint ToNSPoint (AvnPoint p);
 extern AvnPoint ToAvnPoint (NSPoint p);

+ 6 - 0
src/Avalonia.Native.OSX/main.mm

@@ -94,6 +94,12 @@ public:
         *ppv = CreatePlatformThreading();
         return S_OK;
     }
+    
+    virtual HRESULT CreateSystemDialogs(IAvnSystemDialogs** ppv)
+    {
+        *ppv = ::CreateSystemDialogs();
+        return  S_OK;
+    }
 };
 
 extern "C" IAvaloniaNativeFactory* CreateAvaloniaNative()

+ 24 - 22
src/Avalonia.Native/SystemDialogs.cs

@@ -20,35 +20,37 @@ namespace Avalonia.Native
 
         public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
         {
-            var events = new SystemDialogEvents();
-
-            if(dialog is OpenFileDialog ofd)
-            {
-                _native.OpenFileDialog(events, ofd.AllowMultiple,
-                                        ofd.Title,
-                                        ofd.InitialDirectory,
-                                        ofd.InitialFileName,
-                                        string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
-            }
-            else
+            using (var events = new SystemDialogEvents())
             {
-                _native.SaveFileDialog(events,
-                                        dialog.Title,
-                                        dialog.InitialDirectory,
-                                        dialog.InitialFileName,
-                                        string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
-            }
+                if (dialog is OpenFileDialog ofd)
+                {
+                    _native.OpenFileDialog(events, ofd.AllowMultiple,
+                                            ofd.Title,
+                                            ofd.InitialDirectory,
+                                            ofd.InitialFileName,
+                                            string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
+                }
+                else
+                {
+                    _native.SaveFileDialog(events,
+                                            dialog.Title,
+                                            dialog.InitialDirectory,
+                                            dialog.InitialFileName,
+                                            string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
+                }
 
-            return events.Task;
+                return events.Task;
+            }
         }
 
         public async Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
         {
-            var events = new SystemDialogEvents();
-
-            _native.SelectFolderDialog(events, dialog.Title, dialog.InitialDirectory);
+            using (var events = new SystemDialogEvents())
+            {
+                _native.SelectFolderDialog(events, dialog.Title, dialog.InitialDirectory);
 
-            return (await events.Task).FirstOrDefault();
+                return (await events.Task).FirstOrDefault();
+            }
         }
     }