MAINT-1276: Add ability to paste LSL tooltips into scripts. Reviewed by Kelly

meow-7.2.2
simon@Simon-PC.lindenlab.com 2012-07-17 13:52:08 -07:00
parent 7cd5f7d479
commit 891af8055a
5 changed files with 90 additions and 19 deletions

View File

@ -237,7 +237,8 @@ LLTextEditor::Params::Params()
show_line_numbers("show_line_numbers", false),
default_color("default_color"),
commit_on_focus_lost("commit_on_focus_lost", false),
show_context_menu("show_context_menu")
show_context_menu("show_context_menu"),
enable_tooltip_paste("enable_tooltip_paste")
{
addSynonym(prevalidate_callback, "text_type");
}
@ -256,7 +257,8 @@ LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) :
mTabsToNextField(p.ignore_tab),
mPrevalidateFunc(p.prevalidate_callback()),
mContextMenu(NULL),
mShowContextMenu(p.show_context_menu)
mShowContextMenu(p.show_context_menu),
mEnableTooltipPaste(p.enable_tooltip_paste)
{
mSourceID.generate();
@ -1409,6 +1411,23 @@ void LLTextEditor::pasteHelper(bool is_primary)
// Clean up string (replace tabs and remove characters that our fonts don't support).
LLWString clean_string(paste);
cleanStringForPaste(clean_string);
// Insert the new text into the existing text.
//paste text with linebreaks.
pasteTextWithLinebreaks(clean_string);
deselect();
onKeyStroke();
mParseOnTheFly = TRUE;
}
// Clean up string (replace tabs and remove characters that our fonts don't support).
void LLTextEditor::cleanStringForPaste(LLWString & clean_string)
{
LLWStringUtil::replaceTabsWithSpaces(clean_string, SPACES_PER_TAB);
if( mAllowEmbeddedItems )
{
@ -1427,10 +1446,11 @@ void LLTextEditor::pasteHelper(bool is_primary)
}
}
}
}
// Insert the new text into the existing text.
//paste text with linebreaks.
void LLTextEditor::pasteTextWithLinebreaks(LLWString & clean_string)
{
std::basic_string<llwchar>::size_type start = 0;
std::basic_string<llwchar>::size_type pos = clean_string.find('\n',start);
@ -1449,15 +1469,8 @@ void LLTextEditor::pasteHelper(bool is_primary)
std::basic_string<llwchar> str = std::basic_string<llwchar>(clean_string,start,clean_string.length()-start);
setCursorPos(mCursorPos + insert(mCursorPos, str, FALSE, LLTextSegmentPtr()));
deselect();
onKeyStroke();
mParseOnTheFly = TRUE;
}
// copy selection to primary
void LLTextEditor::copyPrimary()
{
@ -1678,19 +1691,50 @@ BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask )
{
return FALSE;
}
if (mReadOnly && mScroller)
{
handled = (mScroller && mScroller->handleKeyHere( key, mask ))
|| handleSelectionKey(key, mask)
|| handleControlKey(key, mask);
}
else
{
if (mEnableTooltipPaste &&
LLToolTipMgr::instance().toolTipVisible() &&
KEY_TAB == key)
{ // Paste the first line of a tooltip into the editor
std::string message;
LLToolTipMgr::instance().getToolTipMessage(message);
LLWString tool_tip_text(utf8str_to_wstring(message));
if (tool_tip_text.size() > 0)
{
// Delete any selected characters (the tooltip text replaces them)
if(hasSelection())
{
deleteSelection(TRUE);
}
std::basic_string<llwchar>::size_type pos = tool_tip_text.find('\n',0);
if (pos != -1)
{ // Extract the first line of the tooltip
tool_tip_text = std::basic_string<llwchar>(tool_tip_text, 0, pos);
}
// Add the text
cleanStringForPaste(tool_tip_text);
pasteTextWithLinebreaks(tool_tip_text);
handled = TRUE;
}
}
else
{ // Normal key handling
handled = handleNavigationKey( key, mask )
|| handleSelectionKey(key, mask)
|| handleControlKey(key, mask)
|| handleSpecialKey(key, mask);
}
else
{
handled = handleNavigationKey( key, mask )
|| handleSelectionKey(key, mask)
|| handleControlKey(key, mask)
|| handleSpecialKey(key, mask);
}
if( handled )

View File

@ -64,7 +64,8 @@ public:
ignore_tab,
show_line_numbers,
commit_on_focus_lost,
show_context_menu;
show_context_menu,
enable_tooltip_paste;
//colors
Optional<LLUIColor> default_color;
@ -288,6 +289,8 @@ private:
// Methods
//
void pasteHelper(bool is_primary);
void cleanStringForPaste(LLWString & clean_string);
void pasteTextWithLinebreaks(LLWString & clean_string);
void drawLineNumbers();
@ -321,6 +324,7 @@ private:
BOOL mAllowEmbeddedItems;
bool mShowContextMenu;
bool mParseOnTheFly;
bool mEnableTooltipPaste;
LLUUID mSourceID;

View File

@ -390,6 +390,15 @@ bool LLToolTip::hasClickCallback()
return mHasClickCallback;
}
void LLToolTip::getToolTipMessage(std::string & message)
{
if (mTextBox)
{
message = mTextBox->getText();
}
}
//
// LLToolTipMgr
@ -594,5 +603,14 @@ void LLToolTipMgr::updateToolTipVisibility()
}
// Return the current tooltip text
void LLToolTipMgr::getToolTipMessage(std::string & message)
{
if (toolTipVisible())
{
mToolTip->getToolTipMessage(message);
}
}
// EOF

View File

@ -105,6 +105,8 @@ public:
LLToolTip(const Params& p);
void initFromParams(const LLToolTip::Params& params);
void getToolTipMessage(std::string & message);
private:
class LLTextBox* mTextBox;
class LLButton* mInfoButton;
@ -142,6 +144,8 @@ public:
LLRect getMouseNearRect();
void updateToolTipVisibility();
void getToolTipMessage(std::string & message);
private:
void createToolTip(const LLToolTip::Params& params);

View File

@ -158,6 +158,7 @@
text_readonly_color="DkGray"
width="487"
show_line_numbers="true"
enable_tooltip_paste="true"
word_wrap="true">
Loading...
</text_editor>