diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-09-03 20:08:47 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-09-03 20:34:09 +0300 |
commit | 6173f83e54d00047bbe22a453cb637cff5794afd (patch) | |
tree | ee9f4804c27a8e3d84e4b727791ed2fc71b1bec5 | |
parent | 8470ca99ec94d23ce6e82169fb0a6bfdf0938063 (diff) |
[mac] Fix expansion buttons not restoring
Expand/CollapseItem don't always trigger a call to the overrides
based on wether the item should be open or not to start with. So
we'll force the issue to ensure reused buttons get restored to
their closed state properly.
Fixes #610
-rw-r--r-- | Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs index 53c5ec2..49f2665 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs @@ -25,7 +25,7 @@ namespace Xamarin.PropertyEditing.Mac public void UpdateExpansions (NSOutlineView outlineView) { - this.isExpanding = true; + this.isUpdatingExpansions = true; if (!String.IsNullOrWhiteSpace (this.dataSource.DataContext.FilterText)) { outlineView.ExpandItem (null, true); @@ -36,12 +36,12 @@ namespace Xamarin.PropertyEditing.Mac continue; if (this.dataSource.DataContext.GetIsExpanded (g.Category)) - outlineView.ExpandItem (item); + EnsureOpenOrClose (outlineView, item, open: true); else - outlineView.CollapseItem (item); + EnsureOpenOrClose (outlineView, item, open: false); } } - this.isExpanding = false; + this.isUpdatingExpansions = false; } public override NSView GetView (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) @@ -146,7 +146,7 @@ namespace Xamarin.PropertyEditing.Mac var outline = (NSOutlineView)notification.Object; nint row = outline.RowForItem (facade); - if (this.isExpanding) { + if (this.isUpdatingExpansions) { NSView view = outline.GetView (0, row, makeIfNecessary: true); if (view.Subviews[0] is NSButton expander) expander.State = NSCellStateValue.On; @@ -168,7 +168,7 @@ namespace Xamarin.PropertyEditing.Mac var outline = (NSOutlineView)notification.Object; nint row = outline.RowForItem (facade); - if (this.isExpanding) { + if (this.isUpdatingExpansions) { NSView view = outline.GetView (0, row, makeIfNecessary: true); if (view.Subviews[0] is NSButton expander) expander.State = NSCellStateValue.Off; @@ -239,17 +239,29 @@ namespace Xamarin.PropertyEditing.Mac public const string CategoryIdentifier = "label"; private PropertyTableDataSource dataSource; - private bool isExpanding; + private bool isUpdatingExpansions; private readonly PropertyEditorSelector editorSelector = new PropertyEditorSelector (); private readonly IHostResourceProvider hostResources; private readonly Dictionary<string, EditorRegistration> registrations = new Dictionary<string, EditorRegistration> (); private readonly Dictionary<string, IEditorView> firstCache = new Dictionary<string, IEditorView> (); - private NSView GetViewForItem (NSOutlineView outline, NSObjectFacade facade) + private void EnsureOpenOrClose (NSOutlineView outline, NSObjectFacade item, bool open) + { + if (open) + outline.ExpandItem (item); + else + outline.CollapseItem (item); + + NSView view = GetViewForItem (outline, item, makeIfNeccessary: true); + if (view.Subviews[0] is NSButton expander) + expander.State = (open) ? NSCellStateValue.On : NSCellStateValue.Off; + } + + private NSView GetViewForItem (NSOutlineView outline, NSObjectFacade facade, bool makeIfNeccessary = false) { nint row = outline.RowForItem (facade); - return outline.GetView (0, row, false); + return outline.GetView (0, row, makeIfNeccessary); } private void SetRowValueBackground (NSView view, bool valueBackground) |