Flow.Launcher/Flow.Launcher.Plugin/Result.cs

169 lines
5.2 KiB
C#
Raw Normal View History

2021-12-20 20:19:31 +00:00
using System;
2013-12-20 11:38:10 +00:00
using System.Collections.Generic;
using System.IO;
using System.Windows.Media;
2013-12-19 15:51:20 +00:00
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin
2014-10-23 10:39:11 +00:00
{
2014-07-05 15:10:34 +00:00
2014-10-23 10:39:11 +00:00
public class Result
{
private string _pluginDirectory;
2021-12-29 19:39:39 +00:00
private string _icoPath;
/// <summary>
2021-12-29 19:39:39 +00:00
/// The title of the result. This is always required.
/// </summary>
2014-10-23 10:39:11 +00:00
public string Title { get; set; }
/// <summary>
/// Provides additional details for the result. This is optional
/// </summary>
public string SubTitle { get; set; } = string.Empty;
2014-10-23 10:39:11 +00:00
/// <summary>
/// This holds the action keyword that triggered the result.
/// If result is triggered by global keyword: *, this should be empty.
/// </summary>
public string ActionKeywordAssigned { get; set; }
2021-12-04 05:48:18 +00:00
public string CopyText { get; set; } = String.Empty;
2021-12-04 06:14:08 +00:00
public string FileCopy { get; set; } = String.Empty;
2021-12-04 05:48:18 +00:00
/// <summary>
/// This holds the text which can be provided by plugin to help Flow autocomplete text
/// for user on the plugin result. If autocomplete action for example is tab, pressing tab will have
/// the default constructed autocomplete text (result's Title), or the text provided here if not empty.
/// </summary>
public string AutoCompleteText { get; set; }
2021-12-03 10:44:33 +00:00
2021-12-29 19:39:39 +00:00
/// <summary>
/// Image Displayed on the result
2021-12-30 21:56:28 +00:00
/// <value>Relative Path to the Image File</value>
2021-12-30 21:56:13 +00:00
/// <remarks>GlyphInfo is prioritized if not null</remarks>
2021-12-29 19:39:39 +00:00
/// </summary>
public string IcoPath
2014-10-23 10:39:11 +00:00
{
get { return _icoPath; }
set
2014-10-23 10:39:11 +00:00
{
if (!string.IsNullOrEmpty(PluginDirectory) && !Path.IsPathRooted(value))
2014-10-23 10:39:11 +00:00
{
_icoPath = Path.Combine(value, IcoPath);
}
else
{
_icoPath = value;
2014-10-23 10:39:11 +00:00
}
}
}
public delegate ImageSource IconDelegate();
2021-07-31 07:44:41 +00:00
/// <summary>
/// Delegate to Get Image Source
/// </summary>
public IconDelegate Icon;
2021-07-31 07:44:41 +00:00
/// <summary>
2021-12-29 19:39:39 +00:00
/// Information for Glyph Icon (Prioritized than IcoPath/Icon if user enable Glyph Icons)
2021-07-31 07:44:41 +00:00
/// </summary>
2021-12-29 19:39:39 +00:00
public GlyphInfo Glyph { get; init; }
2014-10-23 10:39:11 +00:00
/// <summary>
/// Delegate. An action to take in the form of a function call when the result has been selected
2021-12-29 19:39:39 +00:00
/// <returns>
/// true to hide flowlauncher after select result
/// </returns>
2014-10-23 10:39:11 +00:00
/// </summary>
public Func<ActionContext, bool> Action { get; set; }
2021-12-29 19:39:39 +00:00
/// <summary>
/// Priority of the current result
2021-12-29 19:45:22 +00:00
/// <value>default: 0</value>
2021-12-29 19:39:39 +00:00
/// </summary>
2014-10-23 10:39:11 +00:00
public int Score { get; set; }
2019-12-03 14:10:21 +00:00
/// <summary>
/// A list of indexes for the characters to be highlighted in Title
/// </summary>
public IList<int> TitleHighlightData { get; set; }
2021-12-20 20:19:31 +00:00
[Obsolete("Deprecated as of Flow Launcher v1.9.1. Subtitle highlighting is no longer offered")]
2019-12-03 14:10:21 +00:00
public IList<int> SubTitleHighlightData { get; set; }
2014-10-23 10:39:11 +00:00
/// <summary>
2021-12-29 19:39:39 +00:00
/// Query information associated with the result
2014-10-23 10:39:11 +00:00
/// </summary>
2020-03-03 22:25:59 +00:00
internal Query OriginQuery { get; set; }
2014-10-23 10:39:11 +00:00
/// <summary>
2015-01-24 14:34:55 +00:00
/// Plugin directory
2014-10-23 10:39:11 +00:00
/// </summary>
public string PluginDirectory
{
get { return _pluginDirectory; }
set
{
_pluginDirectory = value;
2016-05-03 22:21:03 +00:00
if (!string.IsNullOrEmpty(IcoPath) && !Path.IsPathRooted(IcoPath))
{
IcoPath = Path.Combine(value, IcoPath);
}
}
}
2014-10-23 10:39:11 +00:00
2021-12-29 19:39:39 +00:00
/// <inheritdoc />
2015-11-06 21:30:38 +00:00
public override bool Equals(object obj)
2014-10-23 10:39:11 +00:00
{
2019-08-31 06:58:15 +00:00
var r = obj as Result;
var equality = string.Equals(r?.Title, Title) &&
string.Equals(r?.SubTitle, SubTitle) &&
2019-12-03 14:10:21 +00:00
string.Equals(r?.IcoPath, IcoPath) &&
2021-12-20 20:19:31 +00:00
TitleHighlightData == r.TitleHighlightData;
2019-08-31 06:58:15 +00:00
return equality;
2015-11-06 21:30:38 +00:00
}
2014-10-23 10:39:11 +00:00
2021-12-29 19:39:39 +00:00
/// <inheritdoc />
2015-11-06 21:30:38 +00:00
public override int GetHashCode()
{
var hashcode = (Title?.GetHashCode() ?? 0) ^
(SubTitle?.GetHashCode() ?? 0);
return hashcode;
2014-10-23 10:39:11 +00:00
}
2021-12-29 19:39:39 +00:00
/// <inheritdoc />
2014-10-23 10:39:11 +00:00
public override string ToString()
{
return Title + SubTitle;
}
2015-02-04 15:16:41 +00:00
/// <summary>
/// Additional data associated with this result
2021-12-29 19:39:39 +00:00
/// <example>
/// As external information for ContextMenu
/// </example>
2015-02-04 15:16:41 +00:00
/// </summary>
public object ContextData { get; set; }
2015-01-24 14:34:55 +00:00
/// <summary>
2019-12-03 21:02:24 +00:00
/// Plugin ID that generated this result
2015-01-24 14:34:55 +00:00
/// </summary>
2020-03-03 22:25:59 +00:00
public string PluginID { get; internal set; }
/// <summary>
/// Show message as ToolTip on result Title hover over
/// </summary>
public string TitleToolTip { get; set; }
/// <summary>
/// Show message as ToolTip on result SubTitle hover over
/// </summary>
public string SubTitleToolTip { get; set; }
2014-10-23 10:39:11 +00:00
}
2013-12-19 15:51:20 +00:00
}