codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.9k stars 358 forks source link

Add type-specific sorting definitions to the Reorganizing > Type page #1005

Open 5cover opened 1 year ago

5cover commented 1 year ago

Environment

Description

Add type-specific sorting definitions to Reorganizing > Type

In order to increase reorganizing flexibility, each member type could have an associated sorting definition in the Reorganizing > Type page.

Each member is composed of multiple parts (excluding optional keywords such as static, abstract, virtual ...) Properties, for instance, have a access modifier, a type and a name Nested classes, on the other hand, only have a access modifier and a name.

The sorting definition would decide the sorting order when using the "Alphabetize members of the same group" (Reorganizing > General) feature.

For example, if the sorting definition for properties is "Access, type, name", it means that properties should be sorted by their access modifier, then by their type, then by their name.

This would also implement #965.

Current behavior

Currently, the "Alphabetize members of the same group" feature only allows for sorting members by their access modifiers, then by their name.

But sorting members by type before sorting by name could increase readablity drastically.

Sample code:

Here's a bunch of properties sorted using the current "Alphabetize members of the same group" setting.

    public Category Category { get; set; }
    public ScriptCode Code { get; }
    public Impact Impact { get; set; }
    public string InvariantName => LocalizedName[InvariantCulture];
    public LocalizedString LocalizedDescription { get; init; }
    public LocalizedString LocalizedName { get; init; }
    public string Name { get => LocalizedName[CurrentUICulture]; set => LocalizedName[CurrentUICulture] = value; }
    public SafetyLevel SafetyLevel { get; set; }
    public ScriptType Type { get; }
    public SemVersionRange Versions { get; set; }

The same properties, sorted by access modifier, then by type, then by name. (I used the "Sort Lines" feature)

    public Category Category { get; set; }
    public Impact Impact { get; set; }
    public LocalizedString LocalizedDescription { get; init; }
    public LocalizedString LocalizedName { get; init; }
    public SafetyLevel SafetyLevel { get; set; }
    public ScriptCode Code { get; }
    public ScriptType Type { get; }
    public SemVersionRange Versions { get; set; }
    public string InvariantName => LocalizedName[InvariantCulture];
    public string Name { get => LocalizedName[CurrentUICulture]; set => LocalizedName[CurrentUICulture] = value; }

This looks considerably prettier in my opinion, as the properties are now grouped by type in addition to the alphabetical order.

Possible interface design

Current Reorganizing < Types page

As you can see, there's a bunch of unused space on the right part of the list view.

I suggest we change the list to display 2 columns : Kind and Sort order

The Kind column would contain each member type, and the Sort order column would contain a member type-specific sort order definition.

Suggested Reorganizing < Types page

Keep in mind though, that I am not knowledgeable in UI design in any way, those are just some ideas about how to implement this feature.

codecadwallader commented 1 year ago

Thank you for the suggestion, I can see you've put a lot of thought into it.