foobar2000 SDK  2015-08-03
contextmenu.cpp
Go to the documentation of this file.
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 // Simple context menu item class.
18 public:
19  enum {
20  cmd_test1 = 0,
23  };
25  unsigned get_num_items() {return cmd_total;}
26  void get_item_name(unsigned p_index,pfc::string_base & p_out) {
27  switch(p_index) {
28  case cmd_test1: p_out = "Test command"; break;
29  case cmd_test2: p_out = "Calculate peak"; break;
30  default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
31  }
32  }
33  void context_command(unsigned p_index,metadb_handle_list_cref p_data,const GUID& p_caller) {
34  switch(p_index) {
35  case cmd_test1:
36  RunTestCommand(p_data);
37  break;
38  case cmd_test2:
39  RunCalculatePeak(p_data);
40  break;
41  default:
42  uBugCheck();
43  }
44  }
45  // Overriding this is not mandatory. We're overriding it just to demonstrate stuff that you can do such as context-sensitive menu item labels.
46  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) {
47  switch(p_index) {
48  case cmd_test1:
49  if (!__super::context_get_display(p_index, p_data, p_out, p_displayflags, p_caller)) return false;
50  // Example context sensitive label: append the count of selected items to the label.
51  p_out << " : " << p_data.get_count() << " item";
52  if (p_data.get_count() != 1) p_out << "s";
53  p_out << " selected";
54  return true;
55  case cmd_test2:
56  return __super::context_get_display(p_index, p_data, p_out, p_displayflags, p_caller);
57  default: uBugCheck();
58  }
59  }
60  GUID get_item_guid(unsigned p_index) {
61  // These GUIDs identify our context menu items. Substitute with your own GUIDs when reusing code.
62  static const GUID guid_test1 = { 0x4021c80d, 0x9340, 0x423b, { 0xa3, 0xe2, 0x8e, 0x1e, 0xda, 0x87, 0x13, 0x7f } };
63  static const GUID guid_test2 = { 0xe629b5c3, 0x5af3, 0x4a1e, { 0xa0, 0xcd, 0x2d, 0x5b, 0xff, 0xa6, 0x4, 0x58 } };
64  switch(p_index) {
65  case cmd_test1: return guid_test1;
66  case cmd_test2: return guid_test2;
67  default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
68  }
69 
70  }
71  bool get_item_description(unsigned p_index,pfc::string_base & p_out) {
72  switch(p_index) {
73  case cmd_test1:
74  p_out = "This is a sample command.";
75  return true;
76  case cmd_test2:
77  p_out = "This is a sample command that decodes the selected tracks and reports the peak sample value.";
78  return true;
79  default:
80  uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
81  }
82  }
83 };
84 
86 
87 
89  pfc::string_formatter message;
90  message << "This is a test command.\n";
91  if (data.get_count() > 0) {
92  message << "Parameters:\n";
93  for(t_size walk = 0; walk < data.get_count(); ++walk) {
94  message << data[walk] << "\n";
95  }
96  }
97  popup_message::g_show(message, "Blah");
98 }
unsigned get_num_items()
Retrieves number of menu items provided by this contextmenu_item implementation.
Definition: contextmenu.cpp:25
GUID get_parent()
Definition: contextmenu.cpp:24
void get_item_name(unsigned p_index, pfc::string_base &p_out)
Retrieves human-readable name of the context menu item.
Definition: contextmenu.cpp:26
Definition: pfc.h:71
static const GUID root
Definition: contextmenu.h:282
bool get_item_description(unsigned p_index, pfc::string_base &p_out)
Retrieves item&#39;s description to show in the status bar. Set p_out to the string to be displayed and r...
Definition: contextmenu.cpp:71
static contextmenu_group_popup_factory g_mygroup(guid_mygroup, contextmenu_groups::root,"Sample component", 0)
GUID get_item_guid(unsigned p_index)
Retrieves GUID of the context menu item.
Definition: contextmenu.cpp:60
size_t t_size
Definition: int_types.h:48
virtual t_size get_count() const =0
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)
Definition: contextmenu.cpp:46
static contextmenu_item_factory_t< myitem > g_myitem_factory
Definition: contextmenu.cpp:85
void RunCalculatePeak(metadb_handle_list_cref data)
Definition: decode.cpp:64
static void g_show(const char *p_msg, const char *p_title, t_icon p_icon=icon_information)
Static helper function instantiating the service and activating the message dialog. See show() for description of parameters.
Definition: popup_message.h:26
PFC_NORETURN void SHARED_EXPORT uBugCheck()
void context_command(unsigned p_index, metadb_handle_list_cref p_data, const GUID &p_caller)
Definition: contextmenu.cpp:33
contextmenu_item implementation helper for implementing non-dynamically-generated context menu items;...
Definition: contextmenu.h:153
static void RunTestCommand(metadb_handle_list_cref data)
Definition: contextmenu.cpp:88
static const GUID guid_mygroup
Definition: contextmenu.cpp:5