SL-19982 Adjustable font size in LSL editor

meow-7.2.2
Mnikolenko Productengine 2023-08-01 20:14:27 +03:00
parent 6cd91770e1
commit 62245de7ae
18 changed files with 294 additions and 63 deletions

View File

@ -479,7 +479,7 @@ LLTrace::BlockTimerStatHandle FTM_SYNTAX_COLORING("Syntax Coloring");
// Walk through a string, applying the rules specified by the keyword token list and
// create a list of color segments.
void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLWString& wtext, const LLColor4 &defaultColor, LLTextEditor& editor)
void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLWString& wtext, LLTextEditor& editor, LLStyleConstSP style)
{
LL_RECORD_BLOCK_TIME(FTM_SYNTAX_COLORING);
seg_list->clear();
@ -491,7 +491,7 @@ void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLW
S32 text_len = wtext.size() + 1;
seg_list->push_back( new LLNormalTextSegment( defaultColor, 0, text_len, editor ) );
seg_list->push_back( new LLNormalTextSegment( style, 0, text_len, editor ) );
const llwchar* base = wtext.c_str();
const llwchar* cur = base;
@ -503,7 +503,7 @@ void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLW
{
LLTextSegmentPtr text_segment = new LLLineBreakTextSegment(cur-base);
text_segment->setToken( 0 );
insertSegment( *seg_list, text_segment, text_len, defaultColor, editor);
insertSegment( *seg_list, text_segment, text_len, style, editor);
cur++;
if( !*cur || *cur == '\n' )
{
@ -541,7 +541,7 @@ void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLW
S32 seg_end = cur - base;
//create segments from seg_start to seg_end
insertSegments(wtext, *seg_list,cur_token, text_len, seg_start, seg_end, defaultColor, editor);
insertSegments(wtext, *seg_list,cur_token, text_len, seg_start, seg_end, style, editor);
line_done = TRUE; // to break out of second loop.
break;
}
@ -648,7 +648,7 @@ void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLW
seg_end = seg_start + between_delimiters + cur_delimiter->getLengthHead();
}
insertSegments(wtext, *seg_list,cur_delimiter, text_len, seg_start, seg_end, defaultColor, editor);
insertSegments(wtext, *seg_list,cur_delimiter, text_len, seg_start, seg_end, style, editor);
/*
LLTextSegmentPtr text_segment = new LLNormalTextSegment( cur_delimiter->getColor(), seg_start, seg_end, editor );
text_segment->setToken( cur_delimiter );
@ -682,7 +682,7 @@ void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLW
// LL_INFOS("SyntaxLSL") << "Seg: [" << word.c_str() << "]" << LL_ENDL;
insertSegments(wtext, *seg_list,cur_token, text_len, seg_start, seg_end, defaultColor, editor);
insertSegments(wtext, *seg_list,cur_token, text_len, seg_start, seg_end, style, editor);
}
cur += seg_len;
continue;
@ -697,30 +697,32 @@ void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLW
}
}
void LLKeywords::insertSegments(const LLWString& wtext, std::vector<LLTextSegmentPtr>& seg_list, LLKeywordToken* cur_token, S32 text_len, S32 seg_start, S32 seg_end, const LLColor4 &defaultColor, LLTextEditor& editor )
void LLKeywords::insertSegments(const LLWString& wtext, std::vector<LLTextSegmentPtr>& seg_list, LLKeywordToken* cur_token, S32 text_len, S32 seg_start, S32 seg_end, LLStyleConstSP style, LLTextEditor& editor )
{
std::string::size_type pos = wtext.find('\n',seg_start);
LLStyleConstSP cur_token_style = new LLStyle(LLStyle::Params().font(style->getFont()).color(cur_token->getColor()));
while (pos!=-1 && pos < (std::string::size_type)seg_end)
{
if (pos!=seg_start)
{
LLTextSegmentPtr text_segment = new LLNormalTextSegment( cur_token->getColor(), seg_start, pos, editor );
LLTextSegmentPtr text_segment = new LLNormalTextSegment(cur_token_style, seg_start, pos, editor);
text_segment->setToken( cur_token );
insertSegment( seg_list, text_segment, text_len, defaultColor, editor);
insertSegment( seg_list, text_segment, text_len, style, editor);
}
LLTextSegmentPtr text_segment = new LLLineBreakTextSegment(pos);
text_segment->setToken( cur_token );
insertSegment( seg_list, text_segment, text_len, defaultColor, editor);
insertSegment( seg_list, text_segment, text_len, style, editor);
seg_start = pos+1;
pos = wtext.find('\n',seg_start);
}
LLTextSegmentPtr text_segment = new LLNormalTextSegment( cur_token->getColor(), seg_start, seg_end, editor );
LLTextSegmentPtr text_segment = new LLNormalTextSegment(cur_token_style, seg_start, seg_end, editor);
text_segment->setToken( cur_token );
insertSegment( seg_list, text_segment, text_len, defaultColor, editor);
insertSegment( seg_list, text_segment, text_len, style, editor);
}
void LLKeywords::insertSegment(std::vector<LLTextSegmentPtr>& seg_list, LLTextSegmentPtr new_segment, S32 text_len, const LLColor4 &defaultColor, LLTextEditor& editor )
@ -744,6 +746,27 @@ void LLKeywords::insertSegment(std::vector<LLTextSegmentPtr>& seg_list, LLTextSe
}
}
void LLKeywords::insertSegment(std::vector<LLTextSegmentPtr>& seg_list, LLTextSegmentPtr new_segment, S32 text_len, LLStyleConstSP style, LLTextEditor& editor )
{
LLTextSegmentPtr last = seg_list.back();
S32 new_seg_end = new_segment->getEnd();
if( new_segment->getStart() == last->getStart() )
{
seg_list.pop_back();
}
else
{
last->setEnd( new_segment->getStart() );
}
seg_list.push_back( new_segment );
if( new_seg_end < text_len )
{
seg_list.push_back( new LLNormalTextSegment( style, new_seg_end, text_len, editor ) );
}
}
#ifdef _DEBUG
void LLKeywords::dump()
{

View File

@ -29,6 +29,7 @@
#include "lldir.h"
#include "llstyle.h"
#include "llstring.h"
#include "v3color.h"
#include "v4color.h"
@ -115,8 +116,8 @@ public:
void findSegments(std::vector<LLTextSegmentPtr> *seg_list,
const LLWString& text,
const LLColor4 &defaultColor,
class LLTextEditor& editor);
class LLTextEditor& editor,
LLStyleConstSP style);
void initialize(LLSD SyntaxXML);
void processTokens();
@ -181,9 +182,11 @@ protected:
S32 text_len,
S32 seg_start,
S32 seg_end,
const LLColor4 &defaultColor,
LLStyleConstSP style,
LLTextEditor& editor);
void insertSegment(std::vector<LLTextSegmentPtr>& seg_list, LLTextSegmentPtr new_segment, S32 text_len, LLStyleConstSP style, LLTextEditor& editor );
bool mLoaded;
LLSD mSyntax;
word_token_map_t mWordTokenMap;

View File

@ -5420,6 +5420,17 @@
<key>Value</key>
<string>http://wiki.secondlife.com/wiki/[LSL_STRING]</string>
</map>
<key>LSLFontSizeName</key>
<map>
<key>Comment</key>
<string>Text font size in LSL editor</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>String</string>
<key>Value</key>
<string>Monospace</string>
</map>
<key>GridStatusRSS</key>
<map>
<key>Comment</key>

View File

@ -114,6 +114,7 @@
#include "llpresetsmanager.h"
#include "llviewercontrol.h"
#include "llpresetsmanager.h"
#include "llinventoryfunctions.h"
#include "llsearchableui.h"
#include "llperfstats.h"
@ -1609,25 +1610,6 @@ void LLFloaterPreference::onChangeMaturity()
getChild<LLIconCtrl>("rating_icon_adult")->setVisible(sim_access == SIM_ACCESS_ADULT);
}
std::string get_category_path(LLUUID cat_id)
{
LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
std::string localized_cat_name;
if (!LLTrans::findString(localized_cat_name, "InvFolder " + cat->getName()))
{
localized_cat_name = cat->getName();
}
if (cat->getParentUUID().notNull())
{
return get_category_path(cat->getParentUUID()) + " > " + localized_cat_name;
}
else
{
return localized_cat_name;
}
}
std::string get_category_path(LLFolderType::EType cat_type)
{
LLUUID cat_id = gInventory.findUserDefinedCategoryUUIDForType(cat_type);

View File

@ -1967,6 +1967,24 @@ void move_items_to_new_subfolder(const uuid_vec_t& selected_uuids, const std::st
}
std::string get_category_path(LLUUID cat_id)
{
LLViewerInventoryCategory *cat = gInventory.getCategory(cat_id);
std::string localized_cat_name;
if (!LLTrans::findString(localized_cat_name, "InvFolder " + cat->getName()))
{
localized_cat_name = cat->getName();
}
if (cat->getParentUUID().notNull())
{
return get_category_path(cat->getParentUUID()) + " > " + localized_cat_name;
}
else
{
return localized_cat_name;
}
}
///----------------------------------------------------------------------------
/// LLInventoryCollectFunctor implementations
///----------------------------------------------------------------------------

View File

@ -97,6 +97,7 @@ void move_items_to_new_subfolder(const uuid_vec_t& selected_uuids, const std::st
void move_items_to_folder(const LLUUID& new_cat_uuid, const uuid_vec_t& selected_uuids);
bool is_only_cats_selected(const uuid_vec_t& selected_uuids);
bool is_only_items_selected(const uuid_vec_t& selected_uuids);
std::string get_category_path(LLUUID cat_id);
/** Miscellaneous global functions
** **

View File

@ -86,6 +86,9 @@
#include "llexperiencecache.h"
#include "llfloaterexperienceprofile.h"
#include "llviewerassetupload.h"
#include "lltoggleablemenu.h"
#include "llmenubutton.h"
#include "llinventoryfunctions.h"
const std::string HELLO_LSL =
"default\n"
@ -459,6 +462,13 @@ BOOL LLScriptEdCore::postBuild()
LLSyntaxIdLSL::getInstance()->initialize();
processKeywords();
mCommitCallbackRegistrar.add("FontSize.Set", boost::bind(&LLScriptEdCore::onChangeFontSize, this, _2));
mEnableCallbackRegistrar.add("FontSize.Check", boost::bind(&LLScriptEdCore::isFontSizeChecked, this, _2));
LLToggleableMenu *context_menu = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>(
"menu_lsl_font_size.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
getChild<LLMenuButton>("font_btn")->setMenu(context_menu, LLMenuButton::MP_BOTTOM_LEFT, true);
return TRUE;
}
@ -1287,7 +1297,21 @@ LLUUID LLScriptEdCore::getAssociatedExperience()const
return mAssociatedExperience;
}
void LLLiveLSLEditor::setExperienceIds( const LLSD& experience_ids )
void LLScriptEdCore::onChangeFontSize(const LLSD &userdata)
{
const std::string font_name = userdata.asString();
gSavedSettings.setString("LSLFontSizeName", font_name);
}
bool LLScriptEdCore::isFontSizeChecked(const LLSD &userdata)
{
const std::string current_size_name = LLScriptEditor::getScriptFontSize();
const std::string size_name = userdata.asString();
return (size_name == current_size_name);
}
void LLLiveLSLEditor::setExperienceIds( const LLSD& experience_ids )
{
mExperienceIds=experience_ids;
updateExperiencePanel();
@ -1475,7 +1499,21 @@ bool LLScriptEdContainer::onExternalChange(const std::string& filename)
return true;
}
/// ---------------------------------------------------------------------------
BOOL LLScriptEdContainer::handleKeyHere(KEY key, MASK mask)
{
if (('A' == key) && (MASK_CONTROL == (mask & MASK_MODIFIERS)))
{
mScriptEd->selectAll();
return TRUE;
}
if (!LLPreview::handleKeyHere(key, mask))
{
return mScriptEd->handleKeyHere(key, mask);
}
return TRUE;
}
/// ---------------------------------------------------------------------------
/// LLPreviewLSL
/// ---------------------------------------------------------------------------
@ -1527,10 +1565,14 @@ BOOL LLPreviewLSL::postBuild()
if (item)
{
getChild<LLUICtrl>("desc")->setValue(item->getDescription());
std::string item_path = get_category_path(item->getParentUUID());
getChild<LLUICtrl>("path_txt")->setValue(item_path);
getChild<LLUICtrl>("path_txt")->setToolTip(item_path);
}
childSetCommitCallback("desc", LLPreview::onText, this);
getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
return LLPreview::postBuild();
}

View File

@ -36,6 +36,7 @@
#include "llfloatergotoline.h"
#include "lllivefile.h"
#include "llsyntaxid.h"
#include "llscripteditor.h"
class LLLiveLSLFile;
class LLMessageSystem;
@ -145,7 +146,13 @@ public:
void setAssetID( const LLUUID& asset_id){ mAssetID = asset_id; };
LLUUID getAssetID() { return mAssetID; }
private:
bool isFontSizeChecked(const LLSD &userdata);
void onChangeFontSize(const LLSD &size_name);
virtual BOOL handleKeyHere(KEY key, MASK mask);
void selectAll() { mEditor->selectAll(); }
private:
void onBtnDynamicHelp();
void onBtnUndoChanges();
@ -153,8 +160,6 @@ private:
void selectFirstError();
virtual BOOL handleKeyHere(KEY key, MASK mask);
void enableSave(BOOL b) {mEnableSave = b;}
protected:
@ -207,6 +212,8 @@ public:
LLScriptEdContainer(const LLSD& key);
LLScriptEdContainer(const LLSD& key, const bool live);
BOOL handleKeyHere(KEY key, MASK mask);
protected:
std::string getTmpFileName(const std::string& script_name);
bool onExternalChange(const std::string& filename);

View File

@ -30,19 +30,22 @@
#include "llsyntaxid.h"
#include "lllocalcliprect.h"
#include "llviewercontrol.h"
const S32 UI_TEXTEDITOR_LINE_NUMBER_MARGIN = 32;
static LLDefaultChildRegistry::Register<LLScriptEditor> r("script_editor");
LLScriptEditor::Params::Params()
: show_line_numbers("show_line_numbers", true)
: show_line_numbers("show_line_numbers", true),
default_font_size("default_font_size", false)
{}
LLScriptEditor::LLScriptEditor(const Params& p)
: LLTextEditor(p)
, mShowLineNumbers(p.show_line_numbers)
, mShowLineNumbers(p.show_line_numbers),
mUseDefaultFontSize(p.default_font_size)
{
if (mShowLineNumbers)
{
@ -51,6 +54,12 @@ LLScriptEditor::LLScriptEditor(const Params& p)
}
}
BOOL LLScriptEditor::postBuild()
{
gSavedSettings.getControl("LSLFontSizeName")->getCommitSignal()->connect(boost::bind(&LLScriptEditor::onFontSizeChange, this));
return LLTextEditor::postBuild();
}
void LLScriptEditor::draw()
{
{
@ -110,12 +119,11 @@ void LLScriptEditor::drawLineNumbers()
// 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(
getScriptFont()->render(
ltext, // string to draw
0, // begin offset
UI_TEXTEDITOR_LINE_NUMBER_MARGIN - 2, // x
@ -143,8 +151,10 @@ void LLScriptEditor::loadKeywords()
LL_PROFILE_ZONE_SCOPED;
mKeywords.processTokens();
LLStyleConstSP style = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get()));
segment_vec_t segment_list;
mKeywords.findSegments(&segment_list, getWText(), mDefaultColor.get(), *this);
mKeywords.findSegments(&segment_list, getWText(), *this, style);
mSegments.clear();
segment_set_t::iterator insert_it = mSegments.begin();
@ -159,9 +169,12 @@ void LLScriptEditor::updateSegments()
if (mReflowIndex < S32_MAX && mKeywords.isLoaded() && mParseOnTheFly)
{
LL_PROFILE_ZONE_SCOPED;
LLStyleConstSP style = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get()));
// HACK: No non-ascii keywords for now
segment_vec_t segment_list;
mKeywords.findSegments(&segment_list, getWText(), mDefaultColor.get(), *this);
mKeywords.findSegments(&segment_list, getWText(), *this, style);
clearSegments();
for (segment_vec_t::iterator list_it = segment_list.begin(); list_it != segment_list.end(); ++list_it)
@ -211,3 +224,23 @@ void LLScriptEditor::drawSelectionBackground()
}
}
}
std::string LLScriptEditor::getScriptFontSize()
{
static LLCachedControl<std::string> size_name(gSavedSettings, "LSLFontSizeName", "Monospace");
return size_name;
}
LLFontGL* LLScriptEditor::getScriptFont()
{
std::string font_size_name = mUseDefaultFontSize ? "Monospace" : getScriptFontSize();
return LLFontGL::getFont(LLFontDescriptor("Monospace", font_size_name, 0));
}
void LLScriptEditor::onFontSizeChange()
{
if (!mUseDefaultFontSize)
{
needsReflow();
}
}

View File

@ -37,7 +37,7 @@ public:
struct Params : public LLInitParam::Block<Params, LLTextEditor::Params>
{
Optional<bool> show_line_numbers;
Optional<bool> default_font_size;
Params();
};
@ -45,6 +45,7 @@ public:
// LLView override
virtual void draw();
BOOL postBuild();
void initKeywords();
void loadKeywords();
@ -52,7 +53,11 @@ public:
LLKeywords::keyword_iterator_t keywordsBegin() { return mKeywords.begin(); }
LLKeywords::keyword_iterator_t keywordsEnd() { return mKeywords.end(); }
protected:
static std::string getScriptFontSize();
LLFontGL* getScriptFont();
void onFontSizeChange();
protected:
friend class LLUICtrlFactory;
LLScriptEditor(const Params& p);
@ -65,6 +70,7 @@ private:
LLKeywords mKeywords;
bool mShowLineNumbers;
bool mUseDefaultFontSize;
};
#endif // LL_SCRIPTEDITOR_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -881,4 +881,7 @@ with the same filename but different name
<texture name="System_Notification" file_name="icons/SL_Logo.png" preload="true"/>
<texture name="Icon_Attachment_Small" file_name="icons/Icon_Attachment_Small.png" preload="true"/>
<texture name="Icon_Attachment_Large" file_name="icons/Icon_Attachment_Large.png" preload="true"/>
<texture name="Icon_Color_Palette" file_name="icons/Icon_Color_Palette.png" preload="false"/>
<texture name="Icon_Font_Size" file_name="icons/Icon_Font_Size.png" preload="false"/>
</textures>

View File

@ -335,6 +335,7 @@
layout="topleft"
max_length="300"
name="Script Preview"
default_font_size="true"
text_color="ScriptText"
default_color="ScriptText"
bg_writeable_color="ScriptBackground"

View File

@ -2,10 +2,10 @@
<floater
legacy_header_height="18"
can_resize="true"
height="570"
height="593"
layout="topleft"
min_height="271"
min_width="290"
min_width="320"
name="preview lsl text"
help_topic="preview_lsl_text"
save_rect="true"
@ -21,7 +21,7 @@
layout="topleft"
left="10"
name="script panel"
top="42"
top="65"
width="497" />
<icon
follows="top|right"
@ -33,6 +33,21 @@
name="lock"
top="4"
width="18" />
<text
type="string"
length="1"
follows="left|top|right"
width="490"
use_ellipses="true"
font="SansSerif"
height="19"
layout="topleft"
left="13"
name="path_txt"
text_color="white"
top="21">
File path
</text>
<text
type="string"
length="1"
@ -42,7 +57,7 @@
layout="topleft"
left="13"
name="desc txt"
top="19"
top_pad="5"
width="80">
Description:
</text>

View File

@ -170,4 +170,12 @@
comment="Size of small font (points, or 1/72 of an inch)"
size="7.6"
/>
<font_size name="SmallLSL"
comment="Size of small font for LSL editor (points, or 1/72 of an inch)"
size="7"
/>
<font_size name="HugeLSL"
comment="Size of huge font for LSL editor (points, or 1/72 of an inch)"
size="12"
/>
</fonts>

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<toggleable_menu
bottom="806"
layout="topleft"
left="0"
mouse_opaque="false"
name="menu_font_size"
visible="false">
<menu_item_check
label="Small"
layout="topleft"
name="font_small">
<on_click
function="FontSize.Set"
parameter="SmallLSL" />
<on_check
function="FontSize.Check"
parameter="SmallLSL" />
</menu_item_check>
<menu_item_check
label="Default"
layout="topleft"
name="font_monospace">
<on_click
function="FontSize.Set"
parameter="Monospace" />
<on_check
function="FontSize.Check"
parameter="Monospace" />
</menu_item_check>
<menu_item_check
label="Medium"
layout="topleft"
name="font_medium">
<on_click
function="FontSize.Set"
parameter="Medium" />
<on_check
function="FontSize.Check"
parameter="Medium" />
</menu_item_check>
<menu_item_check
label="Large"
layout="topleft"
name="font_large">
<on_click
function="FontSize.Set"
parameter="Large" />
<on_check
function="FontSize.Check"
parameter="Large" />
</menu_item_check>
<menu_item_check
label="Huge"
layout="topleft"
name="font_huge">
<on_click
function="FontSize.Set"
parameter="HugeLSL" />
<on_check
function="FontSize.Check"
parameter="HugeLSL" />
</menu_item_check>
</toggleable_menu>

View File

@ -48,6 +48,7 @@
width="138">
<menu_item_call
label="Save"
shortcut="control|S"
layout="topleft"
name="Save" />
<menu_item_separator
@ -66,16 +67,6 @@
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"
@ -117,6 +108,7 @@
name="separator2" />
<menu_item_call
label="Select All"
shortcut="control|A"
layout="topleft"
name="Select All" />
<menu_item_call
@ -150,12 +142,34 @@
name="Keyword Help..." />
</menu>
</menu_bar>
<menu_button
follows="right|top"
height="24"
image_overlay="Icon_Font_Size"
layout="topleft"
top_delta="-2"
right="453"
name="font_btn"
width="32" />
<button
follows="right|top"
height="24"
image_overlay="Icon_Color_Palette"
layout="topleft"
top_delta="0"
right="487"
name="color_btn"
width="32">
<button.commit_callback
function="Floater.Toggle"
parameter="script_colors"/>
</button>
<script_editor
left="0"
type="string"
length="1"
follows="left|top|right|bottom"
font="Monospace"
height="376"
ignore_tab="false"
layout="topleft"