Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Corrado <alexc@xamarin.com>2017-06-09 03:30:09 +0300
committerDominique Louis <savagesoftware@gmail.com>2017-06-15 20:28:00 +0300
commit32aa3e4b9c791c231f23cdf9fe73c7569617e89b (patch)
tree2e85de35e0f2907dcba8f97ca4ed362d69514a8a /Xamarin.PropertyEditing.Mac
parentf5dc980900dfa34fb219bc80bebf17304e0264b5 (diff)
[Mac] Mostly work around tabbing issue
There seems to be an issue with the way the key view loop is calculated with the NSTableView. This patch fixes it 95%, but I can still cause it to break if I scroll the table really quickly and then go back to where I was and attempt to keep tabbing forward/backward. This workaround overrides a private selector, as suggested by: https://forums.developer.apple.com/thread/16528#184148
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs3
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs6
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs3
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/EnumEditorControl.cs3
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs8
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs49
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs3
-rw-r--r--Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs50
-rw-r--r--Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs71
9 files changed, 94 insertions, 102 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs
index ca0cb8a..6a2723d 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs
@@ -49,6 +49,9 @@ namespace Xamarin.PropertyEditing.Mac
internal NSTextField NumericEditor { get; set; }
internal NSStepper Stepper { get; set; }
+ public override NSView FirstKeyView => NumericEditor;
+ public override NSView LastKeyView => NumericEditor;
+
protected NSNumberFormatter Formatter = new NSNumberFormatter ();
NSNumberFormatterStyle numberStyle;
protected NSNumberFormatterStyle NumberStyle {
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs
index 3e6e144..d53d659 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs
@@ -20,6 +20,9 @@ namespace Xamarin.PropertyEditing.Mac
protected NSTextView HeightLabel { get; set; }
protected NSTextField HeightEditor { get; set; }
+ public override NSView FirstKeyView => XEditor;
+ public override NSView LastKeyView => HeightEditor;
+
internal new PropertyViewModel<T> ViewModel {
get { return (PropertyViewModel<T>)base.ViewModel; }
set { base.ViewModel = value; }
@@ -38,6 +41,7 @@ namespace Xamarin.PropertyEditing.Mac
YLabel = new NSTextView {
Editable = false,
+ Selectable = false,
};
YEditor = new NSTextField ();
YEditor.BackgroundColor = NSColor.Clear;
@@ -47,6 +51,7 @@ namespace Xamarin.PropertyEditing.Mac
WidthLabel = new NSTextView {
Editable = false,
+ Selectable = false,
};
WidthEditor = new NSTextField ();
WidthEditor.BackgroundColor = NSColor.Clear;
@@ -56,6 +61,7 @@ namespace Xamarin.PropertyEditing.Mac
HeightLabel = new NSTextView {
Editable = false,
+ Selectable = false,
};
HeightEditor = new NSTextField ();
HeightEditor.BackgroundColor = NSColor.Clear;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs
index 008f71e..a5fe61d 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs
@@ -29,6 +29,9 @@ namespace Xamarin.PropertyEditing.Mac
internal NSButton BooleanEditor { get; set; }
+ public override NSView FirstKeyView => BooleanEditor;
+ public override NSView LastKeyView => BooleanEditor;
+
public string Title {
get { return BooleanEditor.Title; }
set { BooleanEditor.Title = value; }
diff --git a/Xamarin.PropertyEditing.Mac/Controls/EnumEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/EnumEditorControl.cs
index 5dd300f..91ef2d1 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/EnumEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/EnumEditorControl.cs
@@ -14,6 +14,9 @@ namespace Xamarin.PropertyEditing.Mac
{
NSComboBox ComboBoxEditor;
+ public override NSView FirstKeyView => ComboBoxEditor;
+ public override NSView LastKeyView => ComboBoxEditor;
+
EnumPropertyViewModel<T> EnumEditorViewModel => (EnumPropertyViewModel<T>)ViewModel;
public EnumEditorControl ()
diff --git a/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs
index ed25474..c058283 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs
@@ -14,6 +14,9 @@ namespace Xamarin.PropertyEditing.Mac
internal NSTextField XEditor { get; set; }
internal NSTextField YEditor { get; set; }
+ public override NSView FirstKeyView => XEditor;
+ public override NSView LastKeyView => YEditor;
+
internal new PropertyViewModel<CGPoint> ViewModel {
get { return (PropertyViewModel<CGPoint>)base.ViewModel; }
set { base.ViewModel = value; }
@@ -29,8 +32,6 @@ namespace Xamarin.PropertyEditing.Mac
XEditor.Activated += (sender, e) => {
ViewModel.Value = new CGPoint (XEditor.IntValue, YEditor.IntValue);
};
- xLabel.NextResponder = XEditor;
- XEditor.BecomeFirstResponder ();
var yLabel = new UnfocusableTextField (new CGRect (85, -5, 25, 20), "Y:");
@@ -40,8 +41,6 @@ namespace Xamarin.PropertyEditing.Mac
YEditor.Activated += (sender, e) => {
ViewModel.Value = new CGPoint (XEditor.IntValue, YEditor.IntValue);
};
- yLabel.NextResponder = YEditor;
- YEditor.BecomeFirstResponder ();
AddSubview (xLabel);
AddSubview (XEditor);
@@ -98,6 +97,7 @@ namespace Xamarin.PropertyEditing.Mac
{
Value = text;
Editable = false;
+ Selectable = false;
var t = ResignFirstResponder ();
Debug.WriteLine ("Resigned: {0}", t);
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs
index a58dd00..7c6c68f 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs
@@ -1,20 +1,25 @@
using System;
using System.Collections;
+using System.Runtime.InteropServices;
+
using AppKit;
using CoreGraphics;
using Foundation;
+using ObjCRuntime;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
public abstract class PropertyEditorControl : NSView
{
- public PropertyEditorControl ()
- {
- }
-
public string Label { get; set; }
+ public abstract NSView FirstKeyView { get; }
+ public abstract NSView LastKeyView { get; }
+
+ public nint TableRow { get; set; }
+ public NSTableView TableView { get; set; }
+
PropertyViewModel viewModel;
internal PropertyViewModel ViewModel {
get { return viewModel; }
@@ -41,6 +46,35 @@ namespace Xamarin.PropertyEditing.Mac
SetEnabled ();
}
+ [Export ("_primitiveSetDefaultNextKeyView:")]
+ public void SetDefaultNextKeyView (NSView child)
+ {
+ if (child == FirstKeyView || child == LastKeyView) {
+ UpdateKeyViews ();
+ } else {
+ //FIXME: Unfortunately, XamMac doesn't provide an easier way to call super on a selector
+ // we manually declare with [Export]
+ objc_msgSendSuper (SuperHandle, Selector.GetHandle ("_primitiveSetDefaultNextKeyView:"), child.Handle);
+ }
+ }
+
+ public void UpdateKeyViews (bool backward = true, bool forward = true)
+ {
+ PropertyEditorControl ctrl = null;
+
+ //FIXME: don't hardcode column
+ if (backward && TableRow > 0 && (ctrl = TableView.GetView (1, TableRow - 1, false) as PropertyEditorControl) != null) {
+ ctrl.LastKeyView.NextKeyView = FirstKeyView;
+ ctrl.UpdateKeyViews (forward: false);
+ }
+
+ //FIXME: don't hardcode column
+ if (forward && TableRow < TableView.RowCount - 1 && (ctrl = TableView.GetView (1, TableRow + 1, false) as PropertyEditorControl) != null) {
+ LastKeyView.NextKeyView = ctrl.FirstKeyView;
+ ctrl.UpdateKeyViews (backward: false);
+ }
+ }
+
protected abstract void HandlePropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e);
/// <summary>
@@ -53,10 +87,7 @@ namespace Xamarin.PropertyEditing.Mac
protected abstract void SetEnabled ();
- [Export ("validateProposedFirstResponder:forEvent:")]
- public bool validateProposedFirstResponder (NSResponder responder, NSEvent ev)
- {
- return true;
- }
+ [DllImport (Constants.ObjectiveCLibrary)]
+ static extern void objc_msgSendSuper (IntPtr objc_super, IntPtr sel, IntPtr arg);
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs
index 7b324bd..f851b9b 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs
@@ -29,6 +29,9 @@ namespace Xamarin.PropertyEditing.Mac
internal NSTextField StringEditor { get; set; }
+ public override NSView FirstKeyView => StringEditor;
+ public override NSView LastKeyView => StringEditor;
+
internal new StringPropertyViewModel ViewModel {
get { return (StringPropertyViewModel)base.ViewModel; }
set { base.ViewModel = value; }
diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs
index 33dc2e7..7432c8c 100644
--- a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs
+++ b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs
@@ -77,9 +77,10 @@ namespace Xamarin.PropertyEditing.Mac
NSScrollView tableContainer = new NSScrollView (Frame) {
AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable
};
- propertyTable = new FirstResponderTableView {
+ propertyTable = new NSTableView {
+ RefusesFirstResponder = true,
AutoresizingMask = NSViewResizingMask.WidthSizable,
- // SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.None,
+ SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.None,
};
// create columns for the panel
@@ -99,50 +100,5 @@ namespace Xamarin.PropertyEditing.Mac
tableContainer.DocumentView = propertyTable;
AddSubview (tableContainer);
}
-
- class FirstResponderTableView : NSTableView
- {
- const int NSTabTextMovement = 0x11;
- [Export ("validateProposedFirstResponder:forEvent:")]
- public bool validateProposedFirstResponder (NSResponder responder, NSEvent ev)
- {
- return true;
- }
-
- /* [Export ("shouldSelectRow:NSTableView:RowIndex")]
- public bool shouldSelectRow (NSTableView table, nint row)
- {
- return false;
- }*/
-
- public override void TextDidEndEditing (NSNotification notification)
- {
- nint editedColumn = this.EditedColumn;
- nint editedRow = this.EditedRow;
- nint lastColumn = this.ColumnCount - 1;
- nint lastRow = this.RowCount - 1;
-
- NSDictionary userInfo = notification.UserInfo;
-
- int textMovement = int.Parse (userInfo.ValueForKey (new NSString ("NSTextMovement")).ToString ());
-
- base.TextDidEndEditing (notification);
-
- if (textMovement == NSTabTextMovement) {
- if (editedColumn != lastColumn - 1) {
- this.SelectRows (NSIndexSet.FromIndex (editedRow), false);
- this.EditColumn (editedColumn + 1, editedRow, null, true);
- }
- else {
- if (editedRow != lastRow - 1) {
- this.EditColumn (0, editedRow + 1, null, true);
- }
- else {
- this.EditColumn (0, 0, null, true);// Go to the first cell
- }
- }
- }
- }
- }
}
}
diff --git a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs
index 676594b..305c704 100644
--- a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs
+++ b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs
@@ -29,12 +29,11 @@ namespace Xamarin.PropertyEditing.Mac
PropertyViewModel property = DataSource.ViewModel.Properties[(int)row];
var propertyType = property.GetType ();
var cellIdentifier = propertyType.Name;
- NSView view = new NSView ();
// Setup view based on the column
- switch (tableColumn.Title) {
- case "Properties":
- view = (UnfocusableTextField)tableView.MakeView (cellIdentifier + "props", this);
+ switch (tableColumn.Identifier) {
+ case "PropertiesList":
+ var view = tableView.MakeView (cellIdentifier + "props", this);
if (view == null) {
view = new UnfocusableTextField (new CoreGraphics.CGRect (0, -5, 75, 20), property.Property.Name) {
TextContainerInset = new CoreGraphics.CGSize (0, 7),
@@ -44,39 +43,34 @@ namespace Xamarin.PropertyEditing.Mac
}
//((UnfocusableTextField)view).Value = property.Property.Name;
- break;
- case "Editors":
- view = tableView.MakeView (cellIdentifier + "edits", this);
+ return view;
- // we don't need to do any setup if the editor already exists
- if (view != null)
- return view;
+ case "PropertyEditors":
+ var editor = (PropertyEditorControl)tableView.MakeView (cellIdentifier + "edits", this);
- Type controlType;
- if (viewModelTypes.TryGetValue (propertyType, out controlType)) {
- view = SetUpEditor (view, controlType, property);
- }
- else {
- if (propertyType.IsGenericType) {
- Type genericType = propertyType.GetGenericTypeDefinition ();
- if (genericType == typeof (EnumPropertyViewModel<>))
- controlType = typeof (EnumEditorControl<>).MakeGenericType (property.Property.Type);
- view = SetUpEditor (view, controlType, property);
+ if (editor == null) {
+ Type controlType;
+ if (viewModelTypes.TryGetValue (propertyType, out controlType)) {
+ editor = SetUpEditor (controlType, property, tableView);
}
- }
- var lookupRow = row - 1;
- if (lookupRow< 0)
- lookupRow = DataSource.ViewModel.Properties.Count - 1;
- var ViewAtRow = tableView.GetView (1, lookupRow, false);
- if (ViewAtRow != null) {
- ViewAtRow.NextKeyView = view;
- ViewAtRow.NextResponder = view;
+ else {
+ if (propertyType.IsGenericType) {
+ Type genericType = propertyType.GetGenericTypeDefinition ();
+ if (genericType == typeof (EnumPropertyViewModel<>))
+ controlType = typeof (EnumEditorControl<>).MakeGenericType (property.Property.Type);
+ editor = SetUpEditor (controlType, property, tableView);
+ }
}
-
- break;
+ }
+
+ // we must reset these every time, as the view may have been reused
+ editor.ViewModel = property;
+ editor.TableRow = row;
+ editor.UpdateKeyViews ();
+ return editor;
}
- return view;
+ throw new Exception ("Unknown column identifier: " + tableColumn.Identifier);
}
public override nfloat GetRowHeight (NSTableView tableView, nint row)
@@ -94,20 +88,13 @@ namespace Xamarin.PropertyEditing.Mac
}
// set up the editor based on the type of view model
- NSView SetUpEditor (NSView view, Type controlType, PropertyViewModel property)
+ PropertyEditorControl SetUpEditor (Type controlType, PropertyViewModel property, NSTableView table)
{
- if (view == null) {
- view = (PropertyEditorControl)Activator.CreateInstance (controlType);
- view.Identifier = property.GetType ().Name;
- }
- ((PropertyEditorControl)view).ViewModel = property;
+ var view = (PropertyEditorControl)Activator.CreateInstance (controlType);
+ view.Identifier = property.GetType ().Name;
+ view.TableView = table;
return view;
}
-
- public override bool ShouldSelectRow (NSTableView tableView, nint row)
- {
- return false;
- }
}
}