UI: Use std::bind for visibility undo/redo action

This is better and slightly more optimal code over what it was before.
master
jp9000 2021-04-27 21:31:07 -07:00
parent 20bbc9794d
commit 0d482be14a
1 changed files with 13 additions and 12 deletions

View File

@ -130,34 +130,35 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_)
/* --------------------------------------------------------- */
auto setItemVisible = [this](bool checked) {
auto setItemVisible = [this](bool val) {
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);
const char *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';
auto undo_redo = [](const std::string &name, int64_t id,
bool val) {
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_sceneitem_set_visible(si, val);
obs_scene_release(s);
};
QString str = QTStr(checked ? "Undo.ShowSceneItem"
QString str = QTStr(val ? "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");
main->undo_s.add_action(
str.arg(obs_source_get_name(source), name),
std::bind(undo_redo, std::placeholders::_1, id, !val),
std::bind(undo_redo, std::placeholders::_1, id, val),
name, name);
SignalBlocker sourcesSignalBlocker(this);
obs_sceneitem_set_visible(sceneitem, checked);
obs_sceneitem_set_visible(sceneitem, val);
};
auto setItemLocked = [this](bool checked) {