UI: Add Undo/Redo for source visibility

(Author note: This is why I hate supporting undo/redo.)

Fixes obsproject/obs-studio#4447
This commit is contained in:
jp9000 2021-04-16 20:29:18 -07:00
parent 8515f38bdb
commit 8175700620
2 changed files with 27 additions and 1 deletions

View File

@ -292,7 +292,8 @@ Undo.Properties="Property Change on '%1'"
Undo.Scene.Duplicate="Duplicate Scene '%1'"
Undo.ShowTransition="Show Transition on '%1'"
Undo.HideTransition="Hide Transition on '%1'"
Undo.ShowSceneItem="Show '%1' in '%2'"
Undo.HideSceneItem="Hide '%1' in '%2'"
# transition name dialog
TransitionNameDlg.Text="Please enter the name of the transition"

View File

@ -131,6 +131,31 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_)
/* --------------------------------------------------------- */
auto setItemVisible = [this](bool checked) {
obs_scene_t *scene = obs_sceneitem_get_scene(sceneitem);
obs_source_t *scenesource = obs_scene_get_source(scene);
int64_t id = obs_sceneitem_get_id(sceneitem);
std::string name = obs_source_get_name(scenesource);
obs_source_t *source = obs_sceneitem_get_source(sceneitem);
auto undo_redo = [id, name](const std::string &val) {
bool vis = val[0] == '1';
obs_scene_t *s = obs_get_scene_by_name(name.c_str());
obs_sceneitem_t *si =
obs_scene_find_sceneitem_by_id(s, id);
if (si)
obs_sceneitem_set_visible(si, vis);
obs_scene_release(s);
};
QString str = QTStr(checked ? "Undo.ShowSceneItem"
: "Undo.HideSceneItem");
str = str.arg(obs_source_get_name(source), name.c_str());
OBSBasic *main = OBSBasic::Get();
main->undo_s.add_action(str, undo_redo, undo_redo,
checked ? "0" : "1",
checked ? "1" : "0", nullptr);
SignalBlocker sourcesSignalBlocker(this);
obs_sceneitem_set_visible(sceneitem, checked);
};