Skip to content

Commit f28e5c2

Browse files
committed
Add about dialog
UI improvements
1 parent 001ea04 commit f28e5c2

File tree

5 files changed

+136
-73
lines changed

5 files changed

+136
-73
lines changed

SmartImage 3/Modes/BaseProgramMode.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ protected BaseProgramMode(string[] args1, SearchQuery? sq = null)
3838

3939
protected ProgramStatus Status { get; set; }
4040

41-
protected string[] Args { get; set; }
41+
protected string[] Args { get; init; }
4242

4343
protected int ResultCount { get; set; }
4444

45-
public ManualResetEvent IsReady { get; protected set; }
46-
47-
protected CancellationTokenSource Token { get; set; }
48-
45+
public ManualResetEvent IsReady { get; protected set; }
46+
47+
protected CancellationTokenSource Token { get; set; }
48+
4949
public virtual async Task<object?> RunAsync(object? sender = null)
5050
{
5151
var now = Stopwatch.StartNew();
@@ -79,11 +79,11 @@ protected BaseProgramMode(string[] args1, SearchQuery? sq = null)
7979

8080
protected virtual void ProcessArgs()
8181
{
82-
var enumer = Args.GetEnumerator();
82+
var e = Args.GetEnumerator();
8383

84-
while (enumer.MoveNext()) {
85-
var val = enumer.Current;
86-
ProcessArg(val, enumer);
84+
while (e.MoveNext()) {
85+
var val = e.Current;
86+
ProcessArg(val, e);
8787
}
8888
}
8989

@@ -94,8 +94,6 @@ public virtual void Dispose()
9494
Client.Dispose();
9595
Query.Dispose();
9696
Token.Dispose();
97-
98-
// QueryMat?.Dispose();
9997
}
10098
}
10199

SmartImage 3/Modes/GuiMode.cs

Lines changed: 109 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using Attribute = Terminal.Gui.Attribute;
3434
using Color = Terminal.Gui.Color;
3535
using SmartImage.UI;
36+
using Size = Terminal.Gui.Size;
3637

3738
// ReSharper disable InconsistentNaming
3839

@@ -207,15 +208,10 @@ public GuiMode(string[] args) : base(args, SearchQuery.Null)
207208
m_cbCallbackTok = Application.MainLoop.AddTimeout(TimeoutTimeSpan, ClipboardCallback);
208209

209210
m_clipboard = new List<ustring>();
210-
211-
/*m_tok = Application.MainLoop.AddIdle(() =>
212-
{
213-
return ClipboardCallback(null);
214-
});*/
215-
211+
216212
Mb_Menu.Menus = new MenuBarItem[]
217213
{
218-
// new("_Config", null, ConfigDialog),
214+
new("_About", null, AboutDialog),
219215
};
220216

221217
Top.Add(Mb_Menu);
@@ -454,8 +450,7 @@ private async Task<bool> SetQuery(ustring text)
454450

455451
Lbl_InputOk.Text = Values.OK;
456452

457-
Query = sq;
458-
// QueryMat = Mat.FromImageData(Query.Stream.ToByteArray()); // todo: advances stream position?
453+
Query = sq;
459454
Status = ProgramStatus.Signal;
460455

461456
Lbl_InputInfo.Text = $"[{(sq.IsFile ? "File" : "Uri")}] ({sq.FileTypes.First()})";
@@ -474,7 +469,8 @@ private bool ClipboardCallback(MainLoop c)
474469
* - Input is already semiprimed
475470
* - Clipboard history contains it already
476471
*/
477-
if (Integration.ReadClipboard(out var str) && !IsInputValidIndicator() && !m_clipboard.Contains(str)) {
472+
if (Integration.ReadClipboard(out var str) &&
473+
!IsInputValidIndicator() && !m_clipboard.Contains(str)) {
478474
SetInputText(str);
479475
// Lbl_InputOk.Text = Values.Clp;
480476
Lbl_InputInfo.Text = $"Clipboard data";
@@ -502,13 +498,56 @@ private void OnClear()
502498
Tf_Input.DeleteAll();
503499
Lbl_InputOk.Text = Values.NA;
504500
Lbl_InputOk.SetNeedsDisplay();
505-
Lbl_InputInfo.Text = ustring.Empty;
501+
Lbl_InputInfo.Text = ustring.Empty;
506502
Lbl_InputInfo2.Text = ustring.Empty;
507503
}
508504

505+
private void AboutDialog()
506+
{
507+
var d = new Dialog()
508+
{
509+
Text = $"{R2.Name}",
510+
Title = R2.Name,
511+
AutoSize = true,
512+
Width = Dim.Percent(30),
513+
Height = Dim.Percent(30),
514+
};
515+
516+
void RefreshDialog()
517+
{
518+
d.SetNeedsDisplay();
519+
}
520+
521+
var b1 = new Button() { AutoSize = true, Text = $"Repo", };
522+
523+
b1.Clicked += () =>
524+
{
525+
HttpUtilities.TryOpenUrl(R2.Repo_Url);
526+
RefreshDialog();
527+
};
528+
529+
var b2 = new Button() { AutoSize = true, Text = $"Wiki", };
530+
531+
b2.Clicked += () =>
532+
{
533+
HttpUtilities.TryOpenUrl(R2.Wiki_Url);
534+
RefreshDialog();
535+
};
536+
537+
var b3 = new Button() { Text = $"Ok", AutoSize = true, };
538+
539+
b3.Clicked += () => { Application.RequestStop(); };
540+
541+
d.AddButton(b1);
542+
d.AddButton(b2);
543+
d.AddButton(b3);
544+
545+
Application.Run(d);
546+
}
547+
509548
private void OnConfigDialog()
510549
{
511-
var about = new Dialog("Configuration")
550+
var dlCfg = new Dialog("Configuration")
512551
{
513552
Text = ustring.Empty,
514553
AutoSize = false,
@@ -523,13 +562,31 @@ private void OnConfigDialog()
523562
const int WIDTH = 15;
524563
const int HEIGHT = 20;
525564

565+
Label lbSearchEngines = new(R1.S_SearchEngines)
566+
{
567+
X = 0,
568+
Y = 0,
569+
AutoSize = true,
570+
ColorScheme = Styles.Cs_Lbl1
571+
};
572+
526573
ListView lvSearchEngines = new(ConsoleUtil.EngineOptions)
527574
{
528575
AllowsMultipleSelection = true,
529576
AllowsMarking = true,
530577
AutoSize = true,
531578
Width = WIDTH,
532579
Height = HEIGHT,
580+
581+
Y = Pos.Bottom(lbSearchEngines)
582+
};
583+
584+
Label lbPriorityEngines = new(R1.S_PriorityEngines)
585+
{
586+
X = Pos.Right(lbSearchEngines) + 1,
587+
Y = 0,
588+
AutoSize = true,
589+
ColorScheme = Styles.Cs_Lbl1
533590
};
534591

535592
ListView lvPriorityEngines = new(ConsoleUtil.EngineOptions)
@@ -539,13 +596,15 @@ private void OnConfigDialog()
539596
AutoSize = true,
540597
Width = WIDTH,
541598
Height = HEIGHT,
542-
X = Pos.Right(lvSearchEngines)
599+
600+
Y = Pos.Bottom(lbPriorityEngines),
601+
X = Pos.Right(lvSearchEngines) + 1
543602
};
544603

545604
CheckBox cbContextMenu = new(R2.Int_ContextMenu)
546605
{
547606
Y = Pos.Bottom(lvSearchEngines),
548-
Width = 15,
607+
Width = WIDTH,
549608
Height = 1,
550609
};
551610

@@ -558,16 +617,35 @@ private void OnConfigDialog()
558617
{
559618
X = Pos.Right(cbContextMenu),
560619
Y = Pos.Bottom(lvPriorityEngines),
561-
Width = 15,
620+
Width = WIDTH,
562621
Height = 1,
563622
};
564623

624+
var cfgInfo = new FileInfo(SearchConfig.Configuration.FilePath);
625+
626+
ustring s = $"Config";
627+
628+
Label lbConfig = new(s)
629+
{
630+
X = Pos.Right(lbPriorityEngines) + 1,
631+
Y = 0,
632+
AutoSize = true,
633+
ColorScheme = Styles.Cs_Lbl1
634+
// Height = 10,
635+
};
636+
565637
var tvConfig = new TableView(dtConfig)
566638
{
567639
AutoSize = true,
568-
X = Pos.Right(lvPriorityEngines),
640+
Y = Pos.Bottom(lbConfig),
641+
X = Pos.Right(lvPriorityEngines) + 1,
569642
Width = Dim.Fill(WIDTH),
570-
Height = 10,
643+
Height = 7,
644+
};
645+
646+
lbConfig.Clicked += () =>
647+
{
648+
FileSystem.ExploreFile(cfgInfo.FullName);
571649
};
572650

573651
cbOnTop.Toggled += b =>
@@ -599,7 +677,7 @@ void ReloadDialog()
599677
{
600678
tvConfig.Table = Config.ToTable();
601679
tvConfig.SetNeedsDisplay();
602-
about.SetNeedsDisplay();
680+
dlCfg.SetNeedsDisplay();
603681
}
604682

605683
lvSearchEngines.FromEnum(Config.SearchEngines);
@@ -620,14 +698,14 @@ void ReloadDialog()
620698
ReloadDialog();
621699
};
622700

623-
about.Add(tvConfig, lvSearchEngines, lvPriorityEngines,
624-
cbContextMenu, cbOnTop);
701+
dlCfg.Add(tvConfig, lvSearchEngines, lvPriorityEngines,
702+
cbContextMenu, cbOnTop, lbConfig, lbSearchEngines, lbPriorityEngines);
625703

626-
about.AddButton(btnRefresh);
627-
about.AddButton(btnOk);
628-
about.AddButton(btnSave);
704+
dlCfg.AddButton(btnRefresh);
705+
dlCfg.AddButton(btnOk);
706+
dlCfg.AddButton(btnSave);
629707

630-
Application.Run(about);
708+
Application.Run(dlCfg);
631709

632710
Tf_Input.SetFocus();
633711
Tf_Input.EnsureFocus();
@@ -639,7 +717,7 @@ private void ClearControls()
639717
Tf_Input.ClearHistoryChanges();
640718

641719
Query = SearchQuery.Null;
642-
720+
643721
Lbl_InputOk.Text = Values.NA;
644722
Lbl_InputOk.SetNeedsDisplay();
645723

@@ -658,16 +736,6 @@ private void ClearControls()
658736
Tf_Input.SetFocus();
659737
Tf_Input.EnsureFocus();
660738
Btn_Cancel.Enabled = false;
661-
662-
/*Application.MainLoop.Invoke(() =>
663-
{ });*/
664-
665-
/*try {
666-
// Application.Refresh();
667-
}
668-
catch (Exception e) {
669-
Debug.WriteLine($"{e.Message}", nameof(ClearControls));
670-
}*/
671739
}
672740

673741
private void OnRestart()
@@ -681,22 +749,20 @@ private void OnRestart()
681749
Tv_Results.RowOffset = 0;
682750
Tv_Results.ColumnOffset = 0;
683751
Dt_Results.Clear();
752+
Tv_Results.Visible = false;
684753

685754
m_clipboard.Clear();
686755

687756
Status = ProgramStatus.Restart;
688757
Btn_Restart.Enabled = false;
689-
Btn_Cancel.Enabled = false;
758+
Btn_Cancel.Enabled = false;
690759
Btn_Run.Enabled = true;
691760

692761
Token.Dispose();
693762
Token = new();
694763

695764
Tf_Input.SetFocus();
696765
Tf_Input.EnsureFocus();
697-
698-
/*Application.MainLoop.Invoke(() =>
699-
{ });*/
700766
}
701767

702768
private void OnCellActivated(TableView.CellActivatedEventArgs args)
@@ -757,11 +823,14 @@ private async void OnRun()
757823
{
758824
Btn_Run.Enabled = false;
759825
Btn_Cancel.Enabled = true;
826+
Tv_Results.Visible = true;
760827
var text = Tf_Input.Text;
761828

762-
Debug.WriteLine($"{text}", nameof(OnRun));
829+
Debug.WriteLine($"Input: {text}", nameof(OnRun));
830+
763831
var ok = await SetQuery(text);
764832
Btn_Cancel.Enabled = ok;
833+
765834
if (!ok) {
766835
return;
767836
}

SmartImage 3/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void Init()
5757
public static async Task Main(string[] args)
5858
{
5959
// Console.OutputEncoding = Encoding.Unicode;
60-
60+
Console.Title = R2.Name;
6161
ConsoleUtil.SetConsoleMode();
6262
#if TEST
6363
// args = new String[] { null };

SmartImage 3/UI/Styles.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ internal static class Styles
1414
internal static readonly Attribute Atr_BrightYellow_Black = Attribute.Make(Color.BrightYellow, Color.Black);
1515
internal static readonly Attribute Atr_White_Black = Attribute.Make(Color.White, Color.Black);
1616
internal static readonly Attribute Atr_White_Blue = Attribute.Make(Color.White, Color.Blue);
17-
internal static readonly Attribute Atr_Cyan_Black = Attribute.Make(Color.Cyan, Color.Black);
1817
internal static readonly Attribute Atr_White_Cyan = Attribute.Make(Color.White, Color.Cyan);
19-
internal static readonly Attribute Atr_White_BrightCyan = Attribute.Make(Color.White, Color.BrightCyan);
18+
internal static readonly Attribute Atr_White_DarkGray = Attribute.Make(Color.White, Color.DarkGray);
19+
internal static readonly Attribute Atr_White_BrightCyan = Attribute.Make(Color.White, Color.BrightCyan);
2020
internal static readonly Attribute Atr_BrightCyan_DarkGray = Attribute.Make(Color.BrightCyan, Color.DarkGray);
21+
internal static readonly Attribute Atr_Cyan_Black = Attribute.Make(Color.Cyan, Color.Black);
2122
internal static readonly Attribute Atr_Cyan_White = Attribute.Make(Color.Cyan, Color.White);
2223
internal static readonly Attribute Atr_Blue_White = Attribute.Make(Color.Blue, Color.White);
2324
internal static readonly Attribute Atr_BrightBlue_White = Attribute.Make(Color.BrightBlue, Color.White);
24-
internal static readonly Attribute Atr_BrightBlue_Gray = Attribute.Make(Color.BrightBlue, Color.Gray);
25+
internal static readonly Attribute Atr_BrightBlue_Gray = Attribute.Make(Color.BrightBlue, Color.Gray);
2526
internal static readonly Attribute Atr_BrightRed_Black = Attribute.Make(Color.BrightRed, Color.Black);
2627
internal static readonly Attribute Atr_BrightGreen_Black = Attribute.Make(Color.BrightGreen, Color.Black);
2728
internal static readonly Attribute Atr_Black_White = Attribute.Make(Color.Black, Color.White);
2829
internal static readonly Attribute Atr_Gray_Black = Attribute.Make(Color.Gray, Color.Black);
2930
internal static readonly Attribute Atr_DarkGray_Blue = Attribute.Make(Color.DarkGray, Color.Blue);
30-
internal static readonly Attribute Atr_White_DarkGray = Attribute.Make(Color.White, Color.DarkGray);
3131
internal static readonly Attribute Atr_DarkGray_Black = Attribute.Make(Color.DarkGray, Color.Black);
32+
3233
private static readonly Attribute Atr_BrightBlue_Black = Attribute.Make(Color.BrightBlue, Color.Black);
3334
private static readonly Attribute Atr_Blue_Black = Attribute.Make(Color.Blue, Color.Black);
3435
private static readonly Attribute Atr_Brown_Black = Attribute.Make(Color.Brown, Color.Black);
@@ -44,7 +45,7 @@ internal static class Styles
4445
Disabled = Atr_DarkGray_Blue,
4546
HotNormal = Atr_White_Cyan,
4647
HotFocus = Atr_White_BrightCyan,
47-
Focus = Atr_White_BrightCyan,
48+
Focus = Atr_White_BrightCyan,
4849
};
4950

5051
internal static readonly ColorScheme Cs_Btn1 = new()
@@ -101,6 +102,14 @@ internal static class Styles
101102
HotFocus = Atr_Green_Black
102103
};
103104

105+
internal static readonly ColorScheme Cs_Lbl1 = new ()
106+
{
107+
Normal = Styles.Atr_White_Black,
108+
HotNormal = Styles.Atr_White_Black,
109+
Focus = Styles.Atr_Cyan_Black,
110+
HotFocus = Styles.Atr_Cyan_Black,
111+
};
112+
104113
#endregion
105114

106115
#region Styles

0 commit comments

Comments
 (0)