Code

fix showing style when last-set style is empty (on a new installation of inkscape)
authorbuliabyak <buliabyak@users.sourceforge.net>
Mon, 1 May 2006 05:13:30 +0000 (05:13 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Mon, 1 May 2006 05:13:30 +0000 (05:13 +0000)
src/ui/widget/style-swatch.cpp
src/ui/widget/style-swatch.h

index 023f91c55bef63350f2436a40dc35a1fc2a337f3..204833aa56f53e9596ae1b1b0b49abe5e6dba21b 100644 (file)
@@ -61,12 +61,12 @@ static void style_swatch_tool_attr_changed(Inkscape::XML::Node *repr, gchar cons
                                        bool is_interactive, gpointer data)
 {
     Inkscape::UI::Widget::StyleSwatch *ss = (Inkscape::UI::Widget::StyleSwatch *) data;
-
     if (!strcmp (name, "usecurrent")) { // FIXME: watching only for the style attr, no CSS attrs
         if (!strcmp (new_value, "1")) {
-            ss->setWatched (inkscape_get_repr(INKSCAPE, "desktop"));
+            ss->setWatched (inkscape_get_repr(INKSCAPE, "desktop"), inkscape_get_repr(INKSCAPE, ss->_tool_path));
         } else {
-            ss->setWatched (inkscape_get_repr(INKSCAPE, ss->_tool_path));
+            ss->setWatched (inkscape_get_repr(INKSCAPE, ss->_tool_path), NULL);
         }
         // UGLY HACK: we have to reconnect to the watched tool repr again, retrieving it from the stored
         // tool_path, because the actual repr keeps shifting with each change, no idea why
@@ -161,7 +161,6 @@ StyleSwatch::~StyleSwatch()
     }
 
     if (_watched_tool) {
-        std::cout << " =============remove\n";
         sp_repr_remove_listener_by_data(_watched_tool, this);
         Inkscape::GC::release(_watched_tool);
         _watched_tool = NULL;
@@ -170,7 +169,7 @@ StyleSwatch::~StyleSwatch()
 }
 
 void
-StyleSwatch::setWatched(Inkscape::XML::Node *watched)
+StyleSwatch::setWatched(Inkscape::XML::Node *watched, Inkscape::XML::Node *secondary)
 {
     if (_watched) {
         sp_repr_remove_listener_by_data(_watched, this);
@@ -183,6 +182,18 @@ StyleSwatch::setWatched(Inkscape::XML::Node *watched)
         Inkscape::GC::anchor(_watched);
         sp_repr_add_listener(_watched, &style_swatch_repr_events, this);
         sp_repr_synthesize_events(_watched, &style_swatch_repr_events, this);
+
+        // If desktop's last-set style is empty, a tool uses its own fixed style even if set to use
+        // last-set (so long as it's empty). To correctly show this, we're passed the second repr,
+        // that of the tool prefs node, from which we now setStyle if the watched repr's style is
+        // empty.
+        if (secondary) {
+            SPCSSAttr *css = sp_repr_css_attr_inherited(watched, "style");
+            if (sp_repr_children((Inkscape::XML::Node *) css) == NULL) { // is css empty?
+                SPCSSAttr *css_secondary = sp_repr_css_attr_inherited(secondary, "style");
+                this->setStyle (css_secondary);
+            }
+        }
     }
 }
 
@@ -226,7 +237,8 @@ StyleSwatch::setStyle(SPCSSAttr *css)
 
     gchar const *css_string = sp_repr_css_write_string (_css);
     SPStyle *temp_spstyle = sp_style_new();
-    sp_style_merge_from_style_string (temp_spstyle, css_string);
+    if (css_string)
+        sp_style_merge_from_style_string (temp_spstyle, css_string);
 
     setStyle (temp_spstyle);
 
index a21d6202fab46a1ad9fdb3cf86eafd420cb4240d..1f7dd2e377e1470030e51f64c71d85b1c89aa62d 100644 (file)
@@ -49,7 +49,7 @@ public:
     void setStyle(SPCSSAttr *attr);
     SPCSSAttr *getStyle();
 
-    void setWatched (Inkscape::XML::Node *watched);
+    void setWatched (Inkscape::XML::Node *watched, Inkscape::XML::Node *secondary);
     void setWatchedTool (const char *path, bool synthesize);
 
     char *_tool_path;