mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-24 23:31:36 +08:00
UI: Sort and pretty-print exported collections
This commit is contained in:
@@ -397,10 +397,46 @@ void OBSBasic::on_actionExportSceneCollection_triggered()
|
||||
string file = QT_TO_UTF8(exportFile);
|
||||
|
||||
if (!exportFile.isEmpty() && !exportFile.isNull()) {
|
||||
if (QFile::exists(exportFile))
|
||||
QFile::remove(exportFile);
|
||||
QString inputFile = path + currentFile + ".json";
|
||||
|
||||
QFile::copy(path + currentFile + ".json", exportFile);
|
||||
OBSDataAutoRelease collection =
|
||||
obs_data_create_from_json_file(QT_TO_UTF8(inputFile));
|
||||
|
||||
OBSDataArrayAutoRelease sources =
|
||||
obs_data_get_array(collection, "sources");
|
||||
if (!sources) {
|
||||
blog(LOG_WARNING,
|
||||
"No sources in exported scene collection");
|
||||
return;
|
||||
}
|
||||
obs_data_erase(collection, "sources");
|
||||
|
||||
// We're just using std::sort on a vector to make life easier.
|
||||
vector<OBSData> sourceItems;
|
||||
obs_data_array_enum(
|
||||
sources,
|
||||
[](obs_data_t *data, void *pVec) -> void {
|
||||
auto &sourceItems =
|
||||
*static_cast<vector<OBSData> *>(pVec);
|
||||
sourceItems.push_back(data);
|
||||
},
|
||||
&sourceItems);
|
||||
|
||||
std::sort(sourceItems.begin(), sourceItems.end(),
|
||||
[](const OBSData &a, const OBSData &b) {
|
||||
return astrcmpi(obs_data_get_string(a,
|
||||
"name"),
|
||||
obs_data_get_string(
|
||||
b, "name")) < 0;
|
||||
});
|
||||
|
||||
OBSDataArrayAutoRelease newSources = obs_data_array_create();
|
||||
for (auto &item : sourceItems)
|
||||
obs_data_array_push_back(newSources, item);
|
||||
|
||||
obs_data_set_array(collection, "sources", newSources);
|
||||
obs_data_save_json_pretty_safe(
|
||||
collection, QT_TO_UTF8(exportFile), "tmp", "bak");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user