Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
attrdialog.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Martin Owens
7 *
8 * Copyright (C) Martin Owens 2018 <doctormo@gmail.com>
9 *
10 * Released under GNU GPLv2 or later, read the file 'COPYING' for more information
11 */
12
13#ifndef SEEN_UI_DIALOGS_ATTRDIALOG_H
14#define SEEN_UI_DIALOGS_ATTRDIALOG_H
15
16#include <gtkmm/treemodel.h>
17
19#include "ui/syntax.h"
20#include "xml/node-observer.h"
21
22namespace Gtk {
23class Box;
24class Builder;
25class CellEditable;
26class CellRendererText;
27class Entry;
28class EventControllerKey;
29class Label;
30class ListStore;
31class Popover;
32class ScrolledWindow;
33class TextView;
34class TreeView;
35class TreeViewColumn;
36} // namespace Gtk
37
38namespace Inkscape {
39
40class MessageStack;
41class MessageContext;
42
43namespace UI::Dialog {
44
51 : public DialogBase
52 , private XML::NodeObserver
53{
54public:
55 AttrDialog();
56 ~AttrDialog() override;
57
58 void setRepr(Inkscape::XML::Node * repr);
59 Gtk::ScrolledWindow& get_scrolled_window() { return _scrolled_window; }
60 Gtk::Box& get_status_box() { return _status_box; }
62 void set_mono_font(bool mono);
63
64private:
65 // builder comes first, so it is initialized before other data members
66 Glib::RefPtr<Gtk::Builder> _builder;
67
68 // Data structure
69 class AttrColumns : public Gtk::TreeModel::ColumnRecord
70 {
71 public:
73 {
74 add(_attributeName);
75 add(_attributeValue);
77 }
78 Gtk::TreeModelColumn<Glib::ustring> _attributeName;
79 Gtk::TreeModelColumn<Glib::ustring> _attributeValue;
80 Gtk::TreeModelColumn<Glib::ustring> _attributeValueRender;
81 };
83
84 // TreeView
85 Gtk::TreeView& _treeView;
86 Glib::RefPtr<Gtk::ListStore> _store;
87 Gtk::CellRendererText *_nameRenderer;
88 Gtk::CellRendererText *_valueRenderer;
89 Gtk::TreeViewColumn *_nameCol;
90 Gtk::TreeViewColumn *_valueCol;
91 Gtk::Popover *_popover;
92 Glib::ustring _value_path;
93 Glib::ustring _value_editing;
94 // Status bar
95 std::unique_ptr<Inkscape::MessageStack> _message_stack;
96 std::unique_ptr<Inkscape::MessageContext> _message_context;
97 // Widgets
98 Gtk::ScrolledWindow& _scrolled_window;
99 Gtk::ScrolledWindow& _scrolled_text_view;
100 // Variables - Inkscape
102 Gtk::Box& _status_box;
103 Gtk::Label& _status;
104 bool _updating = true;
105
106 // Helper functions
107 void setUndo(Glib::ustring const &event_description);
108 void createAttribute();
109 void deleteAttribute(Gtk::TreeRow &row);
110
114 void attr_reset_context(gint attr);
115
119 sigc::scoped_connection _message_changed_connection;
120 void onCreateClicked();
121 void onAttrDelete(Glib::ustring const &path);
122 bool onTreeViewKeyPressed (unsigned keyval, unsigned keycode, Gdk::ModifierType state);
123 void onTreeViewKeyReleased(unsigned keyval, unsigned keycode, Gdk::ModifierType state);
124 void truncateDigits() const;
125 void popClosed();
126 void startNameEdit(Gtk::CellEditable *cell, const Glib::ustring &path);
127 void startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &path);
128 void nameEdited(const Glib::ustring &path, const Glib::ustring &name);
129 void valueEdited(const Glib::ustring &path, const Glib::ustring &value);
130 void valueEditedPop();
131 void storeMoveToNext(Gtk::TreeModel::Path modelpath);
132
133 // Track current CellEditable Entry:
134 Gtk::Entry *_editingEntry = nullptr;
135 bool _embedNewline = false;
136 void setEditingEntry(Gtk::Entry *entry, bool embedNewline);
137
138 // Text/comment nodes
139 Gtk::ScrolledWindow& _content_sw;
140 std::unique_ptr<Syntax::TextEditView> _text_edit; // text content editing (plain text)
141 std::unique_ptr<Syntax::TextEditView> _style_edit; // embedded CSS style (with syntax coloring)
142
143 // Attribute value editing
144 std::unique_ptr<Syntax::TextEditView> _css_edit; // in-line CSS style
145 std::unique_ptr<Syntax::TextEditView> _svgd_edit; // SVG path data
146 std::unique_ptr<Syntax::TextEditView> _points_edit; // points in a <polygon> or <polyline>
147 std::unique_ptr<Syntax::TextEditView> _attr_edit; // all other attributes (plain text)
148 Syntax::TextEditView* _current_text_edit = nullptr; // current text edit for attribute value editing
149 sigc::scoped_connection _adjust_size;
150 sigc::scoped_connection _close_popup;
152
153 bool onPopoverKeyPressed(unsigned keyval, unsigned keycode, Gdk::ModifierType state);
154
155 void setPrecision(int const n);
156
157 void notifyAttributeChanged(XML::Node &repr, GQuark name, Util::ptr_shared old_value, Util::ptr_shared new_value) final;
158 void notifyContentChanged(XML::Node &node, Util::ptr_shared old_content, Util::ptr_shared new_content) final;
159 static Glib::ustring round_numbers(const Glib::ustring& text, int precision);
160 Gtk::TextView &_activeTextView() const;
162 static std::unique_ptr<Syntax::TextEditView> init_text_view(AttrDialog* owner, Syntax::SyntaxMode coloring, bool map);
163};
164
165} // namespace UI::Dialog
166
167} // namespace Inkscape
168
169#endif // SEEN_UI_DIALOGS_ATTRDIALOG_H
170
171/*
172 Local Variables:
173 mode:c++
174 c-file-style:"stroustrup"
175 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
176 indent-tabs-mode:nil
177 fill-column:99
178 End:
179*/
180// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99:
Gtk::TreeModelColumn< Glib::ustring > _attributeValue
Definition attrdialog.h:79
Gtk::TreeModelColumn< Glib::ustring > _attributeValueRender
Definition attrdialog.h:80
Gtk::TreeModelColumn< Glib::ustring > _attributeName
Definition attrdialog.h:78
The AttrDialog class This dialog allows to add, delete and modify XML attributes created in the xml e...
Definition attrdialog.h:53
static std::unique_ptr< Syntax::TextEditView > init_text_view(AttrDialog *owner, Syntax::SyntaxMode coloring, bool map)
void setUndo(Glib::ustring const &event_description)
void startNameEdit(Gtk::CellEditable *cell, const Glib::ustring &path)
bool onTreeViewKeyPressed(unsigned keyval, unsigned keycode, Gdk::ModifierType state)
AttrDialog::onTreeViewKeyPressed Delete or create elements based on key presses.
void attr_reset_context(gint attr)
Sets the XML status bar, depending on which attr is selected.
Gtk::ScrolledWindow & _scrolled_text_view
Definition attrdialog.h:99
sigc::scoped_connection _message_changed_connection
Signal handlers.
Definition attrdialog.h:119
Gtk::TreeViewColumn * _valueCol
Definition attrdialog.h:90
Gtk::ScrolledWindow & get_scrolled_window()
Definition attrdialog.h:59
void startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &path)
Gtk::CellRendererText * _valueRenderer
Definition attrdialog.h:88
void set_current_textedit(Syntax::TextEditView *edit)
Gtk::ScrolledWindow & _scrolled_window
Definition attrdialog.h:98
void deleteAttribute(Gtk::TreeRow &row)
std::unique_ptr< Syntax::TextEditView > _points_edit
Definition attrdialog.h:146
void nameEdited(const Glib::ustring &path, const Glib::ustring &name)
Called when the name is edited in the TreeView editable column.
void notifyContentChanged(XML::Node &node, Util::ptr_shared old_content, Util::ptr_shared new_content) final
Content change callback.
void storeMoveToNext(Gtk::TreeModel::Path modelpath)
std::unique_ptr< Syntax::TextEditView > _text_edit
Definition attrdialog.h:140
static Glib::ustring round_numbers(const Glib::ustring &text, int precision)
std::unique_ptr< Inkscape::MessageContext > _message_context
Definition attrdialog.h:96
Gtk::CellRendererText * _nameRenderer
Definition attrdialog.h:87
Syntax::TextEditView * _current_text_edit
Definition attrdialog.h:148
std::unique_ptr< Syntax::TextEditView > _style_edit
Definition attrdialog.h:141
Glib::RefPtr< Gtk::Builder > _builder
Definition attrdialog.h:66
std::unique_ptr< Syntax::TextEditView > _attr_edit
Definition attrdialog.h:147
void truncateDigits() const
Round the selected floating point numbers in the attribute edit popover.
void valueEdited(const Glib::ustring &path, const Glib::ustring &value)
AttrDialog::valueEdited.
void onAttrDelete(Glib::ustring const &path)
AttrDialog::onAttrDelete.
sigc::scoped_connection _adjust_size
Definition attrdialog.h:149
void setRepr(Inkscape::XML::Node *repr)
AttrDialog::setRepr Set the internal xml object that I'm working on right now.
void notifyAttributeChanged(XML::Node &repr, GQuark name, Util::ptr_shared old_value, Util::ptr_shared new_value) final
AttrDialog::notifyAttributeChanged This is called when the XML has an updated attribute.
Gtk::TreeViewColumn * _nameCol
Definition attrdialog.h:89
std::unique_ptr< Inkscape::MessageStack > _message_stack
Definition attrdialog.h:95
sigc::scoped_connection _close_popup
Definition attrdialog.h:150
std::unique_ptr< Syntax::TextEditView > _css_edit
Definition attrdialog.h:144
Inkscape::XML::Node * _repr
Definition attrdialog.h:101
void onTreeViewKeyReleased(unsigned keyval, unsigned keycode, Gdk::ModifierType state)
void onCreateClicked()
AttrDialog::onCreateClicked This function is a slot to signal_clicked for '+' button panel.
Gtk::ScrolledWindow & _content_sw
Definition attrdialog.h:139
Gtk::TextView & _activeTextView() const
std::unique_ptr< Syntax::TextEditView > _svgd_edit
Definition attrdialog.h:145
void setEditingEntry(Gtk::Entry *entry, bool embedNewline)
bool onPopoverKeyPressed(unsigned keyval, unsigned keycode, Gdk::ModifierType state)
AttrDialog()
Constructor A treeview whose each row corresponds to an XML attribute of a selected node New attribut...
Glib::RefPtr< Gtk::ListStore > _store
Definition attrdialog.h:86
DialogBase is the base class for the dialog system.
Definition dialog-base.h:40
Base class for styled text editing widget.
Definition syntax.h:109
Interface for XML node observers.
Interface for refcounted XML nodes.
Definition node.h:80
std::unordered_map< std::string, std::unique_ptr< SPDocument > > map
A base class for all dialogs.
Inkscape::XML::Node * node
Definition desktop.h:50
SyntaxMode
Syntax highlighting mode (language).
Definition syntax.h:98
Helper class to stream background task notifications as a series of messages.
Interface for XML node observers.
guint32 GQuark
Glib::ustring name
Definition toolbars.cpp:55