summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/selectorsdialog.cpp
diff options
context:
space:
mode:
authorJabiertxof <jabier.arraiza@marker.es>2019-08-29 16:35:15 +0000
committerJabiertxof <jabier.arraiza@marker.es>2019-08-29 16:35:27 +0000
commit50edd0c9a6e33fa5e3addefac95477b8fb365551 (patch)
tree01746a2dc08916b75c5fb581171b08bea9881eed /src/ui/dialog/selectorsdialog.cpp
parentNoumerous bugfixes pointed in Rocket Chat (diff)
downloadinkscape-50edd0c9a6e33fa5e3addefac95477b8fb365551.tar.gz
inkscape-50edd0c9a6e33fa5e3addefac95477b8fb365551.zip
Improve CSS and Selectors dialog
Diffstat (limited to 'src/ui/dialog/selectorsdialog.cpp')
-rw-r--r--src/ui/dialog/selectorsdialog.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/ui/dialog/selectorsdialog.cpp b/src/ui/dialog/selectorsdialog.cpp
index bbe0576dc..f66876475 100644
--- a/src/ui/dialog/selectorsdialog.cpp
+++ b/src/ui/dialog/selectorsdialog.cpp
@@ -25,6 +25,7 @@
#include "verbs.h"
#include "xml/attribute-record.h"
+#include "xml/sp-css-attr.h"
#include "xml/node-observer.h"
#include <glibmm/i18n.h>
@@ -569,7 +570,6 @@ void SelectorsDialog::_readStyleElement()
bool rewrite = false;
for (unsigned i = 0; i < tokens.size()-1; i += 2) {
-
Glib::ustring selector = tokens[i];
REMOVE_SPACES(selector); // Remove leading/trailing spaces
Glib::ustring selector_old = selector;
@@ -577,7 +577,7 @@ void SelectorsDialog::_readStyleElement()
if (selector_old != selector) {
rewrite = true;
}
- if (selector.empty()) {
+ if (selector.empty() || selector == "* > .inkscapehacktmp") {
continue;
}
std::vector<Glib::ustring> tokensplus = Glib::Regex::split_simple("[,]+", selector);
@@ -660,7 +660,7 @@ void SelectorsDialog::_writeStyleElement()
_scroollock = true;
_updating = true;
SPDocument *document = SP_ACTIVE_DOCUMENT;
- Glib::ustring styleContent;
+ Glib::ustring styleContent = "";
for (auto& row: _store->children()) {
Glib::ustring selector = row[_mColumns._colSelector];
/*
@@ -675,8 +675,18 @@ void SelectorsDialog::_writeStyleElement()
// We could test if styleContent is empty and then delete the style node here but there is no
// harm in keeping it around ...
Inkscape::XML::Node *textNode = _getStyleTextNode();
+ bool empty = false;
+ if (styleContent.empty()) {
+ empty = true;
+ styleContent = "* > .inkscapehacktmp{}";
+ }
+ textNode->setContent(styleContent.c_str());
+ INKSCAPE.readStyleSheets(true);
+ if (empty) {
+ styleContent = "";
+ textNode->setContent(styleContent.c_str());
+ }
textNode->setContent(styleContent.c_str());
- INKSCAPE.readStyleSheets();
DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_SELECTORS, _("Edited style element."));
_updating = false;
@@ -860,6 +870,24 @@ void SelectorsDialog::_addToSelector(Gtk::TreeModel::Row row)
_updating = false;
// Add entry to style element
+ for (auto &obj : toAddObjVec) {
+ Glib::ustring css_str = "";
+ SPCSSAttr *css = sp_repr_css_attr_new();
+ SPCSSAttr *css_selector = sp_repr_css_attr_new();
+ sp_repr_css_attr_add_from_string(css, obj->getRepr()->attribute("style"));
+ Glib::ustring selprops = row[_mColumns._colProperties];
+ sp_repr_css_attr_add_from_string(css_selector, selprops.c_str());
+ for ( List<AttributeRecord const> iter = css_selector->attributeList() ;
+ iter ; ++iter )
+ {
+ gchar const * key = g_quark_to_string(iter->key);
+ css->setAttribute(key, nullptr);
+ }
+ sp_repr_css_write_string(css, css_str);
+ obj->getRepr()->setAttribute("style", css_str.c_str());
+ obj->style->readFromObject(obj);
+ obj->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
+ }
_writeStyleElement();
}
}
@@ -914,6 +942,8 @@ void SelectorsDialog::_removeFromSelector(Gtk::TreeModel::Row row)
// Add entry to style element
_writeStyleElement();
+ obj->style->readFromObject(obj);
+ obj->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
_scroollock = false;
_vadj->set_value(std::min(_scroolpos, _vadj->get_upper()));
}