Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: names of contextmenu_item objects (Read 4104 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

names of contextmenu_item objects

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?

names of contextmenu_item objects

Reply #1
How could I miss it?
contextmenu_item::get_item_default_path

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?

names of contextmenu_item objects

Reply #2
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.

names of contextmenu_item objects

Reply #3
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.


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.

 

names of contextmenu_item objects

Reply #4
I'm not sure why that sorting code doesn't work for you, but you could try to change it like this:
Code: [Select]
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).