33
44using System . Collections ;
55using System . Collections . Concurrent ;
6+ using System . Data ;
67using System . Diagnostics ;
78using System . Reflection ;
89using AngleSharp . Dom ;
@@ -29,6 +30,10 @@ namespace SmartImage.Mode.Shell;
2930
3031public sealed partial class ShellMode
3132{
33+ private const int INDEX = 1 ;
34+ private const int INV = - 1 ;
35+ private static readonly ConcurrentDictionary < object , ustring > Message = new ( ) ;
36+
3237 /// <summary>
3338 /// <see cref="Tv_Results" />
3439 /// </summary>
@@ -39,7 +44,8 @@ private void Result_CellActivated(TableView.CellActivatedEventArgs args)
3944 }
4045
4146 try {
42- var cell = args . Table . Rows [ args . Row ] [ args . Col ] ;
47+ var rows = args . Table . Rows ;
48+ var cell = rows [ args . Row ] [ args . Col ] ;
4349
4450 if ( cell is Url { } u ) {
4551 HttpUtilities . TryOpenUrl ( u ) ;
@@ -384,7 +390,7 @@ private async void Reload_Clicked()
384390
385391 private static readonly ConcurrentDictionary < Url , ResultMeta > Scanned = new ( ) ;
386392
387- private static ConcurrentBag < Url > sx = new ( ) ;
393+ private static ConcurrentDictionary < Url , bool > sx = new ( ) ;
388394
389395 public sealed record ResultMeta : IDisposable
390396 {
@@ -413,6 +419,11 @@ private async void OnResultKeyPress(View.KeyEventEventArgs eventArgs)
413419 c = 1 ;
414420 Url v = ( Tv_Results . Table . Rows [ r ] [ c ] ) . ToString ( ) ;
415421
422+ if ( ! Message . ContainsKey ( v ) ) {
423+ Message [ v ] = $ "?";
424+
425+ }
426+
416427 switch ( k ) {
417428 case Key . S :
418429 {
@@ -421,11 +432,13 @@ private async void OnResultKeyPress(View.KeyEventEventArgs eventArgs)
421432 break ;
422433 }
423434 case Key . D :
424- if ( sx . Contains ( v ) ) {
435+ if ( sx . TryGetValue ( v , out var b ) && b ) {
425436 return ;
426437 }
427- sx . Add ( v ) ;
428- Lbl_Status2 . Text = "...." ;
438+
439+ sx . TryAdd ( v , true ) ;
440+ Message [ v ] = "Resolving" ;
441+
429442 Pbr_Status . Pulse ( ) ;
430443 var u = await UniSource . TryGetAsync ( v , whitelist : FileType . Image ) ;
431444
@@ -450,16 +463,15 @@ private async void OnResultKeyPress(View.KeyEventEventArgs eventArgs)
450463 open :
451464 u . Dispose ( ) ;
452465 Novus . OS . FileSystem . ExploreFile ( path2 ) ;
466+ Message [ v ] = $ "Downloaded";
453467 }
454468 else {
455- Lbl_Status2 . Text = $ "Invalid";
469+ Message [ v ] = "Invalid" ;
456470 }
457471
458472 // Pbr_Status.Pulse();
459473
460- var list = sx . ToList ( ) ;
461- var bx = list . Remove ( v ) ;
462- sx = new ( list ) ;
474+ sx . TryRemove ( v , out var x ) ;
463475
464476 break ;
465477 }
@@ -470,15 +482,15 @@ private async void OnResultKeyPress(View.KeyEventEventArgs eventArgs)
470482 private static async Task < bool > ScanResult ( Url v )
471483 {
472484
473- if ( sx . Contains ( v ) ) {
485+ if ( sx . ContainsKey ( v ) ) {
474486 Lbl_Status2 . Text = $ "Scanning...!";
475487 Lbl_Status2 . SetNeedsDisplay ( ) ;
476488 return true ;
477489 }
478490 else {
479491 Lbl_Status2 . Text = $ "Scanning started...!";
480492 Lbl_Status2 . SetNeedsDisplay ( ) ;
481- sx . Add ( v ) ;
493+ sx . TryAdd ( v , true ) ;
482494
483495 }
484496
@@ -528,4 +540,25 @@ private static async Task<bool> ScanResult(Url v)
528540
529541 return false ;
530542 }
543+
544+ private static int Norm ( int n , int n2 = 0 ) => n == INV ? n2 : n ;
545+
546+ private void OnCellSelected ( TableView . SelectedCellChangedEventArgs eventArgs )
547+ {
548+ var nr = ( eventArgs . NewRow == INV ? eventArgs . OldRow : eventArgs . NewRow ) ;
549+ var nc = eventArgs . NewCol == INV ? eventArgs . OldCol : eventArgs . NewCol ;
550+ nr = Norm ( nr ) ;
551+ nc = Norm ( nc ) ;
552+
553+ var cell = eventArgs . Table . Rows [ nr ] [ nc ] ;
554+ var cell2 = eventArgs . Table . Rows [ nr ] [ INDEX ] ;
555+
556+ if ( Message . ContainsKey ( cell ) ) {
557+ Lbl_Status2 . Text = Message [ cell ] ;
558+ }
559+
560+ else if ( Message . ContainsKey ( cell2 ) ) {
561+ Lbl_Status2 . Text = Message [ cell2 ] ;
562+ }
563+ }
531564}
0 commit comments