Skip to content

Commit 3d9ef2c

Browse files
authored
Merge pull request #4042 from 01Dri/feature/history_mode
Add "Last opened" history mode & Fix non-result history item save issue
2 parents 4fe3b55 + b13c29a commit 3d9ef2c

File tree

12 files changed

+264
-59
lines changed

12 files changed

+264
-59
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
4-
<!-- Work around https://github.com/dotnet/runtime/issues/109682 -->
4+
<!-- Workaround https://github.com/dotnet/runtime/issues/109682 -->
55
<CETCompat>false</CETCompat>
66
</PropertyGroup>
77
</Project>

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Flow.Launcher.Infrastructure.Hotkey;
88
using Flow.Launcher.Infrastructure.Logger;
99
using Flow.Launcher.Infrastructure.Storage;
10+
using Flow.Launcher.Localization.Attributes;
1011
using Flow.Launcher.Plugin;
1112
using Flow.Launcher.Plugin.SharedModels;
1213

@@ -513,6 +514,21 @@ public bool ShowAtTopmost
513514
[JsonConverter(typeof(JsonStringEnumConverter))]
514515
public LastQueryMode LastQueryMode { get; set; } = LastQueryMode.Selected;
515516

517+
private HistoryStyle _historyStyle = HistoryStyle.Query;
518+
[JsonConverter(typeof(JsonStringEnumConverter))]
519+
public HistoryStyle HistoryStyle
520+
{
521+
get => _historyStyle;
522+
set
523+
{
524+
if (_historyStyle != value)
525+
{
526+
_historyStyle = value;
527+
OnPropertyChanged();
528+
}
529+
}
530+
}
531+
516532
[JsonConverter(typeof(JsonStringEnumConverter))]
517533
public AnimationSpeeds AnimationSpeed { get; set; } = AnimationSpeeds.Medium;
518534
public int CustomAnimationLength { get; set; } = 360;
@@ -695,4 +711,14 @@ public enum DialogJumpFileResultBehaviours
695711
FullPathOpen,
696712
Directory
697713
}
714+
715+
[EnumLocalize]
716+
public enum HistoryStyle
717+
{
718+
[EnumLocalizeKey(nameof(Localize.queryHistory))]
719+
Query,
720+
721+
[EnumLocalizeKey(nameof(Localize.executedHistory))]
722+
LastOpened
723+
}
698724
}

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
</Target>
186186

187187
<Target Name="RemoveDuplicateAnalyzers" BeforeTargets="CoreCompile">
188-
<!-- Work around https://github.com/dotnet/wpf/issues/6792 -->
188+
<!-- Workaround https://github.com/dotnet/wpf/issues/6792 -->
189189
<ItemGroup>
190190
<FilteredAnalyzer Include="@(Analyzer-&gt;Distinct())" />
191191
<Analyzer Remove="@(Analyzer)" />
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Linq;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Flow.Launcher.Core.Plugin;
5+
using Flow.Launcher.Plugin;
6+
using Flow.Launcher.Storage;
7+
8+
namespace Flow.Launcher.Helper;
9+
10+
#nullable enable
11+
12+
public static class ResultHelper
13+
{
14+
public static async Task<Result?> PopulateResultsAsync(LastOpenedHistoryItem item)
15+
{
16+
return await PopulateResultsAsync(item.PluginID, item.Query, item.Title, item.SubTitle, item.RecordKey);
17+
}
18+
19+
public static async Task<Result?> PopulateResultsAsync(string pluginId, string rawQuery, string title, string subTitle, string recordKey)
20+
{
21+
var plugin = PluginManager.GetPluginForId(pluginId);
22+
if (plugin == null) return null;
23+
var query = QueryBuilder.Build(rawQuery, PluginManager.NonGlobalPlugins);
24+
if (query == null) return null;
25+
try
26+
{
27+
var freshResults = await plugin.Plugin.QueryAsync(query, CancellationToken.None);
28+
// Try to match by record key first if it is valid, otherwise fall back to title + subtitle match
29+
if (string.IsNullOrEmpty(recordKey))
30+
{
31+
return freshResults?.FirstOrDefault(r => r.Title == title && r.SubTitle == subTitle);
32+
}
33+
else
34+
{
35+
return freshResults?.FirstOrDefault(r => r.RecordKey == recordKey) ??
36+
freshResults?.FirstOrDefault(r => r.Title == title && r.SubTitle == subTitle);
37+
}
38+
}
39+
catch (System.Exception e)
40+
{
41+
App.API.LogException(nameof(ResultHelper), $"Failed to query results for {plugin.Metadata.Name}", e);
42+
return null;
43+
}
44+
}
45+
}

Flow.Launcher/Languages/en.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@
166166
<system:String x:Key="homePageToolTip">Show home page results when query text is empty.</system:String>
167167
<system:String x:Key="historyResultsForHomePage">Show History Results in Home Page</system:String>
168168
<system:String x:Key="historyResultsCountForHomePage">Maximum History Results Shown in Home Page</system:String>
169+
<system:String x:Key="historyStyle">History Style</system:String>
170+
<system:String x:Key="historyStyleTooltip">Choose the type of history to show in the History and Home Page</system:String>
171+
<system:String x:Key="queryHistory">Query history</system:String>
172+
<system:String x:Key="executedHistory">Last opened history</system:String>
169173
<system:String x:Key="homeToggleBoxToolTip">This can only be edited if plugin supports Home feature and Home Page is enabled.</system:String>
170174
<system:String x:Key="showAtTopmost">Show Search Window at Foremost</system:String>
171175
<system:String x:Key="showAtTopmostToolTip">Overrides other programs' 'Always on Top' setting and displays Flow in the foremost position.</system:String>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)
322322
break;
323323
case nameof(Settings.ShowHomePage):
324324
case nameof(Settings.ShowHistoryResultsForHomePage):
325+
case nameof(Settings.HistoryStyle):
325326
if (_viewModel.QueryResultsSelected() && string.IsNullOrEmpty(_viewModel.QueryText))
326327
{
327328
_viewModel.QueryResults();
@@ -859,7 +860,7 @@ private void InitializeContextMenu()
859860

860861
public void UpdatePosition()
861862
{
862-
// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
863+
// Initialize call twice to workaround multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
863864
if (_viewModel.IsDialogJumpWindowUnderDialog())
864865
{
865866
InitializeDialogJumpPosition();
@@ -883,7 +884,7 @@ private async Task PositionResetAsync()
883884

884885
private void InitializePosition()
885886
{
886-
// Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
887+
// Initialize call twice to workaround multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
887888
InitializePositionInner();
888889
InitializePositionInner();
889890
return;

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ public bool PortableMode
147147
public List<LastQueryModeData> LastQueryModes { get; } =
148148
DropdownDataGeneric<LastQueryMode>.GetValues<LastQueryModeData>("LastQuery");
149149

150+
public List<HistoryStyleLocalized> HistoryStyles { get; } = HistoryStyleLocalized.GetValues();
151+
150152
public bool EnableDialogJump
151153
{
152154
get => Settings.EnableDialogJump;
@@ -213,6 +215,7 @@ private void UpdateEnumDropdownLocalizations()
213215
DropdownDataGeneric<SearchWindowAligns>.UpdateLabels(SearchWindowAligns);
214216
DropdownDataGeneric<SearchPrecisionScore>.UpdateLabels(SearchPrecisionScores);
215217
DropdownDataGeneric<LastQueryMode>.UpdateLabels(LastQueryModes);
218+
HistoryStyleLocalized.UpdateLabels(HistoryStyles);
216219
DropdownDataGeneric<DoublePinyinSchemas>.UpdateLabels(DoublePinyinSchemas);
217220
DropdownDataGeneric<DialogJumpWindowPositions>.UpdateLabels(DialogJumpWindowPositions);
218221
DropdownDataGeneric<DialogJumpResultBehaviours>.UpdateLabels(DialogJumpResultBehaviours);

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@
245245
SelectedValuePath="Value" />
246246
</ui:SettingsCard>
247247

248+
<ui:SettingsCard
249+
Margin="0 14 0 0"
250+
Description="{DynamicResource historyStyleTooltip}"
251+
Header="{DynamicResource historyStyle}">
252+
<ui:SettingsCard.HeaderIcon>
253+
<ui:FontIcon Glyph="&#xE81C;" />
254+
</ui:SettingsCard.HeaderIcon>
255+
256+
<ComboBox
257+
MaxWidth="200"
258+
DisplayMemberPath="Display"
259+
ItemsSource="{Binding HistoryStyles}"
260+
SelectedValue="{Binding Settings.HistoryStyle}"
261+
SelectedValuePath="Value" />
262+
</ui:SettingsCard>
263+
248264
<ui:SettingsCard
249265
Margin="0 14 0 0"
250266
Description="{DynamicResource autoRestartAfterChangingToolTip}"

Flow.Launcher/Storage/HistoryItem.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using System;
1+
using System;
22

33
namespace Flow.Launcher.Storage
44
{
5+
[Obsolete("Use LastOpenedHistoryItem instead. This class will be removed in future versions.")]
56
public class HistoryItem
67
{
78
public string Query { get; set; }
@@ -42,4 +43,4 @@ private string DateTimeAgo(DateTime dt)
4243
return string.Empty;
4344
}
4445
}
45-
}
46+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Flow.Launcher.Plugin;
3+
4+
namespace Flow.Launcher.Storage;
5+
6+
public class LastOpenedHistoryItem
7+
{
8+
public string Title { get; set; } = string.Empty;
9+
public string SubTitle { get; set; } = string.Empty;
10+
public string PluginID { get; set; } = string.Empty;
11+
public string Query { get; set; } = string.Empty;
12+
public string RecordKey { get; set; } = string.Empty;
13+
public DateTime ExecutedDateTime { get; set; }
14+
15+
public bool Equals(Result r)
16+
{
17+
if (string.IsNullOrEmpty(RecordKey) || string.IsNullOrEmpty(r.RecordKey))
18+
{
19+
return Title == r.Title
20+
&& SubTitle == r.SubTitle
21+
&& PluginID == r.PluginID
22+
&& Query == r.OriginQuery.RawQuery;
23+
}
24+
else
25+
{
26+
return RecordKey == r.RecordKey
27+
&& PluginID == r.PluginID
28+
&& Query == r.OriginQuery.RawQuery;
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)