Skip to content

Commit

Permalink
Combine PropertyGrid tab information. (#6108)
Browse files Browse the repository at this point in the history
Combine tab related data into a record for clarity and safety. Use a List<> instead of an array to avoid complicated insert logic.

Maintain tab selection as an instance instead of an index.

Move error handling to CreateTab so thrown exceptions with messages (missing a bitmap / name for the tab) are actually thrown instead of a silent failure.
  • Loading branch information
JeremyKuhne authored Nov 3, 2021
1 parent 582c1b2 commit 39c1cfb
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int Count
return 0;
}

return _ownerPropertyGrid._viewTabs.Length;
return _ownerPropertyGrid._tabs.Count;
}
}

Expand All @@ -55,7 +55,7 @@ public PropertyTab this[int index]
throw new InvalidOperationException(SR.PropertyGridPropertyTabCollectionReadOnly);
}

return _ownerPropertyGrid._viewTabs[index];
return _ownerPropertyGrid._tabs[index].Tab;
}
}

Expand Down Expand Up @@ -100,9 +100,14 @@ void ICollection.CopyTo(Array dest, int index)
return;
}

if (_ownerPropertyGrid._viewTabs.Length > 0)
if (_ownerPropertyGrid._tabs.Count > 0)
{
Array.Copy(_ownerPropertyGrid._viewTabs, 0, dest, index, _ownerPropertyGrid._viewTabs.Length);
Array.Copy(
_ownerPropertyGrid._tabs.Select(i => i.Tab).ToArray(),
0,
dest,
index,
_ownerPropertyGrid._tabs.Count);
}
}

Expand All @@ -116,7 +121,7 @@ public IEnumerator GetEnumerator()
return Array.Empty<PropertyTab>().GetEnumerator();
}

return _ownerPropertyGrid._viewTabs.GetEnumerator();
return _ownerPropertyGrid._tabs.Select(i => i.Tab).GetEnumerator();
}

public void RemoveTabType(Type propertyTabType)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.Windows.Forms.Design;

namespace System.Windows.Forms
{
public partial class PropertyGrid
{
private record TabInfo(PropertyTab Tab, PropertyTabScope Scope, ToolStripButton Button)
{
public Type TabType => Tab.GetType();
}
}
}
Loading

0 comments on commit 39c1cfb

Please sign in to comment.