Route app save decisions through app core
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "node_input_box.h"
|
||||
#include "node_panel_animation.h"
|
||||
#include "layout.h"
|
||||
#include "app_core/document_session.h"
|
||||
|
||||
#if defined(__OBJC__) && defined(__IOS__)
|
||||
#import <Foundation/Foundation.h>
|
||||
@@ -248,6 +249,7 @@ public:
|
||||
void dialog_usermanual();
|
||||
void dialog_changelog();
|
||||
void dialog_about();
|
||||
void save_document(pp::app::DocumentSaveIntent intent);
|
||||
void dialog_newdoc();
|
||||
void dialog_save();
|
||||
void dialog_save_ver();
|
||||
|
||||
@@ -13,6 +13,20 @@ enum class CloseRequestDecision {
|
||||
wait_for_existing_prompt,
|
||||
};
|
||||
|
||||
enum class DocumentSaveIntent {
|
||||
save,
|
||||
save_as,
|
||||
save_version,
|
||||
save_dirty_version,
|
||||
};
|
||||
|
||||
enum class DocumentSaveDecision {
|
||||
no_op,
|
||||
show_save_dialog,
|
||||
save_existing,
|
||||
save_version,
|
||||
};
|
||||
|
||||
[[nodiscard]] constexpr ProjectOpenDecision plan_project_open(bool has_unsaved_changes) noexcept
|
||||
{
|
||||
return has_unsaved_changes
|
||||
@@ -33,4 +47,35 @@ enum class CloseRequestDecision {
|
||||
: CloseRequestDecision::show_unsaved_prompt;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr DocumentSaveDecision plan_document_save(
|
||||
bool is_new_document,
|
||||
bool has_unsaved_changes,
|
||||
DocumentSaveIntent intent) noexcept
|
||||
{
|
||||
switch (intent) {
|
||||
case DocumentSaveIntent::save:
|
||||
if (is_new_document) {
|
||||
return DocumentSaveDecision::show_save_dialog;
|
||||
}
|
||||
return has_unsaved_changes
|
||||
? DocumentSaveDecision::save_existing
|
||||
: DocumentSaveDecision::no_op;
|
||||
case DocumentSaveIntent::save_as:
|
||||
return DocumentSaveDecision::show_save_dialog;
|
||||
case DocumentSaveIntent::save_version:
|
||||
return is_new_document
|
||||
? DocumentSaveDecision::show_save_dialog
|
||||
: DocumentSaveDecision::save_version;
|
||||
case DocumentSaveIntent::save_dirty_version:
|
||||
if (is_new_document) {
|
||||
return DocumentSaveDecision::show_save_dialog;
|
||||
}
|
||||
return has_unsaved_changes
|
||||
? DocumentSaveDecision::save_version
|
||||
: DocumentSaveDecision::no_op;
|
||||
}
|
||||
|
||||
return DocumentSaveDecision::no_op;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -366,6 +366,27 @@ void App::dialog_save_ver()
|
||||
canvas->m_canvas->project_save(doc_path);
|
||||
}
|
||||
|
||||
void App::save_document(pp::app::DocumentSaveIntent intent)
|
||||
{
|
||||
const auto decision = pp::app::plan_document_save(
|
||||
Canvas::I->m_newdoc,
|
||||
Canvas::I->m_unsaved,
|
||||
intent);
|
||||
switch (decision) {
|
||||
case pp::app::DocumentSaveDecision::show_save_dialog:
|
||||
dialog_save();
|
||||
break;
|
||||
case pp::app::DocumentSaveDecision::save_existing:
|
||||
Canvas::I->project_save();
|
||||
break;
|
||||
case pp::app::DocumentSaveDecision::save_version:
|
||||
dialog_save_ver();
|
||||
break;
|
||||
case pp::app::DocumentSaveDecision::no_op:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void App::dialog_save()
|
||||
{
|
||||
if (!check_license())
|
||||
|
||||
@@ -586,26 +586,19 @@ void App::init_menu_file()
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-save"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
if (Canvas::I->m_newdoc)
|
||||
{
|
||||
dialog_save();
|
||||
}
|
||||
else if(Canvas::I->m_unsaved)
|
||||
{
|
||||
canvas->m_canvas->project_save();
|
||||
}
|
||||
save_document(pp::app::DocumentSaveIntent::save);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-save-as"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
dialog_save();
|
||||
save_document(pp::app::DocumentSaveIntent::save_as);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-save-ver"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
Canvas::I->m_newdoc ? dialog_save() : dialog_save_ver();
|
||||
save_document(pp::app::DocumentSaveIntent::save_version);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
|
||||
@@ -617,25 +617,11 @@ kEventResult NodeCanvas::handle_event(Event* e)
|
||||
App::I->keys[(int)kKey::KeyShift] ? ActionManager::redo() : ActionManager::undo();
|
||||
if (ke->m_key == kKey::KeyS && App::I->keys[(int)kKey::KeyCtrl] && !App::I->keys[(int)kKey::KeyShift])
|
||||
{
|
||||
if (Canvas::I->m_newdoc)
|
||||
{
|
||||
App::I->dialog_save();
|
||||
}
|
||||
else if (Canvas::I->m_unsaved)
|
||||
{
|
||||
Canvas::I->project_save();
|
||||
}
|
||||
App::I->save_document(pp::app::DocumentSaveIntent::save);
|
||||
}
|
||||
if (ke->m_key == kKey::KeyS && App::I->keys[(int)kKey::KeyCtrl] && App::I->keys[(int)kKey::KeyShift])
|
||||
{
|
||||
if (Canvas::I->m_newdoc)
|
||||
{
|
||||
App::I->dialog_save();
|
||||
}
|
||||
else if (Canvas::I->m_unsaved)
|
||||
{
|
||||
App::I->dialog_save_ver();
|
||||
}
|
||||
App::I->save_document(pp::app::DocumentSaveIntent::save_dirty_version);
|
||||
}
|
||||
if (ke->m_key == kKey::KeyBracketLeft)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user