20#include <glibmm/i18n.h>
21#include <glibmm/ustring.h>
22#include <gtkmm/messagedialog.h>
34static int run_dialog(Gtk::Window &window,
char const *
const save_text,
35 char const *
const format,
char const *
const document_name)
37 auto fmt =
'\n' + Glib::ustring(format);
38 auto const message = g_markup_printf_escaped(
fmt.c_str(), document_name);
39 auto dialog = Gtk::MessageDialog{window, message,
true, Gtk::MessageType::WARNING,
40 Gtk::ButtonsType::NONE};
43 dialog.property_destroy_with_parent() =
true;
46 auto const ma = dialog.get_message_area();
49 ma_labels.at(0)->set_focusable(
false);
51 dialog.set_title(_(
"Save Document"));
52 dialog.add_button(_(
"Close _without saving"), Gtk::ResponseType::NO);
53 dialog.add_button(_(
"_Cancel"), Gtk::ResponseType::CANCEL);
54 dialog.add_button(_(save_text), Gtk::ResponseType::YES);
55 dialog.set_default_response(Gtk::ResponseType::YES);
71 if (document->isModifiedSinceSave()) {
74 int const response =
run_dialog(*window, _(
"_Save"),
75 _(
"<span weight=\"bold\" size=\"larger\">Save changes to document \"%s\" before closing?</span>\n\n"
76 "If you close without saving, your changes will be discarded."),
77 document->getDocumentName());
80 case GTK_RESPONSE_YES:
99 bool allow_data_loss =
false;
100 while (document->getReprRoot()->attribute(
"inkscape:dataloss") !=
nullptr && allow_data_loss ==
false) {
103 int const response =
run_dialog(*window, _(
"_Save as Inkscape SVG"),
104 _(
"<span weight=\"bold\" size=\"larger\">The file \"%s\" was saved with a format that may cause data loss!</span>\n\n"
105 "Do you want to save this file as Inkscape SVG?"),
106 document->getDocumentName() ? document->getDocumentName() :
"Unnamed");
109 case GTK_RESPONSE_YES:
118 case GTK_RESPONSE_NO:
119 allow_data_loss =
true;
To do: update description of desktop.
SPDocument * getDocument() const
InkscapeWindow const * getInkscapeWindow() const
Editable view implementation.
bool document_check_for_data_loss(SPDesktop *desktop)
Check if closing document associated with window will cause data loss, and if so opens a dialog that ...
static int run_dialog(Gtk::Window &window, char const *const save_text, char const *const format, char const *const document_name)
bool sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extension::FileSaveMethod save_method)
Display a SaveAs dialog.
bool sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc)
Save a document, displaying a SaveAs dialog if necessary.
Inkscape - An SVG editor.
@ FILE_SAVE_METHOD_INKSCAPE_SVG
std::vector< Gtk::Widget * > get_children(Gtk::Widget &widget)
Get a vector of the widgetʼs children, from get_first_child() through each get_next_sibling().
int dialog_run(Gtk::Dialog &dialog)
This is a GTK4 porting aid meant to replace the removal of the Gtk::Dialog synchronous API.
void sp_namedview_document_from_window(SPDesktop *desktop)