llTextBox, patch from Henri

This commit is contained in:
Siana Gearz
2011-02-06 18:38:51 +01:00
parent 144f8d720a
commit 3a4093ccc3
4 changed files with 80 additions and 9 deletions

View File

@@ -139,10 +139,11 @@ LLNotifyBox::LLNotifyBox(LLNotificationPtr notification,
mNumOptions(0),
mNumButtons(0),
mAddedDefaultBtn(FALSE),
mLayoutScriptDialog(layout_script_dialog)
mLayoutScriptDialog(layout_script_dialog),
mUserInputBox(NULL)
{
// clicking on a button does not steal current focus
setIsChrome(TRUE);
std::string edit_text_name;
std::string edit_text_contents;
// class init
{
@@ -174,8 +175,10 @@ LLNotifyBox::LLNotifyBox(LLNotificationPtr notification,
mNumOptions = form->getNumElements();
bool is_textbox = form->getElement("message").isDefined();
LLRect rect = mIsTip ? getNotifyTipRect(mMessage)
: getNotifyRect(mNumOptions, layout_script_dialog, mIsCaution);
: getNotifyRect(is_textbox ? 10 : mNumOptions, layout_script_dialog, mIsCaution);
setRect(rect);
setFollows(mIsTip ? (FOLLOWS_BOTTOM|FOLLOWS_RIGHT) : (FOLLOWS_TOP|FOLLOWS_RIGHT));
setBackgroundVisible(FALSE);
@@ -303,12 +306,42 @@ LLNotifyBox::LLNotifyBox(LLNotificationPtr notification,
{
LLSD form_element = form->getElement(i);
if (form_element["type"].asString() != "button")
std::string element_type = form_element["type"].asString();
if (element_type == "button")
{
continue;
addButton(form_element["name"].asString(), form_element["text"].asString(), TRUE, form_element["default"].asBoolean());
}
else if (element_type == "input")
{
edit_text_contents = form_element["value"].asString();
edit_text_name = form_element["name"].asString();
}
}
addButton(form_element["name"].asString(), form_element["text"].asString(), TRUE, form_element["default"].asBoolean());
if (is_textbox)
{
S32 button_rows = (layout_script_dialog) ? 2 : 1;
LLRect input_rect;
input_rect.setOriginAndSize(x, BOTTOM_PAD + button_rows * (BTN_HEIGHT + VPAD),
3 * 80 + 4 * HPAD, button_rows * (BTN_HEIGHT + VPAD) + BTN_HEIGHT);
mUserInputBox = new LLTextEditor(edit_text_name, input_rect, 254,
edit_text_contents, sFont, FALSE);
mUserInputBox->setBorderVisible(TRUE);
mUserInputBox->setTakesNonScrollClicks(TRUE);
mUserInputBox->setHideScrollbarForShortDocs(TRUE);
mUserInputBox->setWordWrap(TRUE);
mUserInputBox->setTabsToNextField(FALSE);
mUserInputBox->setCommitOnFocusLost(FALSE);
mUserInputBox->setAcceptCallingCardNames(FALSE);
mUserInputBox->setHandleEditKeysDirectly(TRUE);
addChild(mUserInputBox, -1);
}
else
{
setIsChrome(TRUE);
}
if (mNumButtons == 0)
@@ -739,6 +772,10 @@ void LLNotifyBox::onClickButton(void* data)
{
response[button_name] = true;
}
if (self->mUserInputBox)
{
response[self->mUserInputBox->getName()] = self->mUserInputBox->getValue();
}
self->mNotification->respond(response);
}

View File

@@ -41,6 +41,7 @@
class LLButton;
class LLNotifyBoxTemplate;
class LLTextEditor;
// NotifyBox - for notifications that require a response from the user.
class LLNotifyBox :
@@ -103,6 +104,8 @@ private:
protected:
std::string mMessage;
LLTextEditor *mUserInputBox;
LLNotificationPtr mNotification;
BOOL mIsTip;
BOOL mIsCaution; // is this a caution notification?

View File

@@ -6252,6 +6252,10 @@ bool callback_script_dialog(const LLSD& notification, const LLSD& response)
// Didn't click "Ignore"
if (button_idx != -1)
{
if (notification["payload"].has("textbox"))
{
button = response["message"].asString();
}
LLMessageSystem* msg = gMessageSystem;
msg->newMessage("ScriptDialogReply");
msg->nextBlock("AgentData");
@@ -6307,12 +6311,30 @@ void process_script_dialog(LLMessageSystem* msg, void**)
}
LLNotificationForm form;
for (i = 0; i < button_count; i++)
std::string firstbutton;
msg->getString("Buttons", "ButtonLabel", firstbutton, 0);
form.addElement("button", std::string(firstbutton));
bool is_text_box = false;
std::string default_text;
if (firstbutton == "!!llTextBox!!")
{
is_text_box = true;
for (i = 1; i < button_count; i++)
{
std::string tdesc;
msg->getString("Buttons", "ButtonLabel", tdesc, i);
default_text += tdesc;
}
}
else
{
for (i = 1; i < button_count; i++)
{
std::string tdesc;
msg->getString("Buttons", "ButtonLabel", tdesc, i);
form.addElement("button", std::string(tdesc));
}
}
LLSD args;
args["TITLE"] = title;
@@ -6325,9 +6347,19 @@ void process_script_dialog(LLMessageSystem* msg, void**)
{
args["FIRST"] = first_name;
args["LAST"] = last_name;
if (is_text_box)
{
args["DEFAULT"] = default_text;
payload["textbox"] = "true";
LLNotifications::instance().add("ScriptTextBoxDialog", args, payload, callback_script_dialog);
}
else
{
notification = LLNotifications::instance().add(
LLNotification::Params("ScriptDialog").substitutions(args).payload(payload).form_elements(form.asLLSD()));
}
}
else
{
args["GROUPNAME"] = last_name;

View File

@@ -6268,7 +6268,6 @@ Grant this request?
[MESSAGE]
<form name="form">
<input name="message">
[DEFAULT]
</input>
<button
index="-1"