Plan new document creation in app core

This commit is contained in:
2026-06-02 23:14:35 +02:00
parent fd1772a417
commit 853307697a
10 changed files with 284 additions and 21 deletions

View File

@@ -2,6 +2,7 @@
#include "app.h"
#include "action.h"
#include "app_core/document_export.h"
#include "app_core/document_session.h"
#include "settings.h"
#include "node_dialog_open.h"
#include "node_dialog_browse.h"
@@ -158,24 +159,32 @@ void App::dialog_newdoc()
dialog->btn_ok->on_click = [this, dialog](Node*)
{
std::string name = dialog->input->m_text;
const auto target = pp::app::make_document_file_target(work_path, name);
if (!target)
const auto plan = pp::app::plan_new_document(
work_path,
name,
dialog->m_resolution->m_current_index,
[](const std::string& path) {
return Asset::exist(path);
});
if (!plan)
{
message_box("Warning", "You need to specify a name to file.");
const bool missing_name =
plan.status().code == pp::foundation::StatusCode::invalid_argument;
message_box(
"Warning",
missing_name ? "You need to specify a name to file." : plan.status().message);
return;
}
auto action = [this, dialog, target = target.value()] {
std::array<int, 6> resolutions{ 512, 1024, 1536, 2048, 4096, 8192 };
int res = resolutions[dialog->m_resolution->m_current_index];
doc_name = target.name;
doc_path = target.path;
doc_filename = target.name + ".ppi";
doc_dir = target.directory;
auto action = [this, dialog, plan = plan.value()] {
doc_name = plan.target.name;
doc_path = plan.target.path;
doc_filename = plan.target.name + ".ppi";
doc_dir = plan.target.directory;
layers->clear();
canvas->m_canvas->m_layers.clear();
canvas->m_canvas->resize(res, res);
canvas->m_canvas->resize(plan.resolution, plan.resolution);
canvas->reset_camera();
ActionManager::clear();
@@ -189,8 +198,7 @@ void App::dialog_newdoc()
App::I->hideKeyboard();
};
const auto write_decision = pp::app::plan_document_file_write(Asset::exist(target.value().path));
if (write_decision == pp::app::DocumentFileWriteDecision::prompt_overwrite)
if (plan.value().write_decision == pp::app::DocumentFileWriteDecision::prompt_overwrite)
{
// ask confirm is file already exist
auto msgbox = new NodeMessageBox();