2020-05-24 09:11:40 +00:00
|
|
|
|
using Flow.Launcher.Infrastructure;
|
|
|
|
|
|
using Flow.Launcher.Plugin.SharedCommands;
|
|
|
|
|
|
using System;
|
2020-05-24 10:14:36 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2020-05-24 09:11:40 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Plugin.Explorer.Search
|
|
|
|
|
|
{
|
2021-01-29 10:40:51 +00:00
|
|
|
|
public static class ResultManager
|
2020-05-24 09:11:40 +00:00
|
|
|
|
{
|
2021-01-29 10:40:51 +00:00
|
|
|
|
private static PluginInitContext Context;
|
2020-06-08 04:20:22 +00:00
|
|
|
|
|
2021-01-29 10:40:51 +00:00
|
|
|
|
public static void Init(PluginInitContext context)
|
2020-06-08 04:20:22 +00:00
|
|
|
|
{
|
2021-01-29 10:40:51 +00:00
|
|
|
|
Context = context;
|
2020-06-08 04:20:22 +00:00
|
|
|
|
}
|
2021-01-29 10:40:51 +00:00
|
|
|
|
|
2021-04-13 11:40:04 +00:00
|
|
|
|
internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool showIndexState = false, bool windowsIndexed = false)
|
2020-05-24 09:11:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
return new Result
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = title,
|
|
|
|
|
|
IcoPath = path,
|
|
|
|
|
|
SubTitle = subtitle,
|
|
|
|
|
|
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
|
|
|
|
|
|
Action = c =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (c.SpecialKeyState.CtrlPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
FilesFolders.OpenPath(path);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(ex.Message, "Could not start " + path);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-29 20:45:04 +00:00
|
|
|
|
|
2020-05-28 11:35:12 +00:00
|
|
|
|
string changeTo = path.EndsWith(Constants.DirectorySeperator) ? path : path + Constants.DirectorySeperator;
|
2021-01-29 10:40:51 +00:00
|
|
|
|
Context.API.ChangeQuery(string.IsNullOrEmpty(query.ActionKeyword) ?
|
2020-05-24 09:11:40 +00:00
|
|
|
|
changeTo :
|
|
|
|
|
|
query.ActionKeyword + " " + changeTo);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
},
|
2021-04-13 11:40:04 +00:00
|
|
|
|
Score = score,
|
2020-06-29 20:45:04 +00:00
|
|
|
|
TitleToolTip = Constants.ToolTipOpenDirectory,
|
|
|
|
|
|
SubTitleToolTip = Constants.ToolTipOpenDirectory,
|
2020-05-27 09:36:49 +00:00
|
|
|
|
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path, ShowIndexState = showIndexState, WindowsIndexed = windowsIndexed }
|
2020-05-24 09:11:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2020-05-24 10:14:36 +00:00
|
|
|
|
|
2021-01-29 10:40:51 +00:00
|
|
|
|
internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIndexed = false)
|
2020-05-24 10:14:36 +00:00
|
|
|
|
{
|
2020-06-02 10:21:28 +00:00
|
|
|
|
var retrievedDirectoryPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path);
|
2020-05-24 10:14:36 +00:00
|
|
|
|
|
2020-06-01 11:11:29 +00:00
|
|
|
|
var folderName = retrievedDirectoryPath.TrimEnd(Constants.DirectorySeperator).Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last();
|
2020-05-25 23:03:27 +00:00
|
|
|
|
|
2020-06-01 11:11:29 +00:00
|
|
|
|
if (retrievedDirectoryPath.EndsWith(":\\"))
|
2020-05-25 23:03:27 +00:00
|
|
|
|
{
|
2020-06-01 11:11:29 +00:00
|
|
|
|
var driveLetter = path.Substring(0, 1).ToUpper();
|
|
|
|
|
|
folderName = driveLetter + " drive";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var title = "Open current directory";
|
2020-06-01 04:11:51 +00:00
|
|
|
|
|
2020-06-01 11:11:29 +00:00
|
|
|
|
if (retrievedDirectoryPath != path)
|
2020-06-01 04:11:51 +00:00
|
|
|
|
title = "Open " + folderName;
|
2020-05-24 10:14:36 +00:00
|
|
|
|
|
2021-04-13 11:40:04 +00:00
|
|
|
|
|
2020-06-01 11:11:29 +00:00
|
|
|
|
var subtitleFolderName = folderName;
|
2021-04-13 11:40:04 +00:00
|
|
|
|
|
2020-06-01 11:11:29 +00:00
|
|
|
|
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
|
|
|
|
|
|
if (folderName.Length > 19)
|
2020-06-02 03:26:33 +00:00
|
|
|
|
subtitleFolderName = "the directory";
|
2020-06-01 04:11:51 +00:00
|
|
|
|
|
2020-05-24 10:14:36 +00:00
|
|
|
|
return new Result
|
|
|
|
|
|
{
|
2020-06-01 04:11:51 +00:00
|
|
|
|
Title = title,
|
2020-06-01 11:11:29 +00:00
|
|
|
|
SubTitle = $"Use > to search within {subtitleFolderName}, " +
|
|
|
|
|
|
$"* to search for file extensions or >* to combine both searches.",
|
|
|
|
|
|
IcoPath = retrievedDirectoryPath,
|
2020-05-24 10:14:36 +00:00
|
|
|
|
Score = 500,
|
|
|
|
|
|
Action = c =>
|
|
|
|
|
|
{
|
2020-06-01 11:11:29 +00:00
|
|
|
|
FilesFolders.OpenPath(retrievedDirectoryPath);
|
2020-05-24 10:14:36 +00:00
|
|
|
|
return true;
|
2020-05-31 19:52:01 +00:00
|
|
|
|
},
|
2020-06-29 21:53:46 +00:00
|
|
|
|
TitleToolTip = retrievedDirectoryPath,
|
|
|
|
|
|
SubTitleToolTip = retrievedDirectoryPath,
|
2020-06-01 11:11:29 +00:00
|
|
|
|
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = retrievedDirectoryPath, ShowIndexState = true, WindowsIndexed = windowsIndexed }
|
2020-05-24 10:14:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-13 11:40:04 +00:00
|
|
|
|
internal static Result CreateFileResult(string filePath, Query query, int score = 0, bool showIndexState = false, bool windowsIndexed = false)
|
2020-05-24 10:14:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
var result = new Result
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = Path.GetFileName(filePath),
|
|
|
|
|
|
SubTitle = filePath,
|
|
|
|
|
|
IcoPath = filePath,
|
|
|
|
|
|
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
|
2021-04-13 11:40:04 +00:00
|
|
|
|
Score = score,
|
2020-05-24 10:14:36 +00:00
|
|
|
|
Action = c =>
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-29 22:15:10 +00:00
|
|
|
|
if (c.SpecialKeyState.CtrlPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
FilesFolders.OpenContainingFolder(filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
FilesFolders.OpenPath(filePath);
|
|
|
|
|
|
}
|
2020-05-24 10:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(ex.Message, "Could not start " + filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
},
|
2020-06-29 22:15:10 +00:00
|
|
|
|
TitleToolTip = Constants.ToolTipOpenContainingFolder,
|
|
|
|
|
|
SubTitleToolTip = Constants.ToolTipOpenContainingFolder,
|
2020-05-27 09:36:49 +00:00
|
|
|
|
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath, ShowIndexState = showIndexState, WindowsIndexed = windowsIndexed }
|
2020-05-24 10:14:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2020-05-24 09:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-25 08:55:50 +00:00
|
|
|
|
internal class SearchResult
|
2020-05-24 09:11:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
public string FullPath { get; set; }
|
|
|
|
|
|
public ResultType Type { get; set; }
|
2020-05-27 09:36:49 +00:00
|
|
|
|
|
|
|
|
|
|
public bool WindowsIndexed { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public bool ShowIndexState { get; set; }
|
2020-05-24 09:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-26 09:01:12 +00:00
|
|
|
|
public enum ResultType
|
2020-05-24 09:11:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
Volume,
|
|
|
|
|
|
Folder,
|
|
|
|
|
|
File
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|