Skip to content

Commit 426d39c

Browse files
committed
Experimenting
1 parent 67e5dc0 commit 426d39c

File tree

2 files changed

+96
-9
lines changed

2 files changed

+96
-9
lines changed

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

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Novus.FileTypes;
2323
using Novus.Win32.Structures.User32;
2424
using SmartImage.Lib.Engines;
25+
using SmartImage.Lib.Results;
2526
using SmartImage.Lib.Utilities;
2627
using Attribute = Terminal.Gui.Attribute;
2728
using FileSystem = Novus.OS.FileSystem;
@@ -115,6 +116,8 @@ private void Restart_Clicked(bool force = false)
115116
Tf_Input.SetFocus();
116117
Tf_Input.EnsureFocus();
117118

119+
_keyPressHandling = false;
120+
_inputVerifying = false;
118121
}
119122

120123
/// <summary>
@@ -431,7 +434,81 @@ private async void OnResultKeyPress(View.KeyEventEventArgs eventArgs)
431434

432435
break;
433436
}
437+
case Key.X:
438+
//TODO: WIP
439+
440+
if (_keyPressHandling) {
441+
return;
442+
}
443+
444+
_keyPressHandling = true;
445+
446+
var res = m_results.SelectMany(e => e.Results).ToArray();
447+
var dr = new ConcurrentBag<SearchResultItem>();
448+
int ca = 0, cf = 0;
449+
Pbr_Status.Fraction = 0;
450+
Pbr_Status.ProgressBarStyle = ProgressBarStyle.MarqueeContinuous;
451+
452+
await Parallel.ForEachAsync(res, async (result, token) =>
453+
{
454+
var u = await result.GetUniAsync();
455+
456+
if (u) {
457+
dr.Add(result);
458+
}
459+
else {
460+
cf++;
461+
result?.Dispose();
462+
}
463+
464+
Pbr_Status.Fraction = (((float) dr.Count) / (res.Length - cf));
465+
466+
Pbr_Status.Pulse();
467+
468+
return;
469+
});
470+
Lbl_Status2.Text = $"{dr.Count} | {res.Length}";
471+
472+
var d1 = new Dialog()
473+
{
474+
Title = $"",
475+
AutoSize = false,
476+
Width = Dim.Percent(60),
477+
Height = Dim.Percent(55),
478+
// Height = UI.Dim_80_Pct,
479+
};
480+
var drCpy = dr.ToArray();
481+
482+
var lv1 = new ListView(drCpy)
483+
{
484+
Width = Dim.Fill(),
485+
Height = Dim.Percent(80),
486+
Border = new Border()
487+
{
488+
BorderStyle = BorderStyle.Rounded,
489+
BorderThickness = new Thickness(2)
490+
}
491+
};
492+
493+
var bt = new Button("Ok") { };
494+
bt.Clicked += () => { Application.RequestStop(); };
495+
d1.Add(lv1);
496+
d1.AddButton(bt);
497+
lv1.SetFocus();
498+
Application.Run(d1);
499+
500+
foreach (SearchResultItem item in dr) {
501+
item.Dispose();
502+
}
503+
504+
foreach (SearchResultItem sr in drCpy) {
505+
sr.Dispose();
506+
}
507+
508+
break;
434509
case Key.D:
510+
//TODO: WIP
511+
435512
if (sx.TryGetValue(v, out var b) && b) {
436513
return;
437514
}
@@ -541,10 +618,11 @@ private static async Task<bool> ScanResult(Url v)
541618
return false;
542619
}
543620

544-
private static int Norm(int n, int n2=0) => n == INV ? n2 : n;
621+
private static int Norm(int n, int n2 = 0) => n == INV ? n2 : n;
545622

546623
private void OnCellSelected(TableView.SelectedCellChangedEventArgs eventArgs)
547624
{
625+
// TODO: WIP
548626
var nr = (eventArgs.NewRow == INV ? eventArgs.OldRow : eventArgs.NewRow);
549627
var nc = eventArgs.NewCol == INV ? eventArgs.OldCol : eventArgs.NewCol;
550628
nr = Norm(nr);

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static ShellMode() { }
281281
private CancellationTokenSource m_token;
282282
private CancellationTokenSource m_tokenu;
283283

284-
private static int m_seq;
284+
private static int _sequence;
285285

286286
#region
287287

@@ -324,6 +324,10 @@ public bool UseClipboard
324324

325325
internal ManualResetEvent IsReady { get; set; }
326326

327+
private static bool _keyPressHandling;
328+
329+
private static bool _inputVerifying;
330+
327331
#endregion
328332

329333
#endregion
@@ -414,8 +418,8 @@ public ShellMode(string[] args)
414418
Tv_Results.Table = Dt_Results;
415419
Tv_Results.Visible = false;
416420

417-
Tv_Results.SelectedCellChanged += OnCellSelected;
418-
Tv_Results.KeyPress += OnResultKeyPress;
421+
// Tv_Results.SelectedCellChanged += OnCellSelected;
422+
Tv_Results.KeyPress += OnResultKeyPress;
419423

420424
Tv_Results.CellActivated += Result_CellActivated;
421425
Btn_Run.Clicked += Run_Clicked;
@@ -496,6 +500,7 @@ private void PostSearch()
496500
private void OnResult(object o, SearchResult result)
497501
{
498502
m_results.Add(result);
503+
499504
Application.MainLoop.Invoke(() =>
500505
{
501506
Dt_Results.Rows.Add($"{result.Engine.Name} (Raw)",
@@ -631,7 +636,7 @@ private async Task<bool> TrySetQueryAsync(ustring text)
631636
// TODO: IMPROVE
632637

633638
// Btn_Run.Enabled = false;
634-
639+
_inputVerifying = true;
635640
SearchQuery sq = await TryGetQueryAsync(text);
636641

637642
Lbl_InputOk.SetLabelStatus(null);
@@ -652,7 +657,7 @@ private async Task<bool> TrySetQueryAsync(ustring text)
652657
Lbl_Status2.Text = ustring.Empty;
653658
Btn_Delete.Enabled = false;
654659
Btn_Reload.Enabled = false;
655-
660+
_inputVerifying = false;
656661
return false;
657662
}
658663

@@ -674,6 +679,7 @@ private async Task<bool> TrySetQueryAsync(ustring text)
674679
Tf_Input.ReadOnly = true;
675680
Btn_Delete.Enabled = true;
676681
Btn_Reload.Enabled = true;
682+
_inputVerifying = false;
677683

678684
return true;
679685
}
@@ -768,14 +774,14 @@ private bool ClipboardCallback(MainLoop c)
768774
* - Input is already ready
769775
* - Clipboard history contains it already
770776
*/
771-
if (IsQueryReady()) {
777+
if (IsQueryReady() || _inputVerifying) {
772778
Debug.WriteLine($"Ignoring...");
773779
goto r1;
774780
}
775781

776782
int curSeq = Clipboard.SequenceNumber;
777-
int prevSeq = m_seq;
778-
m_seq = curSeq;
783+
int prevSeq = _sequence;
784+
_sequence = curSeq;
779785

780786
if (curSeq != prevSeq) {
781787
Debug.WriteLine($"Sequence changed", nameof(ClipboardCallback));
@@ -895,6 +901,9 @@ private void Clear()
895901

896902
// Queue.Clear();
897903
m_results.Clear();
904+
905+
_keyPressHandling = false;
906+
_inputVerifying = false;
898907
}
899908

900909
public void Close()

0 commit comments

Comments
 (0)