Adding a menu item
Jump to navigation
Jump to search
Menu items in the viewer are specified in XML files, located in the indra/newview/skins/xui/en-us/ directory.
- ...or indra/newview/skins/default/xui/en-us/ ?
There are separate XML files for various categories of menu. They are:
menu_viewer.xml - top of screen menu_inventory.xml - right-click on inventory item menu_pie_attachment.xml - right-click on your own attachment menu_pie_avatar.xml - right-click on other avatar or their attachments menu_pie_land.xml - right-click on land menu_pie_self.xml - right-click on your avatar
The menu callbacks are set up in llviewermenu.cpp.
Let's add a menu item named "Foo" to the Tools menu.
- In menu_viewer.xml find the "Tools" menu item. It is inside a <menu> tag.
- Tear-off sub menus use the <tearoff_menu> tag.
- Find the "Reset Scripts in Selection" menu item.
- After it, add the following text:
<menu_item_call label="Foo" enabled="true" name="foo_menu"> <on_click function="Tools.Foo" userdata="" /> </menu_item_call>
- This sets up a menu item that will call a function. It can be referenced in C++ by the name "foo_menu". The user-visible label is "Foo". It defaults to enabled.
- Open newview/llviewermenu.cpp
- Create an event handler class for this menu item. By convention these are named after the menu name and item name.
class LLToolsFoo : public view_listener_t { bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) { llinfos << "foo!" << llendl; return true; } };
- This class will listen for events from a "view", the base class for all UI widgets. LLPointer is a reference counting smart pointer. LLSD is a structured data class similar to a Perl or Python variable - it can hold data of any type.
- llinfos is the output stream for informational messages. It goes to the ctrl-shift-4 debug console, stdout, and the log file.
- Now associate the "Tools.Foo" function with a C++ class. Open newview/llviewermenu.cpp.
- In the function initialize_menus() add the line:
addMenu(new LLToolsFoo(), "Tools.Foo");
- This associates your listener with the "Tools.Foo" event.
If you added a new source file to implement your new dialog, be sure to include it in newview/files.lst so the build system is aware of it. //If you are using Windows the file to edit is newview/CMakeLists.txt
Compile and run!