IPB

Welcome Guest ( Log In | Register )

> foobar2000 Development Forum Rules

This forum is for developer discussions only. If you have a problem / bug report / idea / feature request that isn't related to foobar2000 SDK, post it in an appropiate forum instead - tech support questions go to support forum, everything else goes to general forum.
All non-developer posts on this forum will be removed. Continued abuse of this forum will result in admin actions (warnings, account suspension).

 
Reply to this topicStart new topic
Dynamical context menu and "Context menu" in preferences
K_S
post Nov 6 2011, 23:37
Post #1





Group: Members
Posts: 25
Joined: 14-September 11
Member No.: 93700



I want to add dynamic context menu. I tried this and that, and finally - when I got context menu called 'Legacy Command (unsorted)' - I must admit I need help.

I have a cfg_objList, storing structs 'pict_prefs'

CODE
struct pict_prefs {
    pfc::string8 cfg_Name;//Unique for each object pict_prefs
    pfc::string8 cfg_DefPath;
    GUID guid;
//(...)
};
//FB2K_STREAM_WRITER/READER_OVERLOAD, defPictPrefs etc.
cfg_objList<pict_prefs> g_cfg_PictPrefs(guid_cfg_PictPrefs, defPictPrefs);


I can add, change and delete stored pict_prefs in preferences, and of course number of pict_prefs is variable.

I'm creating context menu with this code:

CODE

static const GUID guid_mygroup_menu = //(...)

class my_contextmenu_leaf : public contextmenu_item_node_root_leaf{
public:
my_contextmenu_leaf(unsigned p_index) : m_index(p_index){ }

bool get_display_data(pfc::string_base & p_out, unsigned & p_displayflags, metadb_handle_list_cref p_data, const GUID & p_caller) {
p_out = g_cfg_PictPrefs.get_item( m_index ).cfg_Name;
return true;
}

void execute(metadb_handle_list_cref p_data,const GUID & p_caller){
//(...)
}

bool get_description(pfc::string_base & p_out){
p_out = "Downloading pictures of ";
p_out += g_cfg_PictPrefs.get_item( m_index ).cfg_Name;
return true;
}

GUID get_guid(){
return g_cfg_PictPrefs.get_item( m_index ).guid;
// return pfc::guid_null;//With guid_null works too. Which one is correct version?
}

bool is_mappable_shortcut(){ return true; }
private:
unsigned m_index;
};

class contextmenu_popup : public contextmenu_item_node_root_popup
{
public:
contextmenu_popup(){ }

bool get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,metadb_handle_list_cref p_data,const GUID & p_caller){
p_out="Download picture";
return true;
}

t_size get_children_count(){
return g_cfg_PictPrefs.get_size();
}

contextmenu_item_node * get_child(t_size p_index){
return new my_contextmenu_leaf(p_index);//I hope this is correct
}

GUID get_guid(){
return guid_mygroup_menu;
}

bool is_mappable_shortcut(){
return true;
}
};


class pictdownload_contextmenu : public contextmenu_item_v2{
public:
unsigned get_num_items(){
return 1;//Maybe I should check if g_cfg_PictPrefs.get_size() == 0...
}

contextmenu_item_node_root * instantiate_item (unsigned p_index, metadb_handle_list_cref p_data, const GUID &p_caller){
return new contextmenu_popup();
}

GUID get_item_guid (unsigned p_index){
return guid_mygroup_menu;
}

void get_item_name (unsigned p_index, pfc::string_base &p_out){
p_out = "Download picture";
}

bool get_item_description (unsigned p_index, pfc::string_base &p_out){
p_out = "Downloading pictures from Google";
return true;
}

t_enabled_state get_enabled_state (unsigned p_index){
return contextmenu_item::DEFAULT_ON;
}

void item_execute_simple (unsigned p_index, const GUID &p_node, metadb_handle_list_cref p_data, const GUID &p_caller){
// Is this function ever called?
}
};

static contextmenu_item_factory_t<pictdownload_contextmenu> g_myitem_factory;


My menu works, but I have a problem with 'Preferences/Display - Context Menu'. Now it shows only checkbox with "Download picture" and description "Downloading pictures from Google". I can disable/enable only my whole menu. How to add 'submenu', with list of menu options?

Additional questions:

- about my_contextmenu_leaf ::get_guid - can I return pfc::guid_null without problems? Is 'guid' field in pict_prefs necessary? I think it's necessary for disabling/enabling menu leafs in 'Preferences/Display - Context Menu' (when somebody shows me how to do this), but maybe I'm wrong?

- about pictdownload_contextmenu::item_execute_simple - is this function ever executed?
Go to the top of the page
+Quote Post
foosion
post Nov 8 2011, 21:23
Post #2





Group: FB2K Moderator (Donating)
Posts: 4459
Joined: 24-February 03
Member No.: 5153



Firstly I don't know which code calls item_execute_simple(), but if it is easy enough for you to implement it then I would do it.

Secondly I think your contextmenu_popup::is_mappable_shortcut() should return false. Also the contextmenu_popup::get_guid() could return pfc::guid_null, since a non-leaf node normally does not need to be identifiable, i.e. for saving shortcut settings.

Finally you should leave my_contextmenu_leaf::get_guid() as it is. The combination of your guid_mygroup_menu and the leaf GUID will be used to uniquely identify the command. It doesn't actually matter how you generate the GUID for the dynamic entries, as long as they are stable across different runs of the application. You could hash the name of a preset if you wanted, even though that would break keyboard shortcuts when the user renames a preset. Personally I think an explicit GUID that is generated when the preset is created is a good choice.


--------------------
http://foosion.foobar2000.org/ - my components for foobar2000
Go to the top of the page
+Quote Post
Duny
post Nov 17 2011, 17:44
Post #3





Group: Members
Posts: 16
Joined: 9-January 09
Member No.: 65377



I have done simular dynamic context menus as you did.
void item_execute_simple () is called when menu command is bind to the toolbar button.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 1st November 2014 - 03:47