UI: Migrate undo/redo to using UUIDs
This commit is contained in:
parent
0cb812251c
commit
67f7712d83
11 changed files with 193 additions and 196 deletions
|
|
@ -133,12 +133,13 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_)
|
|||
obs_source_t *scenesource = obs_scene_get_source(scene);
|
||||
int64_t id = obs_sceneitem_get_id(sceneitem);
|
||||
const char *name = obs_source_get_name(scenesource);
|
||||
const char *uuid = obs_source_get_uuid(scenesource);
|
||||
obs_source_t *source = obs_sceneitem_get_source(sceneitem);
|
||||
|
||||
auto undo_redo = [](const std::string &name, int64_t id,
|
||||
auto undo_redo = [](const std::string &uuid, int64_t id,
|
||||
bool val) {
|
||||
OBSSourceAutoRelease s =
|
||||
obs_get_source_by_name(name.c_str());
|
||||
obs_get_source_by_uuid(uuid.c_str());
|
||||
obs_scene_t *sc = obs_group_or_scene_from_source(s);
|
||||
obs_sceneitem_t *si =
|
||||
obs_scene_find_sceneitem_by_id(sc, id);
|
||||
|
|
@ -154,7 +155,7 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_)
|
|||
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);
|
||||
uuid, uuid);
|
||||
|
||||
SignalBlocker sourcesSignalBlocker(this);
|
||||
obs_sceneitem_set_visible(sceneitem, val);
|
||||
|
|
@ -452,32 +453,33 @@ void SourceTreeItem::ExitEditModeInternal(bool save)
|
|||
|
||||
SignalBlocker sourcesSignalBlocker(this);
|
||||
std::string prevName(obs_source_get_name(source));
|
||||
std::string scene_name =
|
||||
obs_source_get_name(main->GetCurrentSceneSource());
|
||||
auto undo = [scene_name, prevName, main](const std::string &data) {
|
||||
std::string scene_uuid =
|
||||
obs_source_get_uuid(main->GetCurrentSceneSource());
|
||||
auto undo = [scene_uuid, prevName, main](const std::string &data) {
|
||||
OBSSourceAutoRelease source =
|
||||
obs_get_source_by_name(data.c_str());
|
||||
obs_get_source_by_uuid(data.c_str());
|
||||
obs_source_set_name(source, prevName.c_str());
|
||||
|
||||
OBSSourceAutoRelease scene_source =
|
||||
obs_get_source_by_name(scene_name.c_str());
|
||||
obs_get_source_by_uuid(scene_uuid.c_str());
|
||||
main->SetCurrentScene(scene_source.Get(), true);
|
||||
};
|
||||
|
||||
std::string editedName = newName;
|
||||
|
||||
auto redo = [scene_name, main, editedName](const std::string &data) {
|
||||
auto redo = [scene_uuid, main, editedName](const std::string &data) {
|
||||
OBSSourceAutoRelease source =
|
||||
obs_get_source_by_name(data.c_str());
|
||||
obs_get_source_by_uuid(data.c_str());
|
||||
obs_source_set_name(source, editedName.c_str());
|
||||
|
||||
OBSSourceAutoRelease scene_source =
|
||||
obs_get_source_by_name(scene_name.c_str());
|
||||
obs_get_source_by_uuid(scene_uuid.c_str());
|
||||
main->SetCurrentScene(scene_source.Get(), true);
|
||||
};
|
||||
|
||||
const char *uuid = obs_source_get_uuid(source);
|
||||
main->undo_s.add_action(QTStr("Undo.Rename").arg(newName.c_str()), undo,
|
||||
redo, newName, prevName);
|
||||
redo, uuid, uuid);
|
||||
|
||||
obs_source_set_name(source, newName.c_str());
|
||||
label->setText(QT_UTF8(newName.c_str()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue