Add extending existing xml menus by using filename attribute
This commit is contained in:
@@ -2109,13 +2109,13 @@ LLXMLNodePtr LLMenuGL::getXML(bool save_children) const
|
||||
return node;
|
||||
}
|
||||
|
||||
void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory *factory)
|
||||
void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent)
|
||||
{
|
||||
std::string name(child->getName()->mString);
|
||||
if (child->hasName(LL_MENU_GL_TAG))
|
||||
{
|
||||
// SUBMENU
|
||||
LLMenuGL *submenu = (LLMenuGL*)LLMenuGL::fromXML(child, parent, factory);
|
||||
LLMenuGL *submenu = (LLMenuGL*)LLMenuGL::fromXML(child, parent, LLUICtrlFactory::getInstance());
|
||||
appendMenu(submenu);
|
||||
if (LLMenuGL::sMenuContainer != NULL)
|
||||
{
|
||||
@@ -2193,7 +2193,7 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory
|
||||
{
|
||||
mask |= MASK_SHIFT;
|
||||
}
|
||||
S32 pipe_pos = shortcut.rfind("|");
|
||||
S32 pipe_pos = shortcut.rfind('|');
|
||||
std::string key_str = shortcut.substr(pipe_pos+1);
|
||||
|
||||
KEY key = KEY_NONE;
|
||||
@@ -2471,63 +2471,80 @@ BOOL LLMenuGL::isOpen()
|
||||
}
|
||||
}
|
||||
// static
|
||||
LLView* LLMenuGL::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
|
||||
LLView* LLMenuGL::fromXML(LLXMLNodePtr node, LLView* parent, LLUICtrlFactory* factory)
|
||||
{
|
||||
std::string name("menu");
|
||||
node->getAttributeString("name", name);
|
||||
|
||||
std::string label = name;
|
||||
node->getAttributeString("label", label);
|
||||
LLMenuGL* menu = new LLMenuGL(name);
|
||||
|
||||
LLStringUtil::format(label, LLTrans::getDefaultArgs());
|
||||
|
||||
// parse jump key out of label
|
||||
std::string new_menu_label;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
boost::char_separator<char> sep("_");
|
||||
tokenizer tokens(label, sep);
|
||||
tokenizer::iterator token_iter;
|
||||
|
||||
KEY jump_key = KEY_NONE;
|
||||
S32 token_count = 0;
|
||||
for( token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter)
|
||||
// Menus can be extended using filename
|
||||
if (node->hasAttribute("filename"))
|
||||
{
|
||||
new_menu_label += (*token_iter);
|
||||
if (token_count > 0)
|
||||
std::string filename;
|
||||
node->getAttributeString("filename", filename);
|
||||
LLXMLNodePtr root;
|
||||
LLUICtrlFactory::getLayeredXMLNode(filename, root);
|
||||
menu->initMenuXML(root, parent);
|
||||
}
|
||||
menu->initMenuXML(node, parent);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
void LLMenuGL::initMenuXML(LLXMLNodePtr node, LLView* parent)
|
||||
{
|
||||
std::string label;
|
||||
if (node->getAttributeString("label", label))
|
||||
{
|
||||
LLStringUtil::format(label, LLTrans::getDefaultArgs());
|
||||
|
||||
// parse jump key out of label
|
||||
std::string new_menu_label;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
|
||||
boost::char_separator<char> sep("_");
|
||||
|
||||
KEY jump_key = KEY_NONE;
|
||||
S32 token_count = 0;
|
||||
for (auto token : tokenizer(label, sep))
|
||||
{
|
||||
jump_key = (*token_iter).c_str()[0];
|
||||
new_menu_label += token;
|
||||
if (token_count > 0)
|
||||
{
|
||||
jump_key = token.front();
|
||||
}
|
||||
++token_count;
|
||||
}
|
||||
++token_count;
|
||||
|
||||
setLabel(new_menu_label);
|
||||
setJumpKey(jump_key);
|
||||
}
|
||||
|
||||
BOOL opaque = TRUE;
|
||||
node->getAttributeBOOL("opaque", opaque);
|
||||
|
||||
LLMenuGL *menu = new LLMenuGL(name, new_menu_label);
|
||||
|
||||
bool b(false);
|
||||
node->getAttribute_bool("scrollable", b);
|
||||
menu->setScrollable(b);
|
||||
setScrollable(b);
|
||||
|
||||
menu->setJumpKey(jump_key);
|
||||
|
||||
BOOL tear_off = FALSE;
|
||||
node->getAttributeBOOL("tear_off", tear_off);
|
||||
menu->setCanTearOff(tear_off);
|
||||
setCanTearOff(tear_off);
|
||||
|
||||
if (node->hasAttribute("drop_shadow"))
|
||||
{
|
||||
BOOL drop_shadow = FALSE;
|
||||
node->getAttributeBOOL("drop_shadow", drop_shadow);
|
||||
menu->setDropShadowed(drop_shadow);
|
||||
setDropShadowed(drop_shadow);
|
||||
}
|
||||
|
||||
menu->setBackgroundVisible(opaque);
|
||||
setBackgroundVisible(opaque);
|
||||
LLColor4 color(0,0,0,1);
|
||||
if (opaque && LLUICtrlFactory::getAttributeColor(node,"color", color))
|
||||
{
|
||||
menu->setBackgroundColor(color);
|
||||
setBackgroundColor(color);
|
||||
}
|
||||
|
||||
BOOL create_jump_keys = FALSE;
|
||||
@@ -2536,14 +2553,13 @@ LLView* LLMenuGL::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *fa
|
||||
LLXMLNodePtr child;
|
||||
for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling())
|
||||
{
|
||||
menu->parseChildXML(child, parent, factory);
|
||||
parseChildXML(child, parent);
|
||||
}
|
||||
|
||||
if (create_jump_keys)
|
||||
{
|
||||
menu->createJumpKeys();
|
||||
createJumpKeys();
|
||||
}
|
||||
return menu;
|
||||
}
|
||||
|
||||
|
||||
@@ -4776,7 +4792,7 @@ void LLContextMenu::initXML(LLXMLNodePtr node, LLView *context, LLUICtrlFactory
|
||||
}
|
||||
else
|
||||
{
|
||||
parseChildXML(child, context, factory);
|
||||
parseChildXML(child, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,8 +458,9 @@ public:
|
||||
virtual ~LLMenuGL( void );
|
||||
virtual LLXMLNodePtr getXML(bool save_children = true) const;
|
||||
static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
|
||||
void initMenuXML(LLXMLNodePtr node, LLView* parent);
|
||||
|
||||
void parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory *factory);
|
||||
void parseChildXML(LLXMLNodePtr child, LLView *parent);
|
||||
|
||||
// LLView Functionality
|
||||
/*virtual*/ BOOL handleUnicodeCharHere( llwchar uni_char );
|
||||
@@ -580,15 +581,17 @@ public:
|
||||
void resetScrollPositionOnShow(bool reset_scroll_pos) { mResetScrollPositionOnShow = reset_scroll_pos; }
|
||||
bool isScrollPositionOnShowReset() { return mResetScrollPositionOnShow; }
|
||||
protected:
|
||||
friend class LLTextEditor;
|
||||
void createSpilloverBranch();
|
||||
void cleanupSpilloverBranch();
|
||||
|
||||
public:
|
||||
// Add the menu item to this menu.
|
||||
virtual BOOL append( LLMenuItemGL* item );
|
||||
|
||||
// add a menu - this will create a cascading menu
|
||||
virtual BOOL appendMenu( LLMenuGL* menu );
|
||||
|
||||
protected:
|
||||
// TODO: create accessor methods for these?
|
||||
typedef std::list< LLMenuItemGL* > item_list_t;
|
||||
item_list_t mItems;
|
||||
|
||||
@@ -406,16 +406,16 @@ LLMenuGL *LLUICtrlFactory::buildMenu(const std::string &filename, LLView* parent
|
||||
LLXMLNodePtr root;
|
||||
LLMenuGL* menu;
|
||||
|
||||
if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
|
||||
if (!getLayeredXMLNode(filename, root))
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// root must be called panel
|
||||
if( !root->hasName( "menu_bar" ) && !root->hasName( "menu" ) && !root->hasName("context_menu"))
|
||||
if (!root->hasName("menu_bar") && !root->hasName("menu") && !root->hasName("context_menu"))
|
||||
{
|
||||
LL_WARNS() << "Root node should be named menu bar or menu in : " << filename << LL_ENDL;
|
||||
return NULL;
|
||||
LL_WARNS() << "Root node should be named menu bar or menu in: " << filename << LL_ENDL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (root->hasName("menu") || root->hasName("context_menu"))
|
||||
|
||||
Reference in New Issue
Block a user