forked from jjw24/Wox.Plugin.Todos
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelp.cs
More file actions
110 lines (100 loc) · 5.33 KB
/
Copy pathHelp.cs
File metadata and controls
110 lines (100 loc) · 5.33 KB
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
107
108
109
110
using System;
using System.Collections.Generic;
using System.IO;
using Flow.Launcher.Plugin;
namespace Flow.Launcher.Plugin.Todos
{
public class Help
{
private readonly PluginInitContext _context;
private readonly Query _query;
private readonly string _iconPath;
public Help(PluginInitContext context, Query query)
{
_context = context;
_query = query;
_iconPath = Path.Combine(_context.CurrentPluginMetadata.PluginDirectory, @"ico\app.png");
}
private Result CreateResult(string title, string subtitle, string query, int score)
{
return new Result
{
Title = title,
SubTitle = subtitle,
IcoPath = _iconPath,
Score = score,
Action = _ =>
{
_context.API.ChangeQuery(query);
return false;
}
};
}
private Result CreateExternalLinkResult(string title, string subtitle, string url, int score, string iconPath)
{
return new Result
{
Title = title,
SubTitle = subtitle,
IcoPath = iconPath,
Score = score,
Action = _ =>
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
return true;
}
};
}
public List<Result> Show => GetHelpResults();
public List<Result> GetHelpResults(string searchTerm = "")
{
const int baseScore = 1000000000;
const int scoreDecrement = 1000000;
var commands = new (string title, string subtitle, string query)[] {
($"{_query.ActionKeyword} -h [keyword]", "Show help and filter available commands on keyword", $"{_query.ActionKeyword} -h "),
($"{_query.ActionKeyword} [keyword]", "List todos matching the keyword", $"{_query.ActionKeyword}"),
($"{_query.ActionKeyword} -l [keyword]", "List all todos, including completed ones", $"{_query.ActionKeyword} -l "),
($"{_query.ActionKeyword} -a [text]", "Add a new todo item", $"{_query.ActionKeyword} -a "),
($"{_query.ActionKeyword} -c [keyword]", "Complete a todo item matching the keyword", $"{_query.ActionKeyword} -c "),
($"{_query.ActionKeyword} -c --all", "Complete all todos", $"{_query.ActionKeyword} -c --all"),
($"{_query.ActionKeyword} -u [keyword]", "Uncheck a completed todo item matching the keyword", $"{_query.ActionKeyword} -u "),
($"{_query.ActionKeyword} -u --all", "Uncheck all completed todos", $"{_query.ActionKeyword} -u --all"),
($"{_query.ActionKeyword} -e [keyword]", "Edit an existing todo item matching the keyword", $"{_query.ActionKeyword} -e "),
($"{_query.ActionKeyword} -p [keyword]", "Pin to top an uncompleted todo item matching the keyword", $"{_query.ActionKeyword} -p "),
($"{_query.ActionKeyword} -p --u [keyword]", "Unpin a todo item matching the keyword", $"{_query.ActionKeyword} -p --u "),
($"{_query.ActionKeyword} -r [keyword]", "Remove todos matching the keyword", $"{_query.ActionKeyword} -r "),
($"{_query.ActionKeyword} -r --all", "Remove all todos", $"{_query.ActionKeyword} -r --all"),
($"{_query.ActionKeyword} -r --done", "Remove all completed todos", $"{_query.ActionKeyword} -r --done"),
($"{_query.ActionKeyword} -rl", "Reload todos from the data file", $"{_query.ActionKeyword} -rl"),
($"{_query.ActionKeyword} -s --aa", "Sort todos alphabetical ascending", $"{_query.ActionKeyword} -s --aa"),
($"{_query.ActionKeyword} -s --ad", "Sort todos alphabetical descending", $"{_query.ActionKeyword} -s --ad"),
($"{_query.ActionKeyword} -s --ta", "Sort todos time ascending", $"{_query.ActionKeyword} -s --ta"),
($"{_query.ActionKeyword} -s --td", "Sort todos time descending", $"{_query.ActionKeyword} -s --td"),
};
var results = new List<Result>();
int currentScore = baseScore;
// Add the GitHub Star Option
string githubIconPath = Path.Combine(_context.CurrentPluginMetadata.PluginDirectory, @"ico\github.png");
results.Add(CreateExternalLinkResult(
title: "🌟 Star this plugin on GitHub",
subtitle: "Open the GitHub page to star this repository if you enjoy this plugin!",
url: "https://github.com/Or1g3n/Flow.Launcher.Plugin.Todos",
score: currentScore - scoreDecrement,
iconPath: githubIconPath
));
foreach (var (title, subtitle, query) in commands)
{
if (subtitle.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) || searchTerm == "")
{
results.Add(CreateResult(title, subtitle, query, currentScore));
currentScore -= scoreDecrement;
}
}
return results;
}
}
}