@@ -282,14 +282,14 @@ public void ReQuery()
282282 {
283283 if ( SelectedIsFromQueryResults ( ) )
284284 {
285- _ = QueryResultsAsync ( null , isReQuery : true ) ;
285+ _ = QueryResultsAsync ( false , isReQuery : true ) ;
286286 }
287287 }
288288
289289 public void ReQuery ( bool reselect )
290290 {
291291 BackToQueryResults ( ) ;
292- _ = QueryResultsAsync ( null , isReQuery : true , reSelect : reselect ) ;
292+ _ = QueryResultsAsync ( false , isReQuery : true , reSelect : reselect ) ;
293293 }
294294
295295 [ RelayCommand ]
@@ -622,14 +622,14 @@ public void ChangeQueryText(string queryText, bool isReQuery = false)
622622 {
623623 // re-query is done in QueryText's setter method
624624 QueryText = queryText ;
625- Query ( null ) ;
625+ Query ( false ) ;
626626 // set to false so the subsequent set true triggers
627627 // PropertyChanged and MoveQueryTextToEnd is called
628628 QueryTextCursorMovedToEnd = false ;
629629 }
630630 else if ( isReQuery )
631631 {
632- Query ( null , isReQuery : true ) ;
632+ Query ( false , isReQuery : true ) ;
633633 }
634634
635635 QueryTextCursorMovedToEnd = true ;
@@ -679,15 +679,8 @@ private ResultsViewModel SelectedResults
679679 // setter won't be called when property value is not changed.
680680 // so we need manually call Query()
681681 // http://stackoverflow.com/posts/25895769/revisions
682- if ( string . IsNullOrEmpty ( QueryText ) )
683- {
684- Query ( null ) ;
685- }
686- else
687- {
688- QueryText = string . Empty ;
689- Query ( null ) ;
690- }
682+ QueryText = string . Empty ;
683+ Query ( false ) ;
691684 }
692685
693686 _selectedResults . Visibility = Visibility . Visible ;
@@ -955,27 +948,19 @@ private bool CanExternalPreviewSelectedResult(out string path)
955948
956949 #region Query
957950
958- public void Query ( int ? searchDelay , bool isReQuery = false )
951+ public void Query ( bool searchDelay , bool isReQuery = false )
959952 {
960953 if ( SelectedIsFromQueryResults ( ) )
961954 {
962955 _ = QueryResultsAsync ( searchDelay , isReQuery ) ;
963956 }
964957 else if ( ContextMenuSelected ( ) )
965958 {
966- // Only query history when search delay is null or 0
967- if ( searchDelay . GetValueOrDefault ( 0 ) == 0 )
968- {
969- QueryContextMenu ( ) ;
970- }
959+ QueryContextMenu ( ) ;
971960 }
972961 else if ( HistorySelected ( ) )
973962 {
974- // Only query history when search delay is null or 0
975- if ( searchDelay . GetValueOrDefault ( 0 ) == 0 )
976- {
977- QueryHistory ( ) ;
978- }
963+ QueryHistory ( ) ;
979964 }
980965 }
981966
@@ -1065,8 +1050,9 @@ private void QueryHistory()
10651050
10661051 private readonly IReadOnlyList < Result > _emptyResult = new List < Result > ( ) ;
10671052
1068- private async Task QueryResultsAsync ( int ? searchDelay , bool isReQuery = false , bool reSelect = true )
1053+ private async Task QueryResultsAsync ( bool searchDelay , bool isReQuery = false , bool reSelect = true )
10691054 {
1055+ // TODO: Remove debug codes.
10701056 System . Diagnostics . Debug . WriteLine ( "!!!QueryResults" ) ;
10711057
10721058 _updateSource ? . Cancel ( ) ;
@@ -1130,60 +1116,36 @@ private async Task QueryResultsAsync(int? searchDelay, bool isReQuery = false, b
11301116 }
11311117
11321118 _ = Task . Delay ( 200 , _updateSource . Token ) . ContinueWith ( _ =>
1133- {
1134- // start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
1135- if ( ! _updateSource . Token . IsCancellationRequested && _isQueryRunning )
11361119 {
1137- ProgressBarVisibility = Visibility . Visible ;
1138- }
1120+ // start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
1121+ if ( ! _updateSource . Token . IsCancellationRequested && _isQueryRunning )
1122+ {
1123+ ProgressBarVisibility = Visibility . Visible ;
1124+ }
11391125 } ,
11401126 _updateSource . Token ,
11411127 TaskContinuationOptions . NotOnCanceled ,
11421128 TaskScheduler . Default ) ;
11431129
11441130 // plugins is ICollection, meaning LINQ will get the Count and preallocate Array
11451131
1146- Task [ ] tasks ;
1147- if ( searchDelay . HasValue )
1132+ var tasks = plugins . Select ( plugin => plugin . Metadata . Disabled switch
11481133 {
1149- var searchDelayValue = searchDelay . Value ;
1150- tasks = plugins . Select ( plugin => ( plugin . Metadata . Disabled || plugin . Metadata . SearchDelay != searchDelayValue ) switch
1151- {
1152- false => QueryTaskAsync ( plugin , reSelect ) ,
1153- true => Task . CompletedTask
1154- } ) . ToArray ( ) ;
1134+ false => QueryTaskAsync ( plugin , searchDelay , reSelect , _updateSource . Token ) ,
1135+ true => Task . CompletedTask
1136+ } ) . ToArray ( ) ;
11551137
1156- // TODO: Remove debug codes.
1157- System . Diagnostics . Debug . Write ( $ "!!!{ query . RawQuery } Querying { searchDelayValue } ms") ;
1158- foreach ( var plugin in plugins )
1159- {
1160- if ( ! ( plugin . Metadata . Disabled || plugin . Metadata . SearchDelay != searchDelayValue ) )
1161- {
1162- System . Diagnostics . Debug . Write ( $ "{ plugin . Metadata . Name } ") ;
1163- }
1164- }
1165- System . Diagnostics . Debug . Write ( "\n " ) ;
1166- }
1167- else
1138+ // TODO: Remove debug codes.
1139+ System . Diagnostics . Debug . Write ( $ "!!!Querying { query . RawQuery } : search dalay { searchDelay } ") ;
1140+ foreach ( var plugin in plugins )
11681141 {
1169- tasks = plugins . Select ( plugin => plugin . Metadata . Disabled switch
1170- {
1171- false => QueryTaskAsync ( plugin , reSelect ) ,
1172- true => Task . CompletedTask
1173- } ) . ToArray ( ) ;
1174-
1175- // TODO: Remove debug codes.
1176- System . Diagnostics . Debug . Write ( $ "!!!{ query . RawQuery } Querying null ms") ;
1177- foreach ( var plugin in plugins )
1142+ if ( ! plugin . Metadata . Disabled )
11781143 {
1179- if ( ! plugin . Metadata . Disabled )
1180- {
1181- System . Diagnostics . Debug . Write ( $ "{ plugin . Metadata . Name } ") ;
1182- }
1144+ System . Diagnostics . Debug . Write ( $ "{ plugin . Metadata . Name } , ") ;
11831145 }
1184- System . Diagnostics . Debug . Write ( "\n " ) ;
11851146 }
1186-
1147+ System . Diagnostics . Debug . Write ( "\n " ) ;
1148+
11871149 try
11881150 {
11891151 // Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
@@ -1207,15 +1169,29 @@ private async Task QueryResultsAsync(int? searchDelay, bool isReQuery = false, b
12071169 }
12081170
12091171 // Local function
1210- async Task QueryTaskAsync ( bool searchDelay , PluginPair plugin , bool reSelect , CancellationToken token )
1211- {
1212- if ( ! searchDelay )
1172+ async Task QueryTaskAsync ( PluginPair plugin , bool searchDelay , bool reSelect , CancellationToken token )
12131173 {
1174+ if ( searchDelay )
1175+ {
1176+ // TODO: Remove debug codes.
1177+ System . Diagnostics . Debug . WriteLine ( $ "!!!{ plugin . Metadata . Name } Waiting { plugin . Metadata . SearchDelay } ms") ;
1178+
1179+ // TODO: Remove debug codes.
1180+ await Task . Delay ( plugin . Metadata . SearchDelay * 60 , token ) ;
1181+
1182+ // TODO: Remove debug codes.
1183+ System . Diagnostics . Debug . WriteLine ( $ "!!!{ plugin . Metadata . Name } Waited { plugin . Metadata . SearchDelay } ms") ;
1184+
1185+ if ( token . IsCancellationRequested )
1186+ return ;
1187+ }
1188+
12141189 // Since it is wrapped within a ThreadPool Thread, the synchronous context is null
12151190 // Task.Yield will force it to run in ThreadPool
12161191 await Task . Yield ( ) ;
1217- }
12181192
1193+ // TODO: Remove debug codes.
1194+ System . Diagnostics . Debug . WriteLine ( $ "!!!{ query . RawQuery } Querying { plugin . Metadata . Name } ") ;
12191195 IReadOnlyList < Result > results =
12201196 await PluginManager . QueryForPluginAsync ( plugin , query , token ) ;
12211197
0 commit comments