diff options
author | Mnikolenko Productengine <mnikolenko@productengine.com> | 2024-04-03 14:26:34 +0300 |
---|---|---|
committer | Mnikolenko Productengine <mnikolenko@productengine.com> | 2024-04-03 14:26:34 +0300 |
commit | b351888ed7d395279dfc022363e911d52ebdcc16 (patch) | |
tree | 3ef539d498b094626e764b2281f1ba639cc14836 | |
parent | 479fa4350100dc96382f0b6b09b2b9036d170f04 (diff) |
Add RAII class for adding/erasing script entries; code clean up
-rw-r--r-- | indra/llwindow/llwindowwin32.cpp | 4 | ||||
-rw-r--r-- | indra/llwindow/llwindowwin32.h | 2 | ||||
-rw-r--r-- | indra/newview/llfloaterluascripts.cpp | 7 | ||||
-rw-r--r-- | indra/newview/llfloaterluascripts.h | 2 | ||||
-rw-r--r-- | indra/newview/llluamanager.cpp | 4 | ||||
-rw-r--r-- | indra/newview/llluamanager.h | 18 |
6 files changed, 23 insertions, 14 deletions
diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index e3ef28a27d..7fbc2c8ea2 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -3757,9 +3757,7 @@ S32 OSMessageBoxWin32(const std::string& text, const std::string& caption, U32 t void shell_open(const std::string &file, bool async) { - // this is madness.. no, this is.. - LLWString url_wstring = utf8str_to_wstring(file); - llutf16string url_utf16 = wstring_to_utf16str(url_wstring); + std::wstring url_utf16 = ll_convert(file); // let the OS decide what to use to open the URL SHELLEXECUTEINFO sei = {sizeof(sei)}; diff --git a/indra/llwindow/llwindowwin32.h b/indra/llwindow/llwindowwin32.h index ed64891108..320c1c8b88 100644 --- a/indra/llwindow/llwindowwin32.h +++ b/indra/llwindow/llwindowwin32.h @@ -122,7 +122,7 @@ public: /*virtual*/ void interruptLanguageTextInput(); /*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async); - void openFolder(const std::string &path); + void openFolder(const std::string &path) override; /*virtual*/ F32 getSystemUISize(); diff --git a/indra/newview/llfloaterluascripts.cpp b/indra/newview/llfloaterluascripts.cpp index 87d2cf0c69..bd845a97d6 100644 --- a/indra/newview/llfloaterluascripts.cpp +++ b/indra/newview/llfloaterluascripts.cpp @@ -51,7 +51,7 @@ LLFloaterLUAScripts::LLFloaterLUAScripts(const LLSD &key) BOOL LLFloaterLUAScripts::postBuild() { mScriptList = getChild<LLScrollListCtrl>("scripts_list"); - mScriptList->setRightMouseDownCallback(boost::bind(&LLFloaterLUAScripts::onScrollListRightClicked, this, _1, _2, _3)); + mScriptList->setRightMouseDownCallback([this](LLUICtrl *ctrl, S32 x, S32 y, MASK mask) { onScrollListRightClicked(ctrl, x, y);}); LLContextMenu *menu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>( "menu_lua_scripts.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); @@ -71,13 +71,11 @@ LLFloaterLUAScripts::~LLFloaterLUAScripts() menu->die(); mContextMenuHandle.markDead(); } - - delete mUpdateTimer; } void LLFloaterLUAScripts::draw() { - if (mUpdateTimer->hasExpired()) + if (mUpdateTimer->checkExpirationAndReset(REFRESH_INTERVAL)) { populateScriptList(); } @@ -103,7 +101,6 @@ void LLFloaterLUAScripts::populateScriptList() } mScriptList->setScrollPos(prev_pos); mScriptList->setSelectedByValue(prev_selected, true); - mUpdateTimer->setTimerExpirySec(REFRESH_INTERVAL); } void LLFloaterLUAScripts::onScrollListRightClicked(LLUICtrl *ctrl, S32 x, S32 y) diff --git a/indra/newview/llfloaterluascripts.h b/indra/newview/llfloaterluascripts.h index c8c9e7f020..548bbd10f6 100644 --- a/indra/newview/llfloaterluascripts.h +++ b/indra/newview/llfloaterluascripts.h @@ -44,7 +44,7 @@ private: void populateScriptList(); void onScrollListRightClicked(LLUICtrl *ctrl, S32 x, S32 y); - LLTimer* mUpdateTimer; + std::unique_ptr<LLTimer> mUpdateTimer; LLScrollListCtrl* mScriptList; std::string mTargetFolderPath; diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index 343c7c7459..d2b8ca3a94 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -179,8 +179,7 @@ void LLLUAmanager::runScriptFile(const std::string &filename, script_result_fn r // A script_result_fn will be called when LuaState::expr() completes. LLCoros::instance().launch(filename, [filename, result_cb, finished_cb]() { - std::string coro_name = LLCoros::getName(); - sScriptNames[coro_name] = filename; + ScriptObserver observer(LLCoros::getName(), filename); llifstream in_file; in_file.open(filename.c_str()); @@ -205,7 +204,6 @@ void LLLUAmanager::runScriptFile(const std::string &filename, script_result_fn r result_cb(-1, msg); } } - sScriptNames.erase(coro_name); }); } diff --git a/indra/newview/llluamanager.h b/indra/newview/llluamanager.h index 70728f958e..88467cbf84 100644 --- a/indra/newview/llluamanager.h +++ b/indra/newview/llluamanager.h @@ -40,6 +40,8 @@ class LuaState; class LLLUAmanager { + friend class ScriptObserver; + public: // Pass a callback with this signature to obtain the error message, if // any, from running a script or source string. Empty msg means success. @@ -81,7 +83,7 @@ public: static void runScriptOnLogin(); - static std::map<std::string, std::string> getScriptNames() { return sScriptNames; } + static const std::map<std::string, std::string> getScriptNames() { return sScriptNames; } private: static std::map<std::string, std::string> sScriptNames; @@ -104,4 +106,18 @@ class LLRequireResolver bool findModuleImpl(const std::string& absolutePath); void runModule(const std::string& desc, const std::string& code); }; + +// RAII class to guarantee that a script entry is erased even when coro is terminated +class ScriptObserver +{ + public: + ScriptObserver(const std::string &coro_name, const std::string &filename) : mCoroName(coro_name) + { + LLLUAmanager::sScriptNames[mCoroName] = filename; + } + ~ScriptObserver() { LLLUAmanager::sScriptNames.erase(mCoroName); } + + private: + std::string mCoroName; +}; #endif |