UI: Add Undo/Redo for pasting multiple filters
Closes obsproject/obs-studio#4616
This commit is contained in:
parent
0fd1238d45
commit
d7e4945eab
@ -275,6 +275,7 @@ Undo.Item.Undo="Undo %1"
|
||||
Undo.Item.Redo="Redo %1"
|
||||
Undo.Sources.Multi="Delete %1 Sources"
|
||||
Undo.Filters="Filter Changes on '%1'"
|
||||
Undo.Filters.Paste.Multiple="Copy Filters from '%1' to '%2'"
|
||||
Undo.Transform="Transform source(s) In '%1'"
|
||||
Undo.Transform.Paste="Paste Transformation in '%1'"
|
||||
Undo.Transform.Rotate="Rotation In '%1'"
|
||||
|
@ -125,6 +125,12 @@ public:
|
||||
|
||||
void Init();
|
||||
|
||||
inline void UpdateSource(obs_source_t *target)
|
||||
{
|
||||
if (source == target)
|
||||
UpdateFilters();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
};
|
||||
|
@ -8464,6 +8464,44 @@ void OBSBasic::on_actionCopyFilters_triggered()
|
||||
ui->actionPasteFilters->setEnabled(true);
|
||||
}
|
||||
|
||||
void OBSBasic::CreateFilterPasteUndoRedoAction(const QString &text,
|
||||
obs_source_t *source,
|
||||
obs_data_array_t *undo_array,
|
||||
obs_data_array_t *redo_array)
|
||||
{
|
||||
auto undo_redo = [this](const std::string &json) {
|
||||
obs_data_t *data = obs_data_create_from_json(json.c_str());
|
||||
obs_data_array_t *array = obs_data_get_array(data, "array");
|
||||
const char *name = obs_data_get_string(data, "name");
|
||||
obs_source_t *source = obs_get_source_by_name(name);
|
||||
|
||||
obs_source_restore_filters(source, array);
|
||||
obs_source_release(source);
|
||||
|
||||
obs_data_array_release(array);
|
||||
obs_data_release(data);
|
||||
|
||||
if (filters)
|
||||
filters->UpdateSource(source);
|
||||
};
|
||||
|
||||
const char *name = obs_source_get_name(source);
|
||||
|
||||
obs_data_t *undo_data = obs_data_create();
|
||||
obs_data_t *redo_data = obs_data_create();
|
||||
obs_data_set_array(undo_data, "array", undo_array);
|
||||
obs_data_set_array(redo_data, "array", redo_array);
|
||||
obs_data_set_string(undo_data, "name", name);
|
||||
obs_data_set_string(redo_data, "name", name);
|
||||
|
||||
undo_s.add_action(text, undo_redo, undo_redo,
|
||||
obs_data_get_json(undo_data),
|
||||
obs_data_get_json(redo_data));
|
||||
|
||||
obs_data_release(undo_data);
|
||||
obs_data_release(redo_data);
|
||||
}
|
||||
|
||||
void OBSBasic::on_actionPasteFilters_triggered()
|
||||
{
|
||||
OBSSource source = obs_get_source_by_name(copyFiltersString);
|
||||
@ -8475,7 +8513,19 @@ void OBSBasic::on_actionPasteFilters_triggered()
|
||||
if (source == dstSource)
|
||||
return;
|
||||
|
||||
obs_data_array_t *undo_array = obs_source_backup_filters(dstSource);
|
||||
obs_source_copy_filters(dstSource, source);
|
||||
obs_data_array_t *redo_array = obs_source_backup_filters(dstSource);
|
||||
|
||||
const char *srcName = obs_source_get_name(source);
|
||||
const char *dstName = obs_source_get_name(dstSource);
|
||||
QString text =
|
||||
QTStr("Undo.Filters.Paste.Multiple").arg(srcName, dstName);
|
||||
|
||||
CreateFilterPasteUndoRedoAction(text, source, undo_array, redo_array);
|
||||
|
||||
obs_data_array_release(undo_array);
|
||||
obs_data_array_release(redo_array);
|
||||
}
|
||||
|
||||
static void ConfirmColor(SourceTree *sources, const QColor &color,
|
||||
|
@ -864,6 +864,11 @@ public:
|
||||
void CreateSceneUndoRedoAction(const QString &action_name,
|
||||
OBSData undo_data, OBSData redo_data);
|
||||
|
||||
void CreateFilterPasteUndoRedoAction(const QString &text,
|
||||
obs_source_t *source,
|
||||
obs_data_array_t *undo_array,
|
||||
obs_data_array_t *redo_array);
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
virtual void changeEvent(QEvent *event) override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user