|
1
|
1 #include "stdafx.h"
|
|
|
2
|
|
|
3
|
|
|
4 // Identifier of our context menu group. Substitute with your own when reusing code.
|
|
|
5 static const GUID guid_mygroup = { 0x572de7f4, 0xcbdf, 0x479a, { 0x97, 0x26, 0xa, 0xb0, 0x97, 0x47, 0x69, 0xe3 } };
|
|
|
6
|
|
|
7
|
|
|
8 // Switch to contextmenu_group_factory to embed your commands in the root menu but separated from other commands.
|
|
|
9
|
|
|
10 //static contextmenu_group_factory g_mygroup(guid_mygroup, contextmenu_groups::root, 0);
|
|
|
11 static contextmenu_group_popup_factory g_mygroup(guid_mygroup, contextmenu_groups::root, "Sample component", 0);
|
|
|
12
|
|
|
13 static void RunTestCommand(metadb_handle_list_cref data);
|
|
|
14 void RunCalculatePeak(metadb_handle_list_cref data); //decode.cpp
|
|
|
15
|
|
|
16 void RunCopyFiles(metadb_handle_list_cref data); // IO.cpp
|
|
|
17 void RunAlterTagsLL(metadb_handle_list_cref data); // IO.cpp
|
|
|
18
|
|
|
19 void RunUIAndThreads( metadb_handle_list_cref data ); // ui_and_threads.cpp
|
|
|
20
|
|
|
21 namespace { // anon namespace local classes for good measure
|
|
|
22 class myFilter : public file_info_filter {
|
|
|
23 public:
|
|
|
24 bool apply_filter(metadb_handle_ptr p_location, t_filestats p_stats, file_info & p_info) {
|
|
|
25 p_info.meta_set("comment", "foo_sample was here");
|
|
|
26 // return true to write changes tags to the file, false to suppress the update
|
|
|
27 return true;
|
|
|
28 }
|
|
|
29 };
|
|
|
30 }
|
|
|
31
|
|
|
32 static void RunAlterTags(metadb_handle_list_cref data) {
|
|
|
33 // Simple alter-file-tags functionality
|
|
|
34
|
|
|
35 const auto wndParent = core_api::get_main_window();
|
|
|
36
|
|
|
37 // Filter object that applies our edits to the file tags
|
|
|
38 auto filter = fb2k::service_new<myFilter>();
|
|
|
39
|
|
|
40 auto notify = fb2k::makeCompletionNotify( [] (unsigned code) {
|
|
|
41 // Code values are metadb_io::t_update_info_state enum
|
|
|
42 FB2K_console_formatter() << "Tag update finished, code: " << code;
|
|
|
43 } );
|
|
|
44
|
|
|
45 // Flags
|
|
|
46 // Indicate that we're aware of fb2k 1.3+ partial info semantics
|
|
|
47 const uint32_t flags = metadb_io_v2::op_flag_partial_info_aware;
|
|
|
48
|
|
|
49 metadb_io_v2::get()->update_info_async(data, filter, wndParent, flags, notify);
|
|
|
50 }
|
|
|
51
|
|
|
52 // Simple context menu item class.
|
|
|
53 class myitem : public contextmenu_item_simple {
|
|
|
54 typedef contextmenu_item_simple super_t;
|
|
|
55 public:
|
|
|
56 enum {
|
|
|
57 cmd_test1 = 0,
|
|
|
58 cmd_peak,
|
|
|
59 cmd_copyFiles,
|
|
|
60 cmd_alterTags,
|
|
|
61 cmd_alterTagsLL,
|
|
|
62 cmd_uiAndThreads,
|
|
|
63 cmd_total
|
|
|
64 };
|
|
|
65 GUID get_parent() {return guid_mygroup;}
|
|
|
66 unsigned get_num_items() {return cmd_total;}
|
|
|
67 void get_item_name(unsigned p_index,pfc::string_base & p_out) {
|
|
|
68 switch(p_index) {
|
|
|
69 case cmd_test1: p_out = "Test command"; break;
|
|
|
70 case cmd_peak: p_out = "Calculate peak"; break;
|
|
|
71 case cmd_copyFiles: p_out = "Copy files"; break;
|
|
|
72 case cmd_alterTags: p_out = "Alter tags"; break;
|
|
|
73 case cmd_alterTagsLL: p_out = "Alter tags (low level)"; break;
|
|
|
74 case cmd_uiAndThreads: p_out = "UI and threads demo"; break;
|
|
|
75 default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
|
|
|
76 }
|
|
|
77 }
|
|
|
78 void context_command(unsigned p_index,metadb_handle_list_cref p_data,const GUID& p_caller) {
|
|
|
79 switch(p_index) {
|
|
|
80 case cmd_test1:
|
|
|
81 RunTestCommand(p_data);
|
|
|
82 break;
|
|
|
83 case cmd_peak:
|
|
|
84 RunCalculatePeak(p_data);
|
|
|
85 break;
|
|
|
86 case cmd_copyFiles:
|
|
|
87 RunCopyFiles(p_data);
|
|
|
88 break;
|
|
|
89 case cmd_alterTags:
|
|
|
90 RunAlterTags(p_data);
|
|
|
91 break;
|
|
|
92 case cmd_alterTagsLL:
|
|
|
93 RunAlterTagsLL(p_data);
|
|
|
94 break;
|
|
|
95 case cmd_uiAndThreads:
|
|
|
96 RunUIAndThreads(p_data);
|
|
|
97 break;
|
|
|
98 default:
|
|
|
99 uBugCheck();
|
|
|
100 }
|
|
|
101 }
|
|
|
102 // Overriding this is not mandatory. We're overriding it just to demonstrate stuff that you can do such as context-sensitive menu item labels.
|
|
|
103 bool context_get_display(unsigned p_index,metadb_handle_list_cref p_data,pfc::string_base & p_out,unsigned & p_displayflags,const GUID & p_caller) {
|
|
|
104 switch(p_index) {
|
|
|
105 case cmd_test1:
|
|
|
106 if (!super_t::context_get_display(p_index, p_data, p_out, p_displayflags, p_caller)) return false;
|
|
|
107 // Example context sensitive label: append the count of selected items to the label.
|
|
|
108 p_out << " : " << p_data.get_count() << " item";
|
|
|
109 if (p_data.get_count() != 1) p_out << "s";
|
|
|
110 p_out << " selected";
|
|
|
111 return true;
|
|
|
112 default:
|
|
|
113 return super_t::context_get_display(p_index, p_data, p_out, p_displayflags, p_caller);
|
|
|
114 }
|
|
|
115 }
|
|
|
116 GUID get_item_guid(unsigned p_index) {
|
|
|
117 // These GUIDs identify our context menu items. Substitute with your own GUIDs when reusing code.
|
|
|
118 static const GUID guid_test1 = { 0x4021c80d, 0x9340, 0x423b, { 0xa3, 0xe2, 0x8e, 0x1e, 0xda, 0x87, 0x13, 0x7f } };
|
|
|
119 static const GUID guid_peak = { 0xe629b5c3, 0x5af3, 0x4a1e, { 0xa0, 0xcd, 0x2d, 0x5b, 0xff, 0xa6, 0x4, 0x58 } };
|
|
|
120 static const GUID guid_copyFiles = { 0x7f8a6569, 0xe46b, 0x4698, { 0xaa, 0x30, 0xc4, 0xc1, 0x44, 0xc9, 0xc8, 0x92 } };
|
|
|
121 static const GUID guid_alterTags = { 0xdfb8182b, 0xf8f3, 0x4ce9, { 0xae, 0xf6, 0x8e, 0x4e, 0x51, 0x7c, 0x2d, 0x3 } };
|
|
|
122 static const GUID guid_alterTagsLL = { 0x6b43324d, 0x6cb2, 0x42a6, { 0xbf, 0xc, 0xd9, 0x43, 0xfc, 0x83, 0x2f, 0x39 } };
|
|
|
123 static const GUID guid_uiAndThreads = { 0x30dace2e, 0xcccf, 0x41d4, { 0x8c, 0x24, 0x57, 0xec, 0xf4, 0xa0, 0xd9, 0xc9 } };
|
|
|
124
|
|
|
125 switch(p_index) {
|
|
|
126 case cmd_test1: return guid_test1;
|
|
|
127 case cmd_peak: return guid_peak;
|
|
|
128 case cmd_copyFiles: return guid_copyFiles;
|
|
|
129 case cmd_alterTags: return guid_alterTags;
|
|
|
130 case cmd_alterTagsLL: return guid_alterTagsLL;
|
|
|
131 case cmd_uiAndThreads: return guid_uiAndThreads;
|
|
|
132 default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
|
|
|
133 }
|
|
|
134
|
|
|
135 }
|
|
|
136 bool get_item_description(unsigned p_index,pfc::string_base & p_out) {
|
|
|
137 switch(p_index) {
|
|
|
138 case cmd_test1:
|
|
|
139 p_out = "This is a sample command.";
|
|
|
140 return true;
|
|
|
141 case cmd_peak:
|
|
|
142 p_out = "This is a sample command that decodes the selected tracks and reports the peak sample value.";
|
|
|
143 return true;
|
|
|
144 case cmd_copyFiles:
|
|
|
145 p_out = "This is a sample command that copies the selected tracks to another location.";
|
|
|
146 return true;
|
|
|
147 case cmd_alterTags:
|
|
|
148 p_out = "This is a sample command that performs tag manipulation on the files.";
|
|
|
149 return true;
|
|
|
150 case cmd_alterTagsLL:
|
|
|
151 p_out = "This is a sample command that performs low-level manipulation of tags on the files.";
|
|
|
152 return true;
|
|
|
153 case cmd_uiAndThreads:
|
|
|
154 p_out = "This is a smple command that runs UI and Threads demo.";
|
|
|
155 return true;
|
|
|
156 default:
|
|
|
157 uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
|
|
|
158 }
|
|
|
159 }
|
|
|
160 };
|
|
|
161
|
|
|
162 static contextmenu_item_factory_t<myitem> g_myitem_factory;
|
|
|
163
|
|
|
164
|
|
|
165 static void RunTestCommand(metadb_handle_list_cref data) {
|
|
|
166 pfc::string_formatter message;
|
|
|
167 message << "This is a test command.\n";
|
|
|
168 if (data.get_count() > 0) {
|
|
|
169 message << "Parameters:\n";
|
|
|
170 for(t_size walk = 0; walk < data.get_count(); ++walk) {
|
|
|
171 message << data[walk] << "\n";
|
|
|
172 }
|
|
|
173 }
|
|
|
174 popup_message::g_show(message, "Blah");
|
|
|
175 }
|