From b28492fbffd7bea9e7174260d66d5f52c76d24b2 Mon Sep 17 00:00:00 2001 From: Ima Mechanique Date: Thu, 17 Nov 2011 23:17:26 +0000 Subject: STORM-1708 Adding ability to save/load scripts from file. --- indra/newview/llpreviewscript.cpp | 78 +++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 8 deletions(-) (limited to 'indra/newview/llpreviewscript.cpp') diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index b19bf5d234..072df39514 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -35,6 +35,7 @@ #include "llcombobox.h" #include "lldir.h" #include "llexternaleditor.h" +#include "llfilepicker.h" #include "llfloaterreg.h" #include "llinventorydefines.h" #include "llinventorymodel.h" @@ -89,15 +90,15 @@ const std::string HELLO_LSL = "default\n" "{\n" - " state_entry()\n" - " {\n" - " llSay(0, \"Hello, Avatar!\");\n" - " }\n" + "\tstate_entry()\n" + "\t{\n" + "\t\tllOwnerSay(\"Hello, Avatar!\");\n" + "\t}\n" "\n" - " touch_start(integer total_number)\n" - " {\n" - " llSay(0, \"Touched.\");\n" - " }\n" + "\ttouch_start(integer total_number)\n" + "\t{\n" + "\t\tllSay(llDetectedKey(0), \"Touched.\");\n" + "\t}\n" "}\n"; const std::string HELP_LSL_PORTAL_TOPIC = "LSL_Portal"; @@ -503,6 +504,14 @@ void LLScriptEdCore::initMenu() menuItem = getChild("Keyword Help..."); menuItem->setClickCallback(boost::bind(&LLScriptEdCore::onBtnDynamicHelp, this)); + + menuItem = getChild("LoadFromFile"); + menuItem->setClickCallback(boost::bind(&LLScriptEdCore::onBtnLoadFromFile, this)); +// menuItem->setEnabledCallback(NULL); + + menuItem = getChild("SaveToFile"); + menuItem->setClickCallback(boost::bind(&LLScriptEdCore::onBtnSaveToFile, this)); + menuItem->setEnableCallback(boost::bind(&LLScriptEdCore::hasChanged, this)); } void LLScriptEdCore::setScriptText(const std::string& text, BOOL is_valid) @@ -1096,6 +1105,59 @@ BOOL LLScriptEdCore::handleKeyHere(KEY key, MASK mask) return FALSE; } +void LLScriptEdCore::onBtnLoadFromFile( void* data ) +{ + + LLScriptEdCore* self = (LLScriptEdCore*) data; + + LLFilePicker& file_picker = LLFilePicker::instance(); + if( !file_picker.getOpenFile( LLFilePicker::FFLOAD_SCRIPT ) ) + { + return; + } + + std::string filename = file_picker.getFirstFile(); + + std::ifstream fin(filename.c_str()); + + std::string line; + std::string linetotal; + self->mEditor->clear(); + while (!fin.eof()) + { + getline(fin,line); + line=line+"\n"; + self->mEditor->insertText(line); + + } + fin.close(); +} + +void LLScriptEdCore::onBtnSaveToFile( void* userdata ) +{ + + LLViewerStats::getInstance()->incStat( LLViewerStats::ST_LSL_SAVE_COUNT ); + + LLScriptEdCore* self = (LLScriptEdCore*) userdata; + + if( self->mSaveCallback ) + { + LLFilePicker& file_picker = LLFilePicker::instance(); + if( !file_picker.getSaveFile( LLFilePicker::FFSAVE_SCRIPT ) ) + { + return; + } + + std::string filename = file_picker.getFirstFile(); + std::string scriptText=self->mEditor->getText(); + std::ofstream fout(filename.c_str()); + fout<<(scriptText); + fout.close(); + self->mSaveCallback( self->mUserdata, FALSE ); + } +} + + /// --------------------------------------------------------------------------- /// LLScriptEdContainer /// --------------------------------------------------------------------------- -- cgit v1.2.3 From eeefec394c932b79a22c5ea2b8aa03690bb6061e Mon Sep 17 00:00:00 2001 From: Ima Mechanique Date: Wed, 23 Nov 2011 01:30:15 +0000 Subject: Changes to filter out tabs from file load and to test if loading/saving should be allowed. --- indra/newview/llpreviewscript.cpp | 56 +++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'indra/newview/llpreviewscript.cpp') 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("LoadFromFile"); menuItem->setClickCallback(boost::bind(&LLScriptEdCore::onBtnLoadFromFile, this)); -// menuItem->setEnabledCallback(NULL); + menuItem->setEnableCallback(boost::bind(&LLScriptEdCore::enableLoadFromFileMenu, this)); menuItem = getChild("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::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 -- cgit v1.2.3 From 413cd15f070c6c0406026c96e0b70698120366ef Mon Sep 17 00:00:00 2001 From: Ima Mechanique Date: Thu, 24 Nov 2011 12:48:17 +0000 Subject: Fixed accidental change to HELLO_WORLD script. --- indra/newview/llpreviewscript.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/newview/llpreviewscript.cpp') diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 16b582d188..0a429269ba 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -90,15 +90,15 @@ const std::string HELLO_LSL = "default\n" "{\n" - "\tstate_entry()\n" - "\t{\n" - "\t\tllOwnerSay(\"Hello, Avatar!\");\n" - "\t}\n" + " state_entry()\n" + " {\n" + " llOwnerSay(\"Hello, Avatar!\");\n" + " }\n" "\n" - "\ttouch_start(integer total_number)\n" - "\t{\n" - "\t\tllSay(llDetectedKey(0), \"Touched.\");\n" - "\t}\n" + " touch_start(integer total_number)\n" + " {\n" + " llSay(llDetectedKey(0), \"Touched.\");\n" + " }\n" "}\n"; const std::string HELP_LSL_PORTAL_TOPIC = "LSL_Portal"; -- cgit v1.2.3 From 468543c944b073af41a3cf7f6dfe73f097c2eb2d Mon Sep 17 00:00:00 2001 From: Ima Mechanique Date: Thu, 8 Dec 2011 10:33:23 +0000 Subject: Reverting the changes to default script which leaked in from another project ;-) --- indra/newview/llpreviewscript.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/newview/llpreviewscript.cpp') diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 0a429269ba..62603a2e07 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -90,15 +90,15 @@ const std::string HELLO_LSL = "default\n" "{\n" - " state_entry()\n" - " {\n" - " llOwnerSay(\"Hello, Avatar!\");\n" - " }\n" + " state_entry()\n" + " {\n" + " llSay(0, \"Hello, Avatar!\");\n" + " }\n" "\n" - " touch_start(integer total_number)\n" - " {\n" - " llSay(llDetectedKey(0), \"Touched.\");\n" - " }\n" + " touch_start(integer total_number)\n" + " {\n" + " llSay(0, \"Touched.\");\n" + " }\n" "}\n"; const std::string HELP_LSL_PORTAL_TOPIC = "LSL_Portal"; -- cgit v1.2.3 From 04d5ba4ab982eed493502dca228134191acb78da Mon Sep 17 00:00:00 2001 From: Ima Mechanique Date: Fri, 9 Dec 2011 09:51:25 +0000 Subject: General cleanup of new code (removing commented lines, experimetal stuff), adding some comments per RB feedback. --- indra/newview/llpreviewscript.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'indra/newview/llpreviewscript.cpp') diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 62603a2e07..cab30b1295 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -1108,19 +1108,12 @@ 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::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; - } -*/ + + // TODO Maybe add a dialogue warning here if the current file has unsaved changes. LLFilePicker& file_picker = LLFilePicker::instance(); if( !file_picker.getOpenFile( LLFilePicker::FFLOAD_SCRIPT ) ) { + //File picking cancelled by user, so nothing to do. return; } @@ -1147,7 +1140,6 @@ void LLScriptEdCore::onBtnLoadFromFile( void* data ) { self->mEditor->selectAll(); LLWString script(utf8str_to_wstring(text)); - LLWStringUtil::replaceTabsWithSpaces(script, self->mEditor->spacesPerTab()); self->mEditor->insertText(script); } } @@ -1164,6 +1156,7 @@ void LLScriptEdCore::onBtnSaveToFile( void* userdata ) LLFilePicker& file_picker = LLFilePicker::instance(); if( !file_picker.getSaveFile( LLFilePicker::FFSAVE_SCRIPT ) ) { + //File picking cancelled by user, so nothing to do. return; } -- cgit v1.2.3 From ce6bd89ca4fbc3d1d75725e8cfc8857e21052107 Mon Sep 17 00:00:00 2001 From: Ima Mechanique Date: Wed, 4 Jan 2012 15:16:35 +0000 Subject: Changes per Oz's suggestion on RB. --- indra/newview/llpreviewscript.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'indra/newview/llpreviewscript.cpp') diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index cab30b1295..88727bf59b 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -1154,18 +1154,15 @@ void LLScriptEdCore::onBtnSaveToFile( void* userdata ) if( self->mSaveCallback ) { LLFilePicker& file_picker = LLFilePicker::instance(); - if( !file_picker.getSaveFile( LLFilePicker::FFSAVE_SCRIPT ) ) + if( file_picker.getSaveFile( LLFilePicker::FFSAVE_SCRIPT ) ) { - //File picking cancelled by user, so nothing to do. - return; + std::string filename = file_picker.getFirstFile(); + std::string scriptText=self->mEditor->getText(); + std::ofstream fout(filename.c_str()); + fout<<(scriptText); + fout.close(); + self->mSaveCallback( self->mUserdata, FALSE ); } - - std::string filename = file_picker.getFirstFile(); - std::string scriptText=self->mEditor->getText(); - std::ofstream fout(filename.c_str()); - fout<<(scriptText); - fout.close(); - self->mSaveCallback( self->mUserdata, FALSE ); } } @@ -1187,8 +1184,7 @@ bool LLScriptEdCore::enableSaveToFileMenu(void* userdata) bool LLScriptEdCore::enableLoadFromFileMenu(void* userdata) { LLScriptEdCore* self = (LLScriptEdCore*)userdata; - if (!self || !self->mEditor) return FALSE; - return self->mEditor->canLoadOrSaveToFile(); + return (self && self->mEditor) ? self->mEditor->canLoadOrSaveToFile() : FALSE; } /// --------------------------------------------------------------------------- -- cgit v1.2.3