diff options
Diffstat (limited to 'src/ui/dialog/styledialog.cpp')
| -rw-r--r-- | src/ui/dialog/styledialog.cpp | 437 |
1 files changed, 214 insertions, 223 deletions
diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index adab927fb..b7eec923c 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -13,24 +13,23 @@ */ #include "styledialog.h" -#include "attributes.h" -#include "verbs.h" -#include "selection.h" #include "attribute-rel-svg.h" -#include "inkscape.h" +#include "attributes.h" #include "document-undo.h" +#include "inkscape.h" +#include "io/resource.h" #include "selection.h" #include "style-internal.h" #include "style.h" -#include "io/resource.h" #include "ui/icon-loader.h" #include "ui/widget/iconrenderer.h" +#include "verbs.h" #include "xml/attribute-record.h" #include "xml/node-observer.h" -#include <regex> #include <map> +#include <regex> #include <utility> #include <glibmm/i18n.h> @@ -46,7 +45,8 @@ using Inkscape::XML::AttributeRecord; * This macro is used to remove spaces around selectors or any strings when * parsing is done to update XML style element or row labels in this dialog. */ -#define REMOVE_SPACES(x) x.erase(0, x.find_first_not_of(' ')); \ +#define REMOVE_SPACES(x) \ + x.erase(0, x.find_first_not_of(' ')); \ x.erase(x.find_last_not_of(' ') + 1); namespace Inkscape { @@ -55,26 +55,24 @@ namespace Dialog { // Keeps a watch on style element class StyleDialog::NodeObserver : public Inkscape::XML::NodeObserver { -public: - NodeObserver(StyleDialog* styledialog) : - _styledialog(styledialog) + public: + NodeObserver(StyleDialog *styledialog) + : _styledialog(styledialog) { g_debug("StyleDialog::NodeObserver: Constructor"); }; - void notifyContentChanged(Inkscape::XML::Node &node, - Inkscape::Util::ptr_shared old_content, - Inkscape::Util::ptr_shared new_content) override; + void notifyContentChanged(Inkscape::XML::Node &node, Inkscape::Util::ptr_shared old_content, + Inkscape::Util::ptr_shared new_content) override; - StyleDialog * _styledialog; + StyleDialog *_styledialog; }; -void -StyleDialog::NodeObserver::notifyContentChanged( - Inkscape::XML::Node &/*node*/, - Inkscape::Util::ptr_shared /*old_content*/, - Inkscape::Util::ptr_shared /*new_content*/ ) { +void StyleDialog::NodeObserver::notifyContentChanged(Inkscape::XML::Node & /*node*/, + Inkscape::Util::ptr_shared /*old_content*/, + Inkscape::Util::ptr_shared /*new_content*/) +{ g_debug("StyleDialog::NodeObserver::notifyContentChanged"); _styledialog->_updating = false; @@ -85,61 +83,58 @@ StyleDialog::NodeObserver::notifyContentChanged( // Keeps a watch for new/removed/changed nodes // (Must update objects that selectors match.) class StyleDialog::NodeWatcher : public Inkscape::XML::NodeObserver { -public: - NodeWatcher(StyleDialog* styledialog, Inkscape::XML::Node *repr) : - _styledialog(styledialog), - _repr(repr) + public: + NodeWatcher(StyleDialog *styledialog, Inkscape::XML::Node *repr) + : _styledialog(styledialog) + , _repr(repr) { g_debug("StyleDialog::NodeWatcher: Constructor"); }; - void notifyChildAdded( Inkscape::XML::Node &/*node*/, - Inkscape::XML::Node &child, - Inkscape::XML::Node */*prev*/ ) override + void notifyChildAdded(Inkscape::XML::Node & /*node*/, Inkscape::XML::Node &child, + Inkscape::XML::Node * /*prev*/) override { - if ( _styledialog && _repr ) { - _styledialog->_nodeAdded( child ); + if (_styledialog && _repr) { + _styledialog->_nodeAdded(child); } } - void notifyChildRemoved( Inkscape::XML::Node &/*node*/, - Inkscape::XML::Node &child, - Inkscape::XML::Node */*prev*/ ) override + void notifyChildRemoved(Inkscape::XML::Node & /*node*/, Inkscape::XML::Node &child, + Inkscape::XML::Node * /*prev*/) override { - if ( _styledialog && _repr ) { - _styledialog->_nodeRemoved( child ); + if (_styledialog && _repr) { + _styledialog->_nodeRemoved(child); } } -/* void notifyContentChanged(Inkscape::XML::Node &node, - Inkscape::Util::ptr_shared old_content, - Inkscape::Util::ptr_shared new_content) override{ - if ( _styledialog && _repr && _textNode == node) { - _styledialog->_stylesheetChanged( node ); - } - }; - */ - void notifyAttributeChanged( Inkscape::XML::Node &node, - GQuark qname, - Util::ptr_shared /*old_value*/, - Util::ptr_shared /*new_value*/ ) override { - if ( _styledialog && _repr ) { + /* void notifyContentChanged(Inkscape::XML::Node &node, + Inkscape::Util::ptr_shared old_content, + Inkscape::Util::ptr_shared new_content) override{ + if ( _styledialog && _repr && _textNode == node) { + _styledialog->_stylesheetChanged( node ); + } + }; + */ + void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark qname, Util::ptr_shared /*old_value*/, + Util::ptr_shared /*new_value*/) override + { + if (_styledialog && _repr) { // For the moment only care about attributes that are directly used in selectors. - const gchar * cname = g_quark_to_string (qname); + const gchar *cname = g_quark_to_string(qname); Glib::ustring name; if (cname) { name = cname; } - if ( name == "id" || name == "class" || name == "style" ) { - _styledialog->_nodeChanged( node ); + if (name == "id" || name == "class" || name == "style") { + _styledialog->_nodeChanged(node); } SPObject *obj = SP_ACTIVE_DOCUMENT->getObjectById(node.attribute("id")); if (obj) { for (auto iter : obj->style->properties()) { if (iter->style_src != SP_STYLE_SRC_UNSET) { - if( iter->name == name) { - _styledialog->_nodeChanged( node ); + if (iter->name == name) { + _styledialog->_nodeChanged(node); } } } @@ -147,37 +142,34 @@ public: } } - StyleDialog * _styledialog; - Inkscape::XML::Node * _repr; // Need to track if document changes. + StyleDialog *_styledialog; + Inkscape::XML::Node *_repr; // Need to track if document changes. }; -void -StyleDialog::_nodeAdded( Inkscape::XML::Node &node ) { +void StyleDialog::_nodeAdded(Inkscape::XML::Node &node) +{ - StyleDialog::NodeWatcher *w = new StyleDialog::NodeWatcher (this, &node); - node.addObserver (*w); + StyleDialog::NodeWatcher *w = new StyleDialog::NodeWatcher(this, &node); + node.addObserver(*w); _nodeWatchers.push_back(w); _readStyleElement(); } -void -StyleDialog::_nodeRemoved( Inkscape::XML::Node &repr ) { +void StyleDialog::_nodeRemoved(Inkscape::XML::Node &repr) +{ for (auto it = _nodeWatchers.begin(); it != _nodeWatchers.end(); ++it) { - if ( (*it)->_repr == &repr ) { - (*it)->_repr->removeObserver (**it); - _nodeWatchers.erase( it ); + if ((*it)->_repr == &repr) { + (*it)->_repr->removeObserver(**it); + _nodeWatchers.erase(it); break; } } _readStyleElement(); } -void -StyleDialog::_nodeChanged( Inkscape::XML::Node &object ) { - _readStyleElement(); -} +void StyleDialog::_nodeChanged(Inkscape::XML::Node &object) { _readStyleElement(); } /* void StyleDialog::_stylesheetChanged( Inkscape::XML::Node &repr ) { @@ -191,11 +183,11 @@ StyleDialog::_stylesheetChanged( Inkscape::XML::Node &repr ) { * adds selectors to treeview. _delSelector deletes the selector from the dialog. * Any addition/deletion of the selectors updates XML style element accordingly. */ -StyleDialog::StyleDialog() : - UI::Widget::Panel("/dialogs/style", SP_VERB_DIALOG_STYLE), - _updating(false), - _textNode(nullptr), - _desktopTracker() +StyleDialog::StyleDialog() + : UI::Widget::Panel("/dialogs/style", SP_VERB_DIALOG_STYLE) + , _updating(false) + , _textNode(nullptr) + , _desktopTracker() { g_debug("StyleDialog::StyleDialog"); // Pack widgets @@ -204,8 +196,8 @@ StyleDialog::StyleDialog() : _styleBox.set_orientation(Gtk::ORIENTATION_VERTICAL); _styleBox.set_valign(Gtk::ALIGN_START); _scrolledWindow.add(_styleBox); - Gtk::Box *alltoggler = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)); - Gtk::Label *infotoggler = Gtk::manage(new Gtk::Label(_("Edit Full Stylesheet"))); + Gtk::Box *alltoggler = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)); + Gtk::Label *infotoggler = Gtk::manage(new Gtk::Label(_("Edit Full Stylesheet"))); _all_css = Gtk::manage(new Gtk::Switch()); _all_css->get_style_context()->add_class("switchclean"); _all_css->set_margin_right(5); @@ -218,13 +210,13 @@ StyleDialog::StyleDialog() : _mainBox.set_orientation(Gtk::ORIENTATION_VERTICAL); _getContents()->pack_start(_mainBox, Gtk::PACK_EXPAND_WIDGET); // Document & Desktop - _desktop_changed_connection = _desktopTracker.connectDesktopChanged( - sigc::mem_fun(*this, &StyleDialog::_handleDesktopChanged) ); + _desktop_changed_connection = + _desktopTracker.connectDesktopChanged(sigc::mem_fun(*this, &StyleDialog::_handleDesktopChanged)); _desktopTracker.connect(GTK_WIDGET(gobj())); - _document_replaced_connection = getDesktop()->connectDocumentReplaced( - sigc::mem_fun(this, &StyleDialog::_handleDocumentReplaced)); - + _document_replaced_connection = + getDesktop()->connectDocumentReplaced(sigc::mem_fun(this, &StyleDialog::_handleDocumentReplaced)); + _selection_changed_connection = getDesktop()->getSelection()->connectChanged( sigc::hide(sigc::mem_fun(this, &StyleDialog::_handleSelectionChanged))); // Add watchers @@ -245,18 +237,14 @@ StyleDialog::~StyleDialog() _selection_changed_connection.disconnect(); } -void -StyleDialog::_reload() -{ - _readStyleElement(); -} +void StyleDialog::_reload() { _readStyleElement(); } /** * @return Inkscape::XML::Node* pointing to a style element's text node. * Returns the style element's text node. If there is no style element, one is created. * Ditto for text node. */ -Inkscape::XML::Node* StyleDialog::_getStyleTextNode() +Inkscape::XML::Node *StyleDialog::_getStyleTextNode() { Inkscape::XML::Node *styleNode = nullptr; @@ -287,7 +275,7 @@ Inkscape::XML::Node* StyleDialog::_getStyleTextNode() if (styleNode == nullptr) { // Style element not found, create one styleNode = SP_ACTIVE_DOCUMENT->getReprDoc()->createElement("svg:style"); - textNode = SP_ACTIVE_DOCUMENT->getReprDoc()->createTextNode(""); + textNode = SP_ACTIVE_DOCUMENT->getReprDoc()->createTextNode(""); styleNode->appendChild(textNode); Inkscape::GC::release(textNode); @@ -305,35 +293,33 @@ Inkscape::XML::Node* StyleDialog::_getStyleTextNode() return textNode; } -Glib::RefPtr< Gtk::TreeModel > StyleDialog::_selectTree(Glib::ustring selector) +Glib::RefPtr<Gtk::TreeModel> StyleDialog::_selectTree(Glib::ustring selector) { - Gtk::Label * selectorlabel; - Glib::RefPtr< Gtk::TreeModel > model; - for (auto fullstyle:_styleBox.get_children()){ + Gtk::Label *selectorlabel; + Glib::RefPtr<Gtk::TreeModel> model; + for (auto fullstyle : _styleBox.get_children()) { Gtk::Box *style = dynamic_cast<Gtk::Box *>(fullstyle); - for (auto stylepart:style->get_children()){ + for (auto stylepart : style->get_children()) { switch (style->child_property_position(*stylepart)) { - case 0: - { - Gtk::Box *selectorbox = dynamic_cast<Gtk::Box *>(stylepart); - for (auto styleheader:selectorbox->get_children()){ - if (!selectorbox->child_property_position(*styleheader)) { - selectorlabel = dynamic_cast<Gtk::Label *>(styleheader); - } + case 0: { + Gtk::Box *selectorbox = dynamic_cast<Gtk::Box *>(stylepart); + for (auto styleheader : selectorbox->get_children()) { + if (!selectorbox->child_property_position(*styleheader)) { + selectorlabel = dynamic_cast<Gtk::Label *>(styleheader); } - break; } - case 1: - { - Glib::ustring wdg_selector = selectorlabel->get_text(); - if (wdg_selector == selector){ - Gtk::TreeView* treeview = dynamic_cast<Gtk::TreeView *>(stylepart); - if (treeview) { - return treeview->get_model(); - } + break; + } + case 1: { + Glib::ustring wdg_selector = selectorlabel->get_text(); + if (wdg_selector == selector) { + Gtk::TreeView *treeview = dynamic_cast<Gtk::TreeView *>(stylepart); + if (treeview) { + return treeview->get_model(); } - break; } + break; + } default: break; } @@ -349,10 +335,11 @@ void StyleDialog::_readStyleElement() { g_debug("StyleDialog::_readStyleElement"); - if (_updating) return; // Don't read if we wrote style element. + if (_updating) + return; // Don't read if we wrote style element. _updating = true; - Inkscape::XML::Node * textNode = _getStyleTextNode(); + Inkscape::XML::Node *textNode = _getStyleTextNode(); if (textNode == nullptr) { std::cerr << "StyleDialog::_readStyleElement: No text node!" << std::endl; } @@ -370,11 +357,8 @@ void StyleDialog::_readStyleElement() size_t open = content.find("{", start + 1); size_t close = content.find("}", start + 1); size_t end = content.find("*/", close + 1); - while(!breakme) { - if (open == std::string::npos || - close == std::string::npos || - end == std::string::npos) - { + while (!breakme) { + if (open == std::string::npos || close == std::string::npos || end == std::string::npos) { breakme = true; break; } @@ -383,10 +367,7 @@ void StyleDialog::_readStyleElement() close = content.find("}", close + 1); end = content.find("*/", close + 1); size_t reopen = content.find("{", close + 1); - if (open == std::string::npos || - end == std::string::npos || - end < reopen) - { + if (open == std::string::npos || end == std::string::npos || end < reopen) { if (end < reopen) { content = content.erase(start, end - start + 2); } else { @@ -417,13 +398,13 @@ void StyleDialog::_readStyleElement() // If text node is empty, return (avoids problem with negative below). - for (auto child:_styleBox.get_children()) { + for (auto child : _styleBox.get_children()) { _styleBox.remove(*child); delete child; } - Inkscape::Selection* selection = getDesktop()->getSelection(); + Inkscape::Selection *selection = getDesktop()->getSelection(); SPObject *obj = nullptr; - if(selection->objects().size() == 1) { + if (selection->objects().size() == 1) { obj = selection->objects().back(); } @@ -448,28 +429,30 @@ void StyleDialog::_readStyleElement() _builder->get_widget("CSSTree", css_tree); Glib::RefPtr<Gtk::TreeStore> store = Gtk::TreeStore::create(_mColumns); css_tree->set_model(store); - // We need to handle comments on SPStyle to activate + // We need to handle comments on SPStyle to activate /* Gtk::CellRendererToggle *active = Gtk::manage(new Gtk::CellRendererToggle); int addCol = css_tree->append_column("", *active) - 1; Gtk::TreeViewColumn *col = css_tree->get_column(addCol); if (col) { col->add_attribute(active->property_active(), _mColumns._colActive); } */ - + css_selector_event_add->signal_button_release_event().connect( - sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *, Glib::ustring, gint>( - sigc::mem_fun(*this, &StyleDialog::_addRow), store, css_tree, "style_properties", selectorpos)); - Inkscape::UI::Widget::IconRenderer * addRenderer = manage(new Inkscape::UI::Widget::IconRenderer()); + sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *, Glib::ustring, gint>( + sigc::mem_fun(*this, &StyleDialog::_addRow), store, css_tree, "style_properties", selectorpos)); + Inkscape::UI::Widget::IconRenderer *addRenderer = manage(new Inkscape::UI::Widget::IconRenderer()); addRenderer->add_icon("edit-delete"); int addCol = css_tree->append_column("Delete row", *addRenderer) - 1; Gtk::TreeViewColumn *col = css_tree->get_column(addCol); if (col) { - addRenderer->signal_activated().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore> >(sigc::mem_fun(*this, &StyleDialog::_onPropDelete), store)); + addRenderer->signal_activated().connect( + sigc::bind<Glib::RefPtr<Gtk::TreeStore>>(sigc::mem_fun(*this, &StyleDialog::_onPropDelete), store)); } Gtk::CellRendererText *label = Gtk::manage(new Gtk::CellRendererText()); label->property_placeholder_text() = _("property"); label->property_editable() = true; - label->signal_edited().connect(sigc::bind< Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *>(sigc::mem_fun(*this, &StyleDialog::_nameEdited), store, css_tree)); + label->signal_edited().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *>( + sigc::mem_fun(*this, &StyleDialog::_nameEdited), store, css_tree)); addCol = css_tree->append_column("CSS Property", *label) - 1; col = css_tree->get_column(addCol); if (col) { @@ -478,7 +461,8 @@ void StyleDialog::_readStyleElement() Gtk::CellRendererText *value = Gtk::manage(new Gtk::CellRendererText()); value->property_placeholder_text() = _("value"); value->property_editable() = true; - value->signal_edited().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore> >(sigc::mem_fun(*this, &StyleDialog::_valueEdited), store)); + value->signal_edited().connect( + sigc::bind<Glib::RefPtr<Gtk::TreeStore>>(sigc::mem_fun(*this, &StyleDialog::_valueEdited), store)); addCol = css_tree->append_column("CSS Value", *value) - 1; col = css_tree->get_column(addCol); if (col) { @@ -488,7 +472,7 @@ void StyleDialog::_readStyleElement() std::map<Glib::ustring, Glib::ustring> attr_prop; if (obj || _all_css->get_active()) { Gtk::TreeModel::Path path; - if(!_all_css->get_active() && obj && obj->getRepr()->attribute("style")) { + if (!_all_css->get_active() && obj && obj->getRepr()->attribute("style")) { Glib::ustring style = obj->getRepr()->attribute("style"); attr_prop = parseStyle(style); for (auto iter : obj->style->properties()) { @@ -502,9 +486,9 @@ void StyleDialog::_readStyleElement() row[_mColumns._colStrike] = false; } } - _styleBox.pack_start(*css_selector_container, Gtk::PACK_EXPAND_WIDGET); + _styleBox.pack_start(*css_selector_container, Gtk::PACK_EXPAND_WIDGET); } - selectorpos ++; + selectorpos++; try { _builder = Gtk::Builder::create_from_file(gladefile); } catch (const Glib::Error &ex) { @@ -520,27 +504,31 @@ void StyleDialog::_readStyleElement() _builder->get_widget("CSSTree", css_tree); css_tree->set_model(store); css_selector_event_add->signal_button_release_event().connect( - sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *, Glib::ustring, gint>( - sigc::mem_fun(*this, &StyleDialog::_addRow), store, css_tree, "attributes", selectorpos)); + sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *, Glib::ustring, gint>( + sigc::mem_fun(*this, &StyleDialog::_addRow), store, css_tree, "attributes", selectorpos)); bool hasattributes = false; - if(!_all_css->get_active()) { + if (!_all_css->get_active()) { for (auto iter : obj->style->properties()) { if (iter->style_src != SP_STYLE_SRC_UNSET) { - if( iter->name != "font" && iter->name != "d" && iter->name != "marker") { + if (iter->name != "font" && iter->name != "d" && iter->name != "marker") { const gchar *attr = obj->getRepr()->attribute(iter->name.c_str()); if (attr) { if (!hasattributes) { - Inkscape::UI::Widget::IconRenderer * addRenderer = manage(new Inkscape::UI::Widget::IconRenderer()); + Inkscape::UI::Widget::IconRenderer *addRenderer = + manage(new Inkscape::UI::Widget::IconRenderer()); addRenderer->add_icon("edit-delete"); int addCol = css_tree->append_column("Delete row", *addRenderer) - 1; Gtk::TreeViewColumn *col = css_tree->get_column(addCol); if (col) { - addRenderer->signal_activated().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore> >(sigc::mem_fun(*this, &StyleDialog::_onPropDelete), store)); + addRenderer->signal_activated().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore>>( + sigc::mem_fun(*this, &StyleDialog::_onPropDelete), store)); } Gtk::CellRendererText *label = Gtk::manage(new Gtk::CellRendererText()); label->property_placeholder_text() = _("property"); label->property_editable() = true; - label->signal_edited().connect(sigc::bind< Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView * >(sigc::mem_fun(*this, &StyleDialog::_nameEdited), store, css_tree)); + label->signal_edited().connect( + sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *>( + sigc::mem_fun(*this, &StyleDialog::_nameEdited), store, css_tree)); addCol = css_tree->append_column("CSS Property", *label) - 1; col = css_tree->get_column(addCol); if (col) { @@ -549,7 +537,8 @@ void StyleDialog::_readStyleElement() Gtk::CellRendererText *value = Gtk::manage(new Gtk::CellRendererText()); value->property_placeholder_text() = _("value"); value->property_editable() = true; - value->signal_edited().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore> >(sigc::mem_fun(*this, &StyleDialog::_valueEdited), store)); + value->signal_edited().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore>>( + sigc::mem_fun(*this, &StyleDialog::_valueEdited), store)); addCol = css_tree->append_column("CSS Value", *value) - 1; col = css_tree->get_column(addCol); if (col) { @@ -574,18 +563,18 @@ void StyleDialog::_readStyleElement() } } if (!hasattributes) { - for (auto widg:css_selector_container->get_children()) { + for (auto widg : css_selector_container->get_children()) { delete widg; } } _styleBox.pack_start(*css_selector_container, Gtk::PACK_EXPAND_WIDGET); } - selectorpos ++; + selectorpos++; if (tokens.size() == 0) { _updating = false; return; } - for (unsigned i = 0; i < tokens.size()-1; i += 2) { + for (unsigned i = 0; i < tokens.size() - 1; i += 2) { Glib::ustring selector = tokens[i]; REMOVE_SPACES(selector); // Remove leading/trailing spaces std::vector<Glib::ustring> tokensplus = Glib::Regex::split_simple("[,]+", selector); @@ -593,27 +582,28 @@ void StyleDialog::_readStyleElement() REMOVE_SPACES(tok); } // Get list of objects selector matches - std::vector<SPObject *> objVec = _getObjVec( selector ); + std::vector<SPObject *> objVec = _getObjVec(selector); if (!_all_css->get_active()) { bool stop = true; - for (auto objel:objVec) { - if (objel->getId() == obj->getId()){ + for (auto objel : objVec) { + if (objel->getId() == obj->getId()) { stop = false; } } if (stop) { _updating = false; - selectorpos ++; + selectorpos++; continue; } } Glib::ustring properties; // Check to make sure we do have a value to match selector. - if ((i+1) < tokens.size()) { - properties = tokens[i+1]; + if ((i + 1) < tokens.size()) { + properties = tokens[i + 1]; } else { std::cerr << "StyleDialog::_readStyleElement: Missing values " - "for last selector!" << std::endl; + "for last selector!" + << std::endl; } Glib::RefPtr<Gtk::Builder> _builder; try { @@ -634,24 +624,27 @@ void StyleDialog::_readStyleElement() _builder->get_widget("CSSTree", css_tree); Glib::RefPtr<Gtk::TreeStore> store = Gtk::TreeStore::create(_mColumns); css_tree->set_model(store); - Inkscape::UI::Widget::IconRenderer * addRenderer = manage(new Inkscape::UI::Widget::IconRenderer()); + Inkscape::UI::Widget::IconRenderer *addRenderer = manage(new Inkscape::UI::Widget::IconRenderer()); addRenderer->add_icon("edit-delete"); int addCol = css_tree->append_column("Delete row", *addRenderer) - 1; Gtk::TreeViewColumn *col = css_tree->get_column(addCol); if (col) { - addRenderer->signal_activated().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore> >(sigc::mem_fun(*this, &StyleDialog::_onPropDelete), store)); - } + addRenderer->signal_activated().connect( + sigc::bind<Glib::RefPtr<Gtk::TreeStore>>(sigc::mem_fun(*this, &StyleDialog::_onPropDelete), store)); + } Gtk::CellRendererToggle *active = Gtk::manage(new Gtk::CellRendererToggle); addCol = css_tree->append_column("Active Property", *active) - 1; col = css_tree->get_column(addCol); if (col) { col->add_attribute(active->property_active(), _mColumns._colActive); - active->signal_toggled().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore> >(sigc::mem_fun(*this, &StyleDialog::_activeToggled), store)); + active->signal_toggled().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore>>( + sigc::mem_fun(*this, &StyleDialog::_activeToggled), store)); } Gtk::CellRendererText *label = Gtk::manage(new Gtk::CellRendererText()); label->property_placeholder_text() = _("property"); label->property_editable() = true; - label->signal_edited().connect(sigc::bind< Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView * >(sigc::mem_fun(*this, &StyleDialog::_nameEdited), store, css_tree)); + label->signal_edited().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *>( + sigc::mem_fun(*this, &StyleDialog::_nameEdited), store, css_tree)); addCol = css_tree->append_column("CSS Selector", *label) - 1; col = css_tree->get_column(addCol); if (col) { @@ -659,7 +652,8 @@ void StyleDialog::_readStyleElement() } Gtk::CellRendererText *value = Gtk::manage(new Gtk::CellRendererText()); value->property_editable() = true; - value->signal_edited().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore> >(sigc::mem_fun(*this, &StyleDialog::_valueEdited), store)); + value->signal_edited().connect( + sigc::bind<Glib::RefPtr<Gtk::TreeStore>>(sigc::mem_fun(*this, &StyleDialog::_valueEdited), store)); value->property_placeholder_text() = _("value"); addCol = css_tree->append_column("CSS Value", *value) - 1; col = css_tree->get_column(addCol); @@ -669,20 +663,18 @@ void StyleDialog::_readStyleElement() } Glib::ustring style = properties; Glib::ustring comments = ""; - while(style.find("/*") != std::string::npos) { + while (style.find("/*") != std::string::npos) { size_t beg = style.find("/*"); size_t end = style.find("*/"); - if (end != std::string::npos && - beg != std::string::npos) - { + if (end != std::string::npos && beg != std::string::npos) { comments = comments.append(style, beg + 2, end - beg - 2); style = style.erase(beg, end - beg + 2); } } std::map<Glib::ustring, Glib::ustring> attr_prop_styleshet = parseStyle(style); css_selector_event_add->signal_button_release_event().connect( - sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *, Glib::ustring, gint>( - sigc::mem_fun(*this, &StyleDialog::_addRow), store, css_tree, selector, selectorpos)); + sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *, Glib::ustring, gint>( + sigc::mem_fun(*this, &StyleDialog::_addRow), store, css_tree, selector, selectorpos)); if (!_all_css->get_active()) { for (auto iter : obj->style->properties()) { if (iter->style_src != SP_STYLE_SRC_UNSET) { @@ -713,7 +705,7 @@ void StyleDialog::_readStyleElement() } } std::map<Glib::ustring, Glib::ustring> attr_prop_styleshet_comments = parseStyle(comments); - + for (auto iter : attr_prop_styleshet_comments) { if (!attr_prop_styleshet.count(iter.first)) { Gtk::TreeModel::Row row = *(store->append()); @@ -726,7 +718,7 @@ void StyleDialog::_readStyleElement() } } _styleBox.pack_start(*css_selector_container, Gtk::PACK_EXPAND_WIDGET); - selectorpos ++; + selectorpos++; } } _mainBox.show_all_children(); @@ -743,14 +735,13 @@ void StyleDialog::_readStyleElement() * @return true * Delete the attribute from the style */ -void -StyleDialog::_onPropDelete(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> store) +void StyleDialog::_onPropDelete(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> store) { Gtk::TreeModel::Row row = *store->get_iter(path); if (row) { - _updating = true; //to avoid a crash on deleting an obsolete widget + _updating = true; // to avoid a crash on deleting an obsolete widget Glib::ustring selector = row[_mColumns._colSelector]; - row[_mColumns._colName] = ""; + row[_mColumns._colName] = ""; store->erase(row); _updating = false; _writeStyleElement(store, selector); @@ -763,8 +754,7 @@ StyleDialog::_onPropDelete(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> stor * Convert a style string into a vector map. This should be moved to style.cpp * */ -std::map<Glib::ustring, Glib::ustring> -StyleDialog::parseStyle(Glib::ustring style_string) +std::map<Glib::ustring, Glib::ustring> StyleDialog::parseStyle(Glib::ustring style_string) { std::map<Glib::ustring, Glib::ustring> ret; @@ -794,7 +784,7 @@ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::u if (_updating) { return; } - Inkscape::Selection* selection = getDesktop()->getSelection(); + Inkscape::Selection *selection = getDesktop()->getSelection(); SPObject *obj = nullptr; if (selection->objects().size() == 1) { obj = selection->objects().back(); @@ -806,37 +796,33 @@ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::u _updating = true; gint selectorpos = 0; std::string styleContent = ""; - if (selector != "style_properties" && - selector != "attributes") - { + if (selector != "style_properties" && selector != "attributes") { styleContent = "\n" + selector + " { \n"; } - for (auto& row: store->children()) { + for (auto &row : store->children()) { selector = row[_mColumns._colSelector]; selectorpos = row[_mColumns._colSelectorPos]; - Glib::ustring opencomment =""; - Glib::ustring closecomment = "" ; - if (selector != "style_properties" && - selector != "attributes") { + Glib::ustring opencomment = ""; + Glib::ustring closecomment = ""; + if (selector != "style_properties" && selector != "attributes") { opencomment = row[_mColumns._colActive] ? " " : " /*"; - closecomment = row[_mColumns._colActive] ? "\n" : "*/\n" ; + closecomment = row[_mColumns._colActive] ? "\n" : "*/\n"; } - Glib::ustring name = row[_mColumns._colName]; + Glib::ustring name = row[_mColumns._colName]; Glib::ustring value = row[_mColumns._colValue]; - if (!(name.empty() && value.empty())){ + if (!(name.empty() && value.empty())) { styleContent = styleContent + opencomment + name + ":" + value + ";" + closecomment; } } - if (selector != "style_properties" && - selector != "attributes" ) { + if (selector != "style_properties" && selector != "attributes") { styleContent = styleContent + "}"; } if (selector == "style_properties") { - obj->getRepr()->setAttribute("style",styleContent, false); + obj->getRepr()->setAttribute("style", styleContent, false); } else if (selector == "attributes") { for (auto iter : obj->style->properties()) { if (iter->style_src != SP_STYLE_SRC_UNSET) { - if( iter->name != "font" && iter->name != "d" && iter->name != "marker") { + if (iter->name != "font" && iter->name != "d" && iter->name != "marker") { const gchar *attr = obj->getRepr()->attribute(iter->name.c_str()); if (attr) { obj->getRepr()->setAttribute(iter->name.c_str(), nullptr); @@ -844,14 +830,14 @@ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::u } } } - for (auto& row: store->children()) { - Glib::ustring name = row[_mColumns._colName]; - Glib::ustring value = row[_mColumns._colValue]; - if (!(name.empty() && value.empty())){ + for (auto &row : store->children()) { + Glib::ustring name = row[_mColumns._colName]; + Glib::ustring value = row[_mColumns._colValue]; + if (!(name.empty() && value.empty())) { obj->getRepr()->setAttribute(name.c_str(), value); } } - } else if (!selector.empty()) { //styleshet + } else if (!selector.empty()) { // styleshet // We could test if styleContent is empty and then delete the style node here but there is no // harm in keeping it around ... SP_ACTIVE_DOCUMENT->setStyleSheet(nullptr); @@ -862,10 +848,10 @@ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::u } selectormatch = selectormatch + ")([^}]*?})((.|\n)*)"; Inkscape::XML::Node *textNode = _getStyleTextNode(); - std::regex e (selectormatch.c_str()); + std::regex e(selectormatch.c_str()); std::string content = (textNode->content() ? textNode->content() : ""); std::string result; - std::regex_replace (std::back_inserter(result), content.begin(), content.end(), e, "$1" + styleContent + "$3"); + std::regex_replace(std::back_inserter(result), content.begin(), content.end(), e, "$1" + styleContent + "$3"); textNode->setContent(result.c_str()); } _readStyleElement(); @@ -875,19 +861,21 @@ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::u g_debug("StyleDialog::_writeStyleElement(): | %s |", styleContent.c_str()); } -bool StyleDialog::_addRow(GdkEventButton *evt, Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeView *css_tree, Glib::ustring selector, gint pos) { - if(evt->type == GDK_BUTTON_RELEASE && evt->button == 1) { +bool StyleDialog::_addRow(GdkEventButton *evt, Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeView *css_tree, + Glib::ustring selector, gint pos) +{ + if (evt->type == GDK_BUTTON_RELEASE && evt->button == 1) { Gtk::TreeIter iter = store->append(); Gtk::TreeModel::Path path = (Gtk::TreeModel::Path)iter; Gtk::TreeModel::Row row = *(iter); row[_mColumns._colSelector] = selector; row[_mColumns._colSelectorPos] = pos; row[_mColumns._colActive] = true; - row[_mColumns._colName] = ""; + row[_mColumns._colName] = ""; row[_mColumns._colValue] = ""; row[_mColumns._colStrike] = false; gint col = 2; - if (pos < 2 ){ + if (pos < 2) { col = 1; } css_tree->set_cursor(path, *(css_tree->get_column(col)), true); @@ -903,12 +891,13 @@ bool StyleDialog::_addRow(GdkEventButton *evt, Glib::RefPtr<Gtk::TreeStore> stor * @return * Called when the name is edited in the TreeView editable column */ -void StyleDialog::_nameEdited (const Glib::ustring& path, const Glib::ustring& name, Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeView *css_tree) +void StyleDialog::_nameEdited(const Glib::ustring &path, const Glib::ustring &name, Glib::RefPtr<Gtk::TreeStore> store, + Gtk::TreeView *css_tree) { Gtk::TreeModel::Row row = *store->get_iter(path); Gtk::TreeModel::Path pathel = (Gtk::TreeModel::Path)*store->get_iter(path); - if(row) { + if (row) { gint pos = row[_mColumns._colSelectorPos]; bool write = false; if (row[_mColumns._colName] != name && row[_mColumns._colValue] != "") { @@ -917,11 +906,11 @@ void StyleDialog::_nameEdited (const Glib::ustring& path, const Glib::ustring& n Glib::ustring value = row[_mColumns._colValue]; Glib::ustring selector = row[_mColumns._colSelector]; row[_mColumns._colName] = name; - if(name.empty() && value.empty()) { + if (name.empty() && value.empty()) { store->erase(row); } gint col = 3; - if (pos < 2 ){ + if (pos < 2) { col = 2; } if (write) { @@ -940,31 +929,33 @@ void StyleDialog::_nameEdited (const Glib::ustring& path, const Glib::ustring& n * @return * Called when the value is edited in the TreeView editable column */ -void StyleDialog::_valueEdited(const Glib::ustring& path, const Glib::ustring& value, Glib::RefPtr<Gtk::TreeStore> store) +void StyleDialog::_valueEdited(const Glib::ustring &path, const Glib::ustring &value, + Glib::RefPtr<Gtk::TreeStore> store) { Gtk::TreeModel::Row row = *store->get_iter(path); - if(row) { + if (row) { row[_mColumns._colValue] = value; Glib::ustring selector = row[_mColumns._colSelector]; Glib::ustring name = row[_mColumns._colName]; - if(name.empty() && value.empty()) { + if (name.empty() && value.empty()) { store->erase(row); } _writeStyleElement(store, selector); } } -void StyleDialog::_activeToggled(const Glib::ustring& path, Glib::RefPtr<Gtk::TreeStore> store) +void StyleDialog::_activeToggled(const Glib::ustring &path, Glib::RefPtr<Gtk::TreeStore> store) { Gtk::TreeModel::Row row = *store->get_iter(path); - if(row) { + if (row) { row[_mColumns._colActive] = !row[_mColumns._colActive]; Glib::ustring selector = row[_mColumns._colSelector]; _writeStyleElement(store, selector); } } -void StyleDialog::_addWatcherRecursive(Inkscape::XML::Node *node) { +void StyleDialog::_addWatcherRecursive(Inkscape::XML::Node *node) +{ g_debug("StyleDialog::_addWatcherRecursive()"); @@ -1007,12 +998,13 @@ void StyleDialog::_updateWatchers() * @return objVec: a vector of pointers to SPObject's the selector matches. * Return a vector of all objects that selector matches. */ -std::vector<SPObject *> StyleDialog::_getObjVec(Glib::ustring selector) { +std::vector<SPObject *> StyleDialog::_getObjVec(Glib::ustring selector) +{ - std::vector<SPObject *> objVec = SP_ACTIVE_DOCUMENT->getObjectsBySelector( selector ); + std::vector<SPObject *> objVec = SP_ACTIVE_DOCUMENT->getObjectsBySelector(selector); g_debug("StyleDialog::_getObjVec: | %s |", selector.c_str()); - for (auto& obj: objVec) { + for (auto &obj : objVec) { g_debug(" %s", obj->getId() ? obj->getId() : "null"); } @@ -1026,15 +1018,14 @@ void StyleDialog::_closeDialog(Gtk::Dialog *textDialogPtr) { textDialogPtr->resp * Handle document replaced. (Happens when a default document is immediately replaced by another * document in a new window.) */ -void -StyleDialog::_handleDocumentReplaced(SPDesktop *desktop, SPDocument * /* document */) +void StyleDialog::_handleDocumentReplaced(SPDesktop *desktop, SPDocument * /* document */) { g_debug("StyleDialog::handleDocumentReplaced()"); _selection_changed_connection.disconnect(); - _selection_changed_connection = desktop->getSelection()->connectChanged( - sigc::hide(sigc::mem_fun(this, &StyleDialog::_handleSelectionChanged))); + _selection_changed_connection = + desktop->getSelection()->connectChanged(sigc::hide(sigc::mem_fun(this, &StyleDialog::_handleSelectionChanged))); _updateWatchers(); _readStyleElement(); @@ -1044,8 +1035,8 @@ StyleDialog::_handleDocumentReplaced(SPDesktop *desktop, SPDocument * /* documen /* * When a dialog is floating, it is connected to the active desktop. */ -void -StyleDialog::_handleDesktopChanged(SPDesktop* desktop) { +void StyleDialog::_handleDesktopChanged(SPDesktop *desktop) +{ g_debug("StyleDialog::handleDesktopReplaced()"); if (getDesktop() == desktop) { @@ -1057,12 +1048,12 @@ StyleDialog::_handleDesktopChanged(SPDesktop* desktop) { _selection_changed_connection.disconnect(); _document_replaced_connection.disconnect(); - setDesktop( desktop ); + setDesktop(desktop); - _selection_changed_connection = desktop->getSelection()->connectChanged( - sigc::hide(sigc::mem_fun(this, &StyleDialog::_handleSelectionChanged))); - _document_replaced_connection = desktop->connectDocumentReplaced( - sigc::mem_fun(this, &StyleDialog::_handleDocumentReplaced)); + _selection_changed_connection = + desktop->getSelection()->connectChanged(sigc::hide(sigc::mem_fun(this, &StyleDialog::_handleSelectionChanged))); + _document_replaced_connection = + desktop->connectDocumentReplaced(sigc::mem_fun(this, &StyleDialog::_handleDocumentReplaced)); _updateWatchers(); _readStyleElement(); @@ -1072,8 +1063,8 @@ StyleDialog::_handleDesktopChanged(SPDesktop* desktop) { /* * Handle a change in which objects are selected in a document. */ -void -StyleDialog::_handleSelectionChanged() { +void StyleDialog::_handleSelectionChanged() +{ g_debug("StyleDialog::_handleSelectionChanged()"); _readStyleElement(); } |
