Skip to content

Commit 103e57b

Browse files
committed
UX tweaks; work on #39
1 parent e4efdd0 commit 103e57b

File tree

87 files changed

+74562
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+74562
-20
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,25 @@ void ReloadDialog()
249249
};
250250
cbOpenRaw.Checked = Config.OpenRaw;
251251

252+
CheckBox cbSilent = new(R1.S_Silent)
253+
{
254+
X = Pos.Right(cbOpenRaw) + 1,
255+
Y = Pos.Y(cbOpenRaw),
256+
// Width = WIDTH,
257+
Height = 1,
258+
AutoSize = true,
259+
ColorScheme = UI.Cs_Btn3
260+
261+
};
262+
263+
cbSilent.Toggled += b =>
264+
{
265+
Config.Silent = !b;
266+
ReloadDialog();
267+
};
268+
269+
cbSilent.Checked = Config.Silent;
270+
252271
/*============================================================================*\
253272
Eh username/password
254273
\*============================================================================*/
@@ -314,6 +333,8 @@ Eh username/password
314333
ReloadDialog();
315334
};
316335

336+
#region
337+
317338
var btnClear = new Button("Clear")
318339
{
319340
Y = Pos.Bottom(lvSearchEngines),
@@ -331,16 +352,18 @@ void OnAction(ListView lv, Action<SearchEngineOptions> f)
331352
{
332353
lv.ClearBy<SearchEngineOptions>(_ => false);
333354
lv.FromEnum(default(SearchEngineOptions));
334-
f(default(SearchEngineOptions));
355+
f(default);
335356
ReloadDialog();
336357

337358
lv.SetNeedsDisplay();
338359
}
339360

361+
#endregion
362+
340363
dlCfg.Add(tvConfig, lvSearchEngines, lvPriorityEngines,
341364
cbContextMenu, cbOnTop, lbConfig, lbSearchEngines, lbPriorityEngines,
342365
lbHelp, cbAutoSearch, lbEhUsername, tfEhUsername, lbEhPassword, tfEhPassword,
343-
cbOpenRaw, btnClear, btnClear2);
366+
cbOpenRaw, cbSilent, btnClear, btnClear2);
344367

345368
dlCfg.AddButton(btnRefresh);
346369
dlCfg.AddButton(btnOk);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ private void Clear()
6060
Tv_Results.SetNeedsDisplay();
6161
Tf_Input.SetFocus();
6262
Tf_Input.EnsureFocus();
63+
Btn_Run.Enabled = false;
6364
Btn_Cancel.Enabled = false;
6465

6566
m_queue.Clear();

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

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

44
using System.Diagnostics;
55
using Kantan.Net.Utilities;
6+
using Microsoft.Extensions.Logging;
67
using Microsoft.VisualBasic.FileIO;
78
using Novus.OS;
89
using NStack;
@@ -12,12 +13,14 @@
1213
using Terminal.Gui;
1314
using Clipboard = Novus.Win32.Clipboard;
1415
using Microsoft.VisualBasic.FileIO;
16+
using SmartImage.Lib.Utilities;
1517
using FileSystem = Novus.OS.FileSystem;
1618

1719
namespace SmartImage.Mode.Shell;
1820

1921
public sealed partial class ShellMode
2022
{
23+
2124
/// <summary>
2225
/// <see cref="Tv_Results"/>
2326
/// </summary>
@@ -76,7 +79,7 @@ private void Restart_Clicked(bool force = false)
7679

7780
Btn_Restart.Enabled = false;
7881
Btn_Cancel.Enabled = false;
79-
Btn_Run.Enabled = true;
82+
Btn_Run.Enabled = false;
8083
Btn_Delete.Enabled = false;
8184

8285
m_token.Dispose();
@@ -161,7 +164,8 @@ private static void Clear_Clicked()
161164
Lbl_InputInfo.Text = ustring.Empty;
162165
Lbl_InputInfo2.Text = ustring.Empty;
163166
Lbl_Status2.Text = ustring.Empty;
164-
Btn_Run.Enabled = true;
167+
// Btn_Run.Enabled = true;
168+
Btn_Run.Enabled = false;
165169
Tf_Input.SetFocus();
166170
// Btn_Delete.Enabled = false;
167171
}
@@ -178,19 +182,26 @@ private void Cancel_Clicked()
178182

179183
private void Delete_Clicked()
180184
{
181-
Clipboard.Close();
182-
// Restart_Clicked(true);
185+
try {
186+
Clipboard.Close();
187+
// Restart_Clicked(true);
188+
189+
var file = Tf_Input.Text.ToString();
183190

184-
var file = Tf_Input.Text.ToString();
191+
if (!string.IsNullOrWhiteSpace(file)) {
192+
Query.Dispose();
193+
Debug.WriteLine($"{IsQueryReady()}");
185194

186-
if (!string.IsNullOrWhiteSpace(file)) {
187-
Query.Dispose();
188-
Debug.WriteLine($"{IsQueryReady()}");
195+
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(file, UIOption.OnlyErrorDialogs,
196+
RecycleOption.SendToRecycleBin);
197+
Debug.WriteLine($"deleted {file}");
198+
Clear();
199+
}
189200

190-
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(file, UIOption.OnlyErrorDialogs,
191-
RecycleOption.SendToRecycleBin);
192-
Debug.WriteLine($"deleted {file}");
193-
Clear();
201+
}
202+
catch (Exception e) {
203+
FileLogger.Fl.Writer.WriteLine($"{e.Message} {e.Source} {e.StackTrace}");
204+
FileLogger.Fl.Writer.Flush();
194205
}
195206

196207
}

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
using System.Runtime.Versioning;
1111
using Kantan.Net.Utilities;
1212
using Kantan.Text;
13+
using Microsoft.Extensions.Logging;
1314
using Microsoft.VisualBasic.FileIO;
1415
using Novus.FileTypes;
1516
using Novus.Win32;
1617
using NStack;
1718
using SmartImage.App;
1819
using SmartImage.Lib;
1920
using SmartImage.Lib.Results;
21+
using SmartImage.Lib.Utilities;
2022
using SmartImage.Mode.Shell.Assets;
2123
using SmartImage.Utilities;
2224
using Terminal.Gui;
@@ -83,7 +85,7 @@ static ShellMode() { }
8385
X = Pos.Right(Lbl_InputOk) + 1,
8486
Y = Pos.Y(Tf_Input),
8587
ColorScheme = UI.Cs_Btn1x,
86-
88+
Enabled = false
8789
};
8890

8991
private static readonly Button Btn_Browse = new("Browse")
@@ -496,8 +498,12 @@ private void OnComplete(object sender, SearchResult[] results)
496498
[SupportedOSPlatform(Compat.OS)]
497499
private void OnCompleteWin(object sender, SearchResult[] results)
498500
{
499-
Player.Play();
500-
Native.FlashWindow(ConsoleUtil.HndWindow);
501+
502+
if (!Config.Silent) {
503+
Player.Play();
504+
Native.FlashWindow(ConsoleUtil.HndWindow);
505+
506+
}
501507

502508
/*var u = m_results.SelectMany(r => r.Results).ToArray();
503509
var di = (await SearchClient.GetDirectImagesAsync(u)).ToArray();
@@ -562,10 +568,15 @@ internal void SetInputText(ustring s)
562568

563569
}
564570

571+
private static readonly ILogger Logger = LogUtil.Factory.CreateLogger(nameof(ShellMode));
572+
565573
private async Task<bool> SetQuery(ustring text)
566574
{
575+
Btn_Run.Enabled = false;
576+
567577
if (IsQueryReady() && Query.Uni.Value as string == text) {
568578
Debug.WriteLine($"Already loaded {text}", nameof(SetQuery));
579+
Btn_Run.Enabled = true;
569580
return true;
570581
}
571582

@@ -584,7 +595,7 @@ private async Task<bool> SetQuery(ustring text)
584595

585596
sq = await SearchQuery.TryCreateAsync(text.ToString());
586597

587-
Btn_Run.Enabled = true;
598+
// Btn_Run.Enabled = false;
588599

589600
Pbr_Status.Pulse();
590601
}
@@ -617,6 +628,7 @@ private async Task<bool> SetQuery(ustring text)
617628
Debug.WriteLine($"{e.Message}", nameof(SetQuery));
618629
Lbl_InputInfo.Text = $"Error: {e.Message}";
619630
Lbl_Status2.Text = ustring.Empty;
631+
Btn_Run.Enabled = false;
620632

621633
}
622634

@@ -625,7 +637,7 @@ private async Task<bool> SetQuery(ustring text)
625637
Lbl_InputInfo.Text = "Error: invalid input";
626638

627639
UI.SetLabelStatus(Lbl_InputOk, false);
628-
Btn_Run.Enabled = true;
640+
Btn_Run.Enabled = false;
629641
Lbl_QueryUpload.Text = ustring.Empty;
630642
Pbr_Status.Fraction = 0;
631643
Lbl_Status2.Text = ustring.Empty;

SmartImage.Lib 3/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SmartImage.Lib 3/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,7 @@
148148
<data name="data" type="System.Resources.ResXFileRef, System.Windows.Forms">
149149
<value>Engines\data.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
150150
</data>
151+
<data name="S_Silent" xml:space="preserve">
152+
<value>Silent</value>
153+
</data>
151154
</root>

SmartImage.Lib 3/SearchClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public SearchClient(SearchConfig cfg)
4141
Config = cfg;
4242
ConfigApplied = false;
4343
LoadEngines();
44-
44+
FileLogger.Fl.Writer.WriteLine($"Init");
45+
FileLogger.Fl.Writer.Flush();
4546
}
4647

4748
static SearchClient()

SmartImage.Lib 3/SearchConfig.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ public bool OpenRaw
105105
OnPropertyChanged();
106106
}
107107
}
108+
public bool Silent
109+
{
110+
get { return Configuration.ReadSetting(nameof(Silent), false); }
111+
set
112+
{
113+
Configuration.AddUpdateSetting(nameof(Silent), value.ToString());
114+
OnPropertyChanged();
115+
}
116+
}
108117

109118
public static readonly SearchConfig Default = new();
110119

@@ -140,6 +149,7 @@ public DataTable ToTable()
140149
table.Rows.Add(Resources.S_PriorityEngines, PriorityEngines);
141150
table.Rows.Add(Resources.S_OnTop, OnTop);
142151
table.Rows.Add(Resources.S_OpenRaw, OpenRaw);
152+
table.Rows.Add(Resources.S_Silent, Silent);
143153
table.Rows.Add(Resources.S_EhUsername, EhUsername);
144154
table.Rows.Add(Resources.S_EhPassword, EhPassword);
145155

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Read ​​ SmartImage FileLogger.cs
2+
// 2023-04-28 @ 1:02 PM
3+
4+
namespace SmartImage.Lib.Utilities;
5+
6+
// TODO: TEMPORARY
7+
8+
public class FileLogger : IDisposable
9+
{
10+
internal static readonly FileLogger Fl = new FileLogger("smartimage.log");
11+
12+
public TextWriter Writer { get; }
13+
14+
public FileLogger(string s)
15+
{
16+
// var f = File.Open(s, FileMode.Append);
17+
18+
Writer = StreamWriter.Synchronized(new StreamWriter(s));
19+
20+
}
21+
22+
public void Dispose()
23+
{
24+
Writer.Flush();
25+
Writer.Dispose();
26+
}
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SmartImage.Web.Models
2+
{
3+
public class ResultItem
4+
{
5+
public string Title { get; set; }
6+
}
7+
}

0 commit comments

Comments
 (0)