1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Frank Felfe <innerspace@iname.com>
9 * bulia byak <buliabyak@users.sf.net>
10 * Jon A. Cruz <jon@joncruz.org>
12 * Kris De Gussem <Kris.DeGussem@gmail.com>
14 * Copyright (C) 2012 Kris De Gussem
15 * Copyright (C) 2010 authors
16 * Copyright (C) 1999-2005 authors
17 * Copyright (C) 2004 David Turner
18 * Copyright (C) 2001-2002 Ximian, Inc.
20 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
23 #include "interface.h"
25 #include <cassert> // for assert
26 #include <cstring> // for strlen
28 #include <glibmm/convert.h> // for filename_to_utf8
29 #include <glibmm/i18n.h> // for _
30 #include <glibmm/miscutils.h> // for path_get_basename, path_get_dirname
31 #include <gtk/gtk.h> // for gtk_dialog_run, gtk_widget_destroy
32 #include <gtkmm/messagedialog.h> // for MessageDialog, ButtonsType
34 #include "desktop.h" // for SPDesktop
35 #include "inkscape-application.h" // for InkscapeApplication
36 #include "inkscape-window.h"
37 #include "inkscape.h" // for Application, SP_ACTIVE_DOCUMENT
39 #include "io/sys.h" // for file_test, sanitizeString
40 #include "ui/dialog-events.h" // for sp_transientize
41 #include "ui/dialog-run.h" // for dialog_run
45 Glib::ustring
getLayoutPrefPath(SPDesktop
*desktop
)
47 if (desktop
->is_focusMode()) {
49 } else if (desktop
->is_fullscreen()) {
50 return "/fullscreen/";
56 void sp_ui_error_dialog(char const *message
)
58 auto const safeMsg
= Inkscape::IO::sanitizeString(message
);
60 auto dlg
= Gtk::MessageDialog(safeMsg
, true, Gtk::MessageType::ERROR
, Gtk::ButtonsType::CLOSE
);
63 Inkscape::UI::dialog_run(dlg
);
67 * If necessary, ask the user if a file may be overwritten.
69 * @arg filename path to file.
70 * Value is in platform-native encoding (see Glib::filename_to_utf8).
71 * @returns true if it is okay to write to the file.
72 * This means that the file does not exist yet or the user confirmed that overwriting is okay.
74 bool sp_ui_overwrite_file(std::string
const &filename
)
76 if (!g_file_test(filename
.c_str(), G_FILE_TEST_EXISTS
)) {
80 auto const basename
= Glib::filename_to_utf8(Glib::path_get_basename(filename
));
81 auto const dirname
= Glib::filename_to_utf8(Glib::path_get_dirname(filename
));
82 auto const msg
= Glib::ustring::compose(_("<span weight=\"bold\" size=\"larger\">A file named \"%1\" already exists. Do you want to replace it?</span>\n\n"
83 "The file already exists in \"%2\". Replacing it will overwrite its contents."),
86 auto window
= SP_ACTIVE_DESKTOP
->getInkscapeWindow();
87 auto dlg
= Gtk::MessageDialog(*window
, msg
, true, Gtk::MessageType::QUESTION
, Gtk::ButtonsType::NONE
);
88 dlg
.add_button(_("_Cancel"), Gtk::ResponseType::NO
);
89 dlg
.add_button(_("Replace"), Gtk::ResponseType::YES
);
90 dlg
.set_default_response(Gtk::ResponseType::YES
);
92 return Inkscape::UI::dialog_run(dlg
) == Gtk::ResponseType::YES
;
98 c-file-style:"stroustrup"
99 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
104 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :