mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-01-30 17:12:09 -05:00
Merge pull request #3426 from Programatic/undo_redo
UI: Implement Undo/Redo System
This commit is contained in:
@@ -26,6 +26,10 @@
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
#include <QMessageBox>
|
||||
#include <obs-data.h>
|
||||
#include <obs.h>
|
||||
#include <qpointer.h>
|
||||
#include <util/c99defs.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -74,14 +78,28 @@ OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)
|
||||
/* The OBSData constructor increments the reference once */
|
||||
obs_data_release(oldSettings);
|
||||
|
||||
OBSData settings = obs_source_get_settings(source);
|
||||
OBSData nd_settings = obs_source_get_settings(source);
|
||||
OBSData settings = obs_data_get_defaults(nd_settings);
|
||||
obs_data_apply(settings, nd_settings);
|
||||
obs_data_apply(oldSettings, settings);
|
||||
obs_data_release(settings);
|
||||
obs_data_release(nd_settings);
|
||||
|
||||
auto handle_memory = [](void *vp, obs_data_t *old_settings,
|
||||
obs_data_t *new_settings) {
|
||||
obs_source_t *source = reinterpret_cast<obs_source_t *>(vp);
|
||||
|
||||
obs_source_update(source, new_settings);
|
||||
|
||||
UNUSED_PARAMETER(old_settings);
|
||||
UNUSED_PARAMETER(vp);
|
||||
};
|
||||
|
||||
view = new OBSPropertiesView(
|
||||
settings, source,
|
||||
nd_settings, source,
|
||||
(PropertiesReloadCallback)obs_source_properties,
|
||||
(PropertiesUpdateCallback)obs_source_update);
|
||||
(PropertiesUpdateCallback)handle_memory,
|
||||
(PropertiesVisualUpdateCb)obs_source_update);
|
||||
view->setMinimumHeight(150);
|
||||
|
||||
preview->setMinimumSize(20, 150);
|
||||
@@ -341,6 +359,51 @@ void OBSBasicProperties::on_buttonBox_clicked(QAbstractButton *button)
|
||||
QDialogButtonBox::ButtonRole val = buttonBox->buttonRole(button);
|
||||
|
||||
if (val == QDialogButtonBox::AcceptRole) {
|
||||
|
||||
std::string scene_name =
|
||||
obs_source_get_name(main->GetCurrentSceneSource());
|
||||
|
||||
auto undo_redo = [scene_name](const std::string &data) {
|
||||
obs_data_t *settings =
|
||||
obs_data_create_from_json(data.c_str());
|
||||
obs_source_t *source = obs_get_source_by_name(
|
||||
obs_data_get_string(settings, "undo_sname"));
|
||||
obs_source_update(source, settings);
|
||||
|
||||
obs_source_update_properties(source);
|
||||
|
||||
obs_source_t *scene_source =
|
||||
obs_get_source_by_name(scene_name.c_str());
|
||||
|
||||
OBSBasic::Get()->SetCurrentScene(source);
|
||||
|
||||
obs_source_release(scene_source);
|
||||
|
||||
obs_data_release(settings);
|
||||
obs_source_release(source);
|
||||
};
|
||||
|
||||
obs_data_t *new_settings = obs_data_create();
|
||||
obs_data_t *curr_settings = obs_source_get_settings(source);
|
||||
obs_data_apply(new_settings, curr_settings);
|
||||
obs_data_set_string(new_settings, "undo_sname",
|
||||
obs_source_get_name(source));
|
||||
obs_data_set_string(oldSettings, "undo_sname",
|
||||
obs_source_get_name(source));
|
||||
|
||||
std::string undo_data(obs_data_get_json(oldSettings));
|
||||
std::string redo_data(obs_data_get_json(new_settings));
|
||||
|
||||
if (undo_data.compare(redo_data) != 0)
|
||||
main->undo_s.add_action(
|
||||
QTStr("Undo.Properties")
|
||||
.arg(obs_source_get_name(source)),
|
||||
undo_redo, undo_redo, undo_data, redo_data,
|
||||
NULL);
|
||||
|
||||
obs_data_release(new_settings);
|
||||
obs_data_release(curr_settings);
|
||||
|
||||
acceptClicked = true;
|
||||
close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user