Where (in code) do context-menu actions get associated with their icon?

Hello,

We’re using Slate to write our IDE and one of the tasks that I’m currently stuck on is associating menu actions with icons like so:

114905-prtscr+capture.jpg

For the common History and Edit actions, I’m using UE’s native implementation so I got the icons for free but I still don’t understand how/where the association lives.

What I know so far:

In CoreStyle.cpp, Style->Set("GenericCommands.Delete", new IMAGE_BRUSH("Icons/Edit/icon_Edit_Delete_16x", Icon16x16)); takes care of associating the icon with the FName “GenericCommands.Delete”.

But then a Find All search for this very FName returns very little results. It’s only used in STileLayerList.cpp to override the icon. Every instance of Delete that I’ve found is being added using menu_builder.AddMenuEntry(FGenericCommands::Get().Delete); without ever specifying the icon. I’ve tried it myself and that’s how I was able to build the menu above and it works.

I know that AddMenuEntry() itself has an icon override param but the comment itself says the following:
InIconOverride, Optional name of the slate brush to use for the tool bar image. If omitted, then the action’s icon will be used instead.Where is this action’s icon specified?!

I obviously don’t want to use the override because then I’ll have to specify it each time and any time I make any icon or naming changes, I’ll have to update all instances.

Is it that “GenericCommands.Delete” denotes “ClassName.ActionName”? I noticed that the class is called GenericCommands where the Delete FUICommandInfo is declared but I also tried following that logic with my own code and got nothing. FGenericCommands::RegisterCommands() also doesn’t mention any icons so at this point I’m out of ideas and need help from the pro’s!

Thanks!

Shadi

I think that comment is wrong. It should say “then the command’s icon will be used”. I fixed this for 4.15.

This pertains to the AddMenuEntry() overload that takes an FUICommandInfo as the first parameter. Command infos are created using the static FUICommandInfo::MakeCommandInfo() function, which also allows for specifying an icon.

Oh, I see.

FUICommandInfo::MakeCommandInfo() which then gets called inside UI_COMMAND_Function() in Commands.cpp which in turn passes in a FSlateIcon defined by joining the context name and the command’s name.

So it is a matter of naming your command as “ClassName.ActionName” in the case of GenericCommands.Delete!