Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
interface.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6/* Authors:
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>
11 * Abhishek Sharma
12 * Kris De Gussem <Kris.DeGussem@gmail.com>
13 *
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.
19 *
20 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
21 */
22
23#include "interface.h"
24
25#include <cassert> // for assert
26#include <cstring> // for strlen
27
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
33
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
38
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
42
43class SPDocument;
44
46{
47 if (desktop->is_focusMode()) {
48 return "/focus/";
49 } else if (desktop->is_fullscreen()) {
50 return "/fullscreen/";
51 } else {
52 return "/window/";
53 }
54}
55
56void sp_ui_error_dialog(char const *message)
57{
58 auto const safeMsg = Inkscape::IO::sanitizeString(message);
59
60 auto dlg = Gtk::MessageDialog(safeMsg, true, Gtk::MessageType::ERROR, Gtk::ButtonsType::CLOSE);
61 sp_transientize(dlg);
62
64}
65
74bool sp_ui_overwrite_file(std::string const &filename)
75{
76 if (!g_file_test(filename.c_str(), G_FILE_TEST_EXISTS)) {
77 return true;
78 }
79
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."),
84 basename, dirname);
85
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);
91
92 return Inkscape::UI::dialog_run(dlg) == Gtk::ResponseType::YES;
93}
94
95/*
96 Local Variables:
97 mode:c++
98 c-file-style:"stroustrup"
99 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
100 indent-tabs-mode:nil
101 fill-column:99
102 End:
103*/
104// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
To do: update description of desktop.
Definition desktop.h:149
bool is_fullscreen() const
Definition desktop.cpp:929
bool is_focusMode() const
Checks to see if the user is working in focused mode.
Definition desktop.cpp:939
Typed SVG document implementation.
Definition document.h:101
Glib::ustring msg
Editable view implementation.
void sp_transientize(Gtk::Window &window)
Make the argument dialog transient to the currently active document window.
Event handler for dialog windows.
Inkscape - An SVG editor.
void sp_ui_error_dialog(char const *message)
Definition interface.cpp:56
Glib::ustring getLayoutPrefPath(SPDesktop *desktop)
Definition interface.cpp:45
bool sp_ui_overwrite_file(std::string const &filename)
If necessary, ask the user if a file may be overwritten.
Definition interface.cpp:74
Glib::ustring sanitizeString(char const *str)
Definition sys.cpp:183
int dialog_run(Gtk::Dialog &dialog)
This is a GTK4 porting aid meant to replace the removal of the Gtk::Dialog synchronous API.
SPDesktop * desktop