コード例 #1
0
        public static Task <IDocument> Open(AbsoluteFilePath path, bool giveFocus = false)
        {
            var tcs = new TaskCompletionSource <IDocument>();

            Fusion.Application.MainThread.Schedule(() =>
            {
                if (giveFocus)
                {
                    NSRunningApplication.CurrentApplication.Activate(NSApplicationActivationOptions.ActivateAllWindows | NSApplicationActivationOptions.ActivateIgnoringOtherWindows);
                }

                var controller = (NSDocumentController)NSDocumentController.SharedDocumentController;
                controller.OpenDocument(path.ToNSUrl(), giveFocus,
                                        (document, wasAlreadyOpen, error) =>
                {
                    if (error != null)
                    {
                        tcs.TrySetException(new Exception(error.Description));
                    }
                    else
                    {
                        tcs.TrySetResult((ObservableNSDocument)document);
                    }
                });
            });

            return(tcs.Task);
        }