Skip to content

Commit 03b5af3

Browse files
committed
Work on auto-search
1 parent 537e42f commit 03b5af3

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,23 @@ private void Result_CellActivated(TableView.CellActivatedEventArgs args)
5353

5454
private async void Input_TextChanging(TextChangingEventArgs tc)
5555
{
56-
var text = tc.NewText;
56+
var text = tc.NewText.ToString().TrimStart('\"');
5757

58-
Debug.WriteLine($"testing {text}", nameof(Input_TextChanging));
58+
// Debug.WriteLine($"testing {text}", nameof(Input_TextChanging));
5959

60-
Application.MainLoop.Invoke(() => Task.Delay(TimeSpan.FromSeconds(1)));
60+
// Application.MainLoop.Invoke(() => Task.Delay(TimeSpan.FromSeconds(1)));
6161

62-
var sourceType = SearchQuery.IsValidSourceType(text.ToString());
62+
var sourceType = SearchQuery.IsValidSourceType(text);
6363

6464
if (sourceType) {
6565
var ok = await TrySetQueryAsync(text);
66+
6667
Btn_Run.Enabled = ok;
6768
Debug.WriteLine($"{nameof(Input_TextChanging)} :: ok");
69+
70+
if (ok && m_autoSearch && !Client.IsRunning) {
71+
Run_Clicked();
72+
}
6873
}
6974
}
7075

@@ -239,7 +244,7 @@ private void Cancel_Clicked()
239244
Application.MainLoop.RemoveIdle(m_runIdleTok);
240245
Tv_Results.SetFocus();
241246
Lbl_Status2.ColorScheme = UI.Cs_Lbl1;
242-
247+
243248
}
244249

245250
private void Delete_Clicked()

SmartImage 3/NetUtil.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using AngleSharp.Dom;
8+
using AngleSharp.Html.Dom;
79
using AngleSharp.Html.Parser;
810
using Flurl.Http;
911
using Novus.FileTypes;
@@ -39,17 +41,10 @@ public static async Task<UniSource[]> ScanAsync(Url u, CancellationToken ct = de
3941
var p = new HtmlParser();
4042
var dd = await p.ParseDocumentAsync(stream, ct);
4143

42-
var a = dd.QuerySelectorAll("a")
43-
.Distinct()
44-
.Select(e => e.GetAttribute("href"))
45-
.Distinct();
46-
// .Where(e=> SearchQuery.IsValidSourceType(e));
44+
var a = dd.QueryAllDistinctAttribute("a", "href");
45+
var b = dd.QueryAllDistinctAttribute("img", "src");
4746

48-
var b = dd.QuerySelectorAll("img")
49-
.Distinct()
50-
.Select(e => e.GetAttribute("src"))
51-
.Distinct();
52-
var c = a.Union(b);
47+
var c = a.Union(b).Where(SearchQuery.IsValidSourceType);
5348

5449
await Parallel.ForEachAsync(c, ct, async (s, token) =>
5550
{
@@ -58,6 +53,9 @@ await Parallel.ForEachAsync(c, ct, async (s, token) =>
5853
if (ux != null) {
5954
ul.Add(ux);
6055

56+
}
57+
else {
58+
6159
}
6260

6361
return;
@@ -66,5 +64,14 @@ await Parallel.ForEachAsync(c, ct, async (s, token) =>
6664
dd.Dispose();
6765
ret:
6866
return ul.ToArray();
67+
68+
}
69+
70+
private static IEnumerable<string?> QueryAllDistinctAttribute(this IParentNode doc, string sel, string attr)
71+
{
72+
return doc.QuerySelectorAll(sel)
73+
.Distinct()
74+
.Select(e => e.GetAttribute(attr))
75+
.Distinct();
6976
}
7077
}

SmartImage.Lib 3/SearchClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public async Task<SearchResult[]> RunSearchAsync(SearchQuery query, Cancellation
111111

112112
Logger.LogWarning("Cancellation requested");
113113
IsComplete = true;
114-
114+
IsRunning = false;
115115
return results;
116116
}
117117

0 commit comments

Comments
 (0)