From 820c53ae01fa95075fd3990f56a81a30e38e8312 Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Thu, 10 Jan 2019 10:08:49 +0000 Subject: [Mac] Initial Binding Editor Dialog. --- .../Controls/Custom/BasePanelWindow.cs | 301 +++++++++++++++++++++ .../Controls/Custom/PropertyButton.cs | 23 +- 2 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 Xamarin.PropertyEditing.Mac/Controls/Custom/BasePanelWindow.cs (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom') diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePanelWindow.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePanelWindow.cs new file mode 100644 index 0000000..d22ea4b --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePanelWindow.cs @@ -0,0 +1,301 @@ +using System; +using System.Linq; +using AppKit; +using CoreGraphics; +using Foundation; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class BasePanelWindow : NSPanel + { + protected NSButton ButtonDone; + private NSButton buttonCancel; + private NSButton buttonHelp; + + protected NSPopUpButton BindingTypePopup; + + protected NSPopUpButton ValueConverterPopup; + + protected NSButton AddConverterButton; + + protected NSView AncestorTypeBox; + protected NSView PathBox; + + protected NSView MainContainer; + protected NSView BindingPropertiesView; + protected NSView FlagsPropertiesView; + protected NSButton ButtonMoreSettings; + + protected nfloat MoreSettingsViewHeight { get; set; } + + internal BasePanelWindow () + : base (new CGRect (0, 0, 728, 445), NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, true) + { + FloatingPanel = true; + + MaxSize = new CGSize (960, 720); // TODO discuss what the Max/Min Size should be and if we should have one. + MinSize = new CGSize (320, 240); + + this.MainContainer = new NSView { + TranslatesAutoresizingMaskIntoConstraints = false + }; + + this.ButtonDone = new NSButton { + BezelStyle = NSBezelStyle.Rounded, + KeyEquivalent = "\r", // Fire when enter pressed + Highlighted = true, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.MainContainer.AddSubview (this.ButtonDone); + + this.buttonCancel = new NSButton { + BezelStyle = NSBezelStyle.Rounded, + KeyEquivalent = "0x1b", // TODO Need to double check this is right + Title = Properties.Resources.Cancel, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.buttonCancel.Activated += (sender, e) => { + Close (); + }; + + this.MainContainer.AddSubview (this.buttonCancel); + + this.buttonHelp = new NSButton { + BezelStyle = NSBezelStyle.HelpButton, + Title = string.Empty, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.MainContainer.AddSubview (this.buttonHelp); + + var bindingTypeLabel = new UnfocusableTextField { + TranslatesAutoresizingMaskIntoConstraints = false, + Alignment = NSTextAlignment.Right, + }; + + bindingTypeLabel.StringValue = Properties.Resources.BindingType; + this.MainContainer.AddSubview (bindingTypeLabel); + + this.BindingTypePopup = new FocusablePopUpButton { + TranslatesAutoresizingMaskIntoConstraints = false, + StringValue = String.Empty, + ControlSize = NSControlSize.Small, + Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize), + }; + + var bindingTypeMenuList = new NSMenu (); + this.BindingTypePopup.Menu = bindingTypeMenuList; + this.MainContainer.AddSubview (this.BindingTypePopup); + + var valueConverterLabel = new UnfocusableTextField { + TranslatesAutoresizingMaskIntoConstraints = false, + Alignment = NSTextAlignment.Right, + }; + + this.AncestorTypeBox = new NSView { + TranslatesAutoresizingMaskIntoConstraints = false, + WantsLayer = true, + + // Layer out of alphabetical order so that WantsLayer creates the layer first + Layer = { + CornerRadius = 1.0f, + BorderColor = new CGColor (.5f, .5f, .5f, .5f), + BorderWidth = 1, + }, + }; + + this.MainContainer.AddSubview (this.AncestorTypeBox); + + this.PathBox = new NSView { + TranslatesAutoresizingMaskIntoConstraints = false, + WantsLayer = true, + + // Layer out of alphabetical order so that WantsLayer creates the layer first + Layer = { + CornerRadius = 1.0f, + BorderColor = new CGColor (.5f, .5f, .5f, .5f), + BorderWidth = 1, + }, + }; + + this.MainContainer.AddSubview (this.PathBox); + + valueConverterLabel.StringValue = Properties.Resources.Converter; + this.MainContainer.AddSubview (valueConverterLabel); + + this.ValueConverterPopup = new FocusablePopUpButton { + TranslatesAutoresizingMaskIntoConstraints = false, + StringValue = String.Empty, + ControlSize = NSControlSize.Small, + Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize), + }; + + var valueConverterMenuList = new NSMenu (); + this.ValueConverterPopup.Menu = valueConverterMenuList; + this.MainContainer.AddSubview (this.ValueConverterPopup); + + this.AddConverterButton = new NSButton { + BezelStyle = NSBezelStyle.Rounded, + Image = NSImage.ImageNamed (NSImageName.AddTemplate), + Title = string.Empty, + ToolTip = Properties.Resources.AddValueConverterEllipsis, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.MainContainer.AddSubview (this.AddConverterButton); + + this.ButtonMoreSettings = new NSButton { + BezelStyle = NSBezelStyle.Disclosure, + Title = string.Empty, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + this.ButtonMoreSettings.SetButtonType (NSButtonType.PushOnPushOff); + + this.MainContainer.AddSubview (this.ButtonMoreSettings); + + var labelOtherSettings = new UnfocusableTextField { + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.MainContainer.AddSubview (labelOtherSettings); + + this.BindingPropertiesView = new NSView { + Hidden = true, + TranslatesAutoresizingMaskIntoConstraints = false, + WantsLayer = true, + + // Layer out of alphabetical order so that WantsLayer creates the layer first + Layer = { + CornerRadius = 1.0f, + BorderColor = new CGColor (.5f, .5f, .5f, .5f), + BorderWidth = 1, + }, + }; + + this.MainContainer.AddSubview (this.BindingPropertiesView); + + this.FlagsPropertiesView = new NSView { + Hidden = true, + TranslatesAutoresizingMaskIntoConstraints = false, + WantsLayer = true, + + // Layer out of alphabetical order so that WantsLayer creates the layer first + Layer = { + CornerRadius = 1.0f, + BorderColor = new CGColor (.5f, .5f, .5f, .5f), + BorderWidth = 1, + }, + }; + + this.MainContainer.AddSubview (this.FlagsPropertiesView); + + //Work out the titlebar height + var titleBarHeight = Frame.Size.Height - ContentRectFor (Frame).Size.Height; + + var ancestorTypeBoxHeightConstraint = NSLayoutConstraint.Create (this.AncestorTypeBox, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Bottom, 1f, -100f); + var heightConstant = ancestorTypeBoxHeightConstraint.Constant; + + var bindingPropertiesViewHeightConstraint = NSLayoutConstraint.Create (this.BindingPropertiesView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 124); + + this.ButtonMoreSettings.Activated += (sender, e) => { + if (sender is NSButton moreButton) { + ToggleSettingsLabel (moreButton.State == NSCellStateValue.Off, labelOtherSettings); + + this.BindingPropertiesView.Hidden = moreButton.State == NSCellStateValue.Off; + this.FlagsPropertiesView.Hidden = this.BindingPropertiesView.Hidden; + + bindingPropertiesViewHeightConstraint.Constant = this.MoreSettingsViewHeight; + ancestorTypeBoxHeightConstraint.Constant = this.BindingPropertiesView.Hidden ? heightConstant : heightConstant - (MoreSettingsViewHeight + 20); + this.MainContainer.SetFrameSize (new CGSize (this.MainContainer.Frame.Width, this.BindingPropertiesView.Hidden ? this.MainContainer.Frame.Height - MoreSettingsViewHeight : this.MainContainer.Frame.Height + MoreSettingsViewHeight)); + SetFrame (new CGRect (new CGPoint (Frame.X, Frame.Y), new CGSize (Frame.Width, this.MainContainer.Frame.Height + titleBarHeight)), false, true); + } + }; + + ToggleSettingsLabel (this.ButtonMoreSettings.State == NSCellStateValue.Off, labelOtherSettings); + + this.MainContainer.AddConstraints (new[] { + NSLayoutConstraint.Create (bindingTypeLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Top, 1f, 10f), + NSLayoutConstraint.Create (bindingTypeLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20f), + NSLayoutConstraint.Create (bindingTypeLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + + NSLayoutConstraint.Create (this.BindingTypePopup, NSLayoutAttribute.Top, NSLayoutRelation.Equal, bindingTypeLabel, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.BindingTypePopup, NSLayoutAttribute.Left, NSLayoutRelation.Equal, bindingTypeLabel, NSLayoutAttribute.Right, 1f, 5f), + NSLayoutConstraint.Create (this.BindingTypePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + + NSLayoutConstraint.Create (this.AncestorTypeBox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.BindingTypePopup, NSLayoutAttribute.Bottom, 1f, 10f), + NSLayoutConstraint.Create (this.AncestorTypeBox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20f), + NSLayoutConstraint.Create (this.AncestorTypeBox, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.PathBox, NSLayoutAttribute.Left, 1f, -10f), + ancestorTypeBoxHeightConstraint, + + NSLayoutConstraint.Create (this.PathBox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.AncestorTypeBox, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.PathBox, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Right, 1f, -20f), + NSLayoutConstraint.Create (this.PathBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this.AncestorTypeBox, NSLayoutAttribute.Width, 1f, 0f), + NSLayoutConstraint.Create (this.PathBox, NSLayoutAttribute.Height, NSLayoutRelation.Equal,this.AncestorTypeBox, NSLayoutAttribute.Height, 1f, 0f), + + NSLayoutConstraint.Create (valueConverterLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.AncestorTypeBox, NSLayoutAttribute.Bottom, 1f, 10f), + NSLayoutConstraint.Create (valueConverterLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20f), + NSLayoutConstraint.Create (valueConverterLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + + NSLayoutConstraint.Create (this.ValueConverterPopup, NSLayoutAttribute.Top, NSLayoutRelation.Equal, valueConverterLabel, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.ValueConverterPopup, NSLayoutAttribute.Left, NSLayoutRelation.Equal, valueConverterLabel, NSLayoutAttribute.Right, 1f, 5f), + NSLayoutConstraint.Create (this.ValueConverterPopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + + NSLayoutConstraint.Create (this.AddConverterButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ValueConverterPopup, NSLayoutAttribute.Top, 1f, 2f), + NSLayoutConstraint.Create (this.AddConverterButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal,this.ValueConverterPopup, NSLayoutAttribute.Right, 1f, 5f), + NSLayoutConstraint.Create (this.AddConverterButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 20), + NSLayoutConstraint.Create (this.AddConverterButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 20), + + NSLayoutConstraint.Create (this.ButtonMoreSettings, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ValueConverterPopup, NSLayoutAttribute.Bottom, 1f, 2f), + NSLayoutConstraint.Create (this.ButtonMoreSettings, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 16f), + NSLayoutConstraint.Create (this.ButtonMoreSettings, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 24), + NSLayoutConstraint.Create (this.ButtonMoreSettings, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 24), + + NSLayoutConstraint.Create (labelOtherSettings, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ButtonMoreSettings, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (labelOtherSettings, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.ButtonMoreSettings, NSLayoutAttribute.Right, 1f, -5f), + NSLayoutConstraint.Create (labelOtherSettings, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + + NSLayoutConstraint.Create (this.BindingPropertiesView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ButtonMoreSettings, NSLayoutAttribute.Bottom, 1f, 10f), + NSLayoutConstraint.Create (this.BindingPropertiesView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20f), + NSLayoutConstraint.Create (this.BindingPropertiesView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.FlagsPropertiesView, NSLayoutAttribute.Left, 1f, -10f), + bindingPropertiesViewHeightConstraint, + + NSLayoutConstraint.Create (this.FlagsPropertiesView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.BindingPropertiesView, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.FlagsPropertiesView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Right, 1f, -20f), + NSLayoutConstraint.Create (this.FlagsPropertiesView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this.BindingPropertiesView, NSLayoutAttribute.Width, 1f, 0f), + NSLayoutConstraint.Create (this.FlagsPropertiesView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this.BindingPropertiesView, NSLayoutAttribute.Height, 1f, 0f), + + NSLayoutConstraint.Create (this.buttonHelp, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Bottom, 1f, -40f), + NSLayoutConstraint.Create (this.buttonHelp, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20), + NSLayoutConstraint.Create (this.buttonHelp, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + NSLayoutConstraint.Create (this.buttonHelp, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 24), + + NSLayoutConstraint.Create (this.ButtonDone, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Bottom, 1f, -40f), + NSLayoutConstraint.Create (this.ButtonDone, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Right, 1f, -20f), + NSLayoutConstraint.Create (this.ButtonDone, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + + NSLayoutConstraint.Create (this.buttonCancel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ButtonDone, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.buttonCancel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.ButtonDone, NSLayoutAttribute.Left, 1f, -10f), + NSLayoutConstraint.Create (this.buttonCancel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + }); + + // put the MainContainer inside this panel's ContentView + ContentView.AddSubview (this.MainContainer); + + ContentView.AddConstraints (new[] { + NSLayoutConstraint.Create (this.MainContainer, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.MainContainer, NSLayoutAttribute.Left, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Left, 1f, 0f), + NSLayoutConstraint.Create (this.MainContainer, NSLayoutAttribute.Height, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Height, 1f, 0f), + NSLayoutConstraint.Create (this.MainContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Width, 1f, 0f), + + }); + } + + private static void ToggleSettingsLabel (bool show, UnfocusableTextField labelOtherSettings) + { + labelOtherSettings.StringValue = show ? Properties.Resources.ShowSettings : Properties.Resources.HideSettings; + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs index 3e3347a..2533d97 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs @@ -107,10 +107,25 @@ namespace Xamarin.PropertyEditing.Mac this.popUpContextMenu.AddItem (mi2); } + if (this.viewModel.SupportsBindings) { + this.popUpContextMenu.AddItem (NSMenuItem.SeparatorItem); + + var mi3 = new NSMenuItem (Properties.Resources.CreateDataBindingMenuItem) { + AttributedTitle = new Foundation.NSAttributedString ( + Properties.Resources.CreateDataBindingMenuItem, + new CoreText.CTStringAttributes { + Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1), + }) + }; + + mi3.Activated += OnBindingRequested; + this.popUpContextMenu.AddItem (mi3); + } + this.popUpContextMenu.AddItem (NSMenuItem.SeparatorItem); // TODO If we add more menu items consider making the Label/Command a dictionary that we can iterate over to populate everything. - this.popUpContextMenu.AddItem (new CommandMenuItem (Properties.Resources.Reset, viewModel.ClearValueCommand) { + this.popUpContextMenu.AddItem (new CommandMenuItem (Properties.Resources.Reset, this.viewModel.ClearValueCommand) { AttributedTitle = new Foundation.NSAttributedString ( Properties.Resources.Reset, new CoreText.CTStringAttributes { @@ -236,5 +251,11 @@ namespace Xamarin.PropertyEditing.Mac resourceSelectorPopOver.Show (requestResourceView.Frame, (NSView)this, NSRectEdge.MinYEdge); } + + private void OnBindingRequested (object sender, EventArgs e) + { + var bindingEditorWindow = new BindingEditorWindow (this.hostResources, this.viewModel); + bindingEditorWindow.MakeKeyAndOrderFront (this); + } } } -- cgit v1.2.3 From bbe46e57cb1627d26ccc0e68dc9b2ed877b3d170 Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Thu, 21 Mar 2019 13:54:10 +0000 Subject: [Mac] Make Binding Dialog Modal [Mac] Ensure property button view is cleared --- .../Controls/Custom/BasePanelWindow.cs | 301 --------------------- .../Controls/Custom/CommandButton.cs | 5 +- .../Controls/Custom/PropertyButton.cs | 25 +- 3 files changed, 19 insertions(+), 312 deletions(-) delete mode 100644 Xamarin.PropertyEditing.Mac/Controls/Custom/BasePanelWindow.cs (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom') diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePanelWindow.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePanelWindow.cs deleted file mode 100644 index d22ea4b..0000000 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePanelWindow.cs +++ /dev/null @@ -1,301 +0,0 @@ -using System; -using System.Linq; -using AppKit; -using CoreGraphics; -using Foundation; -using Xamarin.PropertyEditing.ViewModels; - -namespace Xamarin.PropertyEditing.Mac -{ - internal class BasePanelWindow : NSPanel - { - protected NSButton ButtonDone; - private NSButton buttonCancel; - private NSButton buttonHelp; - - protected NSPopUpButton BindingTypePopup; - - protected NSPopUpButton ValueConverterPopup; - - protected NSButton AddConverterButton; - - protected NSView AncestorTypeBox; - protected NSView PathBox; - - protected NSView MainContainer; - protected NSView BindingPropertiesView; - protected NSView FlagsPropertiesView; - protected NSButton ButtonMoreSettings; - - protected nfloat MoreSettingsViewHeight { get; set; } - - internal BasePanelWindow () - : base (new CGRect (0, 0, 728, 445), NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, true) - { - FloatingPanel = true; - - MaxSize = new CGSize (960, 720); // TODO discuss what the Max/Min Size should be and if we should have one. - MinSize = new CGSize (320, 240); - - this.MainContainer = new NSView { - TranslatesAutoresizingMaskIntoConstraints = false - }; - - this.ButtonDone = new NSButton { - BezelStyle = NSBezelStyle.Rounded, - KeyEquivalent = "\r", // Fire when enter pressed - Highlighted = true, - TranslatesAutoresizingMaskIntoConstraints = false, - }; - - this.MainContainer.AddSubview (this.ButtonDone); - - this.buttonCancel = new NSButton { - BezelStyle = NSBezelStyle.Rounded, - KeyEquivalent = "0x1b", // TODO Need to double check this is right - Title = Properties.Resources.Cancel, - TranslatesAutoresizingMaskIntoConstraints = false, - }; - - this.buttonCancel.Activated += (sender, e) => { - Close (); - }; - - this.MainContainer.AddSubview (this.buttonCancel); - - this.buttonHelp = new NSButton { - BezelStyle = NSBezelStyle.HelpButton, - Title = string.Empty, - TranslatesAutoresizingMaskIntoConstraints = false, - }; - - this.MainContainer.AddSubview (this.buttonHelp); - - var bindingTypeLabel = new UnfocusableTextField { - TranslatesAutoresizingMaskIntoConstraints = false, - Alignment = NSTextAlignment.Right, - }; - - bindingTypeLabel.StringValue = Properties.Resources.BindingType; - this.MainContainer.AddSubview (bindingTypeLabel); - - this.BindingTypePopup = new FocusablePopUpButton { - TranslatesAutoresizingMaskIntoConstraints = false, - StringValue = String.Empty, - ControlSize = NSControlSize.Small, - Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize), - }; - - var bindingTypeMenuList = new NSMenu (); - this.BindingTypePopup.Menu = bindingTypeMenuList; - this.MainContainer.AddSubview (this.BindingTypePopup); - - var valueConverterLabel = new UnfocusableTextField { - TranslatesAutoresizingMaskIntoConstraints = false, - Alignment = NSTextAlignment.Right, - }; - - this.AncestorTypeBox = new NSView { - TranslatesAutoresizingMaskIntoConstraints = false, - WantsLayer = true, - - // Layer out of alphabetical order so that WantsLayer creates the layer first - Layer = { - CornerRadius = 1.0f, - BorderColor = new CGColor (.5f, .5f, .5f, .5f), - BorderWidth = 1, - }, - }; - - this.MainContainer.AddSubview (this.AncestorTypeBox); - - this.PathBox = new NSView { - TranslatesAutoresizingMaskIntoConstraints = false, - WantsLayer = true, - - // Layer out of alphabetical order so that WantsLayer creates the layer first - Layer = { - CornerRadius = 1.0f, - BorderColor = new CGColor (.5f, .5f, .5f, .5f), - BorderWidth = 1, - }, - }; - - this.MainContainer.AddSubview (this.PathBox); - - valueConverterLabel.StringValue = Properties.Resources.Converter; - this.MainContainer.AddSubview (valueConverterLabel); - - this.ValueConverterPopup = new FocusablePopUpButton { - TranslatesAutoresizingMaskIntoConstraints = false, - StringValue = String.Empty, - ControlSize = NSControlSize.Small, - Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize), - }; - - var valueConverterMenuList = new NSMenu (); - this.ValueConverterPopup.Menu = valueConverterMenuList; - this.MainContainer.AddSubview (this.ValueConverterPopup); - - this.AddConverterButton = new NSButton { - BezelStyle = NSBezelStyle.Rounded, - Image = NSImage.ImageNamed (NSImageName.AddTemplate), - Title = string.Empty, - ToolTip = Properties.Resources.AddValueConverterEllipsis, - TranslatesAutoresizingMaskIntoConstraints = false, - }; - - this.MainContainer.AddSubview (this.AddConverterButton); - - this.ButtonMoreSettings = new NSButton { - BezelStyle = NSBezelStyle.Disclosure, - Title = string.Empty, - TranslatesAutoresizingMaskIntoConstraints = false, - }; - this.ButtonMoreSettings.SetButtonType (NSButtonType.PushOnPushOff); - - this.MainContainer.AddSubview (this.ButtonMoreSettings); - - var labelOtherSettings = new UnfocusableTextField { - TranslatesAutoresizingMaskIntoConstraints = false, - }; - - this.MainContainer.AddSubview (labelOtherSettings); - - this.BindingPropertiesView = new NSView { - Hidden = true, - TranslatesAutoresizingMaskIntoConstraints = false, - WantsLayer = true, - - // Layer out of alphabetical order so that WantsLayer creates the layer first - Layer = { - CornerRadius = 1.0f, - BorderColor = new CGColor (.5f, .5f, .5f, .5f), - BorderWidth = 1, - }, - }; - - this.MainContainer.AddSubview (this.BindingPropertiesView); - - this.FlagsPropertiesView = new NSView { - Hidden = true, - TranslatesAutoresizingMaskIntoConstraints = false, - WantsLayer = true, - - // Layer out of alphabetical order so that WantsLayer creates the layer first - Layer = { - CornerRadius = 1.0f, - BorderColor = new CGColor (.5f, .5f, .5f, .5f), - BorderWidth = 1, - }, - }; - - this.MainContainer.AddSubview (this.FlagsPropertiesView); - - //Work out the titlebar height - var titleBarHeight = Frame.Size.Height - ContentRectFor (Frame).Size.Height; - - var ancestorTypeBoxHeightConstraint = NSLayoutConstraint.Create (this.AncestorTypeBox, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Bottom, 1f, -100f); - var heightConstant = ancestorTypeBoxHeightConstraint.Constant; - - var bindingPropertiesViewHeightConstraint = NSLayoutConstraint.Create (this.BindingPropertiesView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 124); - - this.ButtonMoreSettings.Activated += (sender, e) => { - if (sender is NSButton moreButton) { - ToggleSettingsLabel (moreButton.State == NSCellStateValue.Off, labelOtherSettings); - - this.BindingPropertiesView.Hidden = moreButton.State == NSCellStateValue.Off; - this.FlagsPropertiesView.Hidden = this.BindingPropertiesView.Hidden; - - bindingPropertiesViewHeightConstraint.Constant = this.MoreSettingsViewHeight; - ancestorTypeBoxHeightConstraint.Constant = this.BindingPropertiesView.Hidden ? heightConstant : heightConstant - (MoreSettingsViewHeight + 20); - this.MainContainer.SetFrameSize (new CGSize (this.MainContainer.Frame.Width, this.BindingPropertiesView.Hidden ? this.MainContainer.Frame.Height - MoreSettingsViewHeight : this.MainContainer.Frame.Height + MoreSettingsViewHeight)); - SetFrame (new CGRect (new CGPoint (Frame.X, Frame.Y), new CGSize (Frame.Width, this.MainContainer.Frame.Height + titleBarHeight)), false, true); - } - }; - - ToggleSettingsLabel (this.ButtonMoreSettings.State == NSCellStateValue.Off, labelOtherSettings); - - this.MainContainer.AddConstraints (new[] { - NSLayoutConstraint.Create (bindingTypeLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Top, 1f, 10f), - NSLayoutConstraint.Create (bindingTypeLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20f), - NSLayoutConstraint.Create (bindingTypeLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), - - NSLayoutConstraint.Create (this.BindingTypePopup, NSLayoutAttribute.Top, NSLayoutRelation.Equal, bindingTypeLabel, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.BindingTypePopup, NSLayoutAttribute.Left, NSLayoutRelation.Equal, bindingTypeLabel, NSLayoutAttribute.Right, 1f, 5f), - NSLayoutConstraint.Create (this.BindingTypePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), - - NSLayoutConstraint.Create (this.AncestorTypeBox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.BindingTypePopup, NSLayoutAttribute.Bottom, 1f, 10f), - NSLayoutConstraint.Create (this.AncestorTypeBox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20f), - NSLayoutConstraint.Create (this.AncestorTypeBox, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.PathBox, NSLayoutAttribute.Left, 1f, -10f), - ancestorTypeBoxHeightConstraint, - - NSLayoutConstraint.Create (this.PathBox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.AncestorTypeBox, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.PathBox, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Right, 1f, -20f), - NSLayoutConstraint.Create (this.PathBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this.AncestorTypeBox, NSLayoutAttribute.Width, 1f, 0f), - NSLayoutConstraint.Create (this.PathBox, NSLayoutAttribute.Height, NSLayoutRelation.Equal,this.AncestorTypeBox, NSLayoutAttribute.Height, 1f, 0f), - - NSLayoutConstraint.Create (valueConverterLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.AncestorTypeBox, NSLayoutAttribute.Bottom, 1f, 10f), - NSLayoutConstraint.Create (valueConverterLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20f), - NSLayoutConstraint.Create (valueConverterLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), - - NSLayoutConstraint.Create (this.ValueConverterPopup, NSLayoutAttribute.Top, NSLayoutRelation.Equal, valueConverterLabel, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.ValueConverterPopup, NSLayoutAttribute.Left, NSLayoutRelation.Equal, valueConverterLabel, NSLayoutAttribute.Right, 1f, 5f), - NSLayoutConstraint.Create (this.ValueConverterPopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), - - NSLayoutConstraint.Create (this.AddConverterButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ValueConverterPopup, NSLayoutAttribute.Top, 1f, 2f), - NSLayoutConstraint.Create (this.AddConverterButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal,this.ValueConverterPopup, NSLayoutAttribute.Right, 1f, 5f), - NSLayoutConstraint.Create (this.AddConverterButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 20), - NSLayoutConstraint.Create (this.AddConverterButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 20), - - NSLayoutConstraint.Create (this.ButtonMoreSettings, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ValueConverterPopup, NSLayoutAttribute.Bottom, 1f, 2f), - NSLayoutConstraint.Create (this.ButtonMoreSettings, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 16f), - NSLayoutConstraint.Create (this.ButtonMoreSettings, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 24), - NSLayoutConstraint.Create (this.ButtonMoreSettings, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 24), - - NSLayoutConstraint.Create (labelOtherSettings, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ButtonMoreSettings, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (labelOtherSettings, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.ButtonMoreSettings, NSLayoutAttribute.Right, 1f, -5f), - NSLayoutConstraint.Create (labelOtherSettings, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), - - NSLayoutConstraint.Create (this.BindingPropertiesView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ButtonMoreSettings, NSLayoutAttribute.Bottom, 1f, 10f), - NSLayoutConstraint.Create (this.BindingPropertiesView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20f), - NSLayoutConstraint.Create (this.BindingPropertiesView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.FlagsPropertiesView, NSLayoutAttribute.Left, 1f, -10f), - bindingPropertiesViewHeightConstraint, - - NSLayoutConstraint.Create (this.FlagsPropertiesView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.BindingPropertiesView, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.FlagsPropertiesView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Right, 1f, -20f), - NSLayoutConstraint.Create (this.FlagsPropertiesView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this.BindingPropertiesView, NSLayoutAttribute.Width, 1f, 0f), - NSLayoutConstraint.Create (this.FlagsPropertiesView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this.BindingPropertiesView, NSLayoutAttribute.Height, 1f, 0f), - - NSLayoutConstraint.Create (this.buttonHelp, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Bottom, 1f, -40f), - NSLayoutConstraint.Create (this.buttonHelp, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Left, 1f, 20), - NSLayoutConstraint.Create (this.buttonHelp, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), - NSLayoutConstraint.Create (this.buttonHelp, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 24), - - NSLayoutConstraint.Create (this.ButtonDone, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Bottom, 1f, -40f), - NSLayoutConstraint.Create (this.ButtonDone, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.MainContainer, NSLayoutAttribute.Right, 1f, -20f), - NSLayoutConstraint.Create (this.ButtonDone, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), - - NSLayoutConstraint.Create (this.buttonCancel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ButtonDone, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.buttonCancel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.ButtonDone, NSLayoutAttribute.Left, 1f, -10f), - NSLayoutConstraint.Create (this.buttonCancel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), - }); - - // put the MainContainer inside this panel's ContentView - ContentView.AddSubview (this.MainContainer); - - ContentView.AddConstraints (new[] { - NSLayoutConstraint.Create (this.MainContainer, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.MainContainer, NSLayoutAttribute.Left, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Left, 1f, 0f), - NSLayoutConstraint.Create (this.MainContainer, NSLayoutAttribute.Height, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Height, 1f, 0f), - NSLayoutConstraint.Create (this.MainContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Width, 1f, 0f), - - }); - } - - private static void ToggleSettingsLabel (bool show, UnfocusableTextField labelOtherSettings) - { - labelOtherSettings.StringValue = show ? Properties.Resources.ShowSettings : Properties.Resources.HideSettings; - } - } -} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs index 4904bd8..4fde65f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs @@ -2,7 +2,7 @@ using System; using System.Windows.Input; using AppKit; -namespace Xamarin.PropertyEditing.Mac.Controls.Custom +namespace Xamarin.PropertyEditing.Mac { internal class CommandButton : NSButton { @@ -11,8 +11,7 @@ namespace Xamarin.PropertyEditing.Mac.Controls.Custom public ICommand Command { get { return this.command; } - set - { + set { if (this.command != null) this.command.CanExecuteChanged -= CanExecuteChanged; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs index 2533d97..5fc2093 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using AppKit; using CoreGraphics; using Xamarin.PropertyEditing.ViewModels; @@ -19,11 +20,16 @@ namespace Xamarin.PropertyEditing.Mac set { if (this.viewModel != null) { this.viewModel.PropertyChanged -= OnPropertyChanged; + if (this.viewModel.SupportsBindings) + this.viewModel.CreateBindingRequested -= OnBindingRequested; } this.viewModel = value; + if (this.viewModel != null) { this.viewModel.PropertyChanged += OnPropertyChanged; + if (this.viewModel.SupportsBindings) + this.viewModel.CreateBindingRequested += OnBindingRequested; ValueSourceChanged (this.viewModel.ValueSource); } } @@ -110,16 +116,13 @@ namespace Xamarin.PropertyEditing.Mac if (this.viewModel.SupportsBindings) { this.popUpContextMenu.AddItem (NSMenuItem.SeparatorItem); - var mi3 = new NSMenuItem (Properties.Resources.CreateDataBindingMenuItem) { + this.popUpContextMenu.AddItem (new CommandMenuItem (Properties.Resources.CreateDataBindingMenuItem, this.viewModel.RequestCreateBindingCommand) { AttributedTitle = new Foundation.NSAttributedString ( Properties.Resources.CreateDataBindingMenuItem, new CoreText.CTStringAttributes { Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1), }) - }; - - mi3.Activated += OnBindingRequested; - this.popUpContextMenu.AddItem (mi3); + }); } this.popUpContextMenu.AddItem (NSMenuItem.SeparatorItem); @@ -252,10 +255,16 @@ namespace Xamarin.PropertyEditing.Mac resourceSelectorPopOver.Show (requestResourceView.Frame, (NSView)this, NSRectEdge.MinYEdge); } - private void OnBindingRequested (object sender, EventArgs e) + private void OnBindingRequested (object sender, CreateBindingRequestedEventArgs e) { - var bindingEditorWindow = new BindingEditorWindow (this.hostResources, this.viewModel); - bindingEditorWindow.MakeKeyAndOrderFront (this); + var bindingEditorWindow = new BindingEditorWindow (this.hostResources, this.viewModel) { + Appearance = EffectiveAppearance, + }; + + var result = (NSModalResponse)(int)NSApplication.SharedApplication.RunModalForWindow (bindingEditorWindow); + if (result == NSModalResponse.OK) { + e.BindingObject = bindingEditorWindow.ViewModel.SelectedObjects.Single (); + } } } } -- cgit v1.2.3