Skip to content

Commit 67e5dc0

Browse files
committed
Work on UI
1 parent 3ea6383 commit 67e5dc0

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

SmartImage 3/Mode/Shell/ShellMode.Handlers.cs

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections;
55
using System.Collections.Concurrent;
6+
using System.Data;
67
using System.Diagnostics;
78
using System.Reflection;
89
using AngleSharp.Dom;
@@ -29,6 +30,10 @@ namespace SmartImage.Mode.Shell;
2930

3031
public 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
}

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ public ShellMode(string[] args)
414414
Tv_Results.Table = Dt_Results;
415415
Tv_Results.Visible = false;
416416

417-
Tv_Results.KeyPress += OnResultKeyPress;
417+
Tv_Results.SelectedCellChanged += OnCellSelected;
418+
Tv_Results.KeyPress += OnResultKeyPress;
418419

419420
Tv_Results.CellActivated += Result_CellActivated;
420421
Btn_Run.Clicked += Run_Clicked;
@@ -495,12 +496,12 @@ private void PostSearch()
495496
private void OnResult(object o, SearchResult result)
496497
{
497498
m_results.Add(result);
498-
499499
Application.MainLoop.Invoke(() =>
500500
{
501501
Dt_Results.Rows.Add($"{result.Engine.Name} (Raw)",
502502
result.RawUrl, 0, 0, null, $"{result.Status}",
503503
null, null, null, null, null, null);
504+
Message[result.RawUrl] = "?";
504505

505506
for (int i = 0; i < result.Results.Count; i++) {
506507
SearchResultItem sri = result.Results[i];
@@ -585,6 +586,7 @@ private void ProcessArgs()
585586
Config.AutoSearch = Args.Contains(R2.Arg_AutoSearch);
586587

587588
}
589+
588590
var e = Args.GetEnumerator();
589591

590592
while (e.MoveNext()) {
@@ -766,6 +768,10 @@ private bool ClipboardCallback(MainLoop c)
766768
* - Input is already ready
767769
* - Clipboard history contains it already
768770
*/
771+
if (IsQueryReady()) {
772+
Debug.WriteLine($"Ignoring...");
773+
goto r1;
774+
}
769775

770776
int curSeq = Clipboard.SequenceNumber;
771777
int prevSeq = m_seq;

0 commit comments

Comments
 (0)