aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpreviewscript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llpreviewscript.cpp')
-rw-r--r--linden/indra/newview/llpreviewscript.cpp120
1 files changed, 66 insertions, 54 deletions
diff --git a/linden/indra/newview/llpreviewscript.cpp b/linden/indra/newview/llpreviewscript.cpp
index 69b6864..082b95c 100644
--- a/linden/indra/newview/llpreviewscript.cpp
+++ b/linden/indra/newview/llpreviewscript.cpp
@@ -17,7 +17,8 @@
17 * There are special exceptions to the terms and conditions of the GPL as 17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception 18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or 19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception 20 * online at
21 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 * 22 *
22 * By copying, modifying or distributing this software, you acknowledge 23 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above, 24 * that you have read and understood your obligations described above,
@@ -313,7 +314,8 @@ LLScriptEdCore::LLScriptEdCore(
313 mForceClose( FALSE ), 314 mForceClose( FALSE ),
314 mLastHelpToken(NULL), 315 mLastHelpToken(NULL),
315 mLiveHelpHistorySize(0), 316 mLiveHelpHistorySize(0),
316 mEnableSave(FALSE) 317 mEnableSave(FALSE),
318 mHasScriptData(FALSE)
317{ 319{
318 setFollowsAll(); 320 setFollowsAll();
319 setBorderVisible(FALSE); 321 setBorderVisible(FALSE);
@@ -449,12 +451,21 @@ void LLScriptEdCore::initMenu()
449 menuItem->setEnabledCallback(NULL); 451 menuItem->setEnabledCallback(NULL);
450} 452}
451 453
454void LLScriptEdCore::setScriptText(const std::string& text, BOOL is_valid)
455{
456 if (mEditor)
457 {
458 mEditor->setText(text);
459 mHasScriptData = is_valid;
460 }
461}
462
452BOOL LLScriptEdCore::hasChanged(void* userdata) 463BOOL LLScriptEdCore::hasChanged(void* userdata)
453{ 464{
454 LLScriptEdCore* self = (LLScriptEdCore*)userdata; 465 LLScriptEdCore* self = (LLScriptEdCore*)userdata;
455 if (!self || !self->mEditor) return FALSE; 466 if (!self || !self->mEditor) return FALSE;
456 467
457 return !self->mEditor->isPristine() || self->mEnableSave; 468 return ((!self->mEditor->isPristine() || self->mEnableSave) && self->mHasScriptData);
458} 469}
459 470
460void LLScriptEdCore::draw() 471void LLScriptEdCore::draw()
@@ -617,27 +628,26 @@ BOOL LLScriptEdCore::canClose()
617 else 628 else
618 { 629 {
619 // Bring up view-modal dialog: Save changes? Yes, No, Cancel 630 // Bring up view-modal dialog: Save changes? Yes, No, Cancel
620 gViewerWindow->alertXml("SaveChanges", LLScriptEdCore::handleSaveChangesDialog, this); 631 LLNotifications::instance().add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLScriptEdCore::handleSaveChangesDialog, this, _1, _2));
621 return FALSE; 632 return FALSE;
622 } 633 }
623} 634}
624 635
625// static 636bool LLScriptEdCore::handleSaveChangesDialog(const LLSD& notification, const LLSD& response )
626void LLScriptEdCore::handleSaveChangesDialog( S32 option, void* userdata )
627{ 637{
628 LLScriptEdCore* self = (LLScriptEdCore*) userdata; 638 S32 option = LLNotification::getSelectedOption(notification, response);
629 switch( option ) 639 switch( option )
630 { 640 {
631 case 0: // "Yes" 641 case 0: // "Yes"
632 // close after saving 642 // close after saving
633 LLScriptEdCore::doSave( self, TRUE ); 643 LLScriptEdCore::doSave( this, TRUE );
634 break; 644 break;
635 645
636 case 1: // "No" 646 case 1: // "No"
637 self->mForceClose = TRUE; 647 mForceClose = TRUE;
638 // This will close immediately because mForceClose is true, so we won't 648 // This will close immediately because mForceClose is true, so we won't
639 // infinite loop with these dialogs. JC 649 // infinite loop with these dialogs. JC
640 ((LLFloater*) self->getParent())->close(); 650 ((LLFloater*) getParent())->close();
641 break; 651 break;
642 652
643 case 2: // "Cancel" 653 case 2: // "Cancel"
@@ -646,29 +656,32 @@ void LLScriptEdCore::handleSaveChangesDialog( S32 option, void* userdata )
646 LLAppViewer::instance()->abortQuit(); 656 LLAppViewer::instance()->abortQuit();
647 break; 657 break;
648 } 658 }
659 return false;
649} 660}
650 661
651// static 662// static
652void LLScriptEdCore::onHelpWebDialog(S32 option, void* userdata) 663bool LLScriptEdCore::onHelpWebDialog(const LLSD& notification, const LLSD& response)
653{ 664{
654 LLScriptEdCore* corep = (LLScriptEdCore*)userdata; 665 S32 option = LLNotification::getSelectedOption(notification, response);
655 666
656 switch(option) 667 switch(option)
657 { 668 {
658 case 0: 669 case 0:
659 LLWeb::loadURL(corep->mHelpURL); 670 LLWeb::loadURL(notification["payload"]["help_url"]);
660 break; 671 break;
661 default: 672 default:
662 break; 673 break;
663 } 674 }
675 return false;
664} 676}
665 677
666// static 678// static
667void LLScriptEdCore::onBtnHelp(void* userdata) 679void LLScriptEdCore::onBtnHelp(void* userdata)
668{ 680{
669 gViewerWindow->alertXml("WebLaunchLSLGuide", 681 LLScriptEdCore* corep = (LLScriptEdCore*)userdata;
670 onHelpWebDialog, 682 LLSD payload;
671 userdata); 683 payload["help_url"] = corep->mHelpURL;
684 LLNotifications::instance().add("WebLaunchLSLGuide", LLSD(), payload, onHelpWebDialog);
672} 685}
673 686
674// static 687// static
@@ -828,8 +841,7 @@ void LLScriptEdCore::onBtnUndoChanges( void* userdata )
828 LLScriptEdCore* self = (LLScriptEdCore*) userdata; 841 LLScriptEdCore* self = (LLScriptEdCore*) userdata;
829 if( !self->mEditor->tryToRevertToPristineState() ) 842 if( !self->mEditor->tryToRevertToPristineState() )
830 { 843 {
831 gViewerWindow->alertXml("ScriptCannotUndo", 844 LLNotifications::instance().add("ScriptCannotUndo", LLSD(), LLSD(), boost::bind(&LLScriptEdCore::handleReloadFromServerDialog, self, _1, _2));
832 LLScriptEdCore::handleReloadFromServerDialog, self);
833 } 845 }
834} 846}
835 847
@@ -1029,17 +1041,16 @@ void LLScriptEdCore::onErrorList(LLUICtrl*, void* user_data)
1029 } 1041 }
1030} 1042}
1031 1043
1032// static 1044bool LLScriptEdCore::handleReloadFromServerDialog(const LLSD& notification, const LLSD& response )
1033void LLScriptEdCore::handleReloadFromServerDialog( S32 option, void* userdata )
1034{ 1045{
1035 LLScriptEdCore* self = (LLScriptEdCore*) userdata; 1046 S32 option = LLNotification::getSelectedOption(notification, response);
1036 switch( option ) 1047 switch( option )
1037 { 1048 {
1038 case 0: // "Yes" 1049 case 0: // "Yes"
1039 if( self->mLoadCallback ) 1050 if( mLoadCallback )
1040 { 1051 {
1041 self->mEditor->setText( self->getString("loading") ); 1052 setScriptText(getString("loading"), FALSE);
1042 self->mLoadCallback( self->mUserdata ); 1053 mLoadCallback( mUserdata );
1043 } 1054 }
1044 break; 1055 break;
1045 1056
@@ -1050,6 +1061,7 @@ void LLScriptEdCore::handleReloadFromServerDialog( S32 option, void* userdata )
1050 llassert(0); 1061 llassert(0);
1051 break; 1062 break;
1052 } 1063 }
1064 return false;
1053} 1065}
1054 1066
1055void LLScriptEdCore::selectFirstError() 1067void LLScriptEdCore::selectFirstError()
@@ -1251,7 +1263,7 @@ void LLPreviewLSL::loadAsset()
1251 } 1263 }
1252 else 1264 else
1253 { 1265 {
1254 mScriptEd->mEditor->setText(mScriptEd->getString("can_not_view")); 1266 mScriptEd->setScriptText(mScriptEd->getString("can_not_view"), FALSE);
1255 mScriptEd->mEditor->makePristine(); 1267 mScriptEd->mEditor->makePristine();
1256 mScriptEd->mEditor->setEnabled(FALSE); 1268 mScriptEd->mEditor->setEnabled(FALSE);
1257 mScriptEd->mFunctions->setEnabled(FALSE); 1269 mScriptEd->mFunctions->setEnabled(FALSE);
@@ -1262,7 +1274,7 @@ void LLPreviewLSL::loadAsset()
1262 } 1274 }
1263 else 1275 else
1264 { 1276 {
1265 mScriptEd->mEditor->setText(std::string(HELLO_LSL)); 1277 mScriptEd->setScriptText(std::string(HELLO_LSL), TRUE);
1266 mAssetStatus = PREVIEW_ASSET_LOADED; 1278 mAssetStatus = PREVIEW_ASSET_LOADED;
1267 } 1279 }
1268} 1280}
@@ -1508,9 +1520,9 @@ void LLPreviewLSL::onSaveComplete(const LLUUID& asset_uuid, void* user_data, S32
1508 else 1520 else
1509 { 1521 {
1510 llwarns << "Problem saving script: " << status << llendl; 1522 llwarns << "Problem saving script: " << status << llendl;
1511 LLStringUtil::format_map_t args; 1523 LLSD args;
1512 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status)); 1524 args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
1513 gViewerWindow->alertXml("SaveScriptFailReason", args); 1525 LLNotifications::instance().add("SaveScriptFailReason", args);
1514 } 1526 }
1515 delete info; 1527 delete info;
1516} 1528}
@@ -1546,9 +1558,9 @@ void LLPreviewLSL::onSaveBytecodeComplete(const LLUUID& asset_uuid, void* user_d
1546 else 1558 else
1547 { 1559 {
1548 llwarns << "Problem saving LSL Bytecode (Preview)" << llendl; 1560 llwarns << "Problem saving LSL Bytecode (Preview)" << llendl;
1549 LLStringUtil::format_map_t args; 1561 LLSD args;
1550 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status)); 1562 args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
1551 gViewerWindow->alertXml("SaveBytecodeFailReason", args); 1563 LLNotifications::instance().add("SaveBytecodeFailReason", args);
1552 } 1564 }
1553 delete instance_uuid; 1565 delete instance_uuid;
1554} 1566}
@@ -1573,7 +1585,7 @@ void LLPreviewLSL::onLoadComplete( LLVFS *vfs, const LLUUID& asset_uuid, LLAsset
1573 1585
1574 // put a EOS at the end 1586 // put a EOS at the end
1575 buffer[file_length] = 0; 1587 buffer[file_length] = 0;
1576 preview->mScriptEd->mEditor->setText(LLStringExplicit(buffer)); 1588 preview->mScriptEd->setScriptText(LLStringExplicit(&buffer[0]), TRUE);
1577 preview->mScriptEd->mEditor->makePristine(); 1589 preview->mScriptEd->mEditor->makePristine();
1578 delete [] buffer; 1590 delete [] buffer;
1579 LLInventoryItem* item = gInventory.getItem(*item_uuid); 1591 LLInventoryItem* item = gInventory.getItem(*item_uuid);
@@ -1594,15 +1606,15 @@ void LLPreviewLSL::onLoadComplete( LLVFS *vfs, const LLUUID& asset_uuid, LLAsset
1594 if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status || 1606 if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
1595 LL_ERR_FILE_EMPTY == status) 1607 LL_ERR_FILE_EMPTY == status)
1596 { 1608 {
1597 LLNotifyBox::showXml("ScriptMissing"); 1609 LLNotifications::instance().add("ScriptMissing");
1598 } 1610 }
1599 else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status) 1611 else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
1600 { 1612 {
1601 LLNotifyBox::showXml("ScriptNoPermissions"); 1613 LLNotifications::instance().add("ScriptNoPermissions");
1602 } 1614 }
1603 else 1615 else
1604 { 1616 {
1605 LLNotifyBox::showXml("UnableToLoadScript"); 1617 LLNotifications::instance().add("UnableToLoadScript");
1606 } 1618 }
1607 1619
1608 preview->mAssetStatus = PREVIEW_ASSET_ERROR; 1620 preview->mAssetStatus = PREVIEW_ASSET_ERROR;
@@ -1788,7 +1800,7 @@ void LLLiveLSLEditor::loadAsset(BOOL is_new)
1788 || !gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE)))) 1800 || !gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE))))
1789 { 1801 {
1790 mItem = new LLViewerInventoryItem(item); 1802 mItem = new LLViewerInventoryItem(item);
1791 mScriptEd->mEditor->setText(getString("not_allowed")); 1803 mScriptEd->setScriptText(getString("not_allowed"), FALSE);
1792 mScriptEd->mEditor->makePristine(); 1804 mScriptEd->mEditor->makePristine();
1793 mScriptEd->mEditor->setEnabled(FALSE); 1805 mScriptEd->mEditor->setEnabled(FALSE);
1794 mScriptEd->enableSave(FALSE); 1806 mScriptEd->enableSave(FALSE);
@@ -1820,7 +1832,7 @@ void LLLiveLSLEditor::loadAsset(BOOL is_new)
1820 } 1832 }
1821 else 1833 else
1822 { 1834 {
1823 mScriptEd->mEditor->setText(LLStringUtil::null); 1835 mScriptEd->setScriptText(LLStringUtil::null, FALSE);
1824 mScriptEd->mEditor->makePristine(); 1836 mScriptEd->mEditor->makePristine();
1825 mAssetStatus = PREVIEW_ASSET_LOADED; 1837 mAssetStatus = PREVIEW_ASSET_LOADED;
1826 } 1838 }
@@ -1857,7 +1869,7 @@ void LLLiveLSLEditor::loadAsset(BOOL is_new)
1857 // This may be better than having a accessible null pointer around, 1869 // This may be better than having a accessible null pointer around,
1858 // though this newly allocated object will most likely be replaced. 1870 // though this newly allocated object will most likely be replaced.
1859 mItem = new LLViewerInventoryItem(); 1871 mItem = new LLViewerInventoryItem();
1860 mScriptEd->mEditor->setText(LLStringUtil::null); 1872 mScriptEd->setScriptText(LLStringUtil::null, FALSE);
1861 mScriptEd->mEditor->makePristine(); 1873 mScriptEd->mEditor->makePristine();
1862 mScriptEd->mEditor->setEnabled(FALSE); 1874 mScriptEd->mEditor->setEnabled(FALSE);
1863 mAssetStatus = PREVIEW_ASSET_LOADED; 1875 mAssetStatus = PREVIEW_ASSET_LOADED;
@@ -1865,7 +1877,7 @@ void LLLiveLSLEditor::loadAsset(BOOL is_new)
1865 } 1877 }
1866 else 1878 else
1867 { 1879 {
1868 mScriptEd->mEditor->setText(std::string(HELLO_LSL)); 1880 mScriptEd->setScriptText(std::string(HELLO_LSL), TRUE);
1869 mScriptEd->enableSave(FALSE); 1881 mScriptEd->enableSave(FALSE);
1870 LLPermissions perm; 1882 LLPermissions perm;
1871 perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, gAgent.getGroupID()); 1883 perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, gAgent.getGroupID());
@@ -1910,15 +1922,15 @@ void LLLiveLSLEditor::onLoadComplete(LLVFS *vfs, const LLUUID& asset_id,
1910 if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status || 1922 if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
1911 LL_ERR_FILE_EMPTY == status) 1923 LL_ERR_FILE_EMPTY == status)
1912 { 1924 {
1913 LLNotifyBox::showXml("ScriptMissing"); 1925 LLNotifications::instance().add("ScriptMissing");
1914 } 1926 }
1915 else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status) 1927 else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
1916 { 1928 {
1917 LLNotifyBox::showXml("ScriptNoPermissions"); 1929 LLNotifications::instance().add("ScriptNoPermissions");
1918 } 1930 }
1919 else 1931 else
1920 { 1932 {
1921 LLNotifyBox::showXml("UnableToLoadScript"); 1933 LLNotifications::instance().add("UnableToLoadScript");
1922 } 1934 }
1923 instance->mAssetStatus = PREVIEW_ASSET_ERROR; 1935 instance->mAssetStatus = PREVIEW_ASSET_ERROR;
1924 } 1936 }
@@ -1975,7 +1987,7 @@ void LLLiveLSLEditor::loadScriptText(LLVFS *vfs, const LLUUID &uuid, LLAssetType
1975 1987
1976 buffer[file_length] = '\0'; 1988 buffer[file_length] = '\0';
1977 1989
1978 mScriptEd->mEditor->setText(LLStringExplicit(buffer)); 1990 mScriptEd->setScriptText(LLStringExplicit(&buffer[0]), TRUE);
1979 mScriptEd->mEditor->makePristine(); 1991 mScriptEd->mEditor->makePristine();
1980 delete[] buffer; 1992 delete[] buffer;
1981 1993
@@ -2011,7 +2023,7 @@ void LLLiveLSLEditor::onRunningCheckboxClicked( LLUICtrl*, void* userdata )
2011 else 2023 else
2012 { 2024 {
2013 runningCheckbox->set(!running); 2025 runningCheckbox->set(!running);
2014 gViewerWindow->alertXml("CouldNotStartStopScript"); 2026 LLNotifications::instance().add("CouldNotStartStopScript");
2015 } 2027 }
2016} 2028}
2017 2029
@@ -2040,7 +2052,7 @@ void LLLiveLSLEditor::onReset(void *userdata)
2040 } 2052 }
2041 else 2053 else
2042 { 2054 {
2043 gViewerWindow->alertXml("CouldNotStartStopScript"); 2055 LLNotifications::instance().add("CouldNotStartStopScript");
2044 } 2056 }
2045} 2057}
2046 2058
@@ -2134,7 +2146,7 @@ void LLLiveLSLEditor::saveIfNeeded()
2134 LLViewerObject* object = gObjectList.findObject(mObjectID); 2146 LLViewerObject* object = gObjectList.findObject(mObjectID);
2135 if(!object) 2147 if(!object)
2136 { 2148 {
2137 gViewerWindow->alertXml("SaveScriptFailObjectNotFound"); 2149 LLNotifications::instance().add("SaveScriptFailObjectNotFound");
2138 return; 2150 return;
2139 } 2151 }
2140 2152
@@ -2142,7 +2154,7 @@ void LLLiveLSLEditor::saveIfNeeded()
2142 { 2154 {
2143 // $NOTE: While the error message may not be exactly correct, 2155 // $NOTE: While the error message may not be exactly correct,
2144 // it's pretty close. 2156 // it's pretty close.
2145 gViewerWindow->alertXml("SaveScriptFailObjectNotFound"); 2157 LLNotifications::instance().add("SaveScriptFailObjectNotFound");
2146 return; 2158 return;
2147 } 2159 }
2148 2160
@@ -2344,9 +2356,9 @@ void LLLiveLSLEditor::onSaveTextComplete(const LLUUID& asset_uuid, void* user_da
2344 if (status) 2356 if (status)
2345 { 2357 {
2346 llwarns << "Unable to save text for a script." << llendl; 2358 llwarns << "Unable to save text for a script." << llendl;
2347 LLStringUtil::format_map_t args; 2359 LLSD args;
2348 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status)); 2360 args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
2349 gViewerWindow->alertXml("CompileQueueSaveText", args); 2361 LLNotifications::instance().add("CompileQueueSaveText", args);
2350 } 2362 }
2351 else 2363 else
2352 { 2364 {
@@ -2405,9 +2417,9 @@ void LLLiveLSLEditor::onSaveBytecodeComplete(const LLUUID& asset_uuid, void* use
2405 llinfos << "Problem saving LSL Bytecode (Live Editor)" << llendl; 2417 llinfos << "Problem saving LSL Bytecode (Live Editor)" << llendl;
2406 llwarns << "Unable to save a compiled script." << llendl; 2418 llwarns << "Unable to save a compiled script." << llendl;
2407 2419
2408 LLStringUtil::format_map_t args; 2420 LLSD args;
2409 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status)); 2421 args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
2410 gViewerWindow->alertXml("CompileQueueSaveBytecode", args); 2422 LLNotifications::instance().add("CompileQueueSaveBytecode", args);
2411 } 2423 }
2412 2424
2413 std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_uuid.asString()); 2425 std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,asset_uuid.asString());