Skip to content
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

Port IconEditor; add test #2089

Merged
merged 1 commit into from
Oct 18, 2019
Merged

Conversation

zsd4yr
Copy link
Contributor

@zsd4yr zsd4yr commented Oct 15, 2019

Port Icon Editor for 3.1

Closes #2020

Microsoft Reviewers: Open in CodeFlow

@zsd4yr zsd4yr requested a review from a team as a code owner October 15, 2019 21:48
@zsd4yr zsd4yr changed the title Dev/zadanz/iconeditor Port Drawing.Design Icon Editor Oct 15, 2019
@codecov
Copy link

codecov bot commented Oct 15, 2019

Codecov Report

Merging #2089 into release/3.1 will decrease coverage by 0.00262%.
The diff coverage is 8.43373%.

@@                  Coverage Diff                  @@
##           release/3.1       #2089         +/-   ##
=====================================================
- Coverage     26.51476%   26.51213%   -0.00263%     
=====================================================
  Files              804         806          +2     
  Lines           268062      268164        +102     
  Branches         38066       38079         +13     
=====================================================
+ Hits             71076       71096         +20     
- Misses          191907      191991         +84     
+ Partials          5079        5077          -2
Flag Coverage Δ
#Debug 26.51213% <8.43373%> (-0.00263%) ⬇️
#production 26.51213% <8.43373%> (-0.00263%) ⬇️
#test ?

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a type forwarding to System.Drawing.Design

@ghost ghost added the waiting-author-feedback The team requires more information from the author label Oct 16, 2019
@RussKie RussKie added this to the 3.1 milestone Oct 16, 2019
@weltkante
Copy link
Contributor

weltkante commented Oct 16, 2019

Anyone started coordinating adding TypeDescriptor annotations to System.Drawing classes? As noted in #1119, #1120, #1121 ported editors for System.Drawing won't work otherwise, you'll have to discuss whether the correct place is to add the missing Editor attributes in CoreFX similar to what is already done for TypeConverter attributes, or if WinForms needs to have its own TypeDescriptor extension logic. CoreFX already reserved a hashtable for editor attributes but it currently is empty. I'm not sure if the infrastructure allows two extensions on the same type though, this needs extra care to handle correctly so your extension doesn't accidently revert CoreFX extensions!

@RussKie
Copy link
Member

RussKie commented Oct 16, 2019

@weltkante
Copy link
Contributor

weltkante commented Oct 16, 2019

@RussKie no, type forwarding just affects type resolution not association of the Editor to actual editable classes/properties, if you don't know which type to look for the type forwarding doesn't help. CoreFX removed [Editor] attributes from classes and properties, these need to be restored, either on the class or in some TypeDescriptor extension logic (see links in my previous comment). The question is where it is done, as I understood System.Drawing doesn't want a dependency on WinForms.

For example the Editor attribute on the Icon class in Desktop Framework is not present in CoreFX - it just has a TypeConverter but no Editor. This means TypeDescriptor.GetEditor will return null.

Like said elsewhere it would be useful to add unit tests checking e.g. TypeDescriptor.GetEditor(typeof(Icon)) is IconEditor to verify the class is linked properly. Appropriate tests could be added whenever a missing editor is ported, would detect future regressions.

Without this the ported editor may work in the VS Designer (if VS has its own TypeDescriptor overrides) but it won't work for e.g. PropertyGrid placed in user applications like in the three linked issues. IMHO if the ported editor is only for usage in VS it should be defined there and not in the WinForms repository, if its in WinForms I'd expect it to be usable in standalone PropertyGrid.

@zsd4yr
Copy link
Contributor Author

zsd4yr commented Oct 16, 2019

@weltkante there are really two mechanisms to solve the issue of resolving an editor for a given type

  1. The editor attribute; and
  2. The intrinsic table given to TypeDescriptor

The goal in ultimately to have TypeDescriptor.GetEditor(type) return the desired editor.

So, with both of these mechanisms, there are really 2 equivalence classes of scenarios we care about:

  1. If the type is owned by Windows Forms, then an editor attribute can safely be added to that type associating it with an editor. Examples:

  2. If the type is owned by both CoreFX (or anywhere downstack) then we need to add to the TypeDescriptor's Editor Table; we do that here:

    Hashtable intrinsicEditors = new Hashtable
    {
    // Our set of intrinsic editors.
    [typeof(DateTime)] = "System.ComponentModel.Design.DateTimeEditor, " + AssemblyRef.SystemDesign,
    [typeof(Array)] = "System.ComponentModel.Design.ArrayEditor, " + AssemblyRef.SystemDesign,
    [typeof(IList)] = "System.ComponentModel.Design.CollectionEditor, " + AssemblyRef.SystemDesign,
    [typeof(ICollection)] = "System.ComponentModel.Design.CollectionEditor, " + AssemblyRef.SystemDesign,
    [typeof(byte[])] = "System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign,
    [typeof(Stream)] = "System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign,
    [typeof(string[])] = "System.Windows.Forms.Design.StringArrayEditor, " + AssemblyRef.SystemDesign,
    [typeof(Collection<string>)] = "System.Windows.Forms.Design.StringCollectionEditor, " + AssemblyRef.SystemDesign
    };
    // Add our intrinsic editors to TypeDescriptor.
    TypeDescriptor.AddEditorTable(typeof(UITypeEditor), intrinsicEditors);

All of that said....
you are right that we need to add a line for this editor ala the 2nd mechanism

@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Oct 16, 2019
@weltkante
Copy link
Contributor

Yeah thats what I was looking for, thanks for linking the file, wasn't aware that WinForms already had one. The issues I linked above (FontEditor, ColorEditor, ImageEditor) probably need to be added there as well, I'll drop a note in the issues.

@zsd4yr
Copy link
Contributor Author

zsd4yr commented Oct 16, 2019

Yeah thats what I was looking for, thanks for linking the file, wasn't aware that WinForms already had one. The issues I linked above (FontEditor, ColorEditor, ImageEditor) probably need to be added there as well, I'll drop a note in the issues.

Happy to demystify! I have created an issue #2101 to create tests for these.

I am having an issue right now where the following test fails but I would not expect it to based on the intrinsic table above...

[Fact]
public void CollectionEditor_ICollection_HasEditor()
{
    var editor = TypeDescriptor.GetEditor(typeof(ICollection), typeof(UITypeEditor));
    Assert.NotNull(editor);
}

Oddly it is failing in our tests project but when I do something like it in a dotnet new winforms project, the editor returns non-null

@zsd4yr zsd4yr changed the base branch from release/3.1 to release3.1-editors October 17, 2019 00:23
@zsd4yr
Copy link
Contributor Author

zsd4yr commented Oct 17, 2019

^^ Thanks to @ericstj for helping me figure out the issue with the tests. We need a reference to the fascades

@zsd4yr zsd4yr force-pushed the dev/zadanz/iconeditor branch from bc1839f to b059a2a Compare October 17, 2019 00:27
@zsd4yr
Copy link
Contributor Author

zsd4yr commented Oct 17, 2019

https://github.com/dotnet/winforms/blob/release/3.1/src/System.Design/src/System.Design.Forwards.cs

@RussKie With respect to this, I think you should remove that file as it does not do anything. The Facades are generated automatically by the GenFacades target during the build. You should be able to test this yourself by running Build -pack, opening the resulting Microsoft.Private.WinForms transport package in winforms\artifacts\packages\Debug\NonShipping, and then opening the System.Design ref in something like ILSpy to compare the type forwards before and after the presence of your file.

If this is not the case, then something is very wrong and you should talk to @dreddy-work and @Shyam-Gupta who did the work on generating these facades.

@zsd4yr zsd4yr requested a review from RussKie October 17, 2019 00:37
@zsd4yr zsd4yr force-pushed the dev/zadanz/iconeditor branch from b059a2a to 35f1f4a Compare October 17, 2019 22:20
@zsd4yr zsd4yr changed the title Port Drawing.Design Icon Editor Port and associate Drawing.Design Icon Editor; add test Oct 17, 2019
@RussKie RussKie changed the title Port and associate Drawing.Design Icon Editor; add test Port IconEditor; add test Oct 18, 2019
@ghost ghost added the waiting-author-feedback The team requires more information from the author label Oct 18, 2019
@RussKie RussKie force-pushed the dev/zadanz/iconeditor branch from 35f1f4a to c5844f5 Compare October 18, 2019 02:40
@RussKie RussKie changed the base branch from release3.1-editors to dev/3.1-uitypeeditors October 18, 2019 02:40
@RussKie RussKie force-pushed the dev/zadanz/iconeditor branch from c5844f5 to debccb0 Compare October 18, 2019 02:42
@@ -27,6 +27,8 @@ static UITypeEditor()
[typeof(ICollection)] = "System.ComponentModel.Design.CollectionEditor, " + AssemblyRef.SystemDesign,
[typeof(byte[])] = "System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign,
[typeof(Stream)] = "System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign,

// System.Windows.Forms type Editors
[typeof(string[])] = "System.Windows.Forms.Design.StringArrayEditor, " + AssemblyRef.SystemDesign,

Copy link
Member

@Tanya-Solyanik Tanya-Solyanik Oct 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: group line 32 and 35 under the common header instead of repeating that header, and consider a more descriptive header.. editors that are used in ...

RussKie added a commit that referenced this pull request Oct 18, 2019
@zsd4yr zsd4yr merged commit 24820ff into dev/3.1-uitypeeditors Oct 18, 2019
@zsd4yr zsd4yr deleted the dev/zadanz/iconeditor branch October 18, 2019 15:25
@RussKie
Copy link
Member

RussKie commented Oct 21, 2019

I have verified the behaviour without explicit type forwarding and it appears to be working as expected.
More details here - #2078 (comment)

@zsd4yr zsd4yr mentioned this pull request Oct 22, 2019
RussKie added a commit that referenced this pull request Nov 1, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting-author-feedback The team requires more information from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants