Help - Search - Members - Calendar
Full Version: names of contextmenu_item objects
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
wazoo_999
I've been trying to display the commands from the main and context menus in a tree view (like in General->Keyboard Shortcuts ->Action treeview control).
I can get both static commands as well as context menu commands, but I can't find a method/class to retrieve the name of the contextmenu_item I'm working with (for example for 'Copy Info Between Files' the name of the contextmenu_item should be 'Tagging').
Is there any way to retrieve a name for a given contextmenu_item?
wazoo_999
How could I miss it?
contextmenu_item::get_item_default_path

QUOTE(wazoo_999 @ May 17 2007, 11:25) *

I've been trying to display the commands from the main and context menus in a tree view (like in General->Keyboard Shortcuts ->Action treeview control).
I can get both static commands as well as context menu commands, but I can't find a method/class to retrieve the name of the contextmenu_item I'm working with (for example for 'Copy Info Between Files' the name of the contextmenu_item should be 'Tagging').
Is there any way to retrieve a name for a given contextmenu_item?

foosion
I think what you are looking for is the default path of an item; see the contextmenu_item::get_item_default_path() method.

Note that context menu items are identified by two GUIDs: the command GUID which you get from contextmenu_item::get_item_guid() and the node or subcommand GUID which you get from contextmenu_item_node::get_guid(). The latter is a null GUID for commands that have no subcommands; also it is only guaranteed to be unique if contextmenu_item_node::is_mappable_shortcut() returns true.

Edit: It seems like I was a bit too slow. Anyway, just ask if you have problems with this. The context menu API still could use more documentation and examples.
wazoo_999
I didn't have any problems with this yet, because the last couple of hours I tried to figure out what I need to implement to sort the list with my command_items.

Below's the struct I use to describe the node of the treeview. I didn't want to implement the sorting code myself (or use stl here) because I assumed list_t and its descendants can perform sorting, but I can't figure out how to make the default sorting algorithm use my <> operators :
struct command_item {
typedef ptr_list_t<command_item> command_items;
command_items subitems;

string8 name;
// ... Code removed ...

void sortItems() {
// sort subitems by name
// XXX: for some reason this doesn't result in operator < > calls
subitems.sort(command_items::sort_callback_auto());
// subitems.sort();

// now make those subitems that have children sort themselves
// ... Code removed ...
}

// ... Code removed ...

inline bool operator > (const command_item & p_item) const throw() {
return strcmp(name, p_item.name) > 0;
}
inline bool operator < (const command_item & p_item) const throw() {
return strcmp(name, p_item.name) < 0;
}
};
Are there any examples on pfc foundation classes, it's very hard to figure out how to use pfc containers without reading every line of the pfc source code, which is sadly not documented enough.


QUOTE(foosion @ May 17 2007, 11:45) *

I think what you are looking for is the default path of an item; see the contextmenu_item::get_item_default_path() method.

Note that context menu items are identified by two GUIDs: the command GUID which you get from contextmenu_item::get_item_guid() and the node or subcommand GUID which you get from contextmenu_item_node::get_guid(). The latter is a null GUID for commands that have no subcommands; also it is only guaranteed to be unique if contextmenu_item_node::is_mappable_shortcut() returns true.

Edit: It seems like I was a bit too slow. Anyway, just ask if you have problems with this. The context menu API still could use more documentation and examples.

foosion
I'm not sure why that sorting code doesn't work for you, but you could try to change it like this:
CODE
void sortItems() {
    // sort subitems by name
    subitems.sort_t(command_items::compare_by_name);

    // now make those subitems that have children sort themselves
    // ... Code removed ...
}

static int compare_by_name(command_item const & p_item1, command_item const & p_item2) {
    return strcmp(p_item1.name, p_item2.name);
}

This also has the benefit that the comparison operation is implemented once instead of twice (operator < and >), so it's also easier to change it consistently, for example if you want a case-insensitive comparison (stricmp_utf8).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.