From 5b716795ab41df73ad74abde03909fccc0a02a18 Mon Sep 17 00:00:00 2001 From: Cinders Date: Thu, 16 May 2013 13:28:12 -0600 Subject: [PATCH] More changes to keywords.ini: * Don't read colors from the ini, use LLUIColorTable and let the users and skin artists choose colors * Define more specific sections in the ini * Standardize sections to only contain the section name, no readColor() hack! * Expose color settings for syntax highlighting to the user --- indra/llui/llkeywords.cpp | 183 +++++++-- indra/llui/llkeywords.h | 28 +- indra/newview/app_settings/keywords.ini | 24 +- indra/newview/app_settings/keywords_ossl.ini | 2 +- .../newview/app_settings/keywords_preproc.ini | 6 +- indra/newview/llpreviewscript.cpp | 12 - indra/newview/skins/default/colors.xml | 34 +- .../xui/en/floater_fs_script_editor_prefs.xml | 347 +++++++++++++++++- 8 files changed, 555 insertions(+), 81 deletions(-) diff --git a/indra/llui/llkeywords.cpp b/indra/llui/llkeywords.cpp index d019abaaf0..02169ab5d3 100644 --- a/indra/llui/llkeywords.cpp +++ b/indra/llui/llkeywords.cpp @@ -34,6 +34,8 @@ #include "llstl.h" #include +#include "lluicolortable.h" // Use color table so the user can define colors + // Bump this for Firestorm changes //const U32 KEYWORD_FILE_CURRENT_VERSION = 2; const U32 KEYWORD_FILE_CURRENT_VERSION = 3; @@ -118,19 +120,34 @@ BOOL LLKeywords::loadFromFile( const std::string& filename ) llinfos << filename << " does not appear to be a version " << KEYWORD_FILE_CURRENT_VERSION << " keyword file" << llendl; return mLoaded; } - - // start of line (SOL) -// Use ; for comment, not # so we can add preprocessor directives to keywords.ini + + //////////////////////////////////////////////////////////// + // Start of line (SOL) + // Use ; for comment, not # so we can add preprocessor directives to keywords.ini //std::string SOL_COMMENT("#"); - std::string SOL_COMMENT(";"); -// - std::string SOL_WORD("[word "); - std::string SOL_LINE("[line "); - std::string SOL_ONE_SIDED_DELIMITER("[one_sided_delimiter "); - std::string SOL_TWO_SIDED_DELIMITER("[two_sided_delimiter "); - std::string SOL_DOUBLE_QUOTATION_MARKS("[double_quotation_marks "); - - LLColor3 cur_color( 1, 0, 0 ); + std::string SOL_INI_COMMENT(";"); + //std::string SOL_WORD("[word "); + //std::string SOL_LINE("[line "); + //std::string SOL_ONE_SIDED_DELIMITER("[one_sided_delimiter "); + //std::string SOL_TWO_SIDED_DELIMITER("[two_sided_delimiter "); + //std::string SOL_DOUBLE_QUOTATION_MARKS("[double_quotation_marks "); + std::string SOL_SECTION("[SECTION]"); + std::string SOL_DATATYPE("[DATATYPE]"); + std::string SOL_EVENT("[EVENT]"); + std::string SOL_I_CONSTANT("[I_CONSTANT]"); + std::string SOL_S_CONSTANT("[S_CONSTANT]"); + std::string SOL_F_CONSTANT("[F_CONSTANT]"); + std::string SOL_C_CONSTANT("[C_CONSTANT]"); + std::string SOL_FLOW_CONTROL("[FLOW CONTROL]"); + std::string SOL_FLOW_CONTROL_LABEL("[FLOW CONTROL LABEL]"); + std::string SOL_STRING_LITERAL("[STRING LITERAL]"); + std::string SOL_CODE_COMMENT("[COMMENT]"); + std::string SOL_BLOCK_COMMENT("[BLOCK COMMENT]"); + std::string SOL_PREPROCESSOR("[PREPROCESSOR]"); + + //LLColor3 cur_color( 1, 0, 0 ); + LLColor4 cur_color(LLUIColorTable::instance().getColor("ScriptText")); + // LLKeywordToken::TOKEN_TYPE cur_type = LLKeywordToken::WORD; while (!file.eof()) @@ -138,40 +155,123 @@ BOOL LLKeywords::loadFromFile( const std::string& filename ) buffer[0] = 0; file.getline( buffer, BUFFER_SIZE ); std::string line(buffer); - if( line.find(SOL_COMMENT) == 0 ) + // User defined syntax highlighting + //if( line.find(SOL_COMMENT) == 0 ) + if( line.find(SOL_INI_COMMENT) == 0 ) + // { continue; } - else if( line.find(SOL_WORD) == 0 ) + // User defined syntax highlighting + //else if( line.find(SOL_WORD) == 0 ) + //{ + // cur_color = readColor( line.substr(SOL_WORD.size()) ); + // cur_type = LLKeywordToken::WORD; + // continue; + //} + //else if( line.find(SOL_LINE) == 0 ) + //{ + // cur_color = readColor( line.substr(SOL_LINE.size()) ); + // cur_type = LLKeywordToken::LINE; + // continue; + //} + //else if( line.find(SOL_TWO_SIDED_DELIMITER) == 0 ) + //{ + // cur_color = readColor( line.substr(SOL_TWO_SIDED_DELIMITER.size()) ); + // cur_type = LLKeywordToken::TWO_SIDED_DELIMITER; + // continue; + //} + //else if( line.find(SOL_DOUBLE_QUOTATION_MARKS) == 0 ) + //{ + // cur_color = readColor( line.substr(SOL_DOUBLE_QUOTATION_MARKS.size()) ); + // cur_type = LLKeywordToken::DOUBLE_QUOTATION_MARKS; + // continue; + //} + //else if( line.find(SOL_ONE_SIDED_DELIMITER) == 0 ) + //{ + // cur_color = readColor( line.substr(SOL_ONE_SIDED_DELIMITER.size()) ); + // cur_type = LLKeywordToken::ONE_SIDED_DELIMITER; + // continue; + //} + else if (line.find(SOL_SECTION) == 0 ) { - cur_color = readColor( line.substr(SOL_WORD.size()) ); cur_type = LLKeywordToken::WORD; + cur_color = LLUIColorTable::instance().getColor("SyntaxSection"); continue; } - else if( line.find(SOL_LINE) == 0 ) + else if (line.find(SOL_DATATYPE) == 0) + { + cur_type = LLKeywordToken::WORD; + cur_color = LLUIColorTable::instance().getColor("SyntaxDataType"); + continue; + } + else if (line.find(SOL_EVENT) == 0) + { + cur_type = LLKeywordToken::WORD; + cur_color = LLUIColorTable::instance().getColor("SyntaxEvent"); + continue; + } + else if (line.find(SOL_I_CONSTANT) == 0) + { + cur_type = LLKeywordToken::WORD; + cur_color = LLUIColorTable::instance().getColor("SyntaxIntegerConstant"); + continue; + } + else if (line.find(SOL_S_CONSTANT) == 0) + { + cur_type = LLKeywordToken::WORD; + cur_color = LLUIColorTable::instance().getColor("SyntaxStringConstant"); + continue; + } + else if (line.find(SOL_F_CONSTANT) == 0) + { + cur_type = LLKeywordToken::WORD; + cur_color = LLUIColorTable::instance().getColor("SyntaxFloatConstant"); + continue; + } + else if (line.find(SOL_C_CONSTANT) == 0) + { + cur_type = LLKeywordToken::WORD; + cur_color = LLUIColorTable::instance().getColor("SyntaxCompoundConstant"); + continue; + } + else if (line.find(SOL_FLOW_CONTROL) == 0) + { + cur_type = LLKeywordToken::WORD; + cur_color = LLUIColorTable::instance().getColor("SyntaxFlowControl"); + continue; + } + else if (line.find(SOL_FLOW_CONTROL_LABEL) == 0) { - cur_color = readColor( line.substr(SOL_LINE.size()) ); cur_type = LLKeywordToken::LINE; + cur_color = LLUIColorTable::instance().getColor("SyntaxFlowControl"); continue; } - else if( line.find(SOL_TWO_SIDED_DELIMITER) == 0 ) + else if (line.find(SOL_STRING_LITERAL) == 0) { - cur_color = readColor( line.substr(SOL_TWO_SIDED_DELIMITER.size()) ); - cur_type = LLKeywordToken::TWO_SIDED_DELIMITER; - continue; - } - else if( line.find(SOL_DOUBLE_QUOTATION_MARKS) == 0 ) - { - cur_color = readColor( line.substr(SOL_DOUBLE_QUOTATION_MARKS.size()) ); cur_type = LLKeywordToken::DOUBLE_QUOTATION_MARKS; + cur_color = LLUIColorTable::instance().getColor("SyntaxStringLiteral"); continue; } - else if( line.find(SOL_ONE_SIDED_DELIMITER) == 0 ) + else if (line.find(SOL_CODE_COMMENT) == 0) { - cur_color = readColor( line.substr(SOL_ONE_SIDED_DELIMITER.size()) ); cur_type = LLKeywordToken::ONE_SIDED_DELIMITER; + cur_color = LLUIColorTable::instance().getColor("SyntaxComment"); continue; } + else if (line.find(SOL_BLOCK_COMMENT) == 0) + { + cur_type = LLKeywordToken::TWO_SIDED_DELIMITER; + cur_color = LLUIColorTable::instance().getColor("SyntaxComment"); + continue; + } + else if( line.find(SOL_PREPROCESSOR) == 0 ) + { + cur_type = LLKeywordToken::ONE_SIDED_DELIMITER; + cur_color = LLUIColorTable::instance().getColor("SyntaxPreprocessor"); + continue; + } + // std::string token_buffer( line ); LLStringUtil::trim(token_buffer); @@ -233,7 +333,10 @@ BOOL LLKeywords::loadFromFile( const std::string& filename ) // Add the token as described void LLKeywords::addToken(LLKeywordToken::TOKEN_TYPE type, const std::string& key_in, - const LLColor3& color, + // User defined syntax highlighting + //const LLColor3& color + const LLColor4& color, + // const std::string& tool_tip_in, const std::string& delimiter_in) { @@ -341,17 +444,19 @@ bool LLKeywords::WStringMapIndex::operator<(const LLKeywords::WStringMapIndex &o return result; } -LLColor3 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 LLColor3( r, g, b ); -} +// Deprecate readColor(), Use colors.xml so the user can pick and choose +//LLColor3 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 LLColor3( r, g, b ); +//} +// LLFastTimer::DeclareTimer FTM_SYNTAX_COLORING("Syntax Coloring"); diff --git a/indra/llui/llkeywords.h b/indra/llui/llkeywords.h index ac34015393..3d547f32e6 100644 --- a/indra/llui/llkeywords.h +++ b/indra/llui/llkeywords.h @@ -29,7 +29,10 @@ #include "llstring.h" -#include "v3color.h" +// User defined syntax highlighting +//#include "v3color.h" +#include "v4color.h" +// #include #include #include @@ -60,7 +63,10 @@ public: DOUBLE_QUOTATION_MARKS }; - LLKeywordToken( TOKEN_TYPE type, const LLColor3& color, const LLWString& token, const LLWString& tool_tip, const LLWString& delimiter ) + // User defined syntax highlighting + //LLKeywordToken( TOKEN_TYPE type, const LLColor3& color, const LLWString& token, const LLWString& tool_tip, const LLWString& delimiter ) + LLKeywordToken( TOKEN_TYPE type, const LLColor4& color, const LLWString& token, const LLWString& tool_tip, const LLWString& delimiter ) + // : mType( type ), mToken( token ), @@ -75,7 +81,10 @@ public: BOOL isHead(const llwchar* s) const; BOOL isTail(const llwchar* s) const; const LLWString& getToken() const { return mToken; } - const LLColor3& getColor() const { return mColor; } + // User defined syntax highlighting + //const LLColor3& getColor() const { return mColor; } + const LLColor4& getColor() const { return mColor; } + // TOKEN_TYPE getType() const { return mType; } const LLWString& getToolTip() const { return mToolTip; } const LLWString& getDelimiter() const { return mDelimiter; } @@ -87,7 +96,10 @@ public: private: TOKEN_TYPE mType; LLWString mToken; - LLColor3 mColor; + // User defined syntax highlighting + //LLColor3 mColor; + // + LLColor4 mColor; LLWString mToolTip; LLWString mDelimiter; }; @@ -106,7 +118,10 @@ public: // Add the token as described void addToken(LLKeywordToken::TOKEN_TYPE type, const std::string& key, - const LLColor3& color, + // User defined syntax highlighting + //const LLColor3& color, + const LLColor4& color, + // const std::string& tool_tip = LLStringUtil::null, const std::string& delimiter = LLStringUtil::null); @@ -145,7 +160,8 @@ public: #endif private: - LLColor3 readColor(const std::string& s); + // User defined syntax highlighting - Deprecated, unused function + //LLColor3 readColor(const std::string& s); void insertSegment(std::vector& seg_list, LLTextSegmentPtr new_segment, S32 text_len, const LLColor4 &defaultColor, class LLTextEditor& editor); void insertSegments(const LLWString& wtext, std::vector& seg_list, LLKeywordToken* token, S32 text_len, S32 seg_start, S32 seg_end, const LLColor4 &defaultColor, LLTextEditor& editor); diff --git a/indra/newview/app_settings/keywords.ini b/indra/newview/app_settings/keywords.ini index 2cfa37febe..60ab7bebff 100644 --- a/indra/newview/app_settings/keywords.ini +++ b/indra/newview/app_settings/keywords.ini @@ -1,12 +1,12 @@ llkeywords version 3 ; sections -[word .5, .1, .3] +[SECTION] default Name of default state that all scripts must have state Keyword to indicate state block or state transition ; data types -[word .1, .3, .1] +[DATATYPE] integer Integer type float Floating-point type string String type @@ -16,7 +16,7 @@ rotation Rotation type of 4 floats. Used to represent rotation.:Access compone list List of various data types ; events -[word 0, .3, .5] +[EVENT] state_entry state_entry():Triggered on any state transition and startup state_exit state_exit():Triggered on any state transition touch_start touch_start(integer num_detected):Triggered by the start of agent clicking on task @@ -56,7 +56,7 @@ http_request http_request(key id, string method, string body):Triggered when tas transaction_result transaction_result(key id, integer success, string data): Triggered when L$ is given to task ; integer constants -[word .1, .1, .5] +[I_CONSTANT] TRUE Integer constant for Boolean operations FALSE Integer constant for Boolean operations STATUS_PHYSICS Passed in the llSetStatus library function. If TRUE, object moves physically @@ -828,7 +828,7 @@ CONTENT_TYPE_FORM application/x-www-form-urlencoded CONTENT_TYPE_RSS application/rss+xml ; string constants -[word .1, .3, .5] +[S_CONSTANT] NULL_KEY Indicates an empty key EOF Indicates the last line of a notecard was read TEXTURE_BLANK UUID for the "Blank" texture @@ -841,7 +841,7 @@ URL_REQUEST_GRANTED Used with http_request when a public URL is successfully gr URL_REQUEST_DENIED Used with http_request when a public URL is not available ; float constants -[word .3, .1, .5] +[F_CONSTANT] PI 3.1415926535897932384626433832795 TWO_PI 6.283185307179586476925286766559 PI_BY_TWO 1.5707963267948966192313216916398 @@ -850,13 +850,13 @@ RAD_TO_DEG To convert from radians to degrees SQRT2 1.4142135623730950488016887242097 ; compound constants -[word .4, .2, .4] +[C_CONSTANT] ZERO_VECTOR <0.0, 0.0, 0.0> ZERO_ROTATION <0.0, 0.0, 0.0, 1.0> ; flow control keywords -[word 0, 0, .8] +[FLOW CONTROL] for for loop:for (initializer; test; iteration):{: statements:} do do loop:do:{: statements:} while (test); while while loop:while (test):{ statements:} @@ -866,17 +866,17 @@ jump jump statement:jump label;: return Leave current function or event handler ; flow control label -[line 0, 0, .8] +[FLOW CONTROL LABEL] @ Label:Target for jump statement ; Comment -[one_sided_delimiter .8, .3, .15] +[COMMENT] // Comment:Non-functional commentary or disabled code -[two_sided_delimiter .8, .3, .15] +[BLOCK COMMENT] /* */ Comment:Non-functional commentary or disabled code ; String literals -[double_quotation_marks 0, .2, 0] +[STRING LITERAL] " String literal ;functions are supplied by the program now diff --git a/indra/newview/app_settings/keywords_ossl.ini b/indra/newview/app_settings/keywords_ossl.ini index c90cc5a6f1..fda813d92d 100644 --- a/indra/newview/app_settings/keywords_ossl.ini +++ b/indra/newview/app_settings/keywords_ossl.ini @@ -2,7 +2,7 @@ llkeywords version 3 ; OSSL/AA keywords ; Reference: http://opensimulator.org/wiki/OSSL_Constants (13 December 2012) -[word .1, .1, .5] +[I_CONSTANT] OS_ATTACH_MSG_ALL Send the message to attachments on every point OS_ATTACH_MSG_INVERT_POINTS Invert how the attachment points list should be treated OS_ATTACH_MSG_OBJECT_CREATOR Send only to those have the same CreatorID with host object CreatorID diff --git a/indra/newview/app_settings/keywords_preproc.ini b/indra/newview/app_settings/keywords_preproc.ini index bd3b72db75..db72e0ee8d 100644 --- a/indra/newview/app_settings/keywords_preproc.ini +++ b/indra/newview/app_settings/keywords_preproc.ini @@ -1,7 +1,7 @@ llkeywords version 3 ; Preprocessor Directives -[one_sided_delimiter 0, 0, .8] +[PREPROCESSOR] #assert Allows definition of preprocessor variables that do not conflict with names in the program name space. #define When the preprocessor encounters this directive, it replaces any occurrence of identifier in the rest of the code by replacement. #elif Specify some condition to be met in order for the portion of code they surround to be compiled. @@ -21,3 +21,7 @@ llkeywords version 3 #unassert Closes an #assert directive. #undef Undefines #define macro. #warning Generate a level one warning from a specific location in your code. + +#switch Allows selection among multiple sections of code, depending on the value of an integral expression. +#case Used with #switch in a union. +#break Stops processing further lines in a #switch directive. diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 2227a55517..238b84dd42 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -382,18 +382,6 @@ BOOL LLScriptEdCore::postBuild() #endif // OPENSIM // mPostEditor->loadKeywords(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "keywords_preproc.ini"), funcs, tooltips, color); - - if(gSavedSettings.getBOOL("_NACL_PreProcLSLSwitch")) - { - mEditor->addToken(LLKeywordToken::WORD,"switch",LLColor3(0.0f,0.0f,0.8f), - std::string("Switch statement. See Advanced menu of the script editor.")); - mEditor->addToken(LLKeywordToken::WORD,"case",LLColor3(0.0f,0.0f,0.8f), - std::string("Switch case. See Advanced menu of the script editor.")); - mEditor->addToken(LLKeywordToken::WORD,"break",LLColor3(0.0f,0.0f,0.8f), - std::string("Switch break. See Advanced menu of the script editor.")); - } - - //couldn'tr define in file because # represented a comment } // NaCl End diff --git a/indra/newview/skins/default/colors.xml b/indra/newview/skins/default/colors.xml index 21bdb77d38..23dcf80f3c 100644 --- a/indra/newview/skins/default/colors.xml +++ b/indra/newview/skins/default/colors.xml @@ -1122,6 +1122,36 @@ name="ScriptBackground" reference="White" /> + name="SyntaxSection" + value=".5 .1 .3 1" /> + + + + + + + + + + diff --git a/indra/newview/skins/default/xui/en/floater_fs_script_editor_prefs.xml b/indra/newview/skins/default/xui/en/floater_fs_script_editor_prefs.xml index 9d221d02e5..ee75e4585e 100644 --- a/indra/newview/skins/default/xui/en/floater_fs_script_editor_prefs.xml +++ b/indra/newview/skins/default/xui/en/floater_fs_script_editor_prefs.xml @@ -8,7 +8,7 @@ title="Script Editor Preferences" single_instance="true" can_resize="false" - width="300"> + width="325"> Text @@ -57,7 +57,7 @@ label_height="0" layout="topleft" left="15" - name="user" + name="background" top_pad="10" width="44" > Background + + + + + + Sections + + + + + + + Data Types + + + + + + + Events + + + + + + + String Literals + + + + + + + + Integer Const + + + + + + + String Const + + + + + + + Float Const + + + + + + + Compound + + + + + + + Flow Control + + + + + + + Comment + + + + + + + Preprocessor + + top="230" + width="150"> Script Editor Options: + width="235" />