Skip to content

Commit e61c41d

Browse files
committed
Work on clipboard multi-selection, priority engine result criteria, etc.
1 parent 947e039 commit e61c41d

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void Restart_Clicked(bool force = false)
140140

141141
Tf_Input.SetFocus();
142142
Tf_Input.EnsureFocus();
143-
143+
Btn_Filter.Text = $"Filter";
144144
_inputVerifying = false;
145145
}
146146

@@ -199,6 +199,8 @@ private async void Filter_Clicked()
199199
}
200200

201201
if (filterOrder == filterMax) {
202+
Btn_Filter.Enabled = false;
203+
202204
var res3 = res as List<SearchResultItem> ?? res.ToList();
203205
var res2 = new ConcurrentBag<SearchResultItem>();
204206

@@ -226,6 +228,9 @@ await Parallel.ForEachAsync(res3, async (item, token) =>
226228
i++;
227229
Tv_Results.Update();
228230
}
231+
232+
Btn_Filter.Enabled = true;
233+
229234
}
230235

231236
private void Queue_Checked(bool b)
@@ -281,7 +286,8 @@ private void Browse_Clicked()
281286
if (!string.IsNullOrWhiteSpace(f)) {
282287
Tf_Input.DeleteAll();
283288
Debug.WriteLine($"Picked file: {f}", nameof(Browse_Clicked));
284-
289+
Cancel_Clicked();
290+
Restart_Clicked(true);
285291
SetInputText(f);
286292
Btn_Run.SetFocus();
287293

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ private void OnComplete(object sender, SearchResult[] results)
655655
Btn_Cancel.Enabled = false;
656656
Lbl_Status2.ColorScheme = UI.Cs_Lbl1_Success;
657657
Lbl_Status2.Text = R2.Inf_Complete;
658-
658+
Btn_Browse.Enabled = true;
659659
}
660660

661661
[SupportedOSPlatform(Compat.OS)]
@@ -861,6 +861,8 @@ private async Task<bool> TrySetQueryAsync(ustring text)
861861
Btn_Run.Enabled = false;
862862
Pbr_Status.Fraction = 0;
863863
// Btn_Delete.Enabled = true;
864+
865+
Btn_Browse.Enabled = QueueMode;
864866

865867
Tf_Input.ReadOnly = true;
866868
Btn_Delete.Enabled = true;

SmartImage 3/SmartImage.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<PackageReference Include="Spectre.Console.Extensions.Table" Version="1.0.0" />
8484
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
8585
<PackageReference Include="System.Json" Version="4.7.1" />
86+
<PackageReference Include="System.Reactive" Version="6.0.0" />
8687
<PackageReference Include="System.Runtime.Caching" Version="7.0.0" />
8788
<PackageReference Include="System.Windows.Extensions" Version="7.0.0" />
8889
<PackageReference Include="Terminal.Gui" Version="1.12.1" />

SmartImage.Lib 3/Results/SearchResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public SearchResultItem Best
7878
return null;
7979
}
8080

81-
return Results.MaxBy(r => r.Score);
81+
return Results.OrderByDescending(r => r.Similarity).FirstOrDefault(r => Url.IsValid(r.Url));
8282
}
8383
}
8484

SmartImage.Lib 3/SearchClient.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ static SearchClient()
7272
};
7373

7474
Client = new FlurlClient(new HttpClient(handler))
75-
{
76-
77-
};
75+
{ };
7876

7977
Logger.LogInformation("Init");
8078

@@ -96,7 +94,7 @@ static SearchClient()
9694
/// <param name="query">Search query</param>
9795
/// <param name="p"><see cref="IProgress{T}"/></param>
9896
/// <param name="token">Cancellation token passed to <see cref="BaseSearchEngine.GetResultAsync"/></param>
99-
public async Task<SearchResult[]> RunSearchAsync(SearchQuery query, [CBN] IProgress<int> p = null,
97+
public async Task<SearchResult[]> RunSearchAsync(SearchQuery query, [CBN] IProgress<int> p = null,
10098
CancellationToken token = default)
10199
{
102100
IsRunning = true;
@@ -152,8 +150,9 @@ public async Task<SearchResult[]> RunSearchAsync(SearchQuery query, [CBN] IProgr
152150
//todo
153151
try {
154152
var rr = results.Where(r => r.Results.Any());
153+
OpenResult(rr.MaxBy(r4 => r4.Results.Select(r5 => r5.Similarity)));
155154

156-
OpenResult(rr.MaxBy(r => r.Results.Average(r2 => r2.Score)));
155+
// OpenResult(rr.MaxBy(r => r.Results.Average(r2 => r2.Score)));
157156
}
158157
catch (Exception e) {
159158
Debug.WriteLine($"{e.Message}");
@@ -234,7 +233,7 @@ public BaseSearchEngine[] LoadEngines()
234233
[CBN]
235234
public BaseSearchEngine TryGetEngine(SearchEngineOptions o) => Engines.FirstOrDefault(e => e.EngineOption == o);
236235

237-
#region
236+
#region
238237

239238
public static ValueTask<IReadOnlyList<SearchResultItem>> Filter(IEnumerable<SearchResultItem> sri)
240239
{

SmartImage.Lib 3/SmartImage.Lib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
5353
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
5454
<PackageReference Include="System.Json" Version="4.7.1" />
55+
<PackageReference Include="System.Reactive" Version="6.0.0" />
5556
<PackageReference Include="System.Runtime.Caching" Version="7.0.0" />
5657
</ItemGroup>
5758

0 commit comments

Comments
 (0)