Name Editors are Name UI too!

This commit is contained in:
Liru Færs
2019-10-09 17:30:27 -04:00
parent 513a4fd16c
commit f80e23ac5e
2 changed files with 47 additions and 98 deletions

View File

@@ -34,80 +34,49 @@
#include "llnameeditor.h"
#include "llcachename.h"
#include "llagent.h"
#include "llfontgl.h"
#include "lluuid.h"
#include "llrect.h"
#include "llstring.h"
#include "llui.h"
#include "llmenugl.h"
#include "lluictrlfactory.h"
static LLRegisterWidget<LLNameEditor> r("name_editor");
// statics
std::set<LLNameEditor*> LLNameEditor::sInstances;
LLNameEditor::LLNameEditor(const std::string& name, const LLRect& rect,
const LLUUID& name_id,
BOOL is_group,
const LLUUID& name_id,
bool is_group,
const std::string& loading,
const LLFontGL* glfont,
S32 max_text_length)
: LLLineEditor(name, rect,
std::string("(retrieving)"),
glfont,
max_text_length),
mNameID(name_id)
: LLNameUI(loading, name_id, is_group)
, LLLineEditor(name, rect, LLStringUtil::null, glfont, max_text_length)
{
LLNameEditor::sInstances.insert(this);
if(!name_id.isNull())
if (!name_id.isNull())
{
setNameID(name_id, is_group);
}
else setText(mInitialValue);
}
LLNameEditor::~LLNameEditor()
// virtual
BOOL LLNameEditor::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
LLNameEditor::sInstances.erase(this);
bool simple_menu = mContextMenuHandle.get()->getName() != "rclickmenu";
std::string new_menu;
// Singu TODO: Generic menus for groups
if ((mIsGroup || mNameID.isNull()) && simple_menu)
{
new_menu = "menu_texteditor.xml";
}
else if (!simple_menu && !mIsGroup)
{
new_menu = "menu_nameeditor_avatar.xml";
}
if (!new_menu.empty()) setContextMenu(LLUICtrlFactory::instance().buildMenu(new_menu, LLMenuGL::sMenuContainer));
return LLLineEditor::handleRightMouseDown(x, y, mask);
}
void LLNameEditor::setNameID(const LLUUID& name_id, BOOL is_group)
void LLNameEditor::setText(const std::string& text)
{
mNameID = name_id;
std::string name;
if (!is_group)
{
gCacheName->getFullName(name_id, name);
}
else
{
gCacheName->getGroupName(name_id, name);
}
setText(name);
}
void LLNameEditor::refresh(const LLUUID& id, const std::string& full_name, bool is_group)
{
if (id == mNameID)
{
setText(full_name);
}
}
void LLNameEditor::refreshAll(const LLUUID& id, const std::string& full_name, bool is_group)
{
std::set<LLNameEditor*>::iterator it;
for (it = LLNameEditor::sInstances.begin();
it != LLNameEditor::sInstances.end();
++it)
{
LLNameEditor* box = *it;
box->refresh(id, full_name, is_group);
}
LLLineEditor::setText(text);
}
void LLNameEditor::setValue( const LLSD& value )
@@ -135,22 +104,21 @@ LLView* LLNameEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory
LLRect rect;
createRect(node, rect, parent, LLRect());
S32 max_text_length = 128;
S32 max_text_length = 1024;
node->getAttributeS32("max_length", max_text_length);
LLFontGL* font = LLView::selectFont(node);
bool is_group = false;
node->getAttribute_bool("is_group", is_group);
LLUUID id;
node->getAttributeUUID("id", id);
std::string loading;
node->getAttributeString("label", loading);
LLNameEditor* line_editor = new LLNameEditor("name_editor",
rect,
LLUUID::null, FALSE,
font,
rect,
id, is_group, loading,
LLView::selectFont(node),
max_text_length);
std::string label;
if(node->getAttributeString("label", label))
{
line_editor->setLabel(label);
}
line_editor->setColorParameters(node);
line_editor->initFromXML(node, parent);

View File

@@ -33,50 +33,31 @@
#ifndef LL_LLNAMEEDITOR_H
#define LL_LLNAMEEDITOR_H
#include <set>
#include "llview.h"
#include "v4color.h"
#include "llstring.h"
#include "llfontgl.h"
#include "lllineeditor.h"
#include "llnameui.h"
class LLNameEditor
: public LLLineEditor
, public LLNameUI
{
public:
LLNameEditor(const std::string& name, const LLRect& rect,
const LLUUID& name_id = LLUUID::null,
BOOL is_group = FALSE,
const LLFontGL* glfont = NULL,
bool is_group = false,
const std::string& loading = LLStringUtil::null,
const LLFontGL* glfont = nullptr,
S32 max_text_length = 254);
// By default, follows top and left and is mouse-opaque.
// If no text, text = name.
// If no font, uses default system font.
virtual ~LLNameEditor();
BOOL handleRightMouseDown(S32 x, S32 y, MASK mask) override final;
virtual LLXMLNodePtr getXML(bool save_children = true) const;
LLXMLNodePtr getXML(bool save_children = true) const override final;
static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
void setNameID(const LLUUID& name_id, BOOL is_group);
void refresh(const LLUUID& id, const std::string& full_name, bool is_group);
static void refreshAll(const LLUUID& id, const std::string& full_name, bool is_group);
// Take/return agent UUIDs
virtual void setValue( const LLSD& value );
virtual LLSD getValue() const;
private:
static std::set<LLNameEditor*> sInstances;
private:
LLUUID mNameID;
void setValue(const LLSD& value) override final;
LLSD getValue() const override final;
void setText(const std::string& text) override final;
};
#endif