Skip to content

Commit 95570cc

Browse files
committed
fix cancellation message
1 parent e09990d commit 95570cc

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

GitContentSearch.UI/ViewModels/MainWindowViewModel.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ private void UpdateJoinedLogOutput()
175175
[ObservableProperty]
176176
private bool isSearching;
177177

178+
[ObservableProperty]
179+
private bool isLocating;
180+
178181
[ObservableProperty]
179182
private bool isLocateOperation;
180183

@@ -319,15 +322,16 @@ private async Task BrowseLogDirectoryAsync()
319322
[RelayCommand(CanExecute = nameof(CanLocateFile))]
320323
private void LocateFile()
321324
{
322-
if (IsSearching)
325+
if (IsLocating)
323326
{
324-
// Cancel the search
325-
LogOutput.Add("File location cancelled by user.");
327+
// Cancel the locate operation
328+
LogOutput.Add("File location operation cancelled by user.");
326329
_cancellationTokenSource?.Cancel();
327330
return;
328331
}
329332

330-
IsSearching = true;
333+
IsLocating = true;
334+
IsSearching = true; // Set this to true to maintain button behavior
331335
IsProcessingCommand = true; // Set to true when starting a command
332336
IsLocateOperation = true;
333337
ShowProgress = true;
@@ -355,6 +359,8 @@ await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
355359
LogOutput.Add($"Error: Working directory '{WorkingDirectory}' does not exist or is invalid.");
356360
ShowProgress = false;
357361
IsProcessingCommand = false; // Reset when command fails
362+
IsLocating = false;
363+
IsSearching = false;
358364
});
359365
return;
360366
}
@@ -432,10 +438,12 @@ await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
432438
{
433439
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
434440
{
435-
LogOutput.Add("File location cancelled by user.");
441+
// Don't add another cancellation message here, it was already added when Cancel was called
436442
SearchProgress = 0;
437443
ShowProgress = false;
438444
IsProcessingCommand = false; // Reset when cancelled
445+
IsLocating = false;
446+
IsSearching = false;
439447
});
440448
}
441449
catch (Exception ex)
@@ -450,6 +458,8 @@ await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
450458
SearchProgress = 0;
451459
ShowProgress = false;
452460
IsProcessingCommand = false; // Reset on error
461+
IsLocating = false;
462+
IsSearching = false;
453463
});
454464
}
455465
finally
@@ -463,6 +473,7 @@ await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
463473
// Reset the UI state on the UI thread
464474
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
465475
{
476+
IsLocating = false;
466477
IsSearching = false;
467478
IsProcessingCommand = false; // Always reset in finally block
468479
// Reset IsLocateOperation when the operation is complete
@@ -480,13 +491,17 @@ private void StartSearch()
480491
{
481492
if (IsSearching)
482493
{
483-
// Cancel the search
484-
LogOutput.Add("Search cancelled by user.");
494+
// Only add cancellation message if this is a search operation, not a locate operation
495+
if (!IsLocating)
496+
{
497+
LogOutput.Add("Search operation cancelled by user.");
498+
}
485499
_cancellationTokenSource?.Cancel();
486500
return;
487501
}
488502

489503
IsSearching = true;
504+
IsLocating = false; // Ensure IsLocating is reset when starting a search
490505
IsProcessingCommand = true; // Set to true when starting a command
491506
IsLocateOperation = false; // Reset the locate operation state when starting a search
492507
ShowProgress = true;
@@ -579,8 +594,9 @@ await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
579594
{
580595
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
581596
{
582-
LogOutput.Add("Search cancelled before it started.");
597+
// Don't add another cancellation message here
583598
IsProcessingCommand = false; // Reset when cancelled
599+
IsSearching = false;
584600
});
585601
return;
586602
}
@@ -610,10 +626,11 @@ await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
610626
{
611627
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
612628
{
613-
LogOutput.Add("Search cancelled by user.");
629+
// Don't add another cancellation message here, it was already added when Cancel was called
614630
SearchProgress = 0;
615631
ShowProgress = false;
616632
IsProcessingCommand = false; // Reset when cancelled
633+
IsSearching = false;
617634
});
618635
}
619636
catch (Exception ex)
@@ -625,6 +642,10 @@ await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
625642
{
626643
LogOutput.Add($"Inner Error: {ex.InnerException.Message}");
627644
}
645+
SearchProgress = 0;
646+
ShowProgress = false;
647+
IsProcessingCommand = false; // Reset on error
648+
IsSearching = false;
628649
});
629650
}
630651
finally

0 commit comments

Comments
 (0)