Skip to content

Added warning icons to HTTP sources in VS Options NuGet Package Manager#4647

Merged
martinrrm merged 14 commits intodevfrom
dev-martinrrm-http-warning-vs-options
Jun 22, 2022
Merged

Added warning icons to HTTP sources in VS Options NuGet Package Manager#4647
martinrrm merged 14 commits intodevfrom
dev-martinrrm-http-warning-vs-options

Conversation

@martinrrm
Copy link
Contributor

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/1154

Regression? Last working version:

Description

Added warning icons to the VS Options Windows for HTTP sources
image

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@martinrrm martinrrm requested a review from a team as a code owner May 30, 2022 18:42
@martinrrm martinrrm force-pushed the dev-martinrrm-http-warning-vs-options branch from 5a93c5b to c99c609 Compare May 31, 2022 05:34
@martinrrm
Copy link
Contributor Author

image
image

Added Accessibility to the Icon in the label at the bottom, adding accessibility to the icon in the custom control looks not possible since we draw it

jeffkl
jeffkl previously approved these changes Jun 2, 2022
};

IVsImageService2 vsImageService = (IVsImageService2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsImageService));
IVsUIObject uIObj = vsImageService.GetImage(KnownMonikers.StatusWarning, attributes);
Copy link
Contributor

@kartheekp-ms kartheekp-ms Jun 4, 2022

Choose a reason for hiding this comment

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

I was wondering if we should get the warning icon image only if the package source is HTTP. It is possible that I don't understand the whole context of how it works currently because I don't know much about WinForms or WPF.

Another option is to get the image only once and use it as and when needed.

Copy link
Member

Choose a reason for hiding this comment

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

I'd go further and say we should store the image in a static variable. This method, OnDrawItem, is called once per package source. There's no need to 1. get the image service instance since Visual Studio services are singletons, and 2. get the known image, which I'm reasonable confident is also a singleton. Admittedly customers don't open the dialog box very often, but this is an easy perf improvement, and this is happening on the UI thread after all.

};

IVsImageService2 vsImageService = (IVsImageService2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsImageService));
IVsUIObject uIObj = vsImageService.GetImage(KnownMonikers.StatusWarning, attributes);
Copy link
Member

Choose a reason for hiding this comment

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

I'd go further and say we should store the image in a static variable. This method, OnDrawItem, is called once per package source. There's no need to 1. get the image service instance since Visual Studio services are singletons, and 2. get the known image, which I'm reasonable confident is also a singleton. Admittedly customers don't open the dialog box very often, but this is an easy perf improvement, and this is happening on the UI thread after all.

@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jun 14, 2022
@ghost
Copy link

ghost commented Jun 14, 2022

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@donnie-msft
Copy link
Contributor

Chatted offline yesterday, so waiting on some changes before I review this one.

@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jun 14, 2022
@martinrrm martinrrm force-pushed the dev-martinrrm-http-warning-vs-options branch from c99c609 to 7a169e0 Compare June 16, 2022 12:51
@martinrrm martinrrm requested a review from jeffkl June 16, 2022 13:07
@martinrrm
Copy link
Contributor Author

@donnie-msft I pushes new changed related to accessibility and deleted the warning PNG.

@martinrrm martinrrm force-pushed the dev-martinrrm-http-warning-vs-options branch from 45c7715 to c43aafe Compare June 16, 2022 14:53
@martinrrm martinrrm force-pushed the dev-martinrrm-http-warning-vs-options branch from 8bc78dc to eb1fd7f Compare June 16, 2022 21:17
Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

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

Looks good. Think there may be a tiny layout edit needed.
Can we remove the PNG?

}
}

public static Icon WarningIcon
Copy link
Member

Choose a reason for hiding this comment

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

Properties are just methods with some syntactic sugar, and static methods are just methods that don't have a this "variable". In order to use a static for caching, it must be a static field.

Also, some people (myself included) believe that properties should not have "business logic", although I don't think this is in our team coding guidelines. It's much easier to understand and optimize for both correctness and performance when we can assume that fields and properties will return values already in memory (and don't change state), and methods are called when internal state is changed or when potentially expensive calculations need to be made.

So, I suggest removing these two static properties, add a private static Icon _warningIcon;, and a private Icon GetWarningIcon() that returns _warningIcon when it's not null, and gets the icon from the image service when it is null.

if (packageSource.IsHttp && !packageSource.IsHttps)
{
var sourceMessage = string.Concat(
"Warning: Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.",
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be in a string resource, so it can be localized for the customer's language.

Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

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

The resizing issue is resolved and overall function looks good.
While testing, I noticed the tab order is nonsensical. I'm guessing the new panels have thrown this off a bit from the original tab order...
image

@martinrrm martinrrm force-pushed the dev-martinrrm-http-warning-vs-options branch from 2e16d73 to 855e7a7 Compare June 20, 2022 16:54
@martinrrm martinrrm requested review from donnie-msft and zivkan June 20, 2022 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants