|
1 | 1 | using System;
|
| 2 | +using System.Collections; |
2 | 3 | using System.Collections.Generic;
|
3 | 4 | using System.Linq;
|
4 | 5 | using System.Text;
|
5 | 6 | using System.Text.RegularExpressions;
|
| 7 | +using System.Threading.Tasks; |
6 | 8 | using System.Windows;
|
7 | 9 | using System.Windows.Controls;
|
8 | 10 | using System.Windows.Input;
|
@@ -190,28 +192,36 @@ private void DeleteAll_CanExecute(object sender, CanExecuteRoutedEventArgs e)
|
190 | 192 | e.CanExecute = false;
|
191 | 193 | }
|
192 | 194 |
|
193 |
| - private void DeleteAll_Executed(object sender, ExecutedRoutedEventArgs e) |
| 195 | + private async void DeleteAll_Executed(object sender, ExecutedRoutedEventArgs e) |
194 | 196 | {
|
195 | 197 | if (Matches is null
|
196 | 198 | || Matches.Count < 1
|
197 | 199 | || textEditWindow is null)
|
198 | 200 | return;
|
199 | 201 |
|
200 |
| - var selection = ResultsListView.SelectedItems; |
201 |
| - if (selection.Count < 2) |
202 |
| - selection = ResultsListView.Items; |
| 202 | + SetWindowToLoading(); |
| 203 | + |
| 204 | + IList selection = ResultsListView.SelectedItems; |
| 205 | + StringBuilder stringBuilderOfText = new(textEditWindow.PassedTextControl.Text); |
203 | 206 |
|
204 |
| - for (int j = selection.Count - 1; j >= 0; j--) |
| 207 | + await Task.Run(() => |
205 | 208 | {
|
206 |
| - if (selection[j] is not FindResult selectedResult) |
207 |
| - continue; |
| 209 | + if (selection.Count < 2) |
| 210 | + selection = ResultsListView.Items; |
208 | 211 |
|
209 |
| - textEditWindow.PassedTextControl.Select(selectedResult.Index, selectedResult.Length); |
210 |
| - textEditWindow.PassedTextControl.SelectedText = string.Empty; |
211 |
| - } |
| 212 | + for (int j = selection.Count - 1; j >= 0; j--) |
| 213 | + { |
| 214 | + if (selection[j] is not FindResult selectedResult) |
| 215 | + continue; |
| 216 | + |
| 217 | + stringBuilderOfText.Remove(selectedResult.Index, selectedResult.Length); |
| 218 | + } |
| 219 | + }); |
| 220 | + |
| 221 | + textEditWindow.PassedTextControl.Text = stringBuilderOfText.ToString(); |
212 | 222 |
|
213 |
| - textEditWindow.PassedTextControl.Select(0, 0); |
214 | 223 | SearchForText();
|
| 224 | + ResetWindowLoading(); |
215 | 225 | }
|
216 | 226 |
|
217 | 227 | private void EditTextBoxChanged(object sender, TextChangedEventArgs e)
|
@@ -314,27 +324,51 @@ private void Replace_Executed(object sender, ExecutedRoutedEventArgs e)
|
314 | 324 | SearchForText();
|
315 | 325 | }
|
316 | 326 |
|
317 |
| - private void ReplaceAll_Executed(object sender, ExecutedRoutedEventArgs e) |
| 327 | + private async void ReplaceAll_Executed(object sender, ExecutedRoutedEventArgs e) |
318 | 328 | {
|
319 | 329 | if (Matches is null
|
320 | 330 | || Matches.Count < 1
|
321 | 331 | || textEditWindow is null)
|
322 | 332 | return;
|
323 | 333 |
|
324 |
| - var selection = ResultsListView.SelectedItems; |
325 |
| - if (selection.Count < 2) |
326 |
| - selection = ResultsListView.Items; |
| 334 | + SetWindowToLoading(); |
| 335 | + |
| 336 | + StringBuilder stringBuilder = new(textEditWindow.PassedTextControl.Text); |
327 | 337 |
|
328 |
| - for (int j = selection.Count - 1; j >= 0; j--) |
| 338 | + IList selection = ResultsListView.SelectedItems; |
| 339 | + string newText = ReplaceTextBox.Text; |
| 340 | + |
| 341 | + await Task.Run(() => |
329 | 342 | {
|
330 |
| - if (selection[j] is not FindResult selectedResult) |
331 |
| - continue; |
| 343 | + if (selection.Count < 2) |
| 344 | + selection = ResultsListView.Items; |
332 | 345 |
|
333 |
| - textEditWindow.PassedTextControl.Select(selectedResult.Index, selectedResult.Length); |
334 |
| - textEditWindow.PassedTextControl.SelectedText = ReplaceTextBox.Text; |
335 |
| - } |
| 346 | + for (int j = selection.Count - 1; j >= 0; j--) |
| 347 | + { |
| 348 | + if (selection[j] is not FindResult selectedResult) |
| 349 | + continue; |
| 350 | + |
| 351 | + stringBuilder.Remove(selectedResult.Index, selectedResult.Length); |
| 352 | + stringBuilder.Insert(selectedResult.Index, newText); |
| 353 | + } |
| 354 | + }); |
| 355 | + |
| 356 | + textEditWindow.PassedTextControl.Text = stringBuilder.ToString(); |
336 | 357 |
|
337 | 358 | SearchForText();
|
| 359 | + ResetWindowLoading(); |
| 360 | + } |
| 361 | + |
| 362 | + private void ResetWindowLoading() |
| 363 | + { |
| 364 | + MainContentGrid.IsEnabled = true; |
| 365 | + LoadingSpinner.Visibility = Visibility.Collapsed; |
| 366 | + } |
| 367 | + |
| 368 | + private void SetWindowToLoading() |
| 369 | + { |
| 370 | + MainContentGrid.IsEnabled = false; |
| 371 | + LoadingSpinner.Visibility = Visibility.Visible; |
338 | 372 | }
|
339 | 373 |
|
340 | 374 | private void ResultsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
0 commit comments