mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
Added the main and settings file which declare most of the plugin interfaces
This commit is contained in:
parent
8e45c41f20
commit
ea75a56d33
@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Plugin.Indexer
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
}
|
128
src/modules/launcher/Plugins/Wox.Plugin.Indexer/Main.cs
Normal file
128
src/modules/launcher/Plugins/Wox.Plugin.Indexer/Main.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wox.Plugin;
|
||||
using System.IO;
|
||||
using System.ComponentModel;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin.Indexer.SearchHelper;
|
||||
using Microsoft.Search.Interop;
|
||||
|
||||
namespace Wox.Plugin.Indexer
|
||||
{
|
||||
class Main : IPlugin, ISavable, IPluginI18n
|
||||
{
|
||||
|
||||
// This variable contains metadata about the Plugin
|
||||
private PluginInitContext _context;
|
||||
|
||||
// This variable contains information about the context menus
|
||||
private Settings _settings;
|
||||
|
||||
// Contains information about the plugin stored in json format
|
||||
private PluginJsonStorage<Settings> _storage;
|
||||
|
||||
// To access Windows Search functionalities
|
||||
private readonly WindowsSearchAPI _api = new WindowsSearchAPI();
|
||||
|
||||
// To save the configurations of plugins
|
||||
public void Save()
|
||||
{
|
||||
_storage.Save();
|
||||
}
|
||||
|
||||
// This function uses the Windows indexer and returns the list of results obtained
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
if (!string.IsNullOrEmpty(query.Search))
|
||||
{
|
||||
var searchQuery = query.Search;
|
||||
if (_settings.MaxSearchCount <= 0)
|
||||
{
|
||||
_settings.MaxSearchCount = 50;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var searchResultsList = _api.Search(searchQuery, maxCount: _settings.MaxSearchCount).ToList();
|
||||
foreach (var searchResult in searchResultsList)
|
||||
{
|
||||
var path = searchResult.Path;
|
||||
|
||||
string workingDir = null;
|
||||
if (_settings.UseLocationAsWorkingDir)
|
||||
workingDir = Path.GetDirectoryName(path);
|
||||
|
||||
Result r = new Result();
|
||||
r.Title = Path.GetFileName(path);
|
||||
r.SubTitle = path;
|
||||
r.IcoPath = path;
|
||||
r.Action = c =>
|
||||
{
|
||||
bool hide;
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = path,
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = workingDir
|
||||
});
|
||||
hide = true;
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{
|
||||
var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
|
||||
var msg = "Can't Open this file";
|
||||
_context.API.ShowMsg(name, msg, string.Empty);
|
||||
hide = false;
|
||||
}
|
||||
return hide;
|
||||
};
|
||||
r.ContextData = searchResult;
|
||||
results.Add(r);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
results.Add(new Result
|
||||
{
|
||||
// TODO: Localize the string
|
||||
Title = "Windows indexer plugin is not running",
|
||||
IcoPath = "Images\\WindowsIndexerImg.bmp"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
// initialize the context of the plugin
|
||||
_context = context;
|
||||
_storage = new PluginJsonStorage<Settings>();
|
||||
_settings = _storage.Load();
|
||||
}
|
||||
|
||||
// TODO: Localize the strings
|
||||
// Set the Plugin Title
|
||||
public string GetTranslatedPluginTitle()
|
||||
{
|
||||
return "Windows Indexer Plugin";
|
||||
}
|
||||
|
||||
// TODO: Localize the string
|
||||
// Set the plugin Description
|
||||
public string GetTranslatedPluginDescription()
|
||||
{
|
||||
return "Returns files and folders";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
23
src/modules/launcher/Plugins/Wox.Plugin.Indexer/Settings.cs
Normal file
23
src/modules/launcher/Plugins/Wox.Plugin.Indexer/Settings.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Plugin.Indexer
|
||||
{
|
||||
public class Settings
|
||||
{
|
||||
public List<ContextMenu> ContextMenus = new List<ContextMenu>();
|
||||
public int MaxSearchCount { get; set; } = 100;
|
||||
public bool UseLocationAsWorkingDir { get; set; } = false;
|
||||
}
|
||||
|
||||
public class ContextMenu
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Command { get; set; }
|
||||
public string Argument { get; set; }
|
||||
public string ImagePath { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user