// 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.
// Code forked from Betsegaw Tadele's https://github.com/betsegaw/windowwalker/
using System.Collections.Generic;
namespace Microsoft.Plugin.WindowWalker.Components
{
///
/// Contains search result windows with each window including the reason why the result was included
///
internal class SearchResult
{
///
/// Gets the actual window reference for the search result
///
internal Window Result
{
get;
private set;
}
///
/// Gets the list of indexes of the matching characters for the search in the title window
///
internal List SearchMatchesInTitle
{
get;
private set;
}
///
/// Gets the list of indexes of the matching characters for the search in the
/// name of the process
///
internal List SearchMatchesInProcessName
{
get;
private set;
}
///
/// Gets the type of match (shortcut, fuzzy or nothing)
///
internal SearchType SearchResultMatchType
{
get;
private set;
}
///
/// Gets a score indicating how well this matches what we are looking for
///
internal int Score
{
get;
private set;
}
///
/// Gets the source of where the best score was found
///
internal TextType BestScoreSource
{
get;
private set;
}
///
/// Initializes a new instance of the class.
/// Constructor
///
internal SearchResult(Window window, List matchesInTitle, List matchesInProcessName, SearchType matchType)
{
Result = window;
SearchMatchesInTitle = matchesInTitle;
SearchMatchesInProcessName = matchesInProcessName;
SearchResultMatchType = matchType;
CalculateScore();
}
///
/// Initializes a new instance of the class.
///
internal SearchResult(Window window)
{
Result = window;
SearchMatchesInTitle = new List();
SearchMatchesInProcessName = new List();
SearchResultMatchType = SearchType.Empty;
CalculateScore();
}
///
/// Calculates the score for how closely this window matches the search string
///
///
/// Higher Score is better
///
private void CalculateScore()
{
if (FuzzyMatching.CalculateScoreForMatches(SearchMatchesInProcessName) >
FuzzyMatching.CalculateScoreForMatches(SearchMatchesInTitle))
{
Score = FuzzyMatching.CalculateScoreForMatches(SearchMatchesInProcessName);
BestScoreSource = TextType.ProcessName;
}
else
{
Score = FuzzyMatching.CalculateScoreForMatches(SearchMatchesInTitle);
BestScoreSource = TextType.WindowTitle;
}
}
///
/// The type of text that a string represents
///
internal enum TextType
{
ProcessName,
WindowTitle,
}
///
/// The type of search
///
internal enum SearchType
{
///
/// the search string is empty, which means all open windows are
/// going to be returned
///
Empty,
///
/// Regular fuzzy match search
///
Fuzzy,
///
/// The user has entered text that has been matched to a shortcut
/// and the shortcut is now being searched
///
Shortcut,
}
}
}