UI: Remove unnecessary Undo/Redo cleanup func

Since fixing the reference holding issue with scene/source deletion, the
undo/redo cleanup function (last param of add_action) is no longer
required.
This commit is contained in:
jp9000 2021-04-27 19:00:29 -07:00
parent 8946f02270
commit 78f1983f7d
12 changed files with 37 additions and 65 deletions

View File

@ -84,7 +84,7 @@ void SourceToolbar::SetUndoProperties(obs_source_t *source)
main->undo_s.add_action(
QTStr("Undo.Properties")
.arg(obs_source_get_name(source)),
undo_redo, undo_redo, undo_data, redo_data, nullptr);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(new_settings);
obs_data_release(curr_settings);

View File

@ -154,7 +154,7 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_)
OBSBasic *main = OBSBasic::Get();
main->undo_s.add_action(str, undo_redo, undo_redo,
checked ? "0" : "1",
checked ? "1" : "0", nullptr);
checked ? "1" : "0");
SignalBlocker sourcesSignalBlocker(this);
obs_sceneitem_set_visible(sceneitem, checked);
@ -454,7 +454,7 @@ void SourceTreeItem::ExitEditMode(bool save)
};
main->undo_s.add_action(QTStr("Undo.Rename").arg(newName.c_str()), undo,
redo, newName, prevName, NULL);
redo, newName, prevName);
obs_source_set_name(source, newName.c_str());
label->setText(QT_UTF8(newName.c_str()));

View File

@ -6,21 +6,8 @@
undo_stack::undo_stack(ui_ptr ui) : ui(ui) {}
void undo_stack::release()
{
for (auto f : undo_items)
if (f.d)
f.d(true);
for (auto f : redo_items)
if (f.d)
f.d(false);
}
void undo_stack::clear()
{
release();
undo_items.clear();
redo_items.clear();
@ -33,16 +20,14 @@ void undo_stack::clear()
void undo_stack::add_action(const QString &name, undo_redo_cb undo,
undo_redo_cb redo, std::string undo_data,
std::string redo_data, func d)
std::string redo_data)
{
while (undo_items.size() >= MAX_STACK_SIZE) {
undo_redo_t item = undo_items.back();
if (item.d)
item.d(true);
undo_items.pop_back();
}
undo_redo_t n = {name, undo_data, redo_data, undo, redo, d};
undo_redo_t n = {name, undo_data, redo_data, undo, redo};
undo_items.push_front(n);
clear_redo();
@ -116,9 +101,5 @@ void undo_stack::disable_undo_redo()
void undo_stack::clear_redo()
{
for (auto f : redo_items)
if (f.d)
f.d(false);
redo_items.clear();
}

View File

@ -20,7 +20,6 @@ class undo_stack {
std::string redo_data;
undo_redo_cb undo;
undo_redo_cb redo;
func d;
};
ui_ptr ui;
@ -36,11 +35,10 @@ public:
void enable_undo_redo();
void disable_undo_redo();
void release();
void clear();
void add_action(const QString &name, undo_redo_cb undo,
undo_redo_cb redo, std::string undo_data,
std::string redo_data, func d);
std::string redo_data);
void undo();
void redo();
};

View File

@ -258,7 +258,7 @@ void OBSBasicFilters::UpdatePropertiesView(int row, bool async)
std::string redo_data = obs_data_get_json(redo_wrapper);
main->undo_s.add_action(QTStr("Undo.Filters").arg(name.c_str()),
undo_redo, undo_redo, undo_data,
redo_data, NULL);
redo_data);
obs_data_release(redo_wrapper);
obs_data_release(undo_wrapper);
@ -621,7 +621,7 @@ void OBSBasicFilters::AddNewFilter(const char *id)
std::string undo_data(obs_data_get_json(wrapper));
std::string redo_data(obs_data_get_json(rwrapper));
main->undo_s.add_action(QTStr("Undo.Add").arg(name.c_str()),
undo, redo, undo_data, redo_data, NULL);
undo, redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -877,7 +877,7 @@ void OBSBasicFilters::on_removeEffectFilter_clicked()
main->undo_s.add_action(
QTStr("Undo.Delete")
.arg(obs_source_get_name(filter)),
undo, redo, undo_data, redo_data, NULL);
undo, redo, undo_data, redo_data);
obs_source_filter_remove(source, filter);
obs_data_release(wrapper);
@ -1166,7 +1166,7 @@ void OBSBasicFilters::FilterNameEdited(QWidget *editor, QListWidget *list)
std::string undo_data(sourceName);
std::string redo_data(sourceName);
main->undo_s.add_action(QTStr("Undo.Rename").arg(name.c_str()),
undo, redo, undo_data, redo_data, NULL);
undo, redo, undo_data, redo_data);
}
listItem->setText(QString());

View File

@ -199,7 +199,7 @@ bool OBSBasic::AddSceneCollection(bool create_new, const QString &qname)
};
undo_s.add_action(QTStr("Undo.Add").arg(name.c_str()), undo, redo, file,
"", NULL);
"");
blog(LOG_INFO, "Added scene collection '%s' (%s, %s.json)",
name.c_str(), create_new ? "clean" : "duplicate", file.c_str());
@ -376,7 +376,7 @@ void OBSBasic::on_actionRenameSceneCollection_triggered()
RefreshSceneCollections();
undo_s.add_action(QTStr("Undo.Rename").arg(name.c_str()), undo, redo,
"", "", NULL);
"", "");
if (api) {
api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED);
@ -450,7 +450,7 @@ void OBSBasic::on_actionRemoveSceneCollection_triggered()
std::string undo_data = std::string(obs_data_get_json(data));
undo_s.add_action(QTStr("Undo.Delete").arg(oldName.c_str()), undo, redo,
undo_data, "", NULL);
undo_data, "");
obs_data_release(data);
os_unlink(oldFile.c_str());

View File

@ -1236,8 +1236,7 @@ QMenu *OBSBasic::CreateVisibilityTransitionMenu(bool visible)
.arg(obs_source_get_name(
obs_sceneitem_get_source(
sceneItem))),
undo_redo, undo_redo, undo_data, redo_data,
NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(newTransitionData);
obs_data_release(oldTransitionData);
};

View File

@ -3663,8 +3663,7 @@ void OBSBasic::DuplicateSelectedScene()
QTStr("Undo.Scene.Duplicate")
.arg(obs_source_get_name(source)),
undo, redo, obs_source_get_name(source),
obs_source_get_name(obs_scene_get_source(curScene)),
NULL);
obs_source_get_name(obs_scene_get_source(curScene)));
obs_scene_release(scene);
@ -3765,7 +3764,7 @@ void OBSBasic::RemoveSelectedScene()
obs_data_set_int(data, "index", ui->scenes->currentRow());
undo_s.add_action("Delete Scene", undo, redo, obs_data_get_json(data),
obs_source_get_name(source), NULL);
obs_source_get_name(source));
obs_data_array_release(array);
obs_data_release(data);
@ -4468,7 +4467,6 @@ void OBSBasic::closeEvent(QCloseEvent *event)
/* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
* sources, etc) so that all references are released before shutdown */
undo_s.release();
ClearSceneData();
App()->quit();
@ -4672,8 +4670,7 @@ void OBSBasic::on_actionAdvAudioProperties_triggered()
if (undo_data.compare(redo_data) != 0)
undo_s.add_action(QTStr("Undo.Audio"), undo_redo,
undo_redo, undo_data, redo_data,
NULL);
undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
});
@ -4917,7 +4914,7 @@ void OBSBasic::on_actionAddScene_triggered()
obs_scene_release(scene);
};
undo_s.add_action(QTStr("Undo.Add").arg(QString(name.c_str())),
undo_fn, redo_fn, name, name, NULL);
undo_fn, redo_fn, name, name);
obs_scene_t *scene = obs_scene_create(name.c_str());
source = obs_scene_get_source(scene);
@ -5552,7 +5549,7 @@ void OBSBasic::CreateSceneUndoRedoAction(const QString &action_name,
const char *redo_json = obs_data_get_last_json(redo_data);
undo_s.add_action(action_name, undo_redo, undo_redo, undo_json,
redo_json, nullptr);
redo_json);
}
void OBSBasic::on_actionRemoveSource_triggered()
@ -5893,7 +5890,7 @@ static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
std::string redo_data(prevName);
parent->undo_s.add_action(
QTStr("Undo.Rename").arg(name.c_str()), undo, redo,
undo_data, redo_data, NULL);
undo_data, redo_data);
listItem->setText(QT_UTF8(name.c_str()));
obs_source_set_name(source, name.c_str());
@ -7183,7 +7180,7 @@ void OBSBasic::on_actionPasteTransform_triggered()
undo_s.add_action(
QTStr("Undo.Transform.Paste")
.arg(obs_source_get_name(GetCurrentSceneSource())),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7233,7 +7230,7 @@ void OBSBasic::on_actionResetTransform_triggered()
undo_s.add_action(
QTStr("Undo.Transform.Reset")
.arg(obs_source_get_name(obs_scene_get_source(scene))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7326,7 +7323,7 @@ void OBSBasic::on_actionRotate90CW_triggered()
undo_s.add_action(QTStr("Undo.Transform.Rotate")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7346,7 +7343,7 @@ void OBSBasic::on_actionRotate90CCW_triggered()
undo_s.add_action(QTStr("Undo.Transform.Rotate")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7366,7 +7363,7 @@ void OBSBasic::on_actionRotate180_triggered()
undo_s.add_action(QTStr("Undo.Transform.Rotate")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7416,7 +7413,7 @@ void OBSBasic::on_actionFlipHorizontal_triggered()
undo_s.add_action(QTStr("Undo.Transform.HFlip")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7438,7 +7435,7 @@ void OBSBasic::on_actionFlipVertical_triggered()
undo_s.add_action(QTStr("Undo.Transform.VFlip")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7493,7 +7490,7 @@ void OBSBasic::on_actionFitToScreen_triggered()
undo_s.add_action(QTStr("Undo.Transform.FitToScreen")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7514,7 +7511,7 @@ void OBSBasic::on_actionStretchToScreen_triggered()
undo_s.add_action(QTStr("Undo.Transform.StretchToScreen")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7589,7 +7586,7 @@ void OBSBasic::on_actionCenterToScreen_triggered()
undo_s.add_action(QTStr("Undo.Transform.Center")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7609,7 +7606,7 @@ void OBSBasic::on_actionVerticalCenter_triggered()
undo_s.add_action(QTStr("Undo.Transform.VCenter")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7629,7 +7626,7 @@ void OBSBasic::on_actionHorizontalCenter_triggered()
undo_s.add_action(QTStr("Undo.Transform.HCenter")
.arg(obs_source_get_name(obs_scene_get_source(
GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
obs_data_release(rwrapper);
@ -7744,7 +7741,7 @@ void OBSBasic::Nudge(int dist, MoveDir dir)
.arg(obs_source_get_name(
GetCurrentSceneSource())),
undo_redo, undo_redo, undo_data,
redo_data, NULL);
redo_data);
recent_nudge = false;
obs_data_release(rwrapper);

View File

@ -745,8 +745,7 @@ void OBSBasicPreview::mouseReleaseEvent(QMouseEvent *event)
QTStr("Undo.Transform")
.arg(obs_source_get_name(
main->GetCurrentSceneSource())),
undo_redo, undo_redo, undo_data, redo_data,
NULL);
undo_redo, undo_redo, undo_data, redo_data);
}
if (wrapper)

View File

@ -398,8 +398,7 @@ void OBSBasicProperties::on_buttonBox_clicked(QAbstractButton *button)
main->undo_s.add_action(
QTStr("Undo.Properties")
.arg(obs_source_get_name(source)),
undo_redo, undo_redo, undo_data, redo_data,
NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(new_settings);
obs_data_release(curr_settings);

View File

@ -292,8 +292,7 @@ void OBSBasicSourceSelect::on_buttonBox_accepted()
undo_s.add_action(QTStr("Undo.Add").arg(ui->sourceName->text()),
undo, redo,
std::string(obs_source_get_name(newSource)),
std::string(obs_data_get_json(wrapper)),
NULL);
std::string(obs_data_get_json(wrapper)));
obs_data_release(wrapper);
obs_sceneitem_release(item);
}

View File

@ -105,7 +105,7 @@ OBSBasicTransform::~OBSBasicTransform()
QTStr("Undo.Transform")
.arg(obs_source_get_name(obs_scene_get_source(
main->GetCurrentScene()))),
undo_redo, undo_redo, undo_data, redo_data, NULL);
undo_redo, undo_redo, undo_data, redo_data);
obs_data_release(wrapper);
}