From feda1aaa283e8a99f6ba1159cfe6b9c1f2934a61 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Thu, 7 Oct 2021 02:59:20 -0700 Subject: [PATCH] UI: Add `_CHANGING` frontend events Adds the following events: - `OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING` - `OBS_FRONTEND_EVENT_PROFILE_CHANGING` Both emitted right before the change occurs. Can provide plugins with better awareness of these critical operations happening, so that they can react accordingly. --- UI/obs-frontend-api/obs-frontend-api.h | 2 ++ UI/window-basic-main-profiles.cpp | 12 ++++++++++++ UI/window-basic-main-scene-collections.cpp | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/UI/obs-frontend-api/obs-frontend-api.h b/UI/obs-frontend-api/obs-frontend-api.h index 36f57bdfb..429998cca 100644 --- a/UI/obs-frontend-api/obs-frontend-api.h +++ b/UI/obs-frontend-api/obs-frontend-api.h @@ -55,6 +55,8 @@ enum obs_frontend_event { OBS_FRONTEND_EVENT_VIRTUALCAM_STOPPED, OBS_FRONTEND_EVENT_TBAR_VALUE_CHANGED, + OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING, + OBS_FRONTEND_EVENT_PROFILE_CHANGING, }; /* ------------------------------------------------------------------------- */ diff --git a/UI/window-basic-main-profiles.cpp b/UI/window-basic-main-profiles.cpp index dc785ad05..31659647e 100644 --- a/UI/window-basic-main-profiles.cpp +++ b/UI/window-basic-main-profiles.cpp @@ -305,6 +305,9 @@ bool OBSBasic::CreateProfile(const std::string &newName, bool create_new, return false; } + if (api) + api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGING); + config_set_string(App()->GlobalConfig(), "Basic", "Profile", newName.c_str()); config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", @@ -514,6 +517,9 @@ void OBSBasic::on_actionDupProfile_triggered() void OBSBasic::on_actionRenameProfile_triggered() { + if (api) + api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGING); + std::string curDir = config_get_string(App()->GlobalConfig(), "Basic", "ProfileDir"); std::string curName = @@ -580,6 +586,9 @@ void OBSBasic::on_actionRemoveProfile_triggered(bool skipConfirmation) return; } + if (api) + api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGING); + newPath.resize(newPath_len); const char *newDir = strrchr(newPath.c_str(), '/') + 1; @@ -755,6 +764,9 @@ void OBSBasic::ChangeProfile() return; } + if (api) + api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGING); + path.resize(path_len); const char *newName = config_get_string(config, "General", "Name"); diff --git a/UI/window-basic-main-scene-collections.cpp b/UI/window-basic-main-scene-collections.cpp index a79937227..9b6d6fe64 100644 --- a/UI/window-basic-main-scene-collections.cpp +++ b/UI/window-basic-main-scene-collections.cpp @@ -166,6 +166,9 @@ bool OBSBasic::AddSceneCollection(bool create_new, const QString &qname) RefreshSceneCollections(); }; + if (api) + api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING); + new_collection(file, name); blog(LOG_INFO, "Added scene collection '%s' (%s, %s.json)", @@ -275,6 +278,9 @@ void OBSBasic::on_actionRenameSceneCollection_triggered() return; } + if (api) + api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING); + oldFile.insert(0, path); oldFile += ".json"; os_unlink(oldFile.c_str()); @@ -336,6 +342,9 @@ void OBSBasic::on_actionRemoveSceneCollection_triggered() return; } + if (api) + api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING); + oldFile.insert(0, path); oldFile += ".json"; @@ -424,6 +433,9 @@ void OBSBasic::ChangeSceneCollection() return; } + if (api) + api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING); + SaveProjectNow(); Load(fileName.c_str());