summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewscript.cpp
diff options
context:
space:
mode:
authorIma Mechanique <none@none>2011-11-23 01:30:15 +0000
committerIma Mechanique <none@none>2011-11-23 01:30:15 +0000
commiteeefec394c932b79a22c5ea2b8aa03690bb6061e (patch)
tree97493f8030bb2cde32da3f680f005ef07287734e /indra/newview/llpreviewscript.cpp
parente875e0548b69d1cf141e3970a81aa3f0a5ff7ed3 (diff)
Changes to filter out tabs from file load and to test if loading/saving should be allowed.
Diffstat (limited to 'indra/newview/llpreviewscript.cpp')
-rw-r--r--indra/newview/llpreviewscript.cpp56
1 files changed, 48 insertions, 8 deletions
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 072df39514..16b582d188 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -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