diff options
author | Mnikolenko Productengine <mnikolenko@productengine.com> | 2024-06-10 14:29:22 +0300 |
---|---|---|
committer | Mnikolenko Productengine <mnikolenko@productengine.com> | 2024-06-10 14:31:37 +0300 |
commit | ad608dbc5f0d57ad29ec3a15e4d0a434dfaa38d2 (patch) | |
tree | 8c2cdac287942493befbf71042798c1ae77e2e5a /indra/llui | |
parent | f08a3c80d61795bb1fc0e576948bca3362ef8e6c (diff) |
Remove SharedCommitCallbackRegistry; add helpers CommitRegistrarHelper and ScopedRegistrarHelper
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/llmenugl.h | 2 | ||||
-rw-r--r-- | indra/llui/llnotifications.cpp | 2 | ||||
-rw-r--r-- | indra/llui/llscrolllistctrl.cpp | 2 | ||||
-rw-r--r-- | indra/llui/lltextbase.cpp | 2 | ||||
-rw-r--r-- | indra/llui/lltoolbar.cpp | 2 | ||||
-rw-r--r-- | indra/llui/llui.cpp | 3 | ||||
-rw-r--r-- | indra/llui/lluictrl.cpp | 18 | ||||
-rw-r--r-- | indra/llui/lluictrl.h | 56 |
8 files changed, 50 insertions, 37 deletions
diff --git a/indra/llui/llmenugl.h b/indra/llui/llmenugl.h index 98b76c08ff..baa6e9624d 100644 --- a/indra/llui/llmenugl.h +++ b/indra/llui/llmenugl.h @@ -953,7 +953,7 @@ public: typedef LLUICtrl::CommitCallbackInfo cb_info; static void addCommit(view_listener_t *listener, const std::string &name, cb_info::EUntrustedCall handle_untrusted = cb_info::UNTRUSTED_ALLOW) { - LLUICtrl::SharedCommitCallbackRegistry::currentRegistrar().add(name, + LLUICtrl::CommitCallbackRegistry::currentRegistrar().add(name, cb_info([listener](LLUICtrl*, const LLSD& param){ return listener->handleEvent(param); }, handle_untrusted)); } diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp index 2fbae73b65..7905ff7ce0 100644 --- a/indra/llui/llnotifications.cpp +++ b/indra/llui/llnotifications.cpp @@ -1243,7 +1243,7 @@ LLNotifications::LLNotifications() mIgnoreAllNotifications(false) { mListener.reset(new LLNotificationsListener(*this)); - LLUICtrl::CommitCallbackRegistry::currentRegistrar().add("Notification.Show", boost::bind(&LLNotifications::addFromCallback, this, _2)); + LLUICtrl::CommitCallbackRegistry::currentRegistrar().add("Notification.Show", { boost::bind(&LLNotifications::addFromCallback, this, _2) }); // touch the instance tracker for notification channels, so that it will still be around in our destructor LLInstanceTracker<LLNotificationChannel, std::string>::instanceCount(); diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp index 7fb732eca3..d32af15f0c 100644 --- a/indra/llui/llscrolllistctrl.cpp +++ b/indra/llui/llscrolllistctrl.cpp @@ -1991,7 +1991,7 @@ BOOL LLScrollListCtrl::handleRightMouseDown(S32 x, S32 y, MASK mask) // set up the callbacks for all of the avatar/group menu items // (N.B. callbacks don't take const refs as id is local scope) bool is_group = (mContextMenuType == MENU_GROUP); - LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; + ScopedRegistrarHelper registrar; registrar.add("Url.ShowProfile", boost::bind(&LLScrollListCtrl::showProfile, id, is_group)); registrar.add("Url.SendIM", boost::bind(&LLScrollListCtrl::sendIM, id)); registrar.add("Url.AddFriend", boost::bind(&LLScrollListCtrl::addFriend, id)); diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index c1eedf93a7..32b28834b2 100644 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -2085,7 +2085,7 @@ void LLTextBase::createUrlContextMenu(S32 x, S32 y, const std::string &in_url) // set up the callbacks for all of the potential menu items, N.B. we // don't use const ref strings in callbacks in case url goes out of scope - LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; + CommitRegistrarHelper registrar(LLUICtrl::CommitCallbackRegistry::currentRegistrar()); registrar.add("Url.Open", boost::bind(&LLUrlAction::openURL, url)); registrar.add("Url.OpenInternal", boost::bind(&LLUrlAction::openURLInternal, url)); registrar.add("Url.OpenExternal", boost::bind(&LLUrlAction::openURLExternal, url)); diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 8a6cb683d2..cb9539a573 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -144,7 +144,7 @@ void LLToolBar::createContextMenu() { // Setup bindings specific to this instance for the context menu options - LLUICtrl::CommitCallbackRegistry::ScopedRegistrar commit_reg; + CommitRegistrarHelper commit_reg(LLUICtrl::CommitCallbackRegistry::currentRegistrar()); commit_reg.add("Toolbars.EnableSetting", boost::bind(&LLToolBar::onSettingEnable, this, _2)); commit_reg.add("Toolbars.RemoveSelectedCommand", boost::bind(&LLToolBar::onRemoveSelectedCommand, this)); diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index c7539fcec7..07a962e515 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -167,8 +167,7 @@ mHelpImpl(NULL) LLFontGL::sShadowColor = LLUIColorTable::instance().getColor("ColorDropShadow"); - LLUICtrl::CommitCallbackRegistry::Registrar& reg = LLUICtrl::CommitCallbackRegistry::defaultRegistrar(); - + LLUICtrl::CommitRegistrarHelper reg(LLUICtrl::CommitCallbackRegistry::defaultRegistrar()); // Callbacks for associating controls with floater visibility: reg.add("Floater.Toggle", boost::bind(&LLFloaterReg::toggleInstance, _2, LLSD())); reg.add("Floater.ToggleOrBringToFront", boost::bind(&LLFloaterReg::toggleInstanceOrBringToFront, _2, LLSD())); diff --git a/indra/llui/lluictrl.cpp b/indra/llui/lluictrl.cpp index 6082a8f771..68d15eb424 100644 --- a/indra/llui/lluictrl.cpp +++ b/indra/llui/lluictrl.cpp @@ -220,10 +220,10 @@ void LLUICtrl::initFromParams(const Params& p) } else { - commit_callback_t* initfunc = (CommitCallbackRegistry::getValue(p.init_callback.function_name)); - if (initfunc) + LLUICtrl::CommitCallbackInfo *info = (CommitCallbackRegistry::getValue(p.init_callback.function_name)); + if (info && info->callback_func) { - (*initfunc)(this, p.init_callback.parameter); + (info->callback_func)(this, p.init_callback.parameter); } } } @@ -283,16 +283,8 @@ LLUICtrl::commit_signal_t::slot_type LLUICtrl::initCommitCallback(const CommitCa { std::string function_name = cb.function_name; setFunctionName(function_name); - commit_callback_t* func = (CommitCallbackRegistry::getValue(function_name)); - LLUICtrl::CommitCallbackInfo *info = LLUICtrl::SharedCommitCallbackRegistry::getValue(function_name); - if (func) - { - if (cb.parameter.isProvided()) - return boost::bind((*func), _1, cb.parameter); - else - return commit_signal_t::slot_type(*func); - } - else if (info && info->callback_func) + LLUICtrl::CommitCallbackInfo *info = (CommitCallbackRegistry::getValue(function_name)); + if (info && info->callback_func) { if (cb.parameter.isProvided()) return boost::bind((info->callback_func), _1, cb.parameter); diff --git a/indra/llui/lluictrl.h b/indra/llui/lluictrl.h index e507178d89..46d651b19c 100644 --- a/indra/llui/lluictrl.h +++ b/indra/llui/lluictrl.h @@ -273,17 +273,6 @@ public: template <typename F, typename DERIVED> class CallbackRegistry : public LLRegistrySingleton<std::string, F, DERIVED > {}; - - class CommitCallbackRegistry : public CallbackRegistry<commit_callback_t, CommitCallbackRegistry> - { - LLSINGLETON_EMPTY_CTOR(CommitCallbackRegistry); - }; - // the enable callback registry is also used for visiblity callbacks - class EnableCallbackRegistry : public CallbackRegistry<enable_callback_t, EnableCallbackRegistry> - { - LLSINGLETON_EMPTY_CTOR(EnableCallbackRegistry); - }; - struct CommitCallbackInfo { enum EUntrustedCall @@ -293,18 +282,51 @@ public: UNTRUSTED_THROTTLE }; - CommitCallbackInfo(commit_callback_t func = {}, EUntrustedCall handle_untrusted = UNTRUSTED_ALLOW) - : callback_func(func), handle_untrusted(handle_untrusted) - {} + CommitCallbackInfo(commit_callback_t func = {}, EUntrustedCall handle_untrusted = UNTRUSTED_ALLOW) : + callback_func(func), + handle_untrusted(handle_untrusted) + { + } public: commit_callback_t callback_func; - EUntrustedCall handle_untrusted; + EUntrustedCall handle_untrusted; + }; + typedef LLUICtrl::CommitCallbackInfo cb_info; + class CommitCallbackRegistry : public CallbackRegistry<CommitCallbackInfo, CommitCallbackRegistry> + { + LLSINGLETON_EMPTY_CTOR(CommitCallbackRegistry); + }; + + class CommitRegistrarHelper + { + public: + CommitRegistrarHelper(LLUICtrl::CommitCallbackRegistry::Registrar ®istrar) : mRegistrar(registrar) {} + + template <typename... ARGS> void add(const std::string &name, ARGS &&...args) + { + mRegistrar.add(name, {std::forward<ARGS>(args)...}); + } + private: + LLUICtrl::CommitCallbackRegistry::Registrar &mRegistrar; + }; + + class ScopedRegistrarHelper + { + public: + template <typename... ARGS> void add(const std::string &name, ARGS &&...args) + { + mRegistrar.add(name, {std::forward<ARGS>(args)...}); + } + + private: + LLUICtrl::CommitCallbackRegistry::ScopedRegistrar mRegistrar; }; - class SharedCommitCallbackRegistry : public CallbackRegistry<CommitCallbackInfo, SharedCommitCallbackRegistry> + // the enable callback registry is also used for visiblity callbacks + class EnableCallbackRegistry : public CallbackRegistry<enable_callback_t, EnableCallbackRegistry> { - LLSINGLETON_EMPTY_CTOR(SharedCommitCallbackRegistry); + LLSINGLETON_EMPTY_CTOR(EnableCallbackRegistry); }; protected: |