Upload FastSeekWpf/MainWindow.xaml.cs
Browse files- FastSeekWpf/MainWindow.xaml.cs +64 -51
FastSeekWpf/MainWindow.xaml.cs
CHANGED
|
@@ -64,10 +64,7 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
| 64 |
if (_initialized) return;
|
| 65 |
_initialized = true;
|
| 66 |
|
| 67 |
-
Task.Run(async () =>
|
| 68 |
-
{
|
| 69 |
-
await InitializeAsync();
|
| 70 |
-
});
|
| 71 |
}
|
| 72 |
|
| 73 |
private async Task InitializeAsync()
|
|
@@ -84,6 +81,7 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
| 84 |
}
|
| 85 |
|
| 86 |
// Try cache first
|
|
|
|
| 87 |
var cache = CacheManager.LoadCache();
|
| 88 |
if (cache != null)
|
| 89 |
{
|
|
@@ -95,6 +93,7 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
| 95 |
|
| 96 |
// Delta catch-up
|
| 97 |
var checkpoints = new List<JournalCheckpoint>(cache.Checkpoints);
|
|
|
|
| 98 |
foreach (var drive in _drives)
|
| 99 |
{
|
| 100 |
var cp = checkpoints.FirstOrDefault(c => c.DriveLetter == drive.Letter);
|
|
@@ -111,24 +110,34 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
| 111 |
}
|
| 112 |
_watchers.Add(watcher);
|
| 113 |
}
|
| 114 |
-
catch
|
| 115 |
{
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
}
|
| 120 |
}
|
| 121 |
}
|
| 122 |
|
| 123 |
-
|
| 124 |
-
while (_eventQueue.TryDequeue(out var evt))
|
| 125 |
{
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
}
|
| 128 |
}
|
| 129 |
-
|
|
|
|
| 130 |
{
|
| 131 |
-
fullscan:
|
| 132 |
lock (_indexLock)
|
| 133 |
{
|
| 134 |
_index = new IndexStore();
|
|
@@ -186,13 +195,9 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
| 186 |
processed++;
|
| 187 |
if (processed > 100) break; // Batch limit
|
| 188 |
}
|
| 189 |
-
if (processed >
|
| 190 |
{
|
| 191 |
-
|
| 192 |
-
if (processed > 50)
|
| 193 |
-
{
|
| 194 |
-
CacheManager.SaveCache(_index);
|
| 195 |
-
}
|
| 196 |
}
|
| 197 |
Thread.Sleep(100);
|
| 198 |
}
|
|
@@ -307,41 +312,46 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
| 307 |
var query = SearchBox.Text.Trim();
|
| 308 |
if (string.IsNullOrEmpty(query))
|
| 309 |
{
|
| 310 |
-
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
| 312 |
return;
|
| 313 |
}
|
| 314 |
|
|
|
|
| 315 |
lock (_indexLock)
|
| 316 |
{
|
| 317 |
-
|
| 318 |
-
var items = results.Select((r, i) => new ResultItem
|
| 319 |
-
{
|
| 320 |
-
FullPath = r.FullPath,
|
| 321 |
-
DisplayName = Path.GetFileNameWithoutExtension(r.FullPath),
|
| 322 |
-
IsSelected = i == 0,
|
| 323 |
-
IsHovered = false,
|
| 324 |
-
Kind = r.Kind,
|
| 325 |
-
IconGlyph = GetIconGlyph(r.Kind),
|
| 326 |
-
BadgeLabel = GetBadgeLabel(r.Kind),
|
| 327 |
-
BadgeColor = GetBadgeColor(r.Kind)
|
| 328 |
-
}).ToList();
|
| 329 |
-
|
| 330 |
-
Dispatcher.Invoke(() =>
|
| 331 |
-
{
|
| 332 |
-
_selectedIndex = 0;
|
| 333 |
-
Results = items;
|
| 334 |
-
UpdateVisibility();
|
| 335 |
-
StatusText.Text = $"{items.Count} results";
|
| 336 |
-
});
|
| 337 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
}
|
| 339 |
|
| 340 |
private void UpdateVisibility()
|
| 341 |
{
|
| 342 |
bool hasResults = Results.Count > 0;
|
| 343 |
SepLine.Visibility = hasResults ? Visibility.Visible : Visibility.Collapsed;
|
| 344 |
-
|
| 345 |
StatusBar.Visibility = Visibility.Visible;
|
| 346 |
}
|
| 347 |
|
|
@@ -349,12 +359,20 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
| 349 |
{
|
| 350 |
if (Results.Count == 0 || newIndex < 0 || newIndex >= Results.Count) return;
|
| 351 |
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
|
|
|
|
|
|
| 356 |
_selectedIndex = newIndex;
|
| 357 |
Results = items;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
}
|
| 359 |
|
| 360 |
// -- Mouse --
|
|
@@ -381,11 +399,6 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
| 381 |
}
|
| 382 |
}
|
| 383 |
|
| 384 |
-
private void ResultItem_Up(object sender, MouseButtonEventArgs e)
|
| 385 |
-
{
|
| 386 |
-
// Double-click handled separately if needed
|
| 387 |
-
}
|
| 388 |
-
|
| 389 |
private void OpenResult(bool folderOnly)
|
| 390 |
{
|
| 391 |
if (Results.Count == 0 || _selectedIndex < 0 || _selectedIndex >= Results.Count) return;
|
|
|
|
| 64 |
if (_initialized) return;
|
| 65 |
_initialized = true;
|
| 66 |
|
| 67 |
+
Task.Run(async () => await InitializeAsync());
|
|
|
|
|
|
|
|
|
|
| 68 |
}
|
| 69 |
|
| 70 |
private async Task InitializeAsync()
|
|
|
|
| 81 |
}
|
| 82 |
|
| 83 |
// Try cache first
|
| 84 |
+
bool needFullScan = true;
|
| 85 |
var cache = CacheManager.LoadCache();
|
| 86 |
if (cache != null)
|
| 87 |
{
|
|
|
|
| 93 |
|
| 94 |
// Delta catch-up
|
| 95 |
var checkpoints = new List<JournalCheckpoint>(cache.Checkpoints);
|
| 96 |
+
bool deltaOk = true;
|
| 97 |
foreach (var drive in _drives)
|
| 98 |
{
|
| 99 |
var cp = checkpoints.FirstOrDefault(c => c.DriveLetter == drive.Letter);
|
|
|
|
| 110 |
}
|
| 111 |
_watchers.Add(watcher);
|
| 112 |
}
|
| 113 |
+
catch (Exception ex)
|
| 114 |
{
|
| 115 |
+
Debug.WriteLine($"Delta catch-up failed: {ex.Message}");
|
| 116 |
+
deltaOk = false;
|
| 117 |
+
break;
|
| 118 |
}
|
| 119 |
}
|
| 120 |
}
|
| 121 |
|
| 122 |
+
if (deltaOk)
|
|
|
|
| 123 |
{
|
| 124 |
+
needFullScan = false;
|
| 125 |
+
// Apply delta events
|
| 126 |
+
while (_eventQueue.TryDequeue(out var evt))
|
| 127 |
+
{
|
| 128 |
+
ApplyEvent(evt);
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
else
|
| 132 |
+
{
|
| 133 |
+
CacheManager.ClearCache();
|
| 134 |
+
_watchers.Clear();
|
| 135 |
+
_eventQueue.Clear();
|
| 136 |
}
|
| 137 |
}
|
| 138 |
+
|
| 139 |
+
if (needFullScan)
|
| 140 |
{
|
|
|
|
| 141 |
lock (_indexLock)
|
| 142 |
{
|
| 143 |
_index = new IndexStore();
|
|
|
|
| 195 |
processed++;
|
| 196 |
if (processed > 100) break; // Batch limit
|
| 197 |
}
|
| 198 |
+
if (processed > 50)
|
| 199 |
{
|
| 200 |
+
CacheManager.SaveCache(_index);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
}
|
| 202 |
Thread.Sleep(100);
|
| 203 |
}
|
|
|
|
| 312 |
var query = SearchBox.Text.Trim();
|
| 313 |
if (string.IsNullOrEmpty(query))
|
| 314 |
{
|
| 315 |
+
Dispatcher.Invoke(() =>
|
| 316 |
+
{
|
| 317 |
+
Results = new List<ResultItem>();
|
| 318 |
+
UpdateVisibility();
|
| 319 |
+
});
|
| 320 |
return;
|
| 321 |
}
|
| 322 |
|
| 323 |
+
List<SearchResult> results;
|
| 324 |
lock (_indexLock)
|
| 325 |
{
|
| 326 |
+
results = SearchEngine.Search(_index, query, 50, _caseSensitive, _excludedDirs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
}
|
| 328 |
+
|
| 329 |
+
var items = results.Select((r, i) => new ResultItem
|
| 330 |
+
{
|
| 331 |
+
FullPath = r.FullPath,
|
| 332 |
+
DisplayName = Path.GetFileNameWithoutExtension(r.FullPath),
|
| 333 |
+
IsSelected = i == 0,
|
| 334 |
+
IsHovered = false,
|
| 335 |
+
Kind = r.Kind,
|
| 336 |
+
IconGlyph = GetIconGlyph(r.Kind),
|
| 337 |
+
BadgeLabel = GetBadgeLabel(r.Kind),
|
| 338 |
+
BadgeColor = GetBadgeColor(r.Kind)
|
| 339 |
+
}).ToList();
|
| 340 |
+
|
| 341 |
+
Dispatcher.Invoke(() =>
|
| 342 |
+
{
|
| 343 |
+
_selectedIndex = 0;
|
| 344 |
+
Results = items;
|
| 345 |
+
UpdateVisibility();
|
| 346 |
+
StatusText.Text = $"{items.Count} results";
|
| 347 |
+
});
|
| 348 |
}
|
| 349 |
|
| 350 |
private void UpdateVisibility()
|
| 351 |
{
|
| 352 |
bool hasResults = Results.Count > 0;
|
| 353 |
SepLine.Visibility = hasResults ? Visibility.Visible : Visibility.Collapsed;
|
| 354 |
+
ResultsScroll.Visibility = hasResults ? Visibility.Visible : Visibility.Collapsed;
|
| 355 |
StatusBar.Visibility = Visibility.Visible;
|
| 356 |
}
|
| 357 |
|
|
|
|
| 359 |
{
|
| 360 |
if (Results.Count == 0 || newIndex < 0 || newIndex >= Results.Count) return;
|
| 361 |
|
| 362 |
+
// Use new list to trigger PropertyChanged
|
| 363 |
+
var items = Results.Select((r, i) => r with
|
| 364 |
+
{
|
| 365 |
+
IsSelected = i == newIndex,
|
| 366 |
+
IsHovered = i == newIndex
|
| 367 |
+
}).ToList();
|
| 368 |
_selectedIndex = newIndex;
|
| 369 |
Results = items;
|
| 370 |
+
|
| 371 |
+
// Scroll selected item into view
|
| 372 |
+
if (ResultsList.ItemContainerGenerator.ContainerFromIndex(newIndex) is FrameworkElement container)
|
| 373 |
+
{
|
| 374 |
+
container.BringIntoView();
|
| 375 |
+
}
|
| 376 |
}
|
| 377 |
|
| 378 |
// -- Mouse --
|
|
|
|
| 399 |
}
|
| 400 |
}
|
| 401 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
private void OpenResult(bool folderOnly)
|
| 403 |
{
|
| 404 |
if (Results.Count == 0 || _selectedIndex < 0 || _selectedIndex >= Results.Count) return;
|