Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
builder-utils.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Michael Kowalski <michal_kowalski@hotmail.com>
7 * Daniel Boles <dboles.src+inkscape@gmail.com>
8 *
9 * Copyright (C) 2021 Michael Kowalski <michal_kowalski@hotmail.com>
10 * Copyright (C) 2023 Daniel Boles
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
14#include <stdexcept>
15#include <glibmm/error.h>
16#include <glibmm/ustring.h>
17
18#include "builder-utils.h"
19#include "io/resource.h"
20
21namespace Inkscape {
22namespace UI {
23
24namespace Detail {
25
26void throw_missing(const char* object_type, const char* id)
27{
28 // TODO: GTK4: Include builder->get_current_object()
29 auto what = Glib::ustring::compose(
30 "Missing %1 `%2` in Gtk::Builder glade/ui resource file", object_type, id);
31 throw std::runtime_error{what.raw()};
32}
33
34} // namespace Detail
35
36Glib::RefPtr<Gtk::Builder> create_builder(const char* filename) {
38 Glib::RefPtr<Gtk::Builder> builder;
39 try {
40 return Gtk::Builder::create_from_file(glade);
41 }
42 catch (Glib::Error& ex) {
43 g_error("Cannot load glade file: %s", ex.what());
44 throw;
45 }
46}
47
48bool hide_widget(const Glib::RefPtr<Gtk::Builder> &builder, std::string const &id)
49{
50 auto widget = builder->get_widget<Gtk::Widget>(id);
51 if (widget) {
52 widget->set_visible(false);
53 return true;
54 }
55 return false;
56}
57
58} } // namespace Inkscape::UI
59
60/*
61 Local Variables:
62 mode:c++
63 c-file-style:"stroustrup"
64 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
65 indent-tabs-mode:nil
66 fill-column:99
67 End:
68*/
69// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99:
Gtk builder utilities.
std::string get_filename(Type type, char const *filename, bool localized, bool silent)
Definition resource.cpp:170
void throw_missing(const char *object_type, const char *id)
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
bool hide_widget(const Glib::RefPtr< Gtk::Builder > &builder, std::string const &id)
Helper class to stream background task notifications as a series of messages.
Inkscape::IO::Resource - simple resource API.
Glib::RefPtr< Gtk::Builder > builder