-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.cs
106 lines (86 loc) · 3.43 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace Flow.Launcher.Plugin.Favorites
{
public class Favorites : IPlugin, IReloadable, IContextMenu
{
List<Item> Items = new List<Item>();
public void Init(PluginInitContext context) => ReloadData();
public static string AssemblyDirectory { get; } = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public static string DataDirectory { get; } = Path.Combine(AssemblyDirectory, @"..\..\");
public static string FolderAppPath { get; set; } = "explorer.exe";
public static string FolderAppArguments { get; set; } = "\"%1\"";
public static DateTime LoadTime;
public List<Result> LoadContextMenus(Result selectedResult)
{
List<Result> results = new List<Result>();
results.Add(new Result()
{
Title = "Execute as admin",
SubTitle = selectedResult.SubTitle,
Action = e =>
{
foreach (Item item in Items)
if (item.Name == selectedResult.Title && item.Value == selectedResult.SubTitle)
item.Execute(true);
return true;
}
});
results.Add(new Result()
{
Title = "Copy to clipboard",
SubTitle = selectedResult.SubTitle,
Action = e =>
{
System.Windows.Clipboard.SetText(selectedResult.SubTitle);
return true;
}
});
return results;
}
public List<Result> Query(Query query)
{
string confFile = DataDirectory + @"Settings\Favorites.conf";
if (LoadTime != File.GetLastWriteTimeUtc(confFile))
ReloadData();
List<Result> results = new List<Result>();
int score = int.MaxValue - 100000;
foreach (Item item in Item.Filter(Items, query.Search))
{
Item tempItem = item;
score -= 5;
string title = tempItem.Name;
if (title.Contains("__"))
title = title.Replace("__", "!dbl!");
if (title.Contains("_"))
title = title.Replace("_", "");
if (title.Contains("!dbl!"))
title = title.Replace("!dbl!", "_");
results.Add(new Result()
{
Title = title,
SubTitle = tempItem.Value,
IcoPath = tempItem.IconPath,
Score = score,
ContextData = this,
Action = e =>
{
bool runAsAdmin = e.SpecialKeyState.CtrlPressed && e.SpecialKeyState.ShiftPressed &&
!e.SpecialKeyState.AltPressed && !e.SpecialKeyState.WinPressed;
tempItem.Execute(runAsAdmin);
return true;
}
});
}
return results;
}
public void ReloadData()
{
string confFile = DataDirectory + @"Settings\Favorites.conf";
Items = Item.LoadFile(confFile);
LoadTime = File.GetLastWriteTimeUtc(confFile);
}
}
}