This repository was archived by the owner on Nov 17, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathbookmark_menu.cpp
More file actions
162 lines (137 loc) · 5.84 KB
/
Copy pathbookmark_menu.cpp
File metadata and controls
162 lines (137 loc) · 5.84 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
#include "stdafx.h"
static const GUID guid_vbookmark_main_menu_group_id = { 0x4da5c373, 0x8c39, 0x49bd, { 0xaf, 0xe4, 0xe3, 0x4c, 0xb0, 0xd9, 0x43, 0x67 } };
static const GUID guid_storeBookmark = { 0x5ae6fa28, 0xe10, 0x4970, { 0xb3, 0x9, 0x8d, 0x37, 0xf0, 0x4a, 0xba, 0x4b } };
// {5EEEF30B-647C-4341-B4E6-8DA88CE326CD}
static const GUID guid_storeBookmarkSelected = { 0x5eeef30b, 0x647c, 0x4341, { 0xb4, 0xe6, 0x8d, 0xa8, 0x8c, 0xe3, 0x26, 0xcd } };
static const GUID guid_restoreBookmark = { 0xc23afd1a, 0xf7bd, 0x4b8f, { 0xa0, 0xff, 0xd, 0xf2, 0x27, 0x1e, 0xe7, 0x48 } };
static const GUID guid_restoreBookmarkActivePlaylistLastPlayed = { 0xafc94d45, 0x65cf, 0x4b41, { 0x97, 0x7e, 0x52, 0xdf, 0xb2, 0xde, 0x38, 0x25 } };
static const GUID guid_clearBookmarks = { 0x2e65ef5a, 0x8620, 0x4cee, { 0xaf, 0x8f, 0xac, 0xd0, 0x6, 0x97, 0x7b, 0xa9 } };
static mainmenu_group_popup_factory g_mainmenu_group(guid_vbookmark_main_menu_group_id, mainmenu_groups::playback, mainmenu_commands::sort_priority_dontcare, COMPONENT_NAME_HC);
//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 = false);
void bbookmarkHook_clear();
bool bbookmarkHook_canStore();
bool bbookmarkHook_canStoreSelected();
bool bbookmarkHook_canRestore();
bool bbookmarkHook_canRestoreActivePlaylist(size_t& last_played, bool check_file = false);
bool bbookmarkHook_canClear();
class mainmenu_commands_basic_bookmark : public mainmenu_commands {
public:
size_t last_played = SIZE_MAX;
enum {
cmd_store = 0,
cmd_store_selected,
cmd_restore,
cmd_restoreActivePlaylistLastPlayed,
cmd_clearBookmarks,
cmd_total
};
t_uint32 get_command_count() {
return cmd_total;
}
GUID get_parent() {
return guid_vbookmark_main_menu_group_id;
}
GUID get_command(t_uint32 p_index) {
switch (p_index) {
case cmd_store_selected: return guid_storeBookmarkSelected;
case cmd_store: return guid_storeBookmark;
case cmd_restore: return guid_restoreBookmark;
case cmd_restoreActivePlaylistLastPlayed: return guid_restoreBookmarkActivePlaylistLastPlayed;
case cmd_clearBookmarks: return guid_clearBookmarks;
default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
}
}
void get_name(t_uint32 p_index, pfc::string_base & p_out) {
switch (p_index) {
case cmd_store_selected: p_out = "Add Selection Bookmarks"; break;
case cmd_store: p_out = "Add Now Playing Bookmark"; break;
case cmd_restore: p_out = "Restore Bookmark"; break;
case cmd_restoreActivePlaylistLastPlayed: p_out = "Restore last bookmark from the active playlist"; break;
case cmd_clearBookmarks: p_out = "Clear Bookmarks"; break;
default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
}
}
bool get_description(t_uint32 p_index, pfc::string_base & p_out) {
switch (p_index) {
case cmd_store_selected: p_out = "Stores selection bookmarks"; return true;
case cmd_store: p_out = "Stores the playback position to a bookmark"; return true;
case cmd_restore: p_out = "Restores the playback position from the bookmark selected by in the first element to be instantiated."; return true;
case cmd_restoreActivePlaylistLastPlayed: p_out = "Restores the last bookmark from the active playlist."; return true;
case cmd_clearBookmarks: p_out = "Removes all bookmarks"; return true;
default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
}
}
virtual bool get_display(t_uint32 p_index, pfc::string_base& p_text, t_uint32& p_flags) override {
p_flags = 0;
switch (p_index) {
case cmd_store_selected:
p_flags = !bbookmarkHook_canStoreSelected();
break;
case cmd_store:
p_flags = !bbookmarkHook_canStore();
break;
case cmd_restore:
p_flags = !bbookmarkHook_canRestore();
break;
case cmd_restoreActivePlaylistLastPlayed:
p_flags = !bbookmarkHook_canRestoreActivePlaylist(last_played);
break;
case cmd_clearBookmarks:
p_flags = !bbookmarkHook_canClear();
break;
}
get_name(p_index, p_text);
return true;
}
void execute(t_uint32 p_index, service_ptr_t<service_base> p_callback) {
switch (p_index) {
case cmd_store_selected: {
metadb_handle_list mhl;
ui_selection_manager::get()->get_selection(mhl);
auto guid_type = ui_selection_manager::get()->get_selection_type();
bool bfrom_nowplaying = pfc::guid_equal(guid_type, contextmenu_item::caller_now_playing);
bool bfrom_playlist = pfc::guid_equal(guid_type, contextmenu_item::caller_active_playlist_selection)
|| pfc::guid_equal(guid_type, 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, mhl.get_item(0), res_pos);
if (res) {
bfrom_playlist = true;
}
}
}
if (bbookmarkHook_canStoreSelected())
bbookmarkHook_store_selected(mhl, bfrom_playlist, bfrom_nowplaying);
break;
}
case cmd_store:
if (bbookmarkHook_canStore())
bbookmarkHook_store();
break;
case cmd_restore:
if (bbookmarkHook_canRestore())
bbookmarkHook_restore();
break;
case cmd_restoreActivePlaylistLastPlayed: {
size_t last_played = SIZE_MAX;
if (bbookmarkHook_canRestoreActivePlaylist(last_played, true)) {
bbookmarkHook_restoreActivePlaylist(last_played, true);
last_played = SIZE_MAX;
}
break;
}
case cmd_clearBookmarks:
if (bbookmarkHook_canClear())
bbookmarkHook_clear();
break;
default: uBugCheck();
}
}
};
static mainmenu_commands_factory_t<mainmenu_commands_basic_bookmark> g_mainmenu_commands_basic_bookmark_factory;