-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
76 lines (62 loc) · 2.39 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using ManagedCommon;
using Wox.Plugin;
namespace Community.PowerToys.Run.Plugin.BoilerplateText
{
public class Main : IPlugin, IPluginI18n
{
public static string PluginID => "6c631b4e-3d6d-4ff3-91df-7a33f94a4ef1";
public string Name => "BoilerPlateText";
public string Description => "Offers boilerplate snippets (text files) from %localappdata%\\Boilerplate and copies them to clipboard.";
private string? IconPath { get; set; }
private PluginInitContext? Context { get; set; }
public string GetTranslatedPluginDescription()
{
// TODO: localization
return Description;
}
public string GetTranslatedPluginTitle()
{
// TODO: localization
return Name;
}
public void Init(PluginInitContext context)
{
Context = context;
Context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(context.API.GetCurrentTheme());
}
public List<Result> Query(Query query)
{
var list = new List<Result>();
foreach (var file in System.IO.Directory.GetFiles(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "Boilerplate")))
{
var basename = System.IO.Path.GetFileNameWithoutExtension(file);
if (query.Search.Length > 0 && !basename.Contains(query.Search, StringComparison.OrdinalIgnoreCase))
{
continue;
}
list.Add(new Result
{
Title = basename,
SubTitle = $"{file} - Copy to clipboard", // TODO: localization
IcoPath = IconPath,
Action = _ =>
{
System.Windows.Clipboard.SetText(System.IO.File.ReadAllText(file));
return true;
},
});
}
return list;
}
private void OnThemeChanged(Theme currentTheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
private void UpdateIconPath(Theme theme)
{
var t = theme == Theme.Light || theme == Theme.HighContrastWhite ? "Light" : "Dark";
IconPath = $@"Images\BoilerPlate{t}.png";
}
}
}