Files
PowerToys/src/modules/launcher/Wox.Plugin/Result.cs
Jeremy Sinclair b2b2856e52 🚧 [Dev][Build] .NET 8 Upgrade (#28655)
* Upgraded projects to target .NET 8

* Updated .NET runtime package targets to use latest .NET 8 build

* Updated PowerToys Interop to target .NET 8

* Switch to use ArgumentNullException.ThrowIfNull

* ArgumentNullException.ThrowIfNull for CropAndLockViewModel

* Switching to ObjectDisposedException.ThrowIf

* Upgrade System.ComponentModel.Composition to 8.0

* ArgumentNullException.ThrowIfNull in Helper

* Switch to StartsWith using StringComparison.Ordinal

* Disabled CA1859, CA1716, SYSLIB1096 analyzers

* Update RIDs to reflect breaking changes in .NET 8

* Updated Microsoft NuGet packages to RC1

* Updated Analyzer package to latest .NET 8 preview package

* CA1854: Use TryGetValue instead of ContainsKey

* [Build] Update TFM to .NET 8 for publish profiles

* [Analyzers] Remove CA1309, CA1860-CA1865, CA1869, CA2208 from warning.

* [Analyzers] Fix for C26495

* [Analyzers] Disable CS1615, CS9191

* [CI] Target .NET 8 in YAML

* [CI] Add .NET preview version flag temporarily.

* [FileLocksmith] Update TFM to .NET 8

* [CI] Switch to preview agent

* [CI] Update NOTICE.md

* [CI] Update Release to target .NET 8 and use Preview agent

* [Analyzers] Disable CA1854

* Fix typo

* Updated Microsoft.CodeAnalysis.NetAnalyzers to latest preview

Updated packages to rc2

* [Analyzers][CPP] Turn off warning for 5271

* [Analyzers][CPP] Turn off warning for 26493

* [KeyboardListener] Add mutex include to resolve error

* [PT Run][Folder] Use static SearchValues to resolve CA1870

* [PowerLauncher] Fix TryGetValue

* [MouseJumpSettings] Use ArgumentNullException.ThrowIfNull

* [Build] Disable parallel dotnet tool restore

* [Build] No cache of dotnet tool packages

* [Build] Temporarily move .NET 8 SDK task before XAML formatting

* [Build][Temp] Try using .NET 7 prior to XAML formatting and then switch to .NET 8 after

* [Build] Use .NET 6 for XAML Styler

* [CI] Updated NOTICE.md

* [FancyZones] Update TFM to .NET 8

* [EnvVar] Update TFM to .NET 8 and update RID

* [EnvVar] Use ArgumentNullException.ThrowIfNull

* [Dev] Updated packages to .NET 8 RTM version

* [Dev] Updated Microsoft.CodeAnalysis.NetAnalyzers to latest

* [CI] Updated NOTICE.md with latest package versions

* Fix new utility target fameworks and runtimeids

* Don't use preview images anymore

* [CI] Add script to update VCToolsVersion environment variable

* [CI] Add Step to Verify VCToolsVersion

* [CI] Use latest flag for vswhere to set proper VCToolsVersion

* Add VCToolsVersion checking to release.yml

* Remove net publishing from local/ PR CI builds

* Revert "Remove net publishing from local/ PR CI builds"

This reverts commit f469778996.

* Only publish necessary projects

* Add verbosity to release pipelines builds of PowerTOys

* Set VCToolsVersion for publish.cmd when called from installer

* [Installer] Moved project publish logic to MSBuild Task

* [CI] Revert using publish.cmd

* [CI] Set VCToolsVersion and unset ClearDevCommandPromptEnvVars property

* Installer publishes for x64 too

* Revert "Add verbosity to release pipelines builds of PowerTOys"

This reverts commit 654d4a7f78.

* [Dev] Update CodeAnalysis library to non-preview package

* Remove unneeded warning removal

* Fix Notice.md

* Rename VCToolsVersion file and task name

* Remove unneeded mutex header include

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
2023-11-22 12:46:59 -05:00

192 lines
5.6 KiB
C#

// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Abstractions;
using System.Text.Json.Serialization;
using System.Windows;
using System.Windows.Media;
namespace Wox.Plugin
{
public class Result
{
private static readonly IFileSystem FileSystem = new FileSystem();
private static readonly IPath Path = FileSystem.Path;
private string _title;
private ToolTipData _toolTipData;
private string _pluginDirectory;
private string _icoPath;
public PluginMetadata Metadata { get; set; }
public string Title
{
get
{
return _title;
}
set
{
ArgumentNullException.ThrowIfNull(value);
// Using Ordinal since this is used internally
_title = value.Replace("\n", " ", StringComparison.Ordinal);
}
}
public bool FromHistory { get; set; }
public string HistoryPluginID { get; set; }
public string HistoryTitle { get; set; }
public string SubTitle { get; set; }
public string Glyph { get; set; }
public string FontFamily { get; set; }
public string ProgramArguments { get; set; }
public Visibility ToolTipVisibility { get; set; } = Visibility.Collapsed;
public ToolTipData ToolTipData
{
get
{
return _toolTipData;
}
set
{
_toolTipData = value;
ToolTipVisibility = Visibility.Visible;
}
}
/// <summary>
/// Gets or sets 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 { get; set; }
/// <summary>
/// Gets or sets the result action.
/// Return <c>true</c> to hide PowerToys Run after the result has been selected.
/// </summary>
[JsonIgnore]
public Func<ActionContext, bool> Action { get; set; }
public int Score { get; set; }
public int SelectedCount { get; set; }
public DateTime LastSelected { get; set; } = DateTime.MinValue;
public Result(IList<int> titleHighlightData = null, IList<int> subTitleHighlightData = null)
{
TitleHighlightData = titleHighlightData;
SubTitleHighlightData = subTitleHighlightData;
}
public IList<int> TitleHighlightData { get; set; }
/// <summary>
/// Gets or sets a list of indexes for the characters to be highlighted in SubTitle
/// </summary>
public IList<int> SubTitleHighlightData { get; set; }
/// <summary>
/// Gets or sets only results that originQuery match with current query will be displayed in the panel
/// </summary>
internal Query OriginQuery { get; set; }
/// <summary>
/// Gets or sets 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;
// Using Ordinal since this is used internally
var equality = string.Equals(r?.Title, Title, StringComparison.Ordinal) &&
string.Equals(r?.SubTitle, SubTitle, StringComparison.Ordinal) &&
string.Equals(r?.IcoPath, IcoPath, StringComparison.Ordinal) &&
TitleHighlightData == r.TitleHighlightData &&
SubTitleHighlightData == r.SubTitleHighlightData;
return equality;
}
public override int GetHashCode()
{
// Using Ordinal since this is used internally
var hashcode = (Title?.GetHashCode(StringComparison.Ordinal) ?? 0) ^
(SubTitle?.GetHashCode(StringComparison.Ordinal) ?? 0);
return hashcode;
}
public override string ToString()
{
// Using CurrentCulture since this is user facing
return string.Format(CultureInfo.CurrentCulture, "{0} : {1}", Title, SubTitle);
}
/// <summary>
/// Gets or sets additional data associate with this result
/// </summary>
public object ContextData { get; set; }
/// <summary>
/// Gets plugin ID that generated this result
/// </summary>
public string PluginID { get; internal set; }
}
}