Skip to content

Commit e4efdd0

Browse files
committed
Work on #39
1 parent 49aceb7 commit e4efdd0

File tree

7 files changed

+63
-10
lines changed

7 files changed

+63
-10
lines changed

SmartImage 3/Mode/Shell/Assets/UI.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ public static void FromEnum<TEnum>(this ListView lv, TEnum e) where TEnum : stru
8383
}
8484
}
8585

86+
public static void ClearBy<T>(this ListView lv, Predicate<T> p)
87+
{
88+
var cc=lv.Source.ToList<T>().ToArray();
89+
90+
for (int i = 0; i < lv.Source.Length; i++) {
91+
lv.Source.SetMark(i, p(cc[i]));
92+
}
93+
}
94+
8695
public static TEnum GetEnum<TEnum>(this IListDataSource lv, TEnum t = default) where TEnum : struct, Enum
8796
{
8897
var m = lv.GetItems<TEnum>();
@@ -133,6 +142,7 @@ internal static void OnEngineSelected(ListView lv, ListViewItemEventArgs lvie, r
133142

134143
ret:
135144
var v = ((SearchEngineOptions) lvie.Value);
145+
136146
if (lv.Source.IsMarked(lvie.Item)) {
137147
e |= v;
138148
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void ReloadDialog()
164164
// Debug.WriteLine($"{GetItems<SearchEngineOptions>(lvSearchEngines.Source).QuickJoin()}");
165165
lvSearchEngines.FromEnum(Config.SearchEngines);
166166
lvPriorityEngines.FromEnum(Config.PriorityEngines);
167-
167+
168168
// var e=lvSearchEngines.Source.GetEnum2(default(SearchEngineOptions));
169169

170170
/*============================================================================*\
@@ -192,7 +192,7 @@ void ReloadDialog()
192192
AutoSize = true,
193193

194194
X = 0,
195-
Y = Pos.Bottom(lvSearchEngines) + 1
195+
Y = Pos.Bottom(lvSearchEngines) + 2
196196
};
197197

198198
CheckBox cbOnTop = new(R1.S_OnTop)
@@ -314,10 +314,33 @@ Eh username/password
314314
ReloadDialog();
315315
};
316316

317+
var btnClear = new Button("Clear")
318+
{
319+
Y = Pos.Bottom(lvSearchEngines),
320+
};
321+
btnClear.Clicked += () => OnAction(lvSearchEngines, (e) => Config.SearchEngines = e);
322+
323+
var btnClear2 = new Button("Clear")
324+
{
325+
Y = Pos.Bottom(lvPriorityEngines),
326+
X = Pos.Bottom(lvPriorityEngines)
327+
};
328+
btnClear2.Clicked += () => OnAction(lvPriorityEngines, (e) => Config.PriorityEngines = e);
329+
330+
void OnAction(ListView lv, Action<SearchEngineOptions> f)
331+
{
332+
lv.ClearBy<SearchEngineOptions>(_ => false);
333+
lv.FromEnum(default(SearchEngineOptions));
334+
f(default(SearchEngineOptions));
335+
ReloadDialog();
336+
337+
lv.SetNeedsDisplay();
338+
}
339+
317340
dlCfg.Add(tvConfig, lvSearchEngines, lvPriorityEngines,
318341
cbContextMenu, cbOnTop, lbConfig, lbSearchEngines, lbPriorityEngines,
319342
lbHelp, cbAutoSearch, lbEhUsername, tfEhUsername, lbEhPassword, tfEhPassword,
320-
cbOpenRaw);
343+
cbOpenRaw, btnClear, btnClear2);
321344

322345
dlCfg.AddButton(btnRefresh);
323346
dlCfg.AddButton(btnOk);
@@ -328,5 +351,4 @@ Eh username/password
328351
Tf_Input.SetFocus();
329352
Tf_Input.EnsureFocus();
330353
}
331-
332354
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ private void Clear()
6363
Btn_Cancel.Enabled = false;
6464

6565
m_queue.Clear();
66-
66+
m_results.Clear();
6767
}
6868
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private static void Clear_Clicked()
161161
Lbl_InputInfo.Text = ustring.Empty;
162162
Lbl_InputInfo2.Text = ustring.Empty;
163163
Lbl_Status2.Text = ustring.Empty;
164-
164+
Btn_Run.Enabled = true;
165165
Tf_Input.SetFocus();
166166
// Btn_Delete.Enabled = false;
167167
}

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Kantan.Net.Utilities;
1212
using Kantan.Text;
1313
using Microsoft.VisualBasic.FileIO;
14+
using Novus.FileTypes;
1415
using Novus.Win32;
1516
using NStack;
1617
using SmartImage.App;
@@ -35,10 +36,7 @@ public sealed partial class ShellMode : IDisposable, IMode
3536

3637
#region Controls
3738

38-
static ShellMode()
39-
{
40-
41-
}
39+
static ShellMode() { }
4240

4341
private static readonly Toplevel Top = Application.Top;
4442

@@ -580,7 +578,14 @@ private async Task<bool> SetQuery(ustring text)
580578
Pbr_Status.Pulse();
581579
Lbl_Status2.Text = $"Verifying...";
582580

581+
lock (Btn_Run) {
582+
Btn_Run.Enabled = false;
583+
}
584+
583585
sq = await SearchQuery.TryCreateAsync(text.ToString());
586+
587+
Btn_Run.Enabled = true;
588+
584589
Pbr_Status.Pulse();
585590
}
586591
catch (Exception e) {
@@ -685,6 +690,16 @@ private bool ClipboardCallback(MainLoop c)
685690
&& Integration.ReadClipboard(out var str)
686691
&& !m_clipboard.Contains(str)
687692
/*&& (m_prevSeq != sequenceNumber)*/) {
693+
/*bool vl = SearchQuery.IsValidSourceType(str);
694+
695+
if (vl) {
696+
var sq = SearchQuery.TryCreateAsync(str);
697+
sq.Wait();
698+
if (sq.Result.Uni.FileTypes
699+
.All(e => e.IsType(FileType.MT_IMAGE))) { }
700+
}
701+
702+
Debug.WriteLine($"{str}");*/
688703

689704
SetInputText(str);
690705
// Lbl_InputOk.Text = UI.Clp;

SmartImage 3/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
global using SConsole = System.Console;
33
global using static Kantan.Diagnostics.LogCategories;
44
using System.CommandLine;
5+
using System.ComponentModel;
56
using System.Diagnostics;
7+
using System.Runtime;
68
using System.Runtime.CompilerServices;
79
using System.Text;
810
using Kantan.Threading;

SmartImage.Lib 3/Engines/Impl/Search/Ascii2DEngine.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ protected override async Task<IDocument> GetDocumentAsync(object sender, SearchQ
9898
return null;
9999
}
100100
}
101+
catch (TaskCanceledException) {
102+
return null;
103+
104+
}
101105
catch (FlurlHttpException e) {
102106
// return await Task.FromException<IDocument>(e);
103107
Debug.WriteLine($"{this} :: {e.Message}", nameof(GetDocumentAsync));

0 commit comments

Comments
 (0)