22using System . Collections . Generic ;
33using System . Diagnostics ;
44using System . Media ;
5+ using System . Text . RegularExpressions ;
56using System . Windows ;
7+ using System . Windows . Controls ;
68using System . Windows . Input ;
79
810namespace PerfView
@@ -22,6 +24,8 @@ public SelectProcess(Window parentWindow, IEnumerable<IProcess> processes, TimeS
2224 AllProcsButton . Visibility = System . Windows . Visibility . Hidden ;
2325 }
2426
27+ ProcessFilterTextBox . Text = "" ;
28+
2529 UpdateItemSource ( ) ;
2630 var filteredProcesses = Grid . ItemsSource as List < IProcess > ;
2731
@@ -95,7 +99,26 @@ private void UpdateItemSource()
9599 return ;
96100 }
97101
98- Grid . ItemsSource = m_processes ;
102+ var filterText = ProcessFilterTextBox . Text ;
103+ if ( filterText == "" )
104+ {
105+ Grid . ItemsSource = m_processes ;
106+ return ;
107+ }
108+ var regex = Regex . Escape ( filterText ) ;
109+ regex = regex . Replace ( @"\*" , ".*" ) ;
110+ var filterRegex = new Regex ( regex , RegexOptions . IgnoreCase ) ;
111+
112+ List < IProcess > processes = new List < IProcess > ( ) ;
113+ foreach ( var process in m_processes )
114+ {
115+ if ( filterRegex . Match ( process . Name ) . Success || filterRegex . Match ( process . CommandLine ) . Success )
116+ {
117+ processes . Add ( process ) ;
118+ }
119+ }
120+
121+ Grid . ItemsSource = processes ;
99122 }
100123
101124 internal void OKClicked ( object sender , RoutedEventArgs e )
@@ -120,7 +143,7 @@ private void DoHyperlinkHelp(object sender, ExecutedRoutedEventArgs e)
120143 {
121144 MainWindow . DisplayUsersGuide ( e . Parameter as string ) ;
122145 }
123- private void KeyDownHander ( object sender , KeyEventArgs e )
146+ private void GridKeyDownHander ( object sender , KeyEventArgs e )
124147 {
125148 if ( e . Key == Key . Return )
126149 {
@@ -147,6 +170,11 @@ private void KeyDownHander(object sender, KeyEventArgs e)
147170 e . Handled = true ;
148171 }
149172 }
173+ private void FilterTextChanged ( object sender , TextChangedEventArgs e )
174+ {
175+ UpdateItemSource ( ) ;
176+ }
177+
150178 private void AllProcsClicked ( object sender , RoutedEventArgs e )
151179 {
152180 m_action ( null ) ;
0 commit comments