diff options
-rwxr-xr-x | indra/llui/llkeywords.cpp | 147 | ||||
-rwxr-xr-x | indra/llui/llkeywords.h | 28 | ||||
-rwxr-xr-x | indra/llui/lltexteditor.cpp | 77 | ||||
-rwxr-xr-x | indra/llui/lltexteditor.h | 7 | ||||
-rwxr-xr-x | indra/newview/CMakeLists.txt | 2 | ||||
-rwxr-xr-x | indra/newview/app_settings/keywords_lsl_default.xml | 10 | ||||
-rw-r--r-- | indra/newview/llfloaterscriptedprefs.cpp | 65 | ||||
-rw-r--r-- | indra/newview/llfloaterscriptedprefs.h | 51 | ||||
-rw-r--r-- | indra/newview/llscripteditor.cpp | 96 | ||||
-rw-r--r-- | indra/newview/llscripteditor.h | 8 | ||||
-rw-r--r-- | indra/newview/llsyntaxid.cpp | 15 | ||||
-rw-r--r-- | indra/newview/llsyntaxid.h | 6 | ||||
-rwxr-xr-x | indra/newview/llviewerfloaterreg.cpp | 2 | ||||
-rwxr-xr-x | indra/newview/skins/default/colors.xml | 29 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/floater_script_ed_prefs.xml | 387 | ||||
-rwxr-xr-x | indra/newview/skins/default/xui/en/panel_script_ed.xml | 22 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/script_editor.xml | 12 |
17 files changed, 721 insertions, 243 deletions
diff --git a/indra/llui/llkeywords.cpp b/indra/llui/llkeywords.cpp index 2d8bd926c0..9c5a339b6d 100755 --- a/indra/llui/llkeywords.cpp +++ b/indra/llui/llkeywords.cpp @@ -67,8 +67,8 @@ inline bool LLKeywordToken::isTail(const llwchar* s) const return res; } -LLKeywords::LLKeywords() : - mLoaded(false) +LLKeywords::LLKeywords() +: mLoaded(false) { } @@ -82,12 +82,6 @@ LLKeywords::~LLKeywords() mDelimiterTokenList.clear(); } -void LLKeywords::addColorGroup(const std::string& key_in, const LLColor4& color) -{ - WStringMapIndex key ( utf8str_to_wstring(key_in) ); - mColorGroupMap[key] = color; -} - // Add the token as described void LLKeywords::addToken(LLKeywordToken::ETokenType type, const std::string& key_in, @@ -98,7 +92,7 @@ void LLKeywords::addToken(LLKeywordToken::ETokenType type, std::string tip_text = tool_tip_in; LLStringUtil::replaceString(tip_text, "\\n", "\n" ); LLStringUtil::replaceString(tip_text, "\t", " " ); - if (tip_text == "") + if (tip_text.empty()) { tip_text = "[no info]"; } @@ -167,7 +161,7 @@ std::string LLKeywords::getArguments(LLSD& arguments) { LL_WARNS("SyntaxLSL") << "Not an array! Invalid arguments LLSD passed to function." << arguments << LL_ENDL; } - return argString == "" ? "" : argString; + return argString; } std::string LLKeywords::getAttribute(const std::string& key) @@ -178,30 +172,14 @@ std::string LLKeywords::getAttribute(const std::string& key) LLColor4 LLKeywords::getColorGroup(const std::string& key_in) { - std::string color_group = "Black"; - if (key_in == "constants-float") - { - color_group = "SyntaxLslConstantFloat"; - } - else if (key_in == "constants-integer") - { - color_group = "SyntaxLslConstantInteger"; - } - else if (key_in == "constants-key") - { - color_group = "SyntaxLslConstantKey"; - } - else if (key_in == "constants-rotation") + std::string color_group = "ScriptText"; + if (key_in == "constants") { - color_group = "SyntaxLslConstantRotation"; + color_group = "SyntaxLslConstant"; } - else if (key_in == "constants-string") + else if (key_in == "controls") { - color_group = "SyntaxLslConstantString"; - } - else if (key_in == "constants-vector") - { - color_group = "SyntaxLslConstantVector"; + color_group = "SyntaxLslControlFlow"; } else if (key_in == "misc-flow-label") { @@ -231,21 +209,9 @@ LLColor4 LLKeywords::getColorGroup(const std::string& key_in) { color_group = "SyntaxLslSection"; } - else if (key_in == "misc-double_quotation_marks") - { - color_group = "SyntaxLslStringLiteral"; - } - else if (key_in == "misc-comments_1_sided") - { - color_group = "SyntaxLslComment1Sided"; - } - else if (key_in == "misc-comments_2_sided") - { - color_group = "SyntaxLslComment2Sided"; - } else { - LL_WARNS("SyntaxLSL") << "Color key '" << key_in << "' not recognized!" << LL_ENDL; + LL_WARNS("SyntaxLSL") << "Color key '" << key_in << "' not recognized." << LL_ENDL; } return LLUIColorTable::instance().getColor(color_group); @@ -267,9 +233,9 @@ void LLKeywords::processTokens() // Add 'standard' stuff: Quotes, Comments, Strings, Labels, etc. before processing the LLSD std::string delimiter; addToken(LLKeywordToken::TT_LABEL, "@", getColorGroup("misc-flow-label"), "Label\nTarget for jump statement", delimiter ); - addToken(LLKeywordToken::TT_ONE_SIDED_DELIMITER, "//", getColorGroup("misc-comments_1_sided"), "Comment (single-line)\nNon-functional commentary or disabled code", delimiter ); - addToken(LLKeywordToken::TT_TWO_SIDED_DELIMITER, "/*", getColorGroup("misc-comments_2_sided"), "Comment (multi-line)\nNon-functional commentary or disabled code", "*/" ); - addToken(LLKeywordToken::TT_DOUBLE_QUOTATION_MARKS, "\"", getColorGroup("misc-double_quotation_marks"), "String literal", "\"" ); + addToken(LLKeywordToken::TT_ONE_SIDED_DELIMITER, "//", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (single-line)\nNon-functional commentary or disabled code", delimiter ); + addToken(LLKeywordToken::TT_TWO_SIDED_DELIMITER, "/*", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (multi-line)\nNon-functional commentary or disabled code", "*/" ); + addToken(LLKeywordToken::TT_DOUBLE_QUOTATION_MARKS, "\"", LLUIColorTable::instance().getColor("SyntaxLslStringLiteral"), "String literal", "\"" ); LLSD::map_iterator itr = mSyntax.beginMap(); for ( ; itr != mSyntax.endMap(); ++itr) @@ -333,14 +299,14 @@ void LLKeywords::processTokensGroup(const LLSD& tokens, const std::string& group if (tokens.isMap()) { LLSD::map_const_iterator outer_itr = tokens.beginMap(); - for ( ; outer_itr != tokens.endMap(); ++outer_itr) + for ( ; outer_itr != tokens.endMap(); ++outer_itr ) { if (outer_itr->second.isMap()) { mAttributes.clear(); LLSD arguments = LLSD(); LLSD::map_const_iterator inner_itr = outer_itr->second.beginMap(); - for ( ; inner_itr != outer_itr->second.endMap(); ++inner_itr) + for ( ; inner_itr != outer_itr->second.endMap(); ++inner_itr ) { if (inner_itr->first == "arguments") { @@ -360,33 +326,34 @@ void LLKeywords::processTokensGroup(const LLSD& tokens, const std::string& group } std::string tooltip = ""; - if (token_type == LLKeywordToken::TT_CONSTANT) + switch (token_type) { - color_group = getColorGroup(group + "-" + getAttribute("type")); - tooltip = "Type: " + getAttribute("type") + ", Value: " + getAttribute("value"); - } - else if (token_type == LLKeywordToken::TT_EVENT) - { - tooltip = outer_itr->first + "(" + getArguments(arguments) + ")"; - } - else if (token_type == LLKeywordToken::TT_FUNCTION) - { - tooltip = getAttribute("return") + " " + outer_itr->first + "(" + getArguments(arguments) + ");"; - tooltip += "\nEnergy: "; - tooltip += getAttribute("energy") == "" ? "0.0" : getAttribute("energy"); - if (getAttribute("sleep") != "") - { - tooltip += ", Sleep: " + getAttribute("sleep"); - } + case LLKeywordToken::TT_CONSTANT: + color_group = getColorGroup(group + "-" + getAttribute("type")); + tooltip = "Type: " + getAttribute("type") + ", Value: " + getAttribute("value"); + break; + case LLKeywordToken::TT_EVENT: + tooltip = outer_itr->first + "(" + getArguments(arguments) + ")"; + break; + case LLKeywordToken::TT_FUNCTION: + tooltip = getAttribute("return") + " " + outer_itr->first + "(" + getArguments(arguments) + ");"; + tooltip.append("\nEnergy: "); + tooltip.append(getAttribute("energy").empty() ? "0.0" : getAttribute("energy")); + if (!getAttribute("sleep").empty()) + { + tooltip += ", Sleep: " + getAttribute("sleep"); + } + default: + break; } - if (getAttribute("tooltip") != "") + if (!getAttribute("tooltip").empty()) { - if (tooltip != "") + if (!tooltip.empty()) { - tooltip += "\n"; + tooltip.append("\n"); } - tooltip += getAttribute("tooltip"); + tooltip.append(getAttribute("tooltip")); } color = getAttribute("deprecated") == "true" ? color_deprecated : color_group; @@ -403,7 +370,7 @@ void LLKeywords::processTokensGroup(const LLSD& tokens, const std::string& group else if (tokens.isArray()) // Currently nothing should need this, but it's here for completeness { LL_INFOS("SyntaxLSL") << "Curious, shouldn't be an array here; adding all using color " << color << LL_ENDL; - for (int count = 0; count < tokens.size(); ++count) + for (S32 count = 0; count < tokens.size(); ++count) { addToken(token_type, tokens[count], color, ""); } @@ -433,15 +400,19 @@ LLKeywords::WStringMapIndex::WStringMapIndex(const LLWString& str) copyData(str.data(), str.size()); } -LLKeywords::WStringMapIndex::WStringMapIndex(const llwchar *start, size_t length): -mData(start), mLength(length), mOwner(false) +LLKeywords::WStringMapIndex::WStringMapIndex(const llwchar *start, size_t length) +: mData(start) +, mLength(length) +, mOwner(false) { } LLKeywords::WStringMapIndex::~WStringMapIndex() { - if(mOwner) + if (mOwner) + { delete[] mData; + } } void LLKeywords::WStringMapIndex::copyData(const llwchar *start, size_t length) @@ -495,34 +466,6 @@ bool LLKeywords::WStringMapIndex::operator<(const LLKeywords::WStringMapIndex &o return result; } -LLColor4 LLKeywords::readColor( const std::string& s ) -{ - F32 r, g, b; - r = g = b = 0.0f; - S32 values_read = sscanf(s.c_str(), "%f, %f, %f]", &r, &g, &b ); - if( values_read != 3 ) - { - llinfos << " poorly formed color in keyword file" << llendl; - } - return LLColor4( r, g, b, 1.f); -} - -LLColor4 LLKeywords::readColor(LLSD& sd) -{ - if (sd.isArray()) - { - return LLColor4(sd, 1.f); - } - else if (sd.isMap()) - { - return LLColor4( sd.get("x").asReal(), sd.get("y").asReal(), sd.get("z").asReal(), 1.f ); - } - else - { - return LLColor4::black; - } -} - LLTrace::BlockTimerStatHandle FTM_SYNTAX_COLORING("Syntax Coloring"); // Walk through a string, applying the rules specified by the keyword token list and diff --git a/indra/llui/llkeywords.h b/indra/llui/llkeywords.h index eecb327fee..18e2ed06c5 100755 --- a/indra/llui/llkeywords.h +++ b/indra/llui/llkeywords.h @@ -109,12 +109,14 @@ public: LLKeywords(); ~LLKeywords(); - void addColorGroup(const std::string& key_in, const LLColor4& color); void clearLoaded() { mLoaded = false; } LLColor4 getColorGroup(const std::string& key_in); bool isLoaded() const { return mLoaded; } - void findSegments(std::vector<LLTextSegmentPtr> *seg_list, const LLWString& text, const LLColor4 &defaultColor, class LLTextEditor& editor ); + void findSegments(std::vector<LLTextSegmentPtr> *seg_list, + const LLWString& text, + const LLColor4 &defaultColor, + class LLTextEditor& editor); void initialize(LLSD SyntaxXML); void processTokens(); @@ -168,12 +170,20 @@ public: protected: void processTokensGroup(const LLSD& Tokens, const std::string& Group); - LLColor4 readColor(const std::string& s); - LLColor4 readColor(LLSD& sd); - void insertSegment(std::vector<LLTextSegmentPtr>& seg_list, LLTextSegmentPtr new_segment, S32 text_len, const LLColor4 &defaultColor, class LLTextEditor& editor); - void insertSegments(const LLWString& wtext, std::vector<LLTextSegmentPtr>& seg_list, LLKeywordToken* token, S32 text_len, S32 seg_start, S32 seg_end, const LLColor4 &defaultColor, LLTextEditor& editor); + void insertSegment(std::vector<LLTextSegmentPtr>& seg_list, + LLTextSegmentPtr new_segment, + S32 text_len, + const LLColor4 &defaultColor, + class LLTextEditor& editor); + void insertSegments(const LLWString& wtext, + std::vector<LLTextSegmentPtr>& seg_list, + LLKeywordToken* token, + S32 text_len, + S32 seg_start, + S32 seg_end, + const LLColor4 &defaultColor, + LLTextEditor& editor); - LLSD mColors; bool mLoaded; LLSD mSyntax; word_token_map_t mWordTokenMap; @@ -186,9 +196,7 @@ protected: element_attributes_t mAttributes; std::string getAttribute(const std::string& key); - std::string getArguments(LLSD& args); - -private: + std::string getArguments(LLSD& arguments); }; #endif // LL_LLKEYWORDS_H diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index a212c5dcd9..686fb80817 100755 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -75,8 +75,6 @@ template class LLTextEditor* LLView::getChild<class LLTextEditor>( // // Constants // -const S32 UI_TEXTEDITOR_LINE_NUMBER_MARGIN = 32; -const S32 UI_TEXTEDITOR_LINE_NUMBER_DIGITS = 4; const S32 SPACES_PER_TAB = 4; const F32 SPELLCHECK_DELAY = 0.5f; // delay between the last keypress and spell checking the word the cursor is on @@ -236,7 +234,6 @@ LLTextEditor::Params::Params() prevalidate_callback("prevalidate_callback"), embedded_items("embedded_items", false), ignore_tab("ignore_tab", true), - show_line_numbers("show_line_numbers", false), auto_indent("auto_indent", true), default_color("default_color"), commit_on_focus_lost("commit_on_focus_lost", false), @@ -252,8 +249,7 @@ LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) : mBaseDocIsPristine(TRUE), mPristineCmd( NULL ), mLastCmd( NULL ), - mDefaultColor( p.default_color() ), - mShowLineNumbers ( p.show_line_numbers ), + mDefaultColor( p.default_color() ), mAutoIndent(p.auto_indent), mCommitOnFocusLost( p.commit_on_focus_lost), mAllowEmbeddedItems( p.embedded_items ), @@ -277,14 +273,7 @@ LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) : params.visible = p.border_visible; mBorder = LLUICtrlFactory::create<LLViewBorder> (params); addChild( mBorder ); - setText(p.default_text()); - - if (mShowLineNumbers) - { - mHPad += UI_TEXTEDITOR_LINE_NUMBER_MARGIN; - updateRects(); - } mParseOnTheFly = TRUE; } @@ -2196,69 +2185,6 @@ void LLTextEditor::drawPreeditMarker() } } - -void LLTextEditor::drawLineNumbers() -{ - LLGLSUIDefault gls_ui; - LLRect scrolled_view_rect = getVisibleDocumentRect(); - LLRect content_rect = getVisibleTextRect(); - LLLocalClipRect clip(content_rect); - S32 first_line = getFirstVisibleLine(); - S32 num_lines = getLineCount(); - if (first_line >= num_lines) - { - return; - } - - S32 cursor_line = mLineInfoList[getLineNumFromDocIndex(mCursorPos)].mLineNum; - - if (mShowLineNumbers) - { - S32 left = 0; - S32 top = getRect().getHeight(); - S32 bottom = 0; - - gl_rect_2d(left, top, UI_TEXTEDITOR_LINE_NUMBER_MARGIN, bottom, mReadOnlyBgColor.get() ); // line number area always read-only - gl_rect_2d(UI_TEXTEDITOR_LINE_NUMBER_MARGIN, top, UI_TEXTEDITOR_LINE_NUMBER_MARGIN-1, bottom, LLColor4::grey3); // separator - - S32 last_line_num = -1; - - for (S32 cur_line = first_line; cur_line < num_lines; cur_line++) - { - line_info& line = mLineInfoList[cur_line]; - - if ((line.mRect.mTop - scrolled_view_rect.mBottom) < mVisibleTextRect.mBottom) - { - break; - } - - S32 line_bottom = line.mRect.mBottom - scrolled_view_rect.mBottom + mVisibleTextRect.mBottom; - // draw the line numbers - if(line.mLineNum != last_line_num && line.mRect.mTop <= scrolled_view_rect.mTop) - { - const LLFontGL *num_font = LLFontGL::getFontMonospace(); - const LLWString ltext = utf8str_to_wstring(llformat("%d", line.mLineNum )); - BOOL is_cur_line = cursor_line == line.mLineNum; - const U8 style = is_cur_line ? LLFontGL::BOLD : LLFontGL::NORMAL; - const LLColor4 fg_color = is_cur_line ? mCursorColor : mReadOnlyFgColor; - num_font->render( - ltext, // string to draw - 0, // begin offset - UI_TEXTEDITOR_LINE_NUMBER_MARGIN - 2, // x - line_bottom, // y - fg_color, - LLFontGL::RIGHT, // horizontal alignment - LLFontGL::BOTTOM, // vertical alignment - style, - LLFontGL::NO_SHADOW, - S32_MAX, // max chars - UI_TEXTEDITOR_LINE_NUMBER_MARGIN - 2); // max pixels - last_line_num = line.mLineNum; - } - } - } -} - void LLTextEditor::draw() { { @@ -2270,7 +2196,6 @@ void LLTextEditor::draw() } LLTextBase::draw(); - drawLineNumbers(); drawPreeditMarker(); diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index 404275026c..2408613824 100755 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -58,7 +58,6 @@ public: Optional<bool> embedded_items, ignore_tab, - show_line_numbers, commit_on_focus_lost, show_context_menu, enable_tooltip_paste, @@ -279,11 +278,11 @@ protected: protected: LLUIColor mDefaultColor; - BOOL mShowLineNumbers; bool mAutoIndent; bool mParseOnTheFly; void updateLinkSegments(); + class LLViewBorder* mBorder; private: // @@ -293,8 +292,6 @@ private: void cleanStringForPaste(LLWString & clean_string); void pasteTextWithLinebreaks(LLWString & clean_string); - void drawLineNumbers(); - void onKeyStroke(); // Concrete TextCmd sub-classes used by the LLTextEditor base class @@ -303,8 +300,6 @@ private: class TextCmdOverwriteChar; class TextCmdRemove; - class LLViewBorder* mBorder; - BOOL mBaseDocIsPristine; TextCmd* mPristineCmd; diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index ddad9c768f..a42a204b82 100755 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -272,6 +272,7 @@ set(viewer_SOURCE_FILES llfloaterregionrestarting.cpp llfloatersceneloadstats.cpp llfloaterscriptdebug.cpp + llfloaterscriptedprefs.cpp llfloaterscriptlimits.cpp llfloatersearch.cpp llfloatersellland.cpp @@ -868,6 +869,7 @@ set(viewer_HEADER_FILES llfloaterregionrestarting.h llfloatersceneloadstats.h llfloaterscriptdebug.h + llfloaterscriptedprefs.h llfloaterscriptlimits.h llfloatersearch.h llfloatersellland.h diff --git a/indra/newview/app_settings/keywords_lsl_default.xml b/indra/newview/app_settings/keywords_lsl_default.xml index 02823136ee..37dd2db93f 100755 --- a/indra/newview/app_settings/keywords_lsl_default.xml +++ b/indra/newview/app_settings/keywords_lsl_default.xml @@ -3,11 +3,6 @@ <map> <key>controls</key> <map> - <key>default</key> - <map> - <key>tooltip</key> - <string>All scripts must have a default state, which is the first state entered when the script starts.\nIf another state is defined before the default state, the compiler will report a syntax error.</string> - </map> <key>do</key> <map> <key>tooltip</key> @@ -6002,6 +5997,11 @@ <key>tooltip</key> <string/> </map> + <key>default</key> + <map> + <key>tooltip</key> + <string>All scripts must have a default state, which is the first state entered when the script starts.\nIf another state is defined before the default state, the compiler will report a syntax error.</string> + </map> </map> <key>events</key> <map> diff --git a/indra/newview/llfloaterscriptedprefs.cpp b/indra/newview/llfloaterscriptedprefs.cpp new file mode 100644 index 0000000000..2484a08626 --- /dev/null +++ b/indra/newview/llfloaterscriptedprefs.cpp @@ -0,0 +1,65 @@ +/** + * @file llfloaterscriptedprefs.cpp + * @brief Color controls for the script editor + * @author Cinder Roxley + * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2014, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" +#include "llfloaterscriptedprefs.h" + +#include "llcolorswatch.h" +#include "llscripteditor.h" + + +LLFloaterScriptEdPrefs::LLFloaterScriptEdPrefs(const LLSD& key) +: LLFloater(key) +, mEditor(NULL) +{ + mCommitCallbackRegistrar.add("ScriptPref.applyUIColor", boost::bind(&LLFloaterScriptEdPrefs::applyUIColor, this ,_1, _2)); + mCommitCallbackRegistrar.add("ScriptPref.getUIColor", boost::bind(&LLFloaterScriptEdPrefs::getUIColor, this ,_1, _2)); +} + +BOOL LLFloaterScriptEdPrefs::postBuild() +{ + mEditor = getChild<LLScriptEditor>("Script Preview"); + if (mEditor) + { + mEditor->initKeywords(); + mEditor->loadKeywords(); + } + return TRUE; +} + +void LLFloaterScriptEdPrefs::applyUIColor(LLUICtrl* ctrl, const LLSD& param) +{ + LLUIColorTable::instance().setColor(param.asString(), LLColor4(ctrl->getValue())); + mEditor->initKeywords(); + mEditor->loadKeywords(); +} + +void LLFloaterScriptEdPrefs::getUIColor(LLUICtrl* ctrl, const LLSD& param) +{ + LLColorSwatchCtrl* color_swatch = dynamic_cast<LLColorSwatchCtrl*>(ctrl); + color_swatch->setOriginal(LLUIColorTable::instance().getColor(param.asString())); +} diff --git a/indra/newview/llfloaterscriptedprefs.h b/indra/newview/llfloaterscriptedprefs.h new file mode 100644 index 0000000000..31df897aac --- /dev/null +++ b/indra/newview/llfloaterscriptedprefs.h @@ -0,0 +1,51 @@ +/** + * @file llfloaterscriptedprefs.h + * @brief Color controls for the script editor + * @author Cinder Roxley + * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2014, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_FLOATERSCRIPTEDPREFS_H +#define LL_FLOATERSCRIPTEDPREFS_H + +#include "llfloater.h" + +class LLScriptEditor; +class LLUICtrl; + +class LLFloaterScriptEdPrefs : public LLFloater +{ +public: + LLFloaterScriptEdPrefs(const LLSD& key); + BOOL postBuild(); + +private: + ~LLFloaterScriptEdPrefs() {}; + + void applyUIColor(LLUICtrl* ctrl, const LLSD& param); + void getUIColor(LLUICtrl* ctrl, const LLSD& param); + + LLScriptEditor* mEditor; +}; + +#endif // LL_FLOATERSCRIPTEDPREFS_H diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index 31d3c29af4..df46380130 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -29,19 +29,109 @@ #include "llscripteditor.h" #include "llsyntaxid.h" +#include "lllocalcliprect.h" + +const S32 UI_TEXTEDITOR_LINE_NUMBER_MARGIN = 32; +const S32 UI_TEXTEDITOR_LINE_NUMBER_DIGITS = 4; static LLDefaultChildRegistry::Register<LLScriptEditor> r("script_editor"); LLScriptEditor::Params::Params() -{ - -} +: show_line_numbers("show_line_numbers", true) +{} LLScriptEditor::LLScriptEditor(const Params& p) : LLTextEditor(p) +, mShowLineNumbers(p.show_line_numbers) +{ + if (mShowLineNumbers) + { + mHPad += UI_TEXTEDITOR_LINE_NUMBER_MARGIN; + updateRects(); + } +} + +void LLScriptEditor::draw() { + { + // pad clipping rectangle so that cursor can draw at full width + // when at left edge of mVisibleTextRect + LLRect clip_rect(mVisibleTextRect); + clip_rect.stretch(1); + LLLocalClipRect clip(clip_rect); + } + LLTextBase::draw(); + drawLineNumbers(); + + drawPreeditMarker(); + + //RN: the decision was made to always show the orange border for keyboard focus but do not put an insertion caret + // when in readonly mode + mBorder->setKeyboardFocusHighlight( hasFocus() );// && !mReadOnly); +} + +void LLScriptEditor::drawLineNumbers() +{ + LLGLSUIDefault gls_ui; + LLRect scrolled_view_rect = getVisibleDocumentRect(); + LLRect content_rect = getVisibleTextRect(); + LLLocalClipRect clip(content_rect); + S32 first_line = getFirstVisibleLine(); + S32 num_lines = getLineCount(); + if (first_line >= num_lines) + { + return; + } + + S32 cursor_line = mLineInfoList[getLineNumFromDocIndex(mCursorPos)].mLineNum; + + if (mShowLineNumbers) + { + S32 left = 0; + S32 top = getRect().getHeight(); + S32 bottom = 0; + + gl_rect_2d(left, top, UI_TEXTEDITOR_LINE_NUMBER_MARGIN, bottom, mReadOnlyBgColor.get() ); // line number area always read-only + gl_rect_2d(UI_TEXTEDITOR_LINE_NUMBER_MARGIN, top, UI_TEXTEDITOR_LINE_NUMBER_MARGIN-1, bottom, LLColor4::grey3); // separator + + S32 last_line_num = -1; + + for (S32 cur_line = first_line; cur_line < num_lines; cur_line++) + { + line_info& line = mLineInfoList[cur_line]; + + if ((line.mRect.mTop - scrolled_view_rect.mBottom) < mVisibleTextRect.mBottom) + { + break; + } + + S32 line_bottom = line.mRect.mBottom - scrolled_view_rect.mBottom + mVisibleTextRect.mBottom; + // draw the line numbers + if(line.mLineNum != last_line_num && line.mRect.mTop <= scrolled_view_rect.mTop) + { + const LLFontGL *num_font = LLFontGL::getFontMonospace(); + const LLWString ltext = utf8str_to_wstring(llformat("%d", line.mLineNum )); + BOOL is_cur_line = cursor_line == line.mLineNum; + const U8 style = is_cur_line ? LLFontGL::BOLD : LLFontGL::NORMAL; + const LLColor4 fg_color = is_cur_line ? mCursorColor : mReadOnlyFgColor; + num_font->render( + ltext, // string to draw + 0, // begin offset + UI_TEXTEDITOR_LINE_NUMBER_MARGIN - 2, // x + line_bottom, // y + fg_color, + LLFontGL::RIGHT, // horizontal alignment + LLFontGL::BOTTOM, // vertical alignment + style, + LLFontGL::NO_SHADOW, + S32_MAX, // max chars + UI_TEXTEDITOR_LINE_NUMBER_MARGIN - 2); // max pixels + last_line_num = line.mLineNum; + } + } + } } void LLScriptEditor::initKeywords() diff --git a/indra/newview/llscripteditor.h b/indra/newview/llscripteditor.h index d3e18021f9..8c5ab362a3 100644 --- a/indra/newview/llscripteditor.h +++ b/indra/newview/llscripteditor.h @@ -36,10 +36,16 @@ public: struct Params : public LLInitParam::Block<Params, LLTextEditor::Params> { + Optional<bool> show_line_numbers; + Params(); }; virtual ~LLScriptEditor() {}; + + // LLView override + virtual void draw(); + void initKeywords(); void loadKeywords(); void clearSegments(); @@ -51,11 +57,13 @@ protected: LLScriptEditor(const Params& p); private: + void drawLineNumbers(); void updateSegments(); void loadKeywords(const std::string& filename_keywords, const std::string& filename_colors); LLKeywords mKeywords; + bool mShowLineNumbers; }; #endif // LL_SCRIPTEDITOR_H diff --git a/indra/newview/llsyntaxid.cpp b/indra/newview/llsyntaxid.cpp index 7551c1a442..0ef5993ac1 100644 --- a/indra/newview/llsyntaxid.cpp +++ b/indra/newview/llsyntaxid.cpp @@ -37,9 +37,9 @@ //----------------------------------------------------------------------------- // fetchKeywordsFileResponder //----------------------------------------------------------------------------- -fetchKeywordsFileResponder::fetchKeywordsFileResponder(std::string filespec) +fetchKeywordsFileResponder::fetchKeywordsFileResponder(const std::string& filespec) +: mFileSpec(filespec) { - mFileSpec = filespec; LL_DEBUGS("SyntaxLSL") << "Instantiating with file saving to: '" << filespec << "'" << LL_ENDL; } @@ -128,18 +128,11 @@ LLSyntaxIdLSL::LLSyntaxIdLSL() : { } -std::string LLSyntaxIdLSL::buildFileNameNew() -{ - mFileNameNew = mSyntaxIdNew.isNull() ? mFileNameDefault : "keywords_lsl_" + mSyntaxIdNew.asString() + ".llsd.xml"; - return mFileNameNew; -} - -std::string LLSyntaxIdLSL::buildFullFileSpec() +void LLSyntaxIdLSL::buildFullFileSpec() { ELLPath path = mSyntaxIdNew.isNull() ? LL_PATH_APP_SETTINGS : LL_PATH_CACHE; - buildFileNameNew(); + mFileNameNew = mSyntaxIdNew.isNull() ? mFileNameDefault : "keywords_lsl_" + mSyntaxIdNew.asString() + ".llsd.xml"; mFullFileSpec = gDirUtilp->getExpandedFilename(path, mFileNameNew); - return mFullFileSpec; } //----------------------------------------------------------------------------- diff --git a/indra/newview/llsyntaxid.h b/indra/newview/llsyntaxid.h index aa69209ca9..2288fb4ab8 100644 --- a/indra/newview/llsyntaxid.h +++ b/indra/newview/llsyntaxid.h @@ -62,14 +62,12 @@ public: boost::signals2::connection addFileFetchedCallback(const file_fetched_signal_t::slot_type& cb); protected: - std::string buildFileNameNew(); - std::string buildFullFileSpec(); + void buildFullFileSpec(); void fetchKeywordsFile(); void loadDefaultKeywordsIntoLLSD(); void loadKeywordsIntoLLSD(); void setSyntaxId(LLUUID SyntaxId) { mSyntaxIdCurrent = SyntaxId; } void setFileNameCurrent(const std::string& name) { mFileNameCurrent = name; } - void setFileNameDefault(const std::string& name) { mFileNameDefault = name; } void setFileNameNew(const std::string name) { mFileNameNew = name; } private: @@ -106,7 +104,7 @@ public: * @brief fetchKeywordsFileResponder * @param filespec File path and name of where to save the returned data */ - fetchKeywordsFileResponder(std::string filespec); + fetchKeywordsFileResponder(const std::string& filespec); void errorWithContent(U32 status, const std::string& reason, diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp index fae35fe664..3cd5b54aaf 100755 --- a/indra/newview/llviewerfloaterreg.cpp +++ b/indra/newview/llviewerfloaterreg.cpp @@ -98,6 +98,7 @@ #include "llfloaterreporter.h" #include "llfloatersceneloadstats.h" #include "llfloaterscriptdebug.h" +#include "llfloaterscriptedprefs.h" #include "llfloaterscriptlimits.h" #include "llfloatersearch.h" #include "llfloatersellland.h" @@ -282,6 +283,7 @@ void LLViewerFloaterReg::registerFloaters() LLFloaterReg::add("preview_texture", "floater_preview_texture.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLPreviewTexture>, "preview"); LLFloaterReg::add("properties", "floater_inventory_item_properties.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterProperties>); LLFloaterReg::add("publish_classified", "floater_publish_classified.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLPublishClassifiedFloater>); + LLFloaterReg::add("script_colors", "floater_script_ed_prefs.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterScriptEdPrefs>); LLFloaterReg::add("telehubs", "floater_telehub.xml",&LLFloaterReg::build<LLFloaterTelehub>); LLFloaterReg::add("test_inspectors", "floater_test_inspectors.xml", &LLFloaterReg::build<LLFloaterTestInspectors>); diff --git a/indra/newview/skins/default/colors.xml b/indra/newview/skins/default/colors.xml index cb1d6aa32b..3a1f3d4e0a 100755 --- a/indra/newview/skins/default/colors.xml +++ b/indra/newview/skins/default/colors.xml @@ -907,29 +907,20 @@ <!-- syntax highlighting (LSL Scripts) --> <color - name="SyntaxLslComment1Sided" - value=".8 .3 .15 1.0" /> - <color - name="SyntaxLslComment2Sided" - value=".8 .3 .15 1.0" /> - <color - name="SyntaxLslConstantFloat" - value=".3 .1 .5 1.0" /> - <color - name="SyntaxLslConstantInteger" - value=".1 .1 .5 1.0" /> + name="ScriptText" + reference="Black" /> <color - name="SyntaxLslConstantKey" - value=".1 .3 .5 1.0" /> + name="ScriptBackground" + reference="White" /> <color - name="SyntaxLslConstantRotation" - value=".2 .4 .2 1.0" /> + name="ScriptCursorColor" + reference="Black" /> <color - name="SyntaxLslConstantString" - value=".1 .3 .5 1.0" /> + name="SyntaxLslComment" + value=".8 .3 .15 1.0" /> <color - name="SyntaxLslConstantVector" - value=".2 .4 .2 1.0" /> + name="SyntaxLslConstant" + value=".3 .1 .5 1.0" /> <color name="SyntaxLslControlFlow" value="0 0 .8 1.0" /> diff --git a/indra/newview/skins/default/xui/en/floater_script_ed_prefs.xml b/indra/newview/skins/default/xui/en/floater_script_ed_prefs.xml new file mode 100644 index 0000000000..8ae0df22b1 --- /dev/null +++ b/indra/newview/skins/default/xui/en/floater_script_ed_prefs.xml @@ -0,0 +1,387 @@ +<?xml version="1.0" encoding="utf-8" standalone="yes" ?> +<floater + legacy_header_height="18" + can_resize="true" + height="400" + layout="topleft" + name="floater_script_colors" + help_topic="script_colors" + save_rect="true" + title="Customize script colors" + width="300"> + <text + follows="left|top" + height="15" + layout="topleft" + left="12" + name="color_pickers_label" + top="30" + width="200"> + Choose desired colors: + </text> + + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="15" + name="text" + top="45" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="ScriptText" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="ScriptText" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="text_label" + top_delta="5" + width="100"> + Text + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="15" + name="cursor" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="ScriptCursorColor" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="ScriptCursorColor" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="cursor_label" + top_delta="5" + width="100"> + Cursor + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="15" + name="background" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="ScriptBackground" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="ScriptBackground" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="background_label" + top_delta="5" + width="100"> + Background + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="15" + name="section" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="SyntaxLslSection" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="SyntaxLslSection" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="section_label" + top_delta="5" + width="100"> + Sections + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="15" + name="datatype" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="SyntaxLslDataType" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="SyntaxLslDataType" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="datatype_label" + top_delta="5" + width="100"> + Data Types + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="15" + name="event" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="SyntaxLslEvent" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="SyntaxLslEvent" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="event_label" + top_delta="5" + width="100"> + Events + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="15" + name="comment" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="SyntaxLslComment" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="SyntaxLslComment" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="comment_label" + top_delta="5" + width="100"> + Comment + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="170" + name="string_literal" + top="45" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="SyntaxLslStringLiteral" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="SyntaxLslStringLiteral" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="string_literal_label" + top_delta="5" + width="100"> + String Literals + </text> + + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="170" + name="constant" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="SyntaxLslConstant" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="SyntaxLslConstant" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="constant_label" + top_delta="5" + width="100"> + Constant + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="170" + name="flow_control" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="SyntaxLslControlFlow" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="SyntaxLslControlFlow" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="flow_control_label" + top_delta="5" + width="100"> + Flow Control + </text> + <color_swatch + can_apply_immediately="true" + follows="left|top" + height="24" + label_height="0" + layout="topleft" + left="170" + name="function" + top_pad="10" + width="44" > + <color_swatch.init_callback + function="ScriptPref.getUIColor" + parameter="SyntaxLslFunction" /> + <color_swatch.commit_callback + function="ScriptPref.applyUIColor" + parameter="SyntaxLslFunction" /> + </color_swatch> + <text + type="string" + length="1" + follows="left|top" + height="10" + layout="topleft" + left_pad="5" + mouse_opaque="false" + name="function_label" + top_delta="5" + width="100"> + Function + </text> + + <script_editor + left="8" + right="-8" + top="250" + bottom="-8" + type="string" + length="1" + follows="left|top|right|bottom" + font="Monospace" + height="100" + ignore_tab="false" + layout="topleft" + max_length="300" + name="Script Preview" + text_color="ScriptText" + default_color="ScriptText" + bg_writeable_color="ScriptBackground" + bg_focus_color="ScriptBackground" + text_readonly_color="ScriptText" + bg_readonly_color="ScriptBackground" + bg_selected_color="ScriptSelectedColor" + cursor_color="ScriptCursorColor" + enable_tooltip_paste="true" + word_wrap="true"> +default +{ + state_entry() + { + llSay(0, "Hello!"); + } +} + </script_editor> +</floater>
\ No newline at end of file diff --git a/indra/newview/skins/default/xui/en/panel_script_ed.xml b/indra/newview/skins/default/xui/en/panel_script_ed.xml index 76a81c4885..5971082380 100755 --- a/indra/newview/skins/default/xui/en/panel_script_ed.xml +++ b/indra/newview/skins/default/xui/en/panel_script_ed.xml @@ -70,6 +70,16 @@ label="Save to file..." layout="topleft" name="SaveToFile" /> + <menu_item_separator + layout="topleft" /> + <menu_item_call + label="Colors..." + layout="topleft" + name="Colors"> + <menu_item_call.on_click + function="Floater.Toggle" + parameter="script_colors"/> + </menu_item_call> </menu> <menu top="0" @@ -159,12 +169,18 @@ layout="topleft" max_length="262144" name="Script Editor" - text_readonly_color="DkGray" width="487" + text_color="ScriptText" + default_color="ScriptText" + bg_writeable_color="ScriptBackground" + bg_focus_color="ScriptBackground" + text_readonly_color="ScriptText" + bg_readonly_color="ScriptBackground" + bg_selected_color="ScriptSelectedColor" + cursor_color="ScriptCursorColor" enable_tooltip_paste="true" word_wrap="true" - show_context_menu="true" - show_line_numbers="true"> + show_context_menu="true"> Loading... </script_editor> <scroll_list diff --git a/indra/newview/skins/default/xui/en/script_editor.xml b/indra/newview/skins/default/xui/en/script_editor.xml index b030a117fc..f1c6161711 100644 --- a/indra/newview/skins/default/xui/en/script_editor.xml +++ b/indra/newview/skins/default/xui/en/script_editor.xml @@ -1,7 +1,11 @@ <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <script_editor - name="script_editor" - parse_urls="false" - show_context_menu="true" - show_line_numbers="true"> + name="script_editor" + parse_urls="false" + show_context_menu="true" + show_line_numbers="true" + text_color="ScriptText" + default_color="ScriptText" + bg_writeable_color="ScriptBackground" + bg_focus_color="ScriptBackground"> </script_editor> |