XML-Driven floater feature (and documentation)

Changes:
Adds LLUICtrlFactory::getBuiltFloater() to return LLFloater* when a floater has been built.
In llviewermenu.cpp's LLShowFloater::handleEvent():
Return early if the floater_name is empty,
otherwise if no anticipated floater is found, build one,
unless one of the same name is already built, then bring it to focus.



Documentation:
In order to add simple codeless floaters, a general understanding of our XMLs is necessary...
A simple codeless floater can be a few things, perhaps not limited to: media browsers, settings controls, and holders for inventory_panels.

So how do you make them conform to the codeless standard?
For the purpose of these examples, my floater file will always be floater_name.xml
Let's start with a shortened xml menu entry:
<menu_item_call label="Name!" name="name">
  <on_click function="ShowFloater" userdata="floater_name.xml"/>
</menu_item_call>
Alright, that wasn't so hard, just remember the key in this is ShowFloater is the function and userdata is the filename.

The next part is the actual floater, which isn't so different from making a complex floater..
There are two ways to do this, depending upon desired behavior:

The first behavior is to have only one of the floater open at a time, the following short xml exemplifies this:
<floater name="floater_name.xml" title="Name!"/>
Having a floater with this behavior will cause the menu entry to bring it into focus.

The other behavior is to allow more than one of the floater open at a time:
<floater name="name" title="Name!"/>
In this case, the menu entry will spawn a new version of the floater with every click, regardless of previous ones existing.

Granted, these short <floater/>'s probably aren't but examples and will not likely stand alone.
This commit is contained in:
Lirusaito
2013-01-30 14:07:59 -05:00
parent 4e96dccd7c
commit 47cbaeed23
3 changed files with 25 additions and 0 deletions

View File

@@ -293,6 +293,20 @@ void LLUICtrlFactory::buildFloaterInternal(LLFloater *floaterp, LLXMLNodePtr &ro
mBuiltFloaters[handle] = filename;
}
//-----------------------------------------------------------------------------
// getBuiltFloater()
//-----------------------------------------------------------------------------
LLFloater* LLUICtrlFactory::getBuiltFloater(const std::string name) const
{
for (built_floater_t::const_iterator i = mBuiltFloaters.begin(); i != mBuiltFloaters.end(); ++i)
{
LLFloater* floater = i->first.get();
if (floater && floater->getName() == name)
return floater;
}
return NULL;
}
//-----------------------------------------------------------------------------
// saveToXML()
//-----------------------------------------------------------------------------

View File

@@ -61,6 +61,8 @@ public:
BOOL buildPanelFromBuffer(LLPanel *panelp, const std::string &buffer,
const LLCallbackMap::map_t* factory_map = NULL);
LLFloater* getBuiltFloater(const std::string name) const;
void removePanel(LLPanel* panelp) { mBuiltPanels.erase(panelp->getHandle()); }
void removeFloater(LLFloater* floaterp) { mBuiltFloaters.erase(floaterp->getHandle()); }

View File

@@ -6517,6 +6517,7 @@ class LLShowFloater : public view_listener_t
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
std::string floater_name = userdata.asString();
if (floater_name.empty()) return false;
if (floater_name == "gestures")
{
LLFloaterGesture::toggleVisibility();
@@ -6688,6 +6689,14 @@ class LLShowFloater : public view_listener_t
{
LLFloaterOutbox::toggleInstance(LLSD());
}
else // Simple codeless floater
{
LLFloater* floater = LLUICtrlFactory::getInstance()->getBuiltFloater(floater_name);
if (floater)
gFloaterView->bringToFront(floater);
else
LLUICtrlFactory::getInstance()->buildFloater(new LLFloater(), floater_name);
}
return true;
}
};