diff options
author | Kelly Washington <kelly@lindenlab.com> | 2007-05-30 17:39:09 +0000 |
---|---|---|
committer | Kelly Washington <kelly@lindenlab.com> | 2007-05-30 17:39:09 +0000 |
commit | 3e9872a297c3cf3f929e688e0e89a78f6bc050f5 (patch) | |
tree | ab3877f764cc27dbdca0b683f07e6ea3a3ac8a23 /indra/llui/lllineeditor.cpp | |
parent | 7b61f1d0ec30e97fd3b7c5caf4b0e675c6e9a1f5 (diff) |
merge -r61423:62602 svn/branches/maintenance --> release
Diffstat (limited to 'indra/llui/lllineeditor.cpp')
-rw-r--r-- | indra/llui/lllineeditor.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index 43ea584aa1..7e7999c9f9 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -137,6 +137,14 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect, { llassert( max_length_bytes > 0 ); + // line history support: + // - initialize line history list + mLineHistory.insert( mLineHistory.end(), "" ); + // - disable line history by default + mHaveHistory = FALSE; + // - reset current history line pointer + mCurrentHistoryLine = 0; + if (font) { mGLFont = font; @@ -209,10 +217,33 @@ void LLLineEditor::onFocusLost() void LLLineEditor::onCommit() { + // put current line into the line history + updateHistory(); + LLUICtrl::onCommit(); selectAll(); } +// line history support +void LLLineEditor::updateHistory() +{ + // On history enabled line editors, remember committed line and + // reset current history line number. + // Be sure only to remember lines that are not empty and that are + // different from the last on the list. + if( mHaveHistory && mText.length() && ( mLineHistory.empty() || getText() != mLineHistory.back() ) ) + { + // discard possible empty line at the end of the history + // inserted by setText() + if( !mLineHistory.back().length() ) + { + mLineHistory.pop_back(); + } + mLineHistory.insert( mLineHistory.end(), getText() ); + mCurrentHistoryLine = mLineHistory.size() - 1; + } +} + void LLLineEditor::reshape(S32 width, S32 height, BOOL called_from_parent) { LLUICtrl::reshape(width, height, called_from_parent ); @@ -220,6 +251,10 @@ void LLLineEditor::reshape(S32 width, S32 height, BOOL called_from_parent) mMaxHPixels = mRect.getWidth() - 2 * (mBorderThickness + UI_LINEEDITOR_H_PAD) + 1 - mBorderRight; } +void LLLineEditor::setEnableLineHistory( BOOL enabled ) +{ + mHaveHistory = enabled; +} void LLLineEditor::setEnabled(BOOL enabled) { @@ -280,6 +315,13 @@ void LLLineEditor::setText(const LLString &new_text) deselect(); } setCursor(llmin((S32)mText.length(), getCursor())); + + // Newly set text goes always in the last line of history. + // Possible empty strings (as with chat line) will be deleted later. + mLineHistory.insert( mLineHistory.end(), new_text ); + // Set current history line to end of history. + mCurrentHistoryLine = mLineHistory.size() - 1; + mPrevText = mText; } @@ -1066,6 +1108,45 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask) } break; + // handle ctrl-uparrow if we have a history enabled line editor. + case KEY_UP: + if( mHaveHistory && ( MASK_CONTROL & mask ) ) + { + if( mCurrentHistoryLine > 0 ) + { + mText.assign( mLineHistory[ --mCurrentHistoryLine ] ); + setCursor(llmin((S32)mText.length(), getCursor())); + } + else + { + reportBadKeystroke(); + } + handled = TRUE; + } + break; + + // handle ctrl-downarrow if we have a history enabled line editor + case KEY_DOWN: + if( mHaveHistory && ( MASK_CONTROL & mask ) ) + { + if( !mLineHistory.empty() && mCurrentHistoryLine < mLineHistory.size() - 1 ) + { + mText.assign( mLineHistory[ ++mCurrentHistoryLine ] ); + setCursor(llmin((S32)mText.length(), getCursor())); + } + else + { + reportBadKeystroke(); + } + handled = TRUE; + } + break; + + case KEY_RETURN: + // store sent line in history + updateHistory(); + break; + case KEY_ESCAPE: if (mRevertOnEsc && mText.getString() != mPrevText) { |