Changes to filter out tabs from file load and to test if loading/saving should be allowed.
parent
e875e0548b
commit
eeefec394c
|
|
@ -2250,6 +2250,22 @@ void LLTextEditor::insertText(const std::string &new_text)
|
|||
setEnabled( enabled );
|
||||
}
|
||||
|
||||
void LLTextEditor::insertText(LLWString &new_text)
|
||||
{
|
||||
BOOL enabled = getEnabled();
|
||||
setEnabled( TRUE );
|
||||
|
||||
// Delete any selected characters (the insertion replaces them)
|
||||
if( hasSelection() )
|
||||
{
|
||||
deleteSelection(TRUE);
|
||||
}
|
||||
|
||||
setCursorPos(mCursorPos + insert( mCursorPos, new_text, FALSE, LLTextSegmentPtr() ));
|
||||
|
||||
setEnabled( enabled );
|
||||
}
|
||||
|
||||
void LLTextEditor::appendWidget(const LLInlineViewSegment::Params& params, const std::string& text, bool allow_undo)
|
||||
{
|
||||
// Save old state
|
||||
|
|
@ -2838,3 +2854,13 @@ void LLTextEditor::clear()
|
|||
getViewModel()->setDisplay(LLWStringUtil::null);
|
||||
clearSegments();
|
||||
}
|
||||
|
||||
bool LLTextEditor::canLoadOrSaveToFile()
|
||||
{
|
||||
return !mReadOnly;
|
||||
}
|
||||
|
||||
S32 LLTextEditor::spacesPerTab()
|
||||
{
|
||||
return SPACES_PER_TAB;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,6 +92,8 @@ public:
|
|||
|
||||
void setParseHighlights(BOOL parsing) {mParseHighlights=parsing;}
|
||||
|
||||
static S32 spacesPerTab();
|
||||
|
||||
// mousehandler overrides
|
||||
virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
|
||||
virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);
|
||||
|
|
@ -140,6 +142,8 @@ public:
|
|||
virtual void selectAll();
|
||||
virtual BOOL canSelectAll() const;
|
||||
|
||||
virtual bool canLoadOrSaveToFile();
|
||||
|
||||
void selectNext(const std::string& search_text_in, BOOL case_insensitive, BOOL wrap = TRUE);
|
||||
BOOL replaceText(const std::string& search_text, const std::string& replace_text, BOOL case_insensitive, BOOL wrap = TRUE);
|
||||
void replaceTextAll(const std::string& search_text, const std::string& replace_text, BOOL case_insensitive);
|
||||
|
|
@ -158,6 +162,7 @@ public:
|
|||
|
||||
// inserts text at cursor
|
||||
void insertText(const std::string &text);
|
||||
void insertText(LLWString &text);
|
||||
|
||||
void appendWidget(const LLInlineViewSegment::Params& params, const std::string& text, bool allow_undo);
|
||||
// Non-undoable
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ LLFilePicker LLFilePicker::sInstance;
|
|||
#define SLOBJECT_FILTER L"Objects (*.slobject)\0*.slobject\0"
|
||||
#define RAW_FILTER L"RAW files (*.raw)\0*.raw\0"
|
||||
#define MODEL_FILTER L"Model files (*.dae)\0*.dae\0"
|
||||
#define SCRIPT_FILTER L"Script files (*.lsl; *.txt)\0*.lsl;*.txt\0"
|
||||
#define SCRIPT_FILTER L"Script files (*.lsl)\0*.lsl\0"
|
||||
#endif
|
||||
|
||||
//
|
||||
|
|
@ -502,16 +502,6 @@ BOOL LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename)
|
|||
L"Compressed Images (*.j2c)\0*.j2c\0" \
|
||||
L"\0";
|
||||
break;
|
||||
case FFSAVE_SCRIPT:
|
||||
if (filename.empty())
|
||||
{
|
||||
wcsncpy( mFilesW,L"untitled.lsl", FILENAME_BUFFER_SIZE);
|
||||
}
|
||||
mOFN.lpstrDefExt = L"txt";
|
||||
mOFN.lpstrFilter =
|
||||
L"LSL Files (*.lsl; *.txt)\0*.lsl;*.txt\0"
|
||||
L"\0";
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -507,11 +507,11 @@ void LLScriptEdCore::initMenu()
|
|||
|
||||
menuItem = getChild<LLMenuItemCallGL>("LoadFromFile");
|
||||
menuItem->setClickCallback(boost::bind(&LLScriptEdCore::onBtnLoadFromFile, this));
|
||||
// menuItem->setEnabledCallback(NULL);
|
||||
menuItem->setEnableCallback(boost::bind(&LLScriptEdCore::enableLoadFromFileMenu, this));
|
||||
|
||||
menuItem = getChild<LLMenuItemCallGL>("SaveToFile");
|
||||
menuItem->setClickCallback(boost::bind(&LLScriptEdCore::onBtnSaveToFile, this));
|
||||
menuItem->setEnableCallback(boost::bind(&LLScriptEdCore::hasChanged, this));
|
||||
menuItem->setEnableCallback(boost::bind(&LLScriptEdCore::enableSaveToFileMenu, this));
|
||||
}
|
||||
|
||||
void LLScriptEdCore::setScriptText(const std::string& text, BOOL is_valid)
|
||||
|
|
@ -1107,9 +1107,17 @@ BOOL LLScriptEdCore::handleKeyHere(KEY key, MASK mask)
|
|||
|
||||
void LLScriptEdCore::onBtnLoadFromFile( void* data )
|
||||
{
|
||||
|
||||
LLScriptEdCore* self = (LLScriptEdCore*) data;
|
||||
|
||||
/*
|
||||
if( self->isDirty())
|
||||
{
|
||||
llwarns << "Script has unsaved changes, loading from disc aborted." << llendl;
|
||||
LLStringBase<char>::format_map_t args;
|
||||
args["[REASON]"] = std::string("Existing script has unsaved changes. You must save this script before loading from disc.");
|
||||
gViewerWindow->alertXml("LoadDiskScriptFailReason", args);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
LLFilePicker& file_picker = LLFilePicker::instance();
|
||||
if( !file_picker.getOpenFile( LLFilePicker::FFLOAD_SCRIPT ) )
|
||||
{
|
||||
|
|
@ -1121,16 +1129,27 @@ void LLScriptEdCore::onBtnLoadFromFile( void* data )
|
|||
std::ifstream fin(filename.c_str());
|
||||
|
||||
std::string line;
|
||||
std::string text;
|
||||
std::string linetotal;
|
||||
self->mEditor->clear();
|
||||
while (!fin.eof())
|
||||
{
|
||||
getline(fin,line);
|
||||
line=line+"\n";
|
||||
self->mEditor->insertText(line);
|
||||
|
||||
text += line;
|
||||
if (!fin.eof())
|
||||
{
|
||||
text += "\n";
|
||||
}
|
||||
}
|
||||
fin.close();
|
||||
|
||||
// Only replace the script if there is something to replace with.
|
||||
if (text.length() > 0)
|
||||
{
|
||||
self->mEditor->selectAll();
|
||||
LLWString script(utf8str_to_wstring(text));
|
||||
LLWStringUtil::replaceTabsWithSpaces(script, self->mEditor->spacesPerTab());
|
||||
self->mEditor->insertText(script);
|
||||
}
|
||||
}
|
||||
|
||||
void LLScriptEdCore::onBtnSaveToFile( void* userdata )
|
||||
|
|
@ -1157,6 +1176,27 @@ void LLScriptEdCore::onBtnSaveToFile( void* userdata )
|
|||
}
|
||||
}
|
||||
|
||||
bool LLScriptEdCore::canLoadOrSaveToFile( void* userdata )
|
||||
{
|
||||
LLScriptEdCore* self = (LLScriptEdCore*) userdata;
|
||||
return self->mEditor->canLoadOrSaveToFile();
|
||||
}
|
||||
|
||||
// static
|
||||
bool LLScriptEdCore::enableSaveToFileMenu(void* userdata)
|
||||
{
|
||||
LLScriptEdCore* self = (LLScriptEdCore*)userdata;
|
||||
if (!self || !self->mEditor) return FALSE;
|
||||
return self->mEditor->canLoadOrSaveToFile();
|
||||
}
|
||||
|
||||
// static
|
||||
bool LLScriptEdCore::enableLoadFromFileMenu(void* userdata)
|
||||
{
|
||||
LLScriptEdCore* self = (LLScriptEdCore*)userdata;
|
||||
if (!self || !self->mEditor) return FALSE;
|
||||
return self->mEditor->canLoadOrSaveToFile();
|
||||
}
|
||||
|
||||
/// ---------------------------------------------------------------------------
|
||||
/// LLScriptEdContainer
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ public:
|
|||
/*virtual*/ BOOL postBuild();
|
||||
BOOL canClose();
|
||||
void setEnableEditing(bool enable);
|
||||
bool canLoadOrSaveToFile( void* userdata );
|
||||
|
||||
void setScriptText(const std::string& text, BOOL is_valid);
|
||||
bool loadScriptText(const std::string& filename);
|
||||
|
|
@ -101,6 +102,9 @@ public:
|
|||
static void onBtnLoadFromFile(void*);
|
||||
static void onBtnSaveToFile(void*);
|
||||
|
||||
static bool enableSaveToFileMenu(void* userdata);
|
||||
static bool enableLoadFromFileMenu(void* userdata);
|
||||
|
||||
virtual bool hasAccelerators() const { return true; }
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Reference in New Issue