-
Notifications
You must be signed in to change notification settings - Fork 1k
Port DataGridViewColumnCollectionEditor #12925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
a1d982c
9083729
3d35be7
df52aea
8cc3595
69fbb61
6991914
435d9e8
1263307
e3975ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.ComponentModel; | ||
using System.ComponentModel.Design; | ||
using System.Drawing.Design; | ||
|
||
namespace System.Windows.Forms.Design; | ||
internal class DataGridViewColumnCollectionEditor : UITypeEditor | ||
{ | ||
public DataGridViewColumnCollectionEditor() : base() { } | ||
|
||
private DataGridViewColumnCollectionDialog? _dataGridViewColumnCollectionDialog; | ||
|
||
public override object? EditValue(ITypeDescriptorContext? context, IServiceProvider provider, object? value) | ||
{ | ||
IWindowsFormsEditorService? edSvc = provider?.GetService<IWindowsFormsEditorService>(); | ||
|
||
if (provider is null || edSvc is null || context?.Instance is null | ||
|| provider.GetService(typeof(IDesignerHost)) is not IDesignerHost host) | ||
{ | ||
return value; | ||
} | ||
|
||
using (ScaleHelper.EnterDpiAwarenessScope(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE)) | ||
{ | ||
_dataGridViewColumnCollectionDialog ??= new(); | ||
Epica3055 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_dataGridViewColumnCollectionDialog.SetLiveDataGridView((DataGridView)context.Instance); | ||
|
||
using DesignerTransaction trans = host.CreateTransaction(SR.DataGridViewColumnCollectionTransaction); | ||
Epica3055 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (edSvc.ShowDialog(_dataGridViewColumnCollectionDialog) == DialogResult.OK) | ||
{ | ||
trans.Commit(); | ||
} | ||
else | ||
{ | ||
trans.Cancel(); | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
|
||
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext? context) => UITypeEditorEditStyle.Modal; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
ricardobossan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#nullable enable | ||
|
||
using Moq; | ||
using System.ComponentModel; | ||
using System.Drawing.Design; | ||
|
||
namespace System.Windows.Forms.Design.Tests; | ||
|
||
public class DataGridViewColumnCollectionEditorTests | ||
{ | ||
[Fact] | ||
public void DataGridViewColumnCollectionEditor_GetEditStyle() | ||
Epica3055 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
=> new DataGridViewColumnCollectionEditor().GetEditStyle().Should().Be(UITypeEditorEditStyle.Modal); | ||
Epica3055 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[Fact] | ||
public void DataGridViewColumnCollectionEditor_IsDropDownResizable() | ||
=> new DataGridViewColumnCollectionEditor().IsDropDownResizable.Should().Be(false); | ||
|
||
[Fact] | ||
public void DataGridViewColumnCollectionEditor_EditValue() | ||
{ | ||
DataGridViewColumnCollectionEditor dataGridViewColumnCollectionEditor = new(); | ||
object value = "123"; | ||
dataGridViewColumnCollectionEditor.EditValue(null, null!, value).Should().Be(value); | ||
|
||
Mock<ITypeDescriptorContext> mockTypeDescriptorContext = new(MockBehavior.Strict); | ||
dataGridViewColumnCollectionEditor.EditValue(mockTypeDescriptorContext.Object, null!, value).Should().Be(value); | ||
|
||
Mock<IServiceProvider> mockServiceProvider = new(MockBehavior.Strict); | ||
mockServiceProvider.Setup(x => x.GetService(typeof(IWindowsFormsEditorService))).Returns(null!); | ||
dataGridViewColumnCollectionEditor.EditValue(null, mockServiceProvider.Object, value).Should().Be(value); | ||
|
||
mockTypeDescriptorContext.Setup(x => x.Instance).Returns(null!); | ||
dataGridViewColumnCollectionEditor.EditValue(null, mockServiceProvider.Object, value).Should().Be(value); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.