From dd99e2a6b5054927bba83d44a7a03bc365c28a77 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Mon, 12 Jan 2009 02:17:03 -0700 Subject: Applied Aimee's patch for doing simple math in the build editor --- linden/indra/llui/lllineeditor.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'linden/indra/llui/lllineeditor.cpp') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 12d1929..9c8ee94 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -41,6 +41,7 @@ #include "llgl.h" #include "lltimer.h" +#include "llcalc.h" //#include "llclipboard.h" #include "llcontrol.h" #include "llbutton.h" @@ -129,6 +130,7 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mDrawAsterixes( FALSE ), mHandleEditKeysDirectly( FALSE ), mSelectAllonFocusReceived( FALSE ), + mSelectAllonCommit( TRUE ), mPassDelete(FALSE), mReadOnly(FALSE), mImage( sImage ), @@ -226,7 +228,10 @@ void LLLineEditor::onCommit() updateHistory(); LLUICtrl::onCommit(); - selectAll(); + + // Selection on commit needs to be turned off when evaluating maths + // expressions, to allow indication of the error position + if (mSelectAllonCommit) selectAll(); } @@ -2082,6 +2087,32 @@ BOOL LLLineEditor::prevalidateASCII(const LLWString &str) return rv; } +BOOL LLLineEditor::evaluateFloat() +{ + bool success; + F32 result = 0.f; + std::string expr = getText(); + + success = LLCalc::getInstance()->evalString(expr, result); + + if (!success) + { + // Move the cursor to near the error on failure + setCursor(LLCalc::getInstance()->getLastErrorPos()); + // *TODO: Translated error message indicating the type of error? Select error text? + } + else + { + // Replace the expression with the result + std::ostringstream result_str; + result_str << result; + setText(result_str.str()); + selectAll(); + } + + return success; +} + void LLLineEditor::onMouseCaptureLost() { endSelection(); -- cgit v1.1