53
53
#include " llslider.h"
54
54
#include " lltooldraganddrop.h"
55
55
#include " llfilesystem.h"
56
+ #include " lllogchat.h"
56
57
57
58
#include " llagent.h"
58
59
#include " llmenugl.h"
@@ -415,7 +416,6 @@ LLScriptEdCore::LLScriptEdCore(
415
416
mLastHelpToken(NULL ),
416
417
mLiveHelpHistorySize(0 ),
417
418
mEnableSave(false ),
418
- mLiveFile(NULL ),
419
419
mLive(live),
420
420
mContainer(container),
421
421
mHasScriptData(false ),
@@ -447,7 +447,6 @@ LLScriptEdCore::~LLScriptEdCore()
447
447
}
448
448
}
449
449
450
- delete mLiveFile ;
451
450
if (mSyntaxIDConnection .connected ())
452
451
{
453
452
mSyntaxIDConnection .disconnect ();
@@ -730,13 +729,13 @@ bool LLScriptEdCore::writeToFile(const std::string& filename)
730
729
void LLScriptEdCore::sync ()
731
730
{
732
731
// Sync with external editor.
733
- if (mLiveFile )
732
+ if (mContainer -> mLiveFile )
734
733
{
735
- std::string tmp_file = mLiveFile ->filename ();
734
+ std::string tmp_file = mContainer -> mLiveFile ->filename ();
736
735
llstat s;
737
736
if (LLFile::stat (tmp_file, &s) == 0 ) // file exists
738
737
{
739
- mLiveFile ->ignoreNextUpdate ();
738
+ mContainer -> mLiveFile ->ignoreNextUpdate ();
740
739
writeToFile (tmp_file);
741
740
}
742
741
}
@@ -1121,7 +1120,11 @@ void LLScriptEdCore::doSave( bool close_after_save )
1121
1120
1122
1121
void LLScriptEdCore::openInExternalEditor ()
1123
1122
{
1124
- delete mLiveFile ; // deletes file
1123
+ if (mContainer ->mLiveFile )
1124
+ {
1125
+ // If already open in an external editor, just return
1126
+ return ;
1127
+ }
1125
1128
1126
1129
// Generate a suitable filename
1127
1130
std::string script_name = mScriptName ;
@@ -1144,8 +1147,8 @@ void LLScriptEdCore::openInExternalEditor()
1144
1147
}
1145
1148
1146
1149
// Start watching file changes.
1147
- mLiveFile = new LLLiveLSLFile (filename, boost::bind (&LLScriptEdContainer::onExternalChange, mContainer , _1));
1148
- mLiveFile ->addToEventTimer ();
1150
+ mContainer -> mLiveFile = new LLLiveLSLFile (filename, boost::bind (&LLScriptEdContainer::onExternalChange, mContainer , _1));
1151
+ mContainer -> mLiveFile ->addToEventTimer ();
1149
1152
1150
1153
// Open it in external editor.
1151
1154
{
@@ -1420,8 +1423,8 @@ void LLLiveLSLEditor::updateExperiencePanel()
1420
1423
{
1421
1424
mExperienceEnabled ->setToolTip (getString (" experience_enabled" ));
1422
1425
mExperienceEnabled ->setEnabled (getIsModifiable ());
1423
- mExperiences ->setVisible (true );
1424
1426
mExperienceEnabled ->set (true );
1427
+ mExperiences ->setVisible (true );
1425
1428
mViewProfileButton ->setToolTip (getString (" show_experience_profile" ));
1426
1429
buildExperienceList ();
1427
1430
}
@@ -1541,10 +1544,21 @@ void LLLiveLSLEditor::receiveExperienceIds(LLSD result, LLHandle<LLLiveLSLEditor
1541
1544
1542
1545
LLScriptEdContainer::LLScriptEdContainer (const LLSD& key) :
1543
1546
LLPreview(key)
1544
- , mScriptEd(NULL )
1547
+ , mScriptEd(nullptr )
1548
+ , mLiveFile(nullptr )
1549
+ , mLiveLogFile(nullptr )
1545
1550
{
1546
1551
}
1547
1552
1553
+ LLScriptEdContainer::~LLScriptEdContainer ()
1554
+ {
1555
+ delete mLiveFile ;
1556
+ mLiveFile = nullptr ;
1557
+
1558
+ delete mLiveLogFile ;
1559
+ mLiveLogFile = nullptr ;
1560
+ }
1561
+
1548
1562
std::string LLScriptEdContainer::getTmpFileName (const std::string& script_name)
1549
1563
{
1550
1564
// Take script inventory item id (within the object inventory)
@@ -1569,6 +1583,60 @@ std::string LLScriptEdContainer::getTmpFileName(const std::string& script_name)
1569
1583
}
1570
1584
}
1571
1585
1586
+ std::string LLScriptEdContainer::getErrorLogFileName (const std::string& script_path)
1587
+ {
1588
+ if (script_path.empty ())
1589
+ {
1590
+ return std::string ();
1591
+ }
1592
+
1593
+ return script_path + " .log" ;
1594
+ }
1595
+
1596
+ bool LLScriptEdContainer::logErrorsToFile (const LLSD& compile_errors)
1597
+ {
1598
+ if (!isOpenInExternalEditor ())
1599
+ {
1600
+ return false ;
1601
+ }
1602
+
1603
+ std::string script_path = getTmpFileName (mScriptEd ->mScriptName );
1604
+ std::string log_path = getErrorLogFileName (script_path);
1605
+
1606
+ llofstream file (log_path.c_str ());
1607
+ if (!file.is_open ())
1608
+ {
1609
+ LL_WARNS () << " Unable to open error log file: " << log_path << LL_ENDL;
1610
+ return false ;
1611
+ }
1612
+
1613
+ // Write timestamp
1614
+ std::string timestamp = LLLogChat::timestamp2LogString (0 , true );
1615
+ file << " // " << timestamp << " \n\n " ;
1616
+
1617
+ // Write errors
1618
+ for (LLSD::array_const_iterator line = compile_errors.beginArray ();
1619
+ line < compile_errors.endArray ();
1620
+ line++)
1621
+ {
1622
+ std::string error_message = line->asString ();
1623
+ LLStringUtil::stripNonprintable (error_message);
1624
+ file << error_message << " \n " ;
1625
+ }
1626
+
1627
+ file.close ();
1628
+
1629
+ // Create a log file handler if we don't already have one,
1630
+ // this is needed to delete the temporary log file properly
1631
+ if (!mLiveLogFile && !log_path.empty ())
1632
+ {
1633
+ // Empty callback since we don't need to react to file changes
1634
+ mLiveLogFile = new LLLiveLSLFile (log_path, [](const std::string& filename) { return true ; });
1635
+ }
1636
+
1637
+ return true ;
1638
+ }
1639
+
1572
1640
bool LLScriptEdContainer::onExternalChange (const std::string& filename)
1573
1641
{
1574
1642
if (!mScriptEd ->loadScriptText (filename))
@@ -1692,6 +1760,15 @@ void LLPreviewLSL::callbackLSLCompileSucceeded()
1692
1760
LL_INFOS () << " LSL Bytecode saved" << LL_ENDL;
1693
1761
mScriptEd ->mErrorList ->setCommentText (LLTrans::getString (" CompileSuccessful" ));
1694
1762
mScriptEd ->mErrorList ->setCommentText (LLTrans::getString (" SaveComplete" ));
1763
+
1764
+ if (isOpenInExternalEditor ())
1765
+ {
1766
+ LLSD success_msg;
1767
+ success_msg.append (LLTrans::getString (" CompileSuccessful" ));
1768
+ success_msg.append (LLTrans::getString (" SaveComplete" ));
1769
+ logErrorsToFile (success_msg);
1770
+ }
1771
+
1695
1772
closeIfNeeded ();
1696
1773
}
1697
1774
@@ -1711,6 +1788,12 @@ void LLPreviewLSL::callbackLSLCompileFailed(const LLSD& compile_errors)
1711
1788
row[" columns" ][0 ][" font" ] = " OCRA" ;
1712
1789
mScriptEd ->mErrorList ->addElement (row);
1713
1790
}
1791
+
1792
+ if (isOpenInExternalEditor ())
1793
+ {
1794
+ logErrorsToFile (compile_errors);
1795
+ }
1796
+
1714
1797
mScriptEd ->selectFirstError ();
1715
1798
closeIfNeeded ();
1716
1799
}
@@ -2042,6 +2125,15 @@ void LLLiveLSLEditor::callbackLSLCompileSucceeded(const LLUUID& task_id,
2042
2125
LL_DEBUGS () << " LSL Bytecode saved" << LL_ENDL;
2043
2126
mScriptEd ->mErrorList ->setCommentText (LLTrans::getString (" CompileSuccessful" ));
2044
2127
mScriptEd ->mErrorList ->setCommentText (LLTrans::getString (" SaveComplete" ));
2128
+
2129
+ if (isOpenInExternalEditor ())
2130
+ {
2131
+ LLSD success_msg;
2132
+ success_msg.append (LLTrans::getString (" CompileSuccessful" ));
2133
+ success_msg.append (LLTrans::getString (" SaveComplete" ));
2134
+ logErrorsToFile (success_msg);
2135
+ }
2136
+
2045
2137
mRunningCheckbox ->set (is_script_running);
2046
2138
mIsSaving = false ;
2047
2139
closeIfNeeded ();
@@ -2051,6 +2143,7 @@ void LLLiveLSLEditor::callbackLSLCompileSucceeded(const LLUUID& task_id,
2051
2143
void LLLiveLSLEditor::callbackLSLCompileFailed (const LLSD& compile_errors)
2052
2144
{
2053
2145
LL_DEBUGS () << " Compile failed!" << LL_ENDL;
2146
+
2054
2147
for (LLSD::array_const_iterator line = compile_errors.beginArray ();
2055
2148
line < compile_errors.endArray ();
2056
2149
line++)
@@ -2063,6 +2156,12 @@ void LLLiveLSLEditor::callbackLSLCompileFailed(const LLSD& compile_errors)
2063
2156
row[" columns" ][0 ][" font" ] = " OCRA" ;
2064
2157
mScriptEd ->mErrorList ->addElement (row);
2065
2158
}
2159
+
2160
+ if (isOpenInExternalEditor ())
2161
+ {
2162
+ logErrorsToFile (compile_errors);
2163
+ }
2164
+
2066
2165
mScriptEd ->selectFirstError ();
2067
2166
mIsSaving = false ;
2068
2167
closeIfNeeded ();
0 commit comments