Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
entity-entry.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * bulia byak <buliabyak@users.sf.net>
5 * Bryce W. Harrington <bryce@bryceharrington.org>
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Jon Phillips <jon@rejon.org>
8 * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
9 * Jon A. Cruz <jon@joncruz.org>
10 * Abhishek Sharma
11 *
12 * Copyright (C) 2000 - 2005 Authors
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#include "entity-entry.h"
18
19#include <gtkmm/scrolledwindow.h>
20#include <gtkmm/entry.h>
21
22#include "desktop.h"
23#include "document.h"
24#include "document-undo.h"
25#include "preferences.h"
26#include "rdf.h"
27
28#include "object/sp-root.h"
29
30#include "ui/widget/registry.h"
31
32namespace Inkscape {
33namespace UI {
34namespace Widget {
35
36//===================================================
37
38//---------------------------------------------------
39
40EntityEntry*
42{
43 g_assert (ent);
44 EntityEntry* obj = nullptr;
45 switch (ent->format)
46 {
47 case RDF_FORMAT_LINE:
48 obj = new EntityLineEntry (ent, wr);
49 break;
51 obj = new EntityMultiLineEntry (ent, wr);
52 break;
53 default:
54 g_warning ("An unknown RDF format was requested.");
55 }
56
57 g_assert (obj);
58 obj->_label.set_visible(true);
59 return obj;
60}
61
63 : _label(Glib::ustring(_(ent->title)), Gtk::Align::END),
64 _packable(nullptr),
65 _entity(ent), _wr(&wr)
66{
67}
68
73
75{
77 const gchar *text = rdf_get_work_entity (doc, _entity);
78 prefs->setString(PREFS_METADATA + Glib::ustring(_entity->name), Glib::ustring(text ? text : ""));
79}
80
82: EntityEntry (ent, wr)
83{
84 Gtk::Entry *e = new Gtk::Entry;
85 e->set_tooltip_text (_(ent->tip));
86 _packable = e;
87 _changed_connection = e->signal_changed().connect (sigc::mem_fun (*this, &EntityLineEntry::on_changed));
88}
89
91{
92 delete static_cast<Gtk::Entry*>(_packable);
93}
94
95void EntityLineEntry::update(SPDocument* doc, bool read_only)
96{
97 const char *text = rdf_get_work_entity(doc, _entity);
98 // If RDF title is not set, get the document's <title> and set the RDF:
99 if (!text && !strcmp(_entity->name, "title") && doc->getRoot()) {
100 text = doc->getRoot()->title();
101 if (!read_only) {
102 rdf_set_work_entity(doc, _entity, text);
103 }
104 }
105 static_cast<Gtk::Entry*>(_packable)->set_text(text ? text : "");
106}
107
108
110{
112 Glib::ustring text = prefs->getString(PREFS_METADATA + Glib::ustring(_entity->name));
113 if (text.length() > 0) {
114 static_cast<Gtk::Entry*>(_packable)->set_text (text.c_str());
115 }
116}
117
118void
120{
121 if (_wr->isUpdating() || !_wr->desktop())
122 return;
123
124 _wr->setUpdating (true);
125 SPDocument *doc = _wr->desktop()->getDocument();
126 Glib::ustring text = static_cast<Gtk::Entry*>(_packable)->get_text();
127 if (rdf_set_work_entity (doc, _entity, text.c_str())) {
128 if (doc->isSensitive()) {
129 DocumentUndo::done(doc, "Document metadata updated", "");
130 }
131 }
132 _wr->setUpdating (false);
133}
134
135Glib::ustring EntityLineEntry::content() const {
136 return static_cast<Gtk::Entry*>(_packable)->get_text();
137}
138
140: EntityEntry (ent, wr)
141{
142 Gtk::ScrolledWindow *s = new Gtk::ScrolledWindow;
143 s->set_policy (Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
144 s->set_has_frame(true);
145 _packable = s;
146 _v.set_size_request (-1, 35);
147 _v.set_wrap_mode (Gtk::WrapMode::WORD);
148 _v.set_accepts_tab (false);
149 s->set_child(_v);
150 _v.set_tooltip_text (_(ent->tip));
151 _changed_connection = _v.get_buffer()->signal_changed().connect (sigc::mem_fun (*this, &EntityMultiLineEntry::on_changed));
152}
153
154Glib::ustring EntityMultiLineEntry::content() const {
155 return _v.get_buffer()->get_text();
156}
157
159{
160 delete static_cast<Gtk::ScrolledWindow*>(_packable);
161}
162
163void EntityMultiLineEntry::update(SPDocument* doc, bool read_only)
164{
165 const char *text = rdf_get_work_entity(doc, _entity);
166 // If RDF title is not set, get the document's <title> and set the RDF:
167 if (!text && !strcmp(_entity->name, "title") && doc->getRoot()) {
168 text = doc->getRoot()->title();
169 if (!read_only) {
170 rdf_set_work_entity(doc, _entity, text);
171 }
172 }
173 Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable);
174 Gtk::TextView *tv = static_cast<Gtk::TextView*>(s->get_child());
175 tv->get_buffer()->set_text(text ? text : "");
176}
177
178
180{
182 Glib::ustring text = prefs->getString(PREFS_METADATA + Glib::ustring(_entity->name));
183 if (text.length() > 0) {
184 Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable);
185 Gtk::TextView *tv = static_cast<Gtk::TextView*>(s->get_child());
186 tv->get_buffer()->set_text (text.c_str());
187 }
188}
189
190
191void
193{
194 if (_wr->isUpdating() || !_wr->desktop())
195 return;
196
197 _wr->setUpdating (true);
198 SPDocument *doc = _wr->desktop()->getDocument();
199 Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable);
200 Gtk::TextView *tv = static_cast<Gtk::TextView*>(s->get_child());
201 Glib::ustring text = tv->get_buffer()->get_text();
202 if (rdf_set_work_entity (doc, _entity, text.c_str())) {
203 DocumentUndo::done(doc, "Document metadata updated", "");
204 }
205 _wr->setUpdating (false);
206}
207
208} // namespace Dialog
209} // namespace UI
210} // namespace Inkscape
211
212/*
213 Local Variables:
214 mode:c++
215 c-file-style:"stroustrup"
216 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
217 indent-tabs-mode:nil
218 fill-column:99
219 End:
220*/
221// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
Preference storage class.
Definition preferences.h:61
Glib::ustring getString(Glib::ustring const &pref_path, Glib::ustring const &def="")
Retrieve an UTF-8 string.
static Preferences * get()
Access the singleton Preferences object.
void setString(Glib::ustring const &pref_path, Glib::ustring const &value)
Set an UTF-8 string value.
void save_to_preferences(SPDocument *doc)
static EntityEntry * create(rdf_work_entity_t *ent, Registry &wr)
EntityEntry(rdf_work_entity_t *ent, Registry &wr)
Glib::ustring content() const override
EntityLineEntry(rdf_work_entity_t *ent, Registry &wr)
void update(SPDocument *doc, bool read_only) override
void update(SPDocument *doc, bool read_only) override
EntityMultiLineEntry(rdf_work_entity_t *ent, Registry &wr)
Glib::ustring content() const override
SPDesktop * desktop() const
Definition registry.h:27
SPDocument * getDocument() const
Definition desktop.h:189
Typed SVG document implementation.
Definition document.h:101
SPRoot * getRoot()
Returns our SPRoot.
Definition document.h:200
bool isSensitive() const
Definition document.h:363
char * title() const
Returns the title of this object, or NULL if there is none.
Editable view implementation.
TODO: insert short description here.
Definition desktop.h:50
static char const * get_text(Gtk::Editable const &editable)
Helper class to stream background task notifications as a series of messages.
Singleton class to access the preferences file in a convenient way.
unsigned int rdf_set_work_entity(SPDocument *doc, struct rdf_work_entity_t *entity, const gchar *text)
Definition rdf.cpp:914
const gchar * rdf_get_work_entity(SPDocument const *doc, struct rdf_work_entity_t *entity)
Retrieves a known RDF/Work entity's contents from the document XML by name.
Definition rdf.cpp:885
headers for RDF types
constexpr auto PREFS_METADATA
Definition rdf.h:19
@ RDF_FORMAT_MULTILINE
Definition rdf.h:58
@ RDF_FORMAT_LINE
Definition rdf.h:57
SPRoot: SVG <svg> implementation.
Holds known RDF/Work tags.
Definition rdf.h:71
char const * tip
Definition rdf.h:76
RDF_Format format
Definition rdf.h:77
char const * name
Definition rdf.h:72