Example #1
0
        public CollectionInlineEditorControl(IHostResourceProvider hostResources)
            : base(hostResources)
        {
            this.label = new UnfocusableTextField {
                TranslatesAutoresizingMaskIntoConstraints = false,
                StringValue = Properties.Resources.CollectionValue,
            };

            AddSubview(this.label);

            this.openCollection = new FocusableButton {
                Title                = Properties.Resources.CollectionEditButton,
                BezelStyle           = NSBezelStyle.Rounded,
                AccessibilityEnabled = true,
                AccessibilityHelp    = Properties.Resources.AccessibilityCollectionHelp
            };

            this.openCollection.Activated += (o, e) => {
                CollectionEditorWindow.EditCollection(EffectiveAppearance, HostResources, ViewModel);
            };

            AddSubview(this.openCollection);

            AddConstraints(new[] {
                NSLayoutConstraint.Create(this.label, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this, NSLayoutAttribute.Leading, 1, 0),
                NSLayoutConstraint.Create(this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
                NSLayoutConstraint.Create(this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, 0),
                NSLayoutConstraint.Create(this.openCollection, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Trailing, 1, 12),
                NSLayoutConstraint.Create(this.openCollection, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
                NSLayoutConstraint.Create(this.openCollection, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1, 70),
                NSLayoutConstraint.Create(this.openCollection, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6)
            });

            ViewDidChangeEffectiveAppearance();
        }
        public static void EditCollection(NSAppearance appearance, IHostResourceProvider hostResources, CollectionPropertyViewModel collectionVm)
        {
            var w = new CollectionEditorWindow(hostResources, collectionVm)
            {
                Appearance = appearance
            };

            var result = (NSModalResponse)(int)NSApplication.SharedApplication.RunModalForWindow(w);

            if (result != NSModalResponse.OK)
            {
                collectionVm.CancelCommand.Execute(null);
                return;
            }

            collectionVm.CommitCommand.Execute(null);
        }
Example #3
0
        public CollectionInlineEditorControl(IHostResourceProvider hostResources)
            : base(hostResources)
        {
            this.label = new UnfocusableTextField {
                TranslatesAutoresizingMaskIntoConstraints = false,
                StringValue = Properties.Resources.CollectionValue,
            };

            AddSubview(this.label);

            this.openCollection = new FocusableButton {
                Title                = Properties.Resources.CollectionEditButton,
                BezelStyle           = NSBezelStyle.Rounded,
                AccessibilityEnabled = true,
                ProxyResponder       = new ProxyResponder(this, ProxyRowType.SingleView),
                AccessibilityHelp    = Properties.Resources.AccessibilityCollectionHelp
            };

            this.openCollection.Activated += (o, e) => {
                var parentWindow = Window;

                var w = new CollectionEditorWindow(hostResources, ViewModel)
                {
                    Appearance = EffectiveAppearance
                };

                var result = (NSModalResponse)(int)NSApplication.SharedApplication.RunModalForWindow(w);

                //after run modal our FocusedWindow is null, we set the parent again
                parentWindow?.MakeKeyAndOrderFront(parentWindow);

                if (result != NSModalResponse.OK)
                {
                    ViewModel.CancelCommand.Execute(null);
                }
                else
                {
                    ViewModel.CommitCommand.Execute(null);
                }

                //small hack to override vs4mac default focus
                System.Threading.Tasks.Task.Delay(DefaultDelayTime)
                .ContinueWith(t => {
                    parentWindow?.MakeFirstResponder(openCollection);
                }, TaskScheduler.FromCurrentSynchronizationContext());
            };

            AddSubview(this.openCollection);

            AddConstraints(new[] {
                NSLayoutConstraint.Create(this.label, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0),
                NSLayoutConstraint.Create(this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
                NSLayoutConstraint.Create(this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, 0),
                NSLayoutConstraint.Create(this.label, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.openCollection, NSLayoutAttribute.Left, 1, -4),

                NSLayoutConstraint.Create(this.openCollection, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
                NSLayoutConstraint.Create(this.openCollection, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
                NSLayoutConstraint.Create(this.openCollection, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, DefaultButtonWidth),
            });

            AppearanceChanged();
        }