Move project save post-commit planning to app core
This commit is contained in:
@@ -135,6 +135,21 @@ struct DocumentCanvasProjectSaveCommitPlan {
|
||||
std::string_view log_message;
|
||||
};
|
||||
|
||||
struct DocumentCanvasProjectSavePostCommitInput {
|
||||
bool save_succeeded = false;
|
||||
bool timelapse_encoder_available = false;
|
||||
bool progress_ui_visible = false;
|
||||
};
|
||||
|
||||
struct DocumentCanvasProjectSavePostCommitPlan {
|
||||
bool marks_document_clean = false;
|
||||
bool marks_new_document_committed = false;
|
||||
bool saves_timelapse_sidecar = false;
|
||||
bool flushes_platform_storage = false;
|
||||
bool dismisses_progress_ui = false;
|
||||
bool updates_title = true;
|
||||
};
|
||||
|
||||
class DocumentCanvasClearServices {
|
||||
public:
|
||||
virtual ~DocumentCanvasClearServices() = default;
|
||||
@@ -444,6 +459,23 @@ plan_document_canvas_project_save_write(
|
||||
return plan;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr DocumentCanvasProjectSavePostCommitPlan plan_document_canvas_project_save_post_commit(
|
||||
DocumentCanvasProjectSavePostCommitInput input) noexcept
|
||||
{
|
||||
DocumentCanvasProjectSavePostCommitPlan plan;
|
||||
plan.dismisses_progress_ui = input.progress_ui_visible;
|
||||
|
||||
if (!input.save_succeeded) {
|
||||
return plan;
|
||||
}
|
||||
|
||||
plan.marks_document_clean = true;
|
||||
plan.marks_new_document_committed = true;
|
||||
plan.saves_timelapse_sidecar = input.timelapse_encoder_available;
|
||||
plan.flushes_platform_storage = true;
|
||||
return plan;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<DocumentCanvasClearPlan> plan_document_canvas_clear(
|
||||
bool has_canvas,
|
||||
float r = 0.0F,
|
||||
|
||||
@@ -2577,32 +2577,50 @@ bool Canvas::project_save_thread(std::string file_path, bool show_progress)
|
||||
LOG("project saved to %s", file_path.c_str());
|
||||
}
|
||||
|
||||
if (success)
|
||||
const auto post_commit_plan = pp::app::plan_document_canvas_project_save_post_commit(
|
||||
pp::app::DocumentCanvasProjectSavePostCommitInput {
|
||||
.save_succeeded = success,
|
||||
.timelapse_encoder_available = Canvas::I->m_encoder != nullptr,
|
||||
.progress_ui_visible = show_progress,
|
||||
});
|
||||
|
||||
if (post_commit_plan.marks_document_clean)
|
||||
{
|
||||
m_unsaved = false;
|
||||
}
|
||||
if (post_commit_plan.marks_new_document_committed)
|
||||
{
|
||||
m_newdoc = false;
|
||||
}
|
||||
|
||||
// save timelapse
|
||||
if (Canvas::I->m_encoder)
|
||||
{
|
||||
BinaryStreamWriter sw;
|
||||
sw.init(BinaryStream::ByteOrder::LittleEndian);
|
||||
Serializer::Descriptor info;
|
||||
info.class_id = "tracks-info";
|
||||
info.name = L"Timelapse Tracks";
|
||||
info.props["has-track-360"] = std::make_shared<Serializer::Boolean>(true);
|
||||
info.props["version"] = std::make_shared<Serializer::Integer>(1);
|
||||
sw << info;
|
||||
sw << *Canvas::I->m_encoder;
|
||||
if (!sw.save(lapse_path))
|
||||
LOG("cannot save timelase to %s", lapse_path.c_str());
|
||||
}
|
||||
if (post_commit_plan.saves_timelapse_sidecar)
|
||||
{
|
||||
BinaryStreamWriter sw;
|
||||
sw.init(BinaryStream::ByteOrder::LittleEndian);
|
||||
Serializer::Descriptor info;
|
||||
info.class_id = "tracks-info";
|
||||
info.name = L"Timelapse Tracks";
|
||||
info.props["has-track-360"] = std::make_shared<Serializer::Boolean>(true);
|
||||
info.props["version"] = std::make_shared<Serializer::Integer>(1);
|
||||
sw << info;
|
||||
sw << *Canvas::I->m_encoder;
|
||||
if (!sw.save(lapse_path))
|
||||
LOG("cannot save timelase to %s", lapse_path.c_str());
|
||||
}
|
||||
|
||||
if (post_commit_plan.flushes_platform_storage)
|
||||
{
|
||||
App::I->flush_platform_storage();
|
||||
}
|
||||
|
||||
if (show_progress)
|
||||
if (post_commit_plan.dismisses_progress_ui)
|
||||
{
|
||||
pb->destroy();
|
||||
App::I->title_update();
|
||||
}
|
||||
if (post_commit_plan.updates_title)
|
||||
{
|
||||
App::I->title_update();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user