Exemplo n.º 1
0
        // Called when the user quits
        public override void WillTerminate(NSNotification notification)
        {
            // Teardown resources
            statusItem.Visible = false;
            statusItem.Dispose();

            statusMenu.Dispose();

            if (popover.Shown)
            {
                popover.Close();
            }
            popover.Dispose();

            Application.Current.Quit();
        }
        public static Task <ITypeInfo> RequestAt(this TypeRequestedEventArgs self, IHostResourceProvider hostResources, NSView source, AsyncValue <IReadOnlyDictionary <IAssemblyInfo, ILookup <string, ITypeInfo> > > assignableTypes)
        {
            var tcs = new TaskCompletionSource <ITypeInfo> ();

            var vm       = new TypeSelectorViewModel(assignableTypes);
            var selector = new TypeSelectorControl {
                ViewModel  = vm,
                Appearance = source.EffectiveAppearance
            };

            vm.PropertyChanged += (vms, ve) => {
                if (ve.PropertyName == nameof(TypeSelectorViewModel.SelectedType))
                {
                    tcs.TrySetResult(vm.SelectedType);
                }
            };

            var popover = new NSPopover {
                Behavior = NSPopoverBehavior.Transient,
                Delegate = new PopoverDelegate <ITypeInfo> (tcs),
                ContentViewController = new NSViewController {
                    View = selector,
                    PreferredContentSize = new CoreGraphics.CGSize(360, 335)
                },
            };

            popover.SetAppearance(hostResources.GetVibrantAppearance(source.EffectiveAppearance));

            tcs.Task.ContinueWith(t => {
                popover.PerformClose(popover);
                popover.Dispose();
            }, TaskScheduler.FromCurrentSynchronizationContext());

            popover.Show(source.Frame, source.Superview, NSRectEdge.MinYEdge);
            return(tcs.Task);
        }