From 3f28fd922991ab65e1fd4a558fcd471e8fdf6355 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Mon, 23 Sep 2019 12:29:25 +0200 Subject: [PATCH] confirm dialog when opening from shell --- src/app.cpp | 72 ++++++++++++++++++++++++++++++--------------- src/app_dialogs.cpp | 3 +- src/log.h | 1 + 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 83f1f98..d8e91e3 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -57,34 +57,60 @@ void App::open_document(std::string path) if (str_iequals(m[3].str(), "abr")) { - std::thread(&NodePanelBrushPreset::import_abr, presets, path).detach(); + auto mb = message_box("Import ABR", "Would you like to import the brushes?", true); + mb->on_submit = [this, path] (Node* target) { + std::thread(&NodePanelBrushPreset::import_abr, presets, path).detach(); + target->destroy(); + }; + } + else if (str_iequals(m[3].str(), "ppbr")) + { + auto mb = message_box("Import PPBR", "Would you like to import the brushes?", true); + mb->on_submit = [this, path] (Node* target) { + std::thread(&NodePanelBrushPreset::import_ppbr, presets, path).detach(); + target->destroy(); + }; } else { - doc_name = m[2].str(); - doc_dir = m[1].str(); - doc_path = path; - canvas->reset_camera(); - layers->clear(); - canvas->m_canvas->project_open(path, [this](bool success){ - // on complete - if (success) - { - title_update(); - for (int layer_index = 0; layer_index < canvas->m_canvas->m_layers.size(); layer_index++) + auto open_action = [this, path, m] { + doc_name = m[2].str(); + doc_dir = m[1].str(); + doc_path = path; + canvas->reset_camera(); + layers->clear(); + canvas->m_canvas->project_open(path, [this](bool success){ + // on complete + if (success) { - auto l = layers->add_layer(canvas->m_canvas->m_layers[layer_index]->m_name.c_str(), false); - l->m_visibility->set_value(canvas->m_canvas->m_layers[layer_index]->m_visible); + title_update(); + for (int layer_index = 0; layer_index < canvas->m_canvas->m_layers.size(); layer_index++) + { + auto l = layers->add_layer(canvas->m_canvas->m_layers[layer_index]->m_name.c_str(), false); + l->m_visibility->set_value(canvas->m_canvas->m_layers[layer_index]->m_visible); + } } - } - else - { - message_box("Open Document Error", - "There was an error opening the document.\n" - "It may be inaccessible or corrupted."); - } - }); - ActionManager::clear(); + else + { + message_box("Open Document Error", + "There was an error opening the document.\n" + "It may be inaccessible or corrupted."); + } + }); + ActionManager::clear(); + }; + if (!Canvas::I->m_unsaved) + { + open_action(); + } + else + { + auto mb = message_box("Unsaved document", "Do you want to close the unsaved document before opening the file?", true); + mb->on_submit = [this, open_action] (Node* target) { + open_action(); + target->destroy(); + }; + } } } diff --git a/src/app_dialogs.cpp b/src/app_dialogs.cpp index 1944f11..bff1d21 100644 --- a/src/app_dialogs.cpp +++ b/src/app_dialogs.cpp @@ -606,7 +606,8 @@ void App::dialog_ppbr_export() info.email = dialog->txt_email->m_text; info.descr = dialog->txt_descr->m_text; info.header_image = dialog->m_header_image; - info.export_data = dialog->export_check->checked; + if (dialog->export_check) + info.export_data = dialog->export_check->checked; #if __IOS__ App::I->pick_file_save("ppbr", [this, dialog, info] (std::string path) { diff --git a/src/log.h b/src/log.h index 5c295f7..6e7ea00 100644 --- a/src/log.h +++ b/src/log.h @@ -3,6 +3,7 @@ #ifdef __APPLE__ #define LOG(M,...) { printf(M"\n", ##__VA_ARGS__); LogRemote::I.log(M, ##__VA_ARGS__); } + #define LOGW #elif __ANDROID__ #define LOG(...) { ((void)__android_log_print(ANDROID_LOG_INFO, "PanoPainterCPP", __VA_ARGS__)); LogRemote::I.log(__VA_ARGS__); } #define LOGW