mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-04 18:27:56 +08:00
8d72bc0ea4
* Fix multiline title issue * Added code to display tooltip for program and indexer plugin * Added tests for Result class * Theme based color for tooltip * Added colors for tooltip * Added string tags to tooltip * Add initial show delay * Seperated textbox for title and path
160 lines
4.4 KiB
C#
160 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Windows.Media;
|
|
using System.Windows;
|
|
|
|
namespace Wox.Plugin
|
|
{
|
|
|
|
public class Result
|
|
{
|
|
|
|
private string _title;
|
|
private ToolTipData _toolTipData;
|
|
private string _pluginDirectory;
|
|
private string _icoPath;
|
|
public string Title {
|
|
get { return _title; }
|
|
set
|
|
{
|
|
_title = value.Replace("\n", " ");
|
|
}
|
|
}
|
|
public string SubTitle { get; set; }
|
|
|
|
public string Glyph { get; set; }
|
|
|
|
public string FontFamily { get; set; }
|
|
|
|
public Visibility ToolTipVisibility { get; set; } = Visibility.Collapsed;
|
|
|
|
public ToolTipData ToolTipData
|
|
{
|
|
get
|
|
{
|
|
return _toolTipData;
|
|
}
|
|
set
|
|
{
|
|
_toolTipData = value;
|
|
ToolTipVisibility = Visibility.Visible;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The text that will get displayed in the Search text box, when this item is selected in the result list.
|
|
/// </summary>
|
|
public string QueryTextDisplay { get; set; }
|
|
|
|
public string IcoPath
|
|
{
|
|
get { return _icoPath; }
|
|
set
|
|
{
|
|
if (!string.IsNullOrEmpty(PluginDirectory) && !Path.IsPathRooted(value))
|
|
{
|
|
_icoPath = Path.Combine(value, IcoPath);
|
|
}
|
|
else
|
|
{
|
|
_icoPath = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public delegate ImageSource IconDelegate();
|
|
|
|
public IconDelegate Icon;
|
|
|
|
|
|
/// <summary>
|
|
/// return true to hide wox after select result
|
|
/// </summary>
|
|
public Func<ActionContext, bool> Action { get; set; }
|
|
|
|
public int Score { get; set; }
|
|
|
|
/// <summary>
|
|
/// A list of indexes for the characters to be highlighted in Title
|
|
/// </summary>
|
|
public IList<int> TitleHighlightData { get; set; }
|
|
|
|
/// <summary>
|
|
/// A list of indexes for the characters to be highlighted in SubTitle
|
|
/// </summary>
|
|
public IList<int> SubTitleHighlightData { get; set; }
|
|
|
|
/// <summary>
|
|
/// Only results that originQuery match with current query will be displayed in the panel
|
|
/// </summary>
|
|
internal Query OriginQuery { get; set; }
|
|
|
|
/// <summary>
|
|
/// Plugin directory
|
|
/// </summary>
|
|
public string PluginDirectory
|
|
{
|
|
get { return _pluginDirectory; }
|
|
set
|
|
{
|
|
_pluginDirectory = value;
|
|
if (!string.IsNullOrEmpty(IcoPath) && !Path.IsPathRooted(IcoPath))
|
|
{
|
|
IcoPath = Path.Combine(value, IcoPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
var r = obj as Result;
|
|
|
|
var equality = string.Equals(r?.Title, Title) &&
|
|
string.Equals(r?.SubTitle, SubTitle) &&
|
|
string.Equals(r?.IcoPath, IcoPath) &&
|
|
TitleHighlightData == r.TitleHighlightData &&
|
|
SubTitleHighlightData == r.SubTitleHighlightData;
|
|
|
|
return equality;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
var hashcode = (Title?.GetHashCode() ?? 0) ^
|
|
(SubTitle?.GetHashCode() ?? 0);
|
|
return hashcode;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return Title + SubTitle;
|
|
}
|
|
|
|
[Obsolete("Use IContextMenu instead")]
|
|
/// <summary>
|
|
/// Context menus associate with this result
|
|
/// </summary>
|
|
public List<Result> ContextMenu { get; set; }
|
|
|
|
[Obsolete("Use Object initializers instead")]
|
|
public Result(string Title, string IcoPath, string SubTitle = null)
|
|
{
|
|
this.Title = Title;
|
|
this.IcoPath = IcoPath;
|
|
this.SubTitle = SubTitle;
|
|
}
|
|
|
|
public Result() { }
|
|
|
|
/// <summary>
|
|
/// Additional data associate with this result
|
|
/// </summary>
|
|
public object ContextData { get; set; }
|
|
|
|
/// <summary>
|
|
/// Plugin ID that generated this result
|
|
/// </summary>
|
|
public string PluginID { get; internal set; }
|
|
}
|
|
} |