-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathShortcut.h
189 lines (133 loc) · 5.57 KB
/
Shortcut.h
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Clavier+
// Keyboard shortcuts manager
//
// Copyright (C) 2000-2008 Guillaume Ryder
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "Keystroke.h"
namespace dialogs {
struct GETFILEICON;
} // namespace dialogs
namespace shortcut {
class Shortcut : public Keystroke {
public:
Shortcut() : Shortcut(Keystroke()) {}
explicit Shortcut(const Shortcut& sh);
explicit Shortcut(const Keystroke& ks);
Shortcut& operator =(const Shortcut& other) = delete;
~Shortcut() {
clearIcons();
}
void save(HANDLE file);
// Assumes the shortcut is initially empty.
bool load(LPTSTR* input);
void execute(bool from_hotkey);
Shortcut* getNext() const {
return m_next_shortcut;
}
void addToList();
// Returns the array of programs of this shortcut, with the last element nullptr,
// or nullptr if no programs.
String* getPrograms() const;
// Removes duplicates from getPrograms().
void cleanPrograms();
// Returns whether this shortcut would be a subset of a shortcut having the given attributes.
bool isSubset(const Keystroke& other_ks, LPCTSTR other_program) const;
// Returns whether this shortcut would conflict (overlap) with a shortcut having the given attributes.
bool testConflict(const Keystroke& other_ks, const String other_programs[], bool other_programs_only) const;
private:
// Returns whether getPrograms() contains the given entry. Case insentitive.
bool containsProgram(LPCTSTR program) const;
public:
void findExecutable(LPTSTR executable);
void findSmallIconIndex();
void findIcon();
void clearIcons();
void fillGetFileIcon(dialogs::GETFILEICON* pgfi, bool small_icon);
int getSmallIconIndex();
HICON getIcon() {
if (!m_icon) {
findIcon();
}
return m_icon;
}
// Appends the shortcut CSV representation to the given string.
void appendCsvLineToString(String& output) const;
void onGetFileInfo(dialogs::GETFILEICON& gfi);
void getColumnText(int column_index, String& output) const;
// The column to sort the shortcuts list against. See col* enum defined in Global.h.
static int s_sort_column;
// Compares two shortcuts according to s_sort_column.
//
// Returns:
// A < 0 integer if shortcut1 is before shortcut2, > 0 if shortcut1 is after shortcut2,
// 0 if the shortcuts are equal for the column.
static int CALLBACK compare(const Shortcut* shortcut1, const Shortcut* shortcut2, LPARAM lParam);
public:
enum class Type { kText, kCommand };
Type m_type;
// Matches kTokShowNormal and following.
static constexpr int kShowOptions[] = { SW_NORMAL, SW_MINIMIZE, SW_MAXIMIZE };
// Index of a kShowOptions. Applies to Type::kCommand shortcuts only.
int m_show_option;
// If true, the program conditions (see m_sPrograms below) are positive: the shortcut must match
// the condition to be executed. If false, the program conditions are negative: the shortcut must
// match none of the conditions to be executed.
bool m_programs_only;
String m_description;
String m_text; // Type::kText only
String m_command; // Type::kCommand only
String m_directory;
// The list of program conditions, as a ';' separated string. The whole condition is satisfied if
// any of the sub-conditions matches. The matching result is reversed if m_bProgramsOnly is false.
//
// Each condition has the following format: "process_name" or "process_name:window_title".
// "process_name" is a process executable basename, such as explorer.exe. If empty, all processes
// match. "window_title" is a wildcards expression (see matchWildcards function) matching the
// window title. If empty, all windows match.
//
// Example: "explorer.exe;Test*;firefox.exe" matches Explorer windows whose title starts with
// "Test" and all Firefox windows.
String m_programs;
// The number of times the shortcut has been used.
int m_usage_count;
private:
Shortcut* m_next_shortcut;
// Special values for m_small_icon_index.
static constexpr int kIconInvalid = -1;
static constexpr int kIconNeeded = -2;
static constexpr int kIconThreadRunning = -3;
int m_small_icon_index;
HICON m_icon;
};
// Initializes the namespace variables. Should be called once.
void initialize();
// Deletes the namespace variables. Should be called once.
void terminate();
// Returns the first shortcut of the linked list.
Shortcut* getFirst();
// Find a shortcut in the linked list
// Should not be called while the main dialog box is displayed
Shortcut* find(const Keystroke& ks, LPCTSTR program);
// Loads the list of shortcuts from e_ini_filepath.
void loadShortcuts();
// Merges the shortcuts of e_ini_filepath into the current list of shortcuts.
void mergeShortcuts(LPCTSTR ini_filepath);
// Saves the list of shortcuts into e_ini_filepath.
void saveShortcuts();
// Clears the list of shortcuts.
void clearShortcuts();
} // namespace shortcut
using shortcut::Shortcut;