Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
selectorsdialog.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Kamalpreet Kaur Grewal
7 * Tavmjong Bah
8 * Jabiertxof
9 *
10 * Copyright (C) Kamalpreet Kaur Grewal 2016 <grewalkamal005@gmail.com>
11 * Copyright (C) Tavmjong Bah 2017 <tavmjong@free.fr>
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#ifndef SELECTORSDIALOG_H
17#define SELECTORSDIALOG_H
18
19#include <gtkmm/paned.h>
20#include <gtkmm/scrolledwindow.h>
21#include <gtkmm/treestore.h>
22#include <gtkmm/treeview.h>
23
26#include "xml/helper-observer.h"
27
28namespace Gtk {
29class Adjustment;
30class Dialog;
31class GestureClick;
32class ToggleButton;
33class SelectionData;
34class TreeModelFilter;
35} // namespace Gtk
36
37namespace Inkscape {
38
39namespace UI::Dialog {
40
41class StyleDialog;
42
54class SelectorsDialog final : public DialogBase
55{
56public:
58 ~SelectorsDialog() final;
59
60 void update() final;
61 void desktopReplaced() final;
62 void documentReplaced() final;
64
65 private:
66 // Monitor <style> element for changes.
67 class NodeObserver;
68
69 void removeObservers();
70
71 // Monitor all objects for addition/removal/attribute change
72 class NodeWatcher;
74 void _nodeAdded( Inkscape::XML::Node &repr );
77 // Data structure
79 class ModelColumns : public Gtk::TreeModel::ColumnRecord {
80 public:
82 add(_colSelector);
83 add(_colExpand);
84 add(_colType);
85 add(_colObj);
86 add(_colProperties);
87 add(_fontWeight);
88 }
89 Gtk::TreeModelColumn<Glib::ustring> _colSelector; // Selector or matching object id.
90 Gtk::TreeModelColumn<bool> _colExpand; // Open/Close store row.
91 Gtk::TreeModelColumn<gint> _colType; // Selector row or child object row.
92 Gtk::TreeModelColumn<SPObject *> _colObj; // Matching object (if any).
93 Gtk::TreeModelColumn<Glib::ustring> _colProperties; // List of properties.
94 Gtk::TreeModelColumn<gint> _fontWeight; // Text label font weight.
95 };
97
98 // Override Gtk::TreeStore to control drag-n-drop (only allow dragging and dropping of selectors).
99 // See: https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview-examples.html.en
100 //
101 // TreeStore implements simple drag and drop (DND) but there appears no way to know when a DND
102 // has been completed (other than doing the whole DND ourselves). As a hack, we use
103 // on_row_deleted to trigger write of style element.
104 class TreeStore final : public Gtk::TreeStore {
105 protected:
107 bool row_draggable_vfunc(const Gtk::TreeModel::Path& path) const final;
108 bool row_drop_possible_vfunc(const Gtk::TreeModel::Path& path,
109 const Glib::ValueBase& selection_data) const final;
110 void on_row_deleted(const TreeModel::Path& path) final;
111
112 public:
113 static Glib::RefPtr<SelectorsDialog::TreeStore> create(SelectorsDialog *styledialog);
114
115 private:
117 };
118
119 // TreeView
120 Glib::RefPtr<Gtk::TreeModelFilter> _modelfilter;
121 Glib::RefPtr<TreeStore> _store;
122 Gtk::TreeView _treeView;
123 Gtk::TreeModel::Path _lastpath;
124 // Widgets
126 Gtk::Paned _paned;
127 Glib::RefPtr<Gtk::Adjustment> _vadj;
128 Gtk::Box _button_box;
130 Gtk::ScrolledWindow _scrolled_window_selectors;
131
132 Gtk::Button _del;
133 Gtk::Button _create;
134
135 // Reading the style element.
136 Inkscape::XML::Node *_getStyleTextNode(bool create_if_missing = false);
137 void _readStyleElement();
138
139 // Helper functions for inserting representations of CSS syntactic elements.
140 void _insertSyntacticElement(CSS::RuleStatement const &rule, bool expand, Gtk::TreeIter<Gtk::TreeRow> where);
141 void _insertSyntacticElement(CSS::BlockAtStatement const &block_at, bool expand, Gtk::TreeIter<Gtk::TreeRow> where);
142 void _insertSyntacticElement(CSS::OtherStatement const &other, bool, Gtk::TreeIter<Gtk::TreeRow> where);
143
144 // Writing the style element.
145 void _writeStyleElement();
146 Glib::ustring _formatRowAsCSS(Gtk::TreeConstRow const &row) const;
147
148 // Update watchers
149 std::unique_ptr<Inkscape::XML::NodeObserver> m_nodewatcher;
150 std::unique_ptr<Inkscape::XML::NodeObserver> m_styletextwatcher;
151
152 // Manipulate Tree
153 [[nodiscard]] std::vector<SPObject *> getSelectedObjects();
154 void _addToSelector(Gtk::TreeModel::Row row);
155 void _removeFromSelector(Gtk::TreeModel::Row row);
156 Glib::ustring _getIdList(std::vector<SPObject *>);
157 std::vector<SPObject *> _getObjVec(Glib::ustring const &selector);
158 void _insertClass(const std::vector<SPObject *>& objVec, const Glib::ustring& className);
159 void _insertClass(SPObject *obj, const Glib::ustring &className);
160 void _removeClass(const std::vector<SPObject *> &objVec, const Glib::ustring &className, bool all = false);
161 void _removeClass(SPObject *obj, const Glib::ustring &className, bool all = false);
162 void _toggleDirection(Gtk::ToggleButton *vertical);
163 void _showWidgets();
164
165 // Variables
166 double _scrollpos{0.0};
167 bool _scrollock{false};
168 bool _updating{false}; // Prevent cyclic actions: read <-> write, select via dialog <-> via desktop
170 Inkscape::XML::Node *_textNode{nullptr}; // Track so we know when to add a NodeObserver.
171
172 void _rowExpand(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path);
173 void _rowCollapse(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path);
174 void _closeDialog(Gtk::Dialog *textDialogPtr);
175
176 Inkscape::XML::SignalObserver _objObserver; // Track object in selected row (for style change).
177
178 // Signal and handlers - Internal
179 void _addSelector();
180 void _delSelector();
181 static Glib::ustring _getSelectorClasses(Glib::ustring selector);
182 void onTreeViewClickReleased(int n_press, double x, double y);
183 void _selectRow(); // Select row in tree when selection changed.
184 void _vscroll();
185
186 // GUI
187 void _styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip);
188};
189
190} // namespace UI::Dialog
191
192} // namespace Inkscape
193
194#endif // SELECTORSDIALOG_H
195
196/*
197 Local Variables:
198 mode:c++
199 c-file-style:"stroustrup"
200 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
201 indent-tabs-mode:nil
202 fill-column:99
203 End:
204*/
205// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
DialogBase is the base class for the dialog system.
Definition dialog-base.h:40
Gtk::TreeModelColumn< Glib::ustring > _colSelector
Gtk::TreeModelColumn< Glib::ustring > _colProperties
void on_row_deleted(const TreeModel::Path &path) final
bool row_drop_possible_vfunc(const Gtk::TreeModel::Path &path, const Glib::ValueBase &selection_data) const final
Allow dropping only in between other selectors.
bool row_draggable_vfunc(const Gtk::TreeModel::Path &path) const final
Allow dragging only selectors.
The SelectorsDialog class A list of CSS selectors will show up in this dialog.
void _readStyleElement()
Fill the internal Gtk::TreeStore from the svg:style element.
SelectorsDialog()
Constructor A treeview and a set of two buttons are added to the dialog.
Inkscape::XML::Node * _getStyleTextNode(bool create_if_missing=false)
void _selectRow()
This function selects the row in treeview corresponding to an object selected in the drawing.
void _insertSyntacticElement(CSS::RuleStatement const &rule, bool expand, Gtk::TreeIter< Gtk::TreeRow > where)
Populate a tree row with a representation of a CSS rule statement.
void update() final
The update() method is essential to Gtk state management.
void _styleButton(Gtk::Button &btn, char const *iconName, char const *tooltip)
void _addToSelector(Gtk::TreeModel::Row row)
void _insertClass(const std::vector< SPObject * > &objVec, const Glib::ustring &className)
Glib::RefPtr< Gtk::Adjustment > _vadj
std::vector< SPObject * > getSelectedObjects()
void _nodeChanged(Inkscape::XML::Node &repr)
void _rowExpand(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path)
Glib::ustring _formatRowAsCSS(Gtk::TreeConstRow const &row) const
Return the representation of the contents of a tree row in the dialog as a CSS string.
void _removeClass(const std::vector< SPObject * > &objVec, const Glib::ustring &className, bool all=false)
void _rowCollapse(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path)
void _writeStyleElement()
Update the content of the style element as selectors (or objects) are added/removed.
void onTreeViewClickReleased(int n_press, double x, double y)
void _nodeAdded(Inkscape::XML::Node &repr)
void _removeFromSelector(Gtk::TreeModel::Row row)
void _addSelector()
This function opens a dialog to add a selector.
void _nodeRemoved(Inkscape::XML::Node &repr)
Glib::RefPtr< Gtk::TreeModelFilter > _modelfilter
std::unique_ptr< Inkscape::XML::NodeObserver > m_styletextwatcher
std::vector< SPObject * > _getObjVec(Glib::ustring const &selector)
void desktopReplaced() final
Called when the desktop has certainly changed.
static Glib::ustring _getSelectorClasses(Glib::ustring selector)
void _delSelector()
This function deletes selector when '-' at the bottom is clicked.
void _toggleDirection(Gtk::ToggleButton *vertical)
void selectionChanged(Selection *selection) final
Inkscape::XML::SignalObserver _objObserver
void _closeDialog(Gtk::Dialog *textDialogPtr)
std::unique_ptr< Inkscape::XML::NodeObserver > m_nodewatcher
Glib::ustring _getIdList(std::vector< SPObject * >)
The StyleDialog class A list of CSS selectors will show up in this dialog.
Definition styledialog.h:64
Interface for refcounted XML nodes.
Definition node.h:80
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
A base class for all dialogs.
TODO: insert short description here.
Definition desktop.h:50
std::string OtherStatement
Another CSS statement, currently not handled in a special way; for example @charset.
Helper class to stream background task notifications as a series of messages.
A decomposed block -statement, consisting of the statement and the contents of the associated block.
A decomposed CSS rule statement, consisting of a selector (which can be complex), and the associated ...
Parsing utils capable of producing a rudimentary syntactic decomposition of a CSS stylesheet.
std::unique_ptr< Toolbar >(* create)()
Definition toolbars.cpp:56