Repository navigation
Expand file tree
/
Copy pathcontext_menu.cpp
More file actions
379 lines (313 loc) · 10.1 KB
/
Copy pathcontext_menu.cpp
File metadata and controls
379 lines (313 loc) · 10.1 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include "stdafx.h"
#include "SDK\contextmenu.h"
#include "bookmark_preferences.h"
#include "context_menu.h"
//ref. to bookmark_dialog.cpp
void bbookmarkHook_store();
void bbookmarkHook_store_selected(metadb_handle_list mhl, bool from_playlist, bool from_nowplaying);
void bbookmarkHook_restore();
void bbookmarkHook_restoreActivePlaylist(size_t last_played, bool check_file);
void bbookmarkHook_clear();
bool bbookmarkHook_canStore();
bool bbookmarkHook_canStoreSelected();
bool bbookmarkHook_canRestore();
bool bbookmarkHook_canRestoreActivePlaylist(size_t &last_played, bool check_file);
bool bbookmarkHook_canClear();
unsigned contextmenu_item_foo_vb::get_num_items()
{
return 1;
}
contextmenu_item_node_root* contextmenu_item_foo_vb::instantiate_item(unsigned p_index, metadb_handle_list_cref p_data, const GUID& p_caller)
{
return new contextmenu_item_node_root_popup_vb(p_index);
}
GUID contextmenu_item_foo_vb::get_item_guid(unsigned p_index)
{
return item_guid[p_index];
}
void contextmenu_item_foo_vb::get_item_name(unsigned p_index, pfc::string_base& p_out)
{
p_out = item_name[p_index];
}
void contextmenu_item_foo_vb::get_item_default_path(unsigned p_index, pfc::string_base& p_out)
{
p_out = "";
}
bool contextmenu_item_foo_vb::get_item_description(unsigned p_index, pfc::string_base& p_out)
{
p_out = item_name[p_index];
return true;
}
contextmenu_item::t_enabled_state contextmenu_item_foo_vb::get_enabled_state(unsigned p_index)
{
return contextmenu_item::DEFAULT_ON;
}
void contextmenu_item_foo_vb::item_execute_simple(unsigned p_index, const GUID& p_node, metadb_handle_list_cref p_data, const GUID& p_caller)
{
//todo: duplicated in node::execute
//called from toolbar
if (p_node == pfc::guid_null)
return;
//property page
if (p_node == guid_ctx_menu_node_properties) {
static_api_ptr_t<ui_control> uc;
uc->show_preferences(g_get_prefs_guid());
return;
}
if (p_node == guid_ctx_menu_node_add_bookmark) {
if (p_data.get_count() != 1) {
return;
}
metadb_handle_ptr mhp;
auto np = playback_control_v3::get()->get_now_playing(mhp);
if (p_data.get_item(0) != mhp) {
return;
}
//add bookmark
if (bbookmarkHook_canStore())
bbookmarkHook_store();
return;
}
if (p_node == guid_ctx_menu_node_add_selected_bookmark) {
bool bfrom_nowplaying = pfc::guid_equal(p_caller, contextmenu_item::caller_now_playing);
bool bfrom_playlist = pfc::guid_equal(p_caller, contextmenu_item::caller_active_playlist_selection)
|| pfc::guid_equal(p_caller, contextmenu_item::caller_active_playlist);
if (bfrom_nowplaying) {
size_t active_playlist = playlist_manager_v5::get()->get_active_playlist();
if (active_playlist != SIZE_MAX) {
size_t res_pos;
bool res = playlist_manager_v5::get()->playlist_find_item(active_playlist, p_data.get_item(0), res_pos);
if (res) {
bfrom_playlist = true;
}
}
}
if (bbookmarkHook_canStoreSelected()) {
bbookmarkHook_store_selected(p_data, bfrom_playlist, bfrom_nowplaying);
}
}
}
double contextmenu_item_foo_vb::get_sort_priority()
{
return 0;
}
GUID contextmenu_item_foo_vb::get_parent()
{
return contextmenu_groups::root;
}
void contextmenu_item_foo_vb::g_context_command(unsigned p_index, metadb_handle_list_cref p_data, const GUID& p_caller)
{
if (!p_data.get_count())
{
popup_message::g_show("No input items.\n", COMPONENT_NAME_HC);
return;
}
}
void contextmenu_item_foo_vb::g_get_item_name(unsigned p_index, pfc::string_base& p_out)
{
p_out = item_name[p_index];
}
const char* const contextmenu_item_foo_vb::item_name[] = { COMPONENT_NAME_HC };
// {2DE982A1-5D33-4D36-BED1-9900932C9D80}
const GUID contextmenu_item_foo_vb::item_guid[] =
{ 0x2de982a1, 0x5d33, 0x4d36, { 0xbe, 0xd1, 0x99, 0x0, 0x93, 0x2c, 0x9d, 0x80 } };
pfc::string8 contextmenu_item_foo_vb::fb2k_path("");
//Root Popup
contextmenu_item_node_root_popup_vb::contextmenu_item_node_root_popup_vb(unsigned p_index) : m_index(p_index)
{ }
bool contextmenu_item_node_root_popup_vb::get_display_data(pfc::string_base& p_out, unsigned& p_displayflags, metadb_handle_list_cref p_data, const GUID& p_caller)
{
if (p_data.get_count() != 1) {
return false;
}
if (!(pfc::guid_equal(p_caller, contextmenu_item::caller_active_playlist_selection)
|| pfc::guid_equal(p_caller, contextmenu_item::caller_active_playlist) ||
pfc::guid_equal(p_caller, contextmenu_item::caller_now_playing) ||
pfc::guid_equal(p_caller, contextmenu_item::caller_media_library_viewer) ||
pfc::guid_equal(p_caller, contextmenu_item::caller_undefined))) {
return false;
}
contextmenu_item_foo_vb::g_get_item_name(m_index, p_out);
return true;
}
t_size contextmenu_item_node_root_popup_vb::get_children_count()
{
return 4 + 1; // add bookmark + add selected + restore latest from active + separator + preference page
}
contextmenu_item_node* contextmenu_item_node_root_popup_vb::get_child(t_size p_index)
{
auto separator_pos = get_children_count() - 2;//- 1 separator - 1 preference page
if (p_index == separator_pos) {
return new contextmenu_item_node_separator;
}
else {
if (p_index == 0) {
return new contextmenu_item_node_add_selected_vb();
}
else if (p_index == 1) {
return new contextmenu_item_node_add_vb();
}
else if (p_index == 2) {
return new contextmenu_item_node_restore_active();
}
else {
return new contextmenu_item_node_prop_vb();
}
}
}
GUID contextmenu_item_node_root_popup_vb::get_guid()
{
return guid_ctx_menu_node_root_popup_vb;
}
bool contextmenu_item_node_root_popup_vb::is_mappable_shortcut()
{
return false;
}
//Properties
contextmenu_item_node_prop_vb::contextmenu_item_node_prop_vb()
{ }
bool contextmenu_item_node_prop_vb::get_display_data(pfc::string_base& p_out, unsigned& p_displayflags, metadb_handle_list_cref p_data, const GUID& p_caller)
{
p_displayflags = 0;
p_out = "Vital Bookmarks preferences...";
return true;
}
bool contextmenu_item_node_prop_vb::get_description(pfc::string_base& p_out)
{
p_out = "Vital Bookmarks configuration";
return true;
}
void contextmenu_item_node_prop_vb::execute(metadb_handle_list_cref p_data, const GUID& p_caller)
{
static_api_ptr_t<ui_control> uc;
uc->show_preferences(g_get_prefs_guid());
}
GUID contextmenu_item_node_prop_vb::get_guid()
{
return guid_ctx_menu_node_properties;
}
bool contextmenu_item_node_prop_vb::is_mappable_shortcut()
{
return true;
}
//Add bookmark
contextmenu_item_node_add_vb::contextmenu_item_node_add_vb()
{ }
bool contextmenu_item_node_add_vb::get_display_data(pfc::string_base& p_out, unsigned& p_displayflags, metadb_handle_list_cref p_data, const GUID& p_caller)
{
metadb_handle_ptr mhp;
auto bres = playback_control_v3::get()->get_now_playing(mhp);
if (!bres|| !p_data.get_count() == 1) {
p_displayflags = FLAG_DISABLED_GRAYED;
}
else {
p_displayflags = 0;
}
p_out = "Add Now Playing bookmark";
return true;
}
bool contextmenu_item_node_add_vb::get_description(pfc::string_base& p_out)
{
p_out = "Add Now Playing bookmark";
return true;
}
void contextmenu_item_node_add_vb::execute(metadb_handle_list_cref p_data, const GUID& p_caller)
{
if (bbookmarkHook_canStore())
bbookmarkHook_store();
}
GUID contextmenu_item_node_add_vb::get_guid()
{
return guid_ctx_menu_node_add_bookmark;
}
bool contextmenu_item_node_add_vb::is_mappable_shortcut()
{
return true;
}
//Add single selection bookmark
contextmenu_item_node_add_selected_vb::contextmenu_item_node_add_selected_vb()
{ }
bool contextmenu_item_node_add_selected_vb::get_display_data(pfc::string_base& p_out, unsigned& p_displayflags, metadb_handle_list_cref p_data, const GUID& p_caller)
{
metadb_handle_ptr mhp;
auto np = playback_control_v3::get()->get_now_playing(mhp);
if (!p_data.get_count()) {
p_displayflags = FLAG_DISABLED_GRAYED;
}
else {
p_displayflags = 0;
}
p_out = "Add bookmark";
return true;
}
bool contextmenu_item_node_add_selected_vb::get_description(pfc::string_base& p_out)
{
p_out = "Add selection to bookmarks";
return true;
}
void contextmenu_item_node_add_selected_vb::execute(metadb_handle_list_cref p_data, const GUID& p_caller)
{
bool bfrom_nowplaying = pfc::guid_equal(p_caller, contextmenu_item::caller_now_playing);
bool bfrom_playlist = pfc::guid_equal(p_caller, contextmenu_item::caller_active_playlist_selection)
|| pfc::guid_equal(p_caller, contextmenu_item::caller_active_playlist);
if (bfrom_nowplaying) {
size_t active_playlist = playlist_manager_v5::get()->get_active_playlist();
if (active_playlist != SIZE_MAX) {
size_t res_pos;
bool res = playlist_manager_v5::get()->playlist_find_item(active_playlist, p_data.get_item(0), res_pos);
if (res) {
bfrom_playlist = true;
}
}
}
if (bbookmarkHook_canStoreSelected())
bbookmarkHook_store_selected(p_data, bfrom_playlist, bfrom_nowplaying);
}
GUID contextmenu_item_node_add_selected_vb::get_guid()
{
return guid_ctx_menu_node_add_selected_bookmark;
}
bool contextmenu_item_node_add_selected_vb::is_mappable_shortcut()
{
return true;
}
//Restore active
contextmenu_item_node_restore_active::contextmenu_item_node_restore_active()
{ }
bool contextmenu_item_node_restore_active::get_display_data(pfc::string_base& p_out, unsigned& p_displayflags, metadb_handle_list_cref p_data, const GUID& p_caller)
{
metadb_handle_ptr mhp;
auto np = playback_control_v3::get()->get_now_playing(mhp);
size_t last_played = SIZE_MAX;
if (!bbookmarkHook_canRestoreActivePlaylist(last_played, false)) {
p_displayflags = FLAG_DISABLED_GRAYED;
}
else {
p_displayflags = 0;
}
p_displayflags = 0;
p_out = "Restore last bookmark from the active playlist";
return true;
}
bool contextmenu_item_node_restore_active::get_description(pfc::string_base& p_out)
{
p_out = "Restore last bookmark from the active playlist";
return true;
}
void contextmenu_item_node_restore_active::execute(metadb_handle_list_cref p_data, const GUID& p_caller)
{
size_t last_played = SIZE_MAX;
if (bbookmarkHook_canRestoreActivePlaylist(last_played, true)) {
bbookmarkHook_restoreActivePlaylist(last_played, true);
}
}
GUID contextmenu_item_node_restore_active::get_guid()
{
return guid_ctx_menu_node_restore_playlist;
}
bool contextmenu_item_node_restore_active::is_mappable_shortcut()
{
return true;
}
//factory
static contextmenu_item_factory_t<contextmenu_item_foo_vb> g_contextmenu_item_foo_vb_factory;