Skip to content

Commit 4858f6c

Browse files
committed
Queue mode working
1 parent bdbd5eb commit 4858f6c

File tree

3 files changed

+81
-45
lines changed

3 files changed

+81
-45
lines changed

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

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private async void Run_Clicked()
123123
await RunMainAsync();
124124
}
125125

126-
private void Queue_Clicked()
126+
private void Queue_Dialog()
127127
{
128128
var d = new Dialog()
129129
{
@@ -146,7 +146,7 @@ private void Queue_Clicked()
146146
{
147147
Width = Dim.Fill(),
148148
Height = Dim.Fill(),
149-
Y =Pos.Bottom(tf)
149+
Y = Pos.Bottom(tf)
150150
};
151151

152152
var btnRm = new Button("Remove")
@@ -163,6 +163,7 @@ private void Queue_Clicked()
163163
btnRm.Clicked += () =>
164164
{
165165
var cpy2 = lv.Source.ToList();
166+
166167
if (lv.SelectedItem < cpy2.Count && lv.SelectedItem >= 0) {
167168
var i = (string) cpy2[lv.SelectedItem];
168169
Debug.WriteLine($"{i}");
@@ -179,12 +180,28 @@ private void Queue_Clicked()
179180

180181
btnRmAll.Clicked += () =>
181182
{
182-
lv.Source = new ListWrapper(Enumerable.Empty<string>().ToList());
183+
lv.Source = new ListWrapper(Array.Empty<string>());
183184
Queue.Clear();
184185
lv.SetFocus();
185186
};
186187

187-
d.Add(tf,lv);
188+
tf.TextChanging += a =>
189+
{
190+
191+
var s = a.NewText.ToString();
192+
193+
if (SearchQuery.IsValidSourceType(s)) {
194+
Queue.Enqueue(s);
195+
lv.Source = new ListWrapper(Queue.ToList());
196+
tf.DeleteAll();
197+
tf.Text = ustring.Empty;
198+
a.Cancel = true;
199+
tf.SetFocus();
200+
tf.SetNeedsDisplay();
201+
}
202+
};
203+
204+
d.Add(tf, lv);
188205
d.AddButton(btnRm);
189206
d.AddButton(btnRmAll);
190207

@@ -196,7 +213,7 @@ private void Queue_Checked(bool b)
196213
QueueMode = !b;
197214

198215
Btn_Queue.Enabled = QueueMode;
199-
Btn_Next.Enabled = QueueMode;
216+
Btn_Next.Enabled = QueueMode;
200217
}
201218

202219
/// <summary>
@@ -227,16 +244,21 @@ private void Browse_Clicked()
227244
foreach (string fs in files) {
228245
Queue.Enqueue(fs);
229246
}
247+
248+
NextQueue();
230249
}
231250

232-
var f = files.FirstOrDefault(); //todo
251+
else {
252+
var f = files.FirstOrDefault(); //todo
233253

234-
if (!string.IsNullOrWhiteSpace(f)) {
235-
Tf_Input.DeleteAll();
236-
Debug.WriteLine($"Picked file: {f}", nameof(Browse_Clicked));
254+
if (!string.IsNullOrWhiteSpace(f)) {
255+
Tf_Input.DeleteAll();
256+
Debug.WriteLine($"Picked file: {f}", nameof(Browse_Clicked));
237257

238-
SetInputText(f);
239-
Btn_Run.SetFocus();
258+
SetInputText(f);
259+
Btn_Run.SetFocus();
260+
261+
}
240262

241263
}
242264

@@ -330,12 +352,17 @@ private void Delete_Clicked()
330352
private void Next_Clicked()
331353
{
332354
Restart_Clicked(true);
355+
NextQueue();
356+
}
357+
358+
private void NextQueue()
359+
{
333360
var tryDequeue = Queue.TryDequeue(out var n);
361+
334362
if (tryDequeue) {
335363
// SetQuery(n);
336364

337365
SetInputText(n);
338366
}
339367
}
340-
341368
}

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public ShellMode(string[] args)
417417
Tf_Input.TextChanging += Input_TextChanging;
418418
Btn_Delete.Clicked += Delete_Clicked;
419419
Cb_Queue.Toggled += Queue_Checked;
420-
Btn_Queue.Clicked += Queue_Clicked;
420+
Btn_Queue.Clicked += Queue_Dialog;
421421
Btn_Next.Clicked += Next_Clicked;
422422

423423
Lbl_QueryUpload.Clicked += () =>
@@ -547,13 +547,20 @@ private void OnCompleteWin(object sender, SearchResult[] results)
547547

548548
#endregion
549549

550-
public void Close()
550+
private async Task<object?> RunSearchAsync()
551551
{
552-
if (Compat.IsWin) {
553-
Player.Dispose();
554-
}
552+
PreSearch();
555553

556-
Application.Shutdown();
554+
Status = null;
555+
IsReady.WaitOne();
556+
557+
var results = await Client.RunSearchAsync(Query, m_token.Token);
558+
559+
Status = false;
560+
561+
PostSearch();
562+
563+
return null;
557564
}
558565

559566
private void ProcessArgs()
@@ -704,22 +711,6 @@ private async Task<bool> SetQuery(ustring text)
704711
return true;
705712
}
706713

707-
private async Task<object?> RunSearchAsync()
708-
{
709-
PreSearch();
710-
711-
Status = null;
712-
IsReady.WaitOne();
713-
714-
var results = await Client.RunSearchAsync(Query, m_token.Token);
715-
716-
Status = false;
717-
718-
PostSearch();
719-
720-
return null;
721-
}
722-
723714
private bool ClipboardCallback(MainLoop c)
724715
{
725716
// Debug.WriteLine($"executing timeout {nameof(ClipboardCallback)} {c} {UseClipboard} {Clipboard.SequenceNumber}");
@@ -793,16 +784,6 @@ private bool ClipboardCallback(MainLoop c)
793784
// return UseClipboard;
794785
}
795786

796-
public void Dispose()
797-
{
798-
Client.Dispose();
799-
Query.Dispose();
800-
m_token.Dispose();
801-
m_tokenu.Dispose();
802-
Queue.Clear();
803-
m_results.Clear();
804-
}
805-
806787
private async Task RunMainAsync()
807788
{
808789
Pbr_Status.BidirectionalMarquee = false;
@@ -862,4 +843,23 @@ private void Clear()
862843
// Queue.Clear();
863844
m_results.Clear();
864845
}
846+
847+
public void Close()
848+
{
849+
if (Compat.IsWin) {
850+
Player.Dispose();
851+
}
852+
853+
Application.Shutdown();
854+
}
855+
856+
public void Dispose()
857+
{
858+
Client.Dispose();
859+
Query.Dispose();
860+
m_token.Dispose();
861+
m_tokenu.Dispose();
862+
Queue.Clear();
863+
m_results.Clear();
864+
}
865865
}

SmartImage.Lib 3/Engines/WebSearchEngine.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
1818
token ??= CancellationToken.None;
1919
var res = await base.GetResultAsync(query, token);
2020

21-
IDocument doc = await GetDocumentAsync(res.RawUrl, query: query, token: token.Value);
21+
IDocument doc;
22+
23+
try {
24+
doc = await GetDocumentAsync(res.RawUrl, query: query, token: token.Value);
25+
}
26+
catch (Exception e) {
27+
Debug.WriteLine($"{e.Message}", nameof(GetResultAsync));
28+
doc = null;
29+
30+
}
2231

2332
if (doc is not { }) {
2433
res.Status = SearchResultStatus.Failure;

0 commit comments

Comments
 (0)