@@ -282,14 +282,14 @@ public void ReQuery()
282
282
{
283
283
if ( SelectedIsFromQueryResults ( ) )
284
284
{
285
- _ = QueryResultsAsync ( null , isReQuery : true ) ;
285
+ _ = QueryResultsAsync ( false , isReQuery : true ) ;
286
286
}
287
287
}
288
288
289
289
public void ReQuery ( bool reselect )
290
290
{
291
291
BackToQueryResults ( ) ;
292
- _ = QueryResultsAsync ( null , isReQuery : true , reSelect : reselect ) ;
292
+ _ = QueryResultsAsync ( false , isReQuery : true , reSelect : reselect ) ;
293
293
}
294
294
295
295
[ RelayCommand ]
@@ -622,14 +622,14 @@ public void ChangeQueryText(string queryText, bool isReQuery = false)
622
622
{
623
623
// re-query is done in QueryText's setter method
624
624
QueryText = queryText ;
625
- Query ( null ) ;
625
+ Query ( false ) ;
626
626
// set to false so the subsequent set true triggers
627
627
// PropertyChanged and MoveQueryTextToEnd is called
628
628
QueryTextCursorMovedToEnd = false ;
629
629
}
630
630
else if ( isReQuery )
631
631
{
632
- Query ( null , isReQuery : true ) ;
632
+ Query ( false , isReQuery : true ) ;
633
633
}
634
634
635
635
QueryTextCursorMovedToEnd = true ;
@@ -679,15 +679,8 @@ private ResultsViewModel SelectedResults
679
679
// setter won't be called when property value is not changed.
680
680
// so we need manually call Query()
681
681
// 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 ) ;
691
684
}
692
685
693
686
_selectedResults . Visibility = Visibility . Visible ;
@@ -955,27 +948,19 @@ private bool CanExternalPreviewSelectedResult(out string path)
955
948
956
949
#region Query
957
950
958
- public void Query ( int ? searchDelay , bool isReQuery = false )
951
+ public void Query ( bool searchDelay , bool isReQuery = false )
959
952
{
960
953
if ( SelectedIsFromQueryResults ( ) )
961
954
{
962
955
_ = QueryResultsAsync ( searchDelay , isReQuery ) ;
963
956
}
964
957
else if ( ContextMenuSelected ( ) )
965
958
{
966
- // Only query history when search delay is null or 0
967
- if ( searchDelay . GetValueOrDefault ( 0 ) == 0 )
968
- {
969
- QueryContextMenu ( ) ;
970
- }
959
+ QueryContextMenu ( ) ;
971
960
}
972
961
else if ( HistorySelected ( ) )
973
962
{
974
- // Only query history when search delay is null or 0
975
- if ( searchDelay . GetValueOrDefault ( 0 ) == 0 )
976
- {
977
- QueryHistory ( ) ;
978
- }
963
+ QueryHistory ( ) ;
979
964
}
980
965
}
981
966
@@ -1065,8 +1050,9 @@ private void QueryHistory()
1065
1050
1066
1051
private readonly IReadOnlyList < Result > _emptyResult = new List < Result > ( ) ;
1067
1052
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 )
1069
1054
{
1055
+ // TODO: Remove debug codes.
1070
1056
System . Diagnostics . Debug . WriteLine ( "!!!QueryResults" ) ;
1071
1057
1072
1058
_updateSource ? . Cancel ( ) ;
@@ -1130,60 +1116,36 @@ private async Task QueryResultsAsync(int? searchDelay, bool isReQuery = false, b
1130
1116
}
1131
1117
1132
1118
_ = 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 )
1136
1119
{
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
+ }
1139
1125
} ,
1140
1126
_updateSource . Token ,
1141
1127
TaskContinuationOptions . NotOnCanceled ,
1142
1128
TaskScheduler . Default ) ;
1143
1129
1144
1130
// plugins is ICollection, meaning LINQ will get the Count and preallocate Array
1145
1131
1146
- Task [ ] tasks ;
1147
- if ( searchDelay . HasValue )
1132
+ var tasks = plugins . Select ( plugin => plugin . Metadata . Disabled switch
1148
1133
{
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 ( ) ;
1155
1137
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 )
1168
1141
{
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 )
1178
1143
{
1179
- if ( ! plugin . Metadata . Disabled )
1180
- {
1181
- System . Diagnostics . Debug . Write ( $ "{ plugin . Metadata . Name } ") ;
1182
- }
1144
+ System . Diagnostics . Debug . Write ( $ "{ plugin . Metadata . Name } , ") ;
1183
1145
}
1184
- System . Diagnostics . Debug . Write ( "\n " ) ;
1185
1146
}
1186
-
1147
+ System . Diagnostics . Debug . Write ( "\n " ) ;
1148
+
1187
1149
try
1188
1150
{
1189
1151
// 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
1207
1169
}
1208
1170
1209
1171
// 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 )
1213
1173
{
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
+
1214
1189
// Since it is wrapped within a ThreadPool Thread, the synchronous context is null
1215
1190
// Task.Yield will force it to run in ThreadPool
1216
1191
await Task . Yield ( ) ;
1217
- }
1218
1192
1193
+ // TODO: Remove debug codes.
1194
+ System . Diagnostics . Debug . WriteLine ( $ "!!!{ query . RawQuery } Querying { plugin . Metadata . Name } ") ;
1219
1195
IReadOnlyList < Result > results =
1220
1196
await PluginManager . QueryForPluginAsync ( plugin , query , token ) ;
1221
1197
0 commit comments