mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add support for record key
This commit is contained in:
parent
0b8db59e39
commit
198442621a
3 changed files with 50 additions and 9 deletions
|
|
@ -185,6 +185,16 @@ namespace Flow.Launcher.Plugin
|
|||
TitleHighlightData = TitleHighlightData,
|
||||
OriginQuery = OriginQuery,
|
||||
PluginDirectory = PluginDirectory,
|
||||
ContextData = ContextData,
|
||||
PluginID = PluginID,
|
||||
TitleToolTip = TitleToolTip,
|
||||
SubTitleToolTip = SubTitleToolTip,
|
||||
PreviewPanel = PreviewPanel,
|
||||
ProgressBar = ProgressBar,
|
||||
ProgressBarColor = ProgressBarColor,
|
||||
Preview = Preview,
|
||||
AddSelectedCount = AddSelectedCount,
|
||||
RecordKey = RecordKey
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -252,6 +262,13 @@ namespace Flow.Launcher.Plugin
|
|||
/// </summary>
|
||||
public const int MaxScore = int.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// The key to identify the record. This is used when FL checks whether the result is the topmost record. Or FL calculates the hashcode of the result for user selected records.
|
||||
/// This can be useful when your plugin will change the Title or SubTitle of the result dynamically.
|
||||
/// If the plugin does not specific this, FL just uses Title and SubTitle to identify this result.
|
||||
/// </summary>
|
||||
public string RecordKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Info of the preview section of a <see cref="Result"/>
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ namespace Flow.Launcher.Storage
|
|||
{
|
||||
PluginID = result.PluginID,
|
||||
Title = result.Title,
|
||||
SubTitle = result.SubTitle
|
||||
SubTitle = result.SubTitle,
|
||||
RecordKey = result.RecordKey
|
||||
};
|
||||
records.AddOrUpdate(result.OriginQuery.RawQuery, record, (key, oldValue) => record);
|
||||
}
|
||||
|
|
@ -49,12 +50,21 @@ namespace Flow.Launcher.Storage
|
|||
public string Title { get; set; }
|
||||
public string SubTitle { get; set; }
|
||||
public string PluginID { get; set; }
|
||||
public string RecordKey { get; set; }
|
||||
|
||||
public bool Equals(Result r)
|
||||
{
|
||||
return Title == r.Title
|
||||
&& SubTitle == r.SubTitle
|
||||
&& PluginID == r.PluginID;
|
||||
if (string.IsNullOrEmpty(RecordKey) || string.IsNullOrEmpty(r.RecordKey))
|
||||
{
|
||||
return Title == r.Title
|
||||
&& SubTitle == r.SubTitle
|
||||
&& PluginID == r.PluginID;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RecordKey == r.RecordKey
|
||||
&& PluginID == r.PluginID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ namespace Flow.Launcher.Storage
|
|||
[JsonInclude, JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public Dictionary<string, int> records { get; private set; }
|
||||
|
||||
|
||||
public UserSelectedRecord()
|
||||
{
|
||||
recordsWithQuery = new Dictionary<int, int>();
|
||||
|
|
@ -45,8 +44,15 @@ namespace Flow.Launcher.Storage
|
|||
|
||||
private static int GenerateResultHashCode(Result result)
|
||||
{
|
||||
int hashcode = GenerateStaticHashCode(result.Title);
|
||||
return GenerateStaticHashCode(result.SubTitle, hashcode);
|
||||
if (string.IsNullOrEmpty(result.RecordKey))
|
||||
{
|
||||
int hashcode = GenerateStaticHashCode(result.Title);
|
||||
return GenerateStaticHashCode(result.SubTitle, hashcode);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GenerateStaticHashCode(result.RecordKey);
|
||||
}
|
||||
}
|
||||
|
||||
private static int GenerateQueryAndResultHashCode(Query query, Result result)
|
||||
|
|
@ -58,8 +64,16 @@ namespace Flow.Launcher.Storage
|
|||
|
||||
int hashcode = GenerateStaticHashCode(query.ActionKeyword);
|
||||
hashcode = GenerateStaticHashCode(query.Search, hashcode);
|
||||
hashcode = GenerateStaticHashCode(result.Title, hashcode);
|
||||
hashcode = GenerateStaticHashCode(result.SubTitle, hashcode);
|
||||
|
||||
if (string.IsNullOrEmpty(result.RecordKey))
|
||||
{
|
||||
hashcode = GenerateStaticHashCode(result.Title, hashcode);
|
||||
hashcode = GenerateStaticHashCode(result.SubTitle, hashcode);
|
||||
}
|
||||
else
|
||||
{
|
||||
hashcode = GenerateStaticHashCode(result.RecordKey, hashcode);
|
||||
}
|
||||
|
||||
return hashcode;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue