33using ast_visual_studio_extension . CxExtension . Toolbar ;
44using ast_visual_studio_extension . CxExtension . Utils ;
55using ast_visual_studio_extension . CxPreferences ;
6+ using ast_visual_studio_extension . CxWrapper . Models ;
67using Microsoft . VisualStudio . Shell ;
78using System . Collections . Generic ;
9+ using System . Diagnostics ;
10+ using System . Diagnostics . CodeAnalysis ;
11+ using System . Linq ;
12+ using System . Threading ;
13+ using System . Threading . Tasks ;
814using System . Windows ;
915using System . Windows . Controls ;
1016using System . Windows . Controls . Primitives ;
1117using System . Windows . Input ;
1218using System . Windows . Media ;
13- using System . Threading ;
14- using System . Threading . Tasks ;
1519using System ;
16- using System . Diagnostics ;
1720using ast_visual_studio_extension . CxExtension . Services ;
18- using System . Diagnostics . CodeAnalysis ;
19- using ast_visual_studio_extension . CxWrapper . Models ;
2021
2122namespace ast_visual_studio_extension . CxExtension
2223{
@@ -71,7 +72,7 @@ public CxWindowControl(AsyncPackage package)
7172 . WithGroupByOptions ( new Dictionary < MenuItem , GroupBy >
7273 {
7374 { SeverityGroupBy , GroupBy . SEVERITY } ,
74- { VulnerabiltyTypeGroupBy , GroupBy . VULNERABILITY_TYPE } ,
75+ { VulnerabilityTypeGroupBy , GroupBy . VULNERABILITY_TYPE } ,
7576 { StateGroupBy , GroupBy . STATE } ,
7677 { StatusGroupBy , GroupBy . STATUS } ,
7778 { LanguageGroupBy , GroupBy . Language } ,
@@ -98,23 +99,55 @@ private async Task InitializeAsync()
9899 private Dictionary < MenuItem , State > CreateStateMenuItems ( List < State > states )
99100 {
100101 StateFilterMenuItem . Items . Clear ( ) ;
101- Dictionary < MenuItem , State > statesMenuItems = new Dictionary < MenuItem , State > ( ) ;
102- foreach ( var item in states )
102+ var statesMenuItems = new Dictionary < MenuItem , State > ( ) ;
103+
104+ // Sort states by formatted name
105+ var sortedStates = states . OrderBy ( s => UIUtils . FormatStateName ( s . name ) ) ;
106+
107+ foreach ( var state in sortedStates )
103108 {
104- string formattedState = UIUtils . FormatStateName ( item . name ) ;
105- var menuItem = new MenuItem
106- {
107- Header = formattedState ,
108- Style = ( Style ) Application . Current . Resources [ "DefaultMenuItemStyle" ]
109- } ;
109+ string formattedState = UIUtils . FormatStateName ( state . name ) ;
110+ var menuItem = CreateMenuItem ( $ "Filter: { formattedState } ") ;
110111 menuItem . Click += StateFilter_Click ;
112+
111113 StateFilterMenuItem . Items . Add ( menuItem ) ;
112- statesMenuItems . Add ( menuItem , item ) ;
114+ statesMenuItems . Add ( menuItem , state ) ;
113115 }
114- AddDependencyFilter ( "SCA Dev & Test Dependencies" , statesMenuItems ) ;
116+
117+ // Add dependency filters before final sort
118+ AddDependencyFilter ( "Filter: SCA Dev & Test Dependencies" , statesMenuItems ) ;
119+
120+ // Sort menu items by Header
121+ SortStateFilterMenuItems ( ) ;
122+
115123 return statesMenuItems ;
116124 }
117125
126+ private MenuItem CreateMenuItem ( string header )
127+ {
128+ return new MenuItem
129+ {
130+ Header = header ,
131+ Style = ( Style ) Application . Current . Resources [ "DefaultMenuItemStyle" ]
132+ } ;
133+ }
134+
135+ private void SortStateFilterMenuItems ( )
136+ {
137+ var sortedItems = StateFilterMenuItem . Items
138+ . Cast < MenuItem > ( )
139+ . OrderBy ( mi => mi . Header . ToString ( ) )
140+ . ToList ( ) ;
141+
142+ StateFilterMenuItem . Items . Clear ( ) ;
143+
144+ foreach ( var item in sortedItems )
145+ {
146+ StateFilterMenuItem . Items . Add ( item ) ;
147+ }
148+ }
149+
150+
118151 private void AddDependencyFilter ( string filterName , Dictionary < MenuItem , State > statesMenuItems )
119152 {
120153 var dependencyState = new State
0 commit comments