summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4dadce1)
raw | patch | inline | side by side (parent: 4dadce1)
author | sasilver <sasilver@users.sourceforge.net> | |
Mon, 14 Jul 2008 10:19:53 +0000 (10:19 +0000) | ||
committer | sasilver <sasilver@users.sourceforge.net> | |
Mon, 14 Jul 2008 10:19:53 +0000 (10:19 +0000) |
src/dialogs/item-properties.cpp | patch | blob | history | |
src/sp-object.cpp | patch | blob | history | |
src/sp-object.h | patch | blob | history |
index fb7753d0054f07f4798b6b47fea65b18a5c7232e..25eafa9a1d99b1f99da69b9d47bde1713b223168 100644 (file)
/* Retrieve the title */
GtkWidget *w = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), "title"));
gchar *title = (gchar *)gtk_entry_get_text(GTK_ENTRY (w));
- g_assert(title != NULL);
- gchar *old_title = obj->title();
- if (old_title == NULL || strcmp(title, old_title)) {
- obj->setTitle(title);
+ if (obj->setTitle(title))
sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM,
_("Set object title"));
- }
- g_free(old_title);
/* Retrieve the description */
GtkTextView *tv = GTK_TEXT_VIEW(gtk_object_get_data(GTK_OBJECT(spw), "desc"));
GtkTextIter start, end;
gtk_text_buffer_get_bounds(buf, &start, &end);
gchar *desc = gtk_text_buffer_get_text(buf, &start, &end, TRUE);
- g_assert(desc != NULL);
- gchar *old_desc = obj->desc();
- if (old_desc == NULL || strcmp(desc, old_desc)) {
- obj->setDesc(desc);
+ if (obj->setDesc(desc))
sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM,
_("Set object description"));
- }
- g_free(old_desc);
g_free(desc);
gtk_object_set_data (GTK_OBJECT (spw), "blocked", GUINT_TO_POINTER (FALSE));
diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index cd90ab7ab494b5063ba58b5a2a8dc073c2ace785..83bb7282c44dd5b617192d5c7d3cdbf397365f93 100644 (file)
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
/**
* Sets the title of this object
- * A NULL or purely whitespace argument is interpreted as meaning that
- * the existing title (if any) should be deleted.
+ * A NULL first argument is interpreted as meaning that the existing title
+ * (if any) should be deleted.
+ * The second argument is optional - see setTitleOrDesc() below for details.
*/
-void
-SPObject::setTitle(gchar const *title)
+bool
+SPObject::setTitle(gchar const *title, bool verbatim)
{
- setTitleOrDesc(title, "svg:title");
+ return setTitleOrDesc(title, "svg:title", verbatim);
}
/**
/**
* Sets the description of this object.
- * A NULL or purely whitespace argument is interpreted as meaning that
- * the existing description (if any) should be deleted.
+ * A NULL first argument is interpreted as meaning that the existing
+ * description (if any) should be deleted.
+ * The second argument is optional - see setTitleOrDesc() below for details.
*/
-void
-SPObject::setDesc(gchar const *desc)
+bool
+SPObject::setDesc(gchar const *desc, bool verbatim)
{
- setTitleOrDesc(desc, "svg:desc");
+ return setTitleOrDesc(desc, "svg:desc", verbatim);
}
/**
/**
* Sets or deletes the title or description of this object.
+ * A NULL 'value' argument causes the title or description to be deleted.
+ *
+ * 'verbatim' parameter:
+ * If verbatim==true, then the title or description is set to exactly the
+ * specified value. If verbatim==false then two exceptions are made:
+ * (1) If the specified value is just whitespace, then the title/description
+ * is deleted.
+ * (2) If the specified value is the same as the current value except for
+ * mark-up, then the current value is left unchanged.
+ * This is usually the desired behaviour, so 'verbatim' defaults to false for
+ * setTitle() and setDesc().
+ *
+ * The return value is true if a change was made to the title/description,
+ * and usually false otherwise.
*/
-void
-SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname)
+bool
+SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verbatim)
{
- SPObject *elem = findFirstChild(svg_tagname);
-
- // if the new title/description is NULL, or just whitespace,
- // then delete any existing title/description
- bool just_whitespace = true;
- if (value)
- for (const gchar *cp = value; *cp; ++cp) {
- if (!std::strchr("\r\n \t", *cp)) {
- just_whitespace = false;
- break;
+ if (!verbatim) {
+ // If the new title/description is just whitespace,
+ // treat it as though it were NULL.
+ if (value) {
+ bool just_whitespace = true;
+ for (const gchar *cp = value; *cp; ++cp) {
+ if (!std::strchr("\r\n \t", *cp)) {
+ just_whitespace = false;
+ break;
+ }
}
+ if (just_whitespace) value = NULL;
}
- if (just_whitespace) {
+ // Don't stomp on mark-up if there is no real change.
+ if (value) {
+ gchar *current_value = getTitleOrDesc(svg_tagname);
+ if (current_value) {
+ bool different = std::strcmp(current_value, value);
+ g_free(current_value);
+ if (!different) return false;
+ }
+ }
+ }
+
+ SPObject *elem = findFirstChild(svg_tagname);
+
+ if (value == NULL) {
+ if (elem == NULL) return false;
// delete the title/description(s)
while (elem) {
elem->deleteObject();
elem = findFirstChild(svg_tagname);
}
- return;
+ return true;
}
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
Inkscape::XML::Node *xml_elem = xml_doc->createElement(svg_tagname);
repr->addChild(xml_elem, NULL);
elem = document->getObjectByRepr(xml_elem);
+ Inkscape::GC::release(xml_elem);
}
else {
// remove the current content of the 'text' or 'desc' element
// add the new content
elem->appendChildRepr(xml_doc->createTextNode(value));
+ return true;
}
/**
diff --git a/src/sp-object.h b/src/sp-object.h
index ccc063d5f1d688ab323bc609aa8b36867861881a..095494a6f67a913ec0a1bb6369d74a036b9653d0 100644 (file)
--- a/src/sp-object.h
+++ b/src/sp-object.h
/** Retrieves the title of this object */
gchar *title() const;
/** Sets the title of this object */
- void setTitle(gchar const *title);
+ bool setTitle(gchar const *title, bool verbatim=false);
/** Retrieves the description of this object */
gchar *desc() const;
/** Sets the description of this object */
- void setDesc(gchar const *desc);
+ bool setDesc(gchar const *desc, bool verbatim=false);
/** @brief Set the policy under which this object will be
* orphan-collected.
private:
// Private member functions used in the definitions of setTitle(),
// setDesc(), title() and desc().
- void setTitleOrDesc(gchar const *value, gchar const *svg_tagname);
+ bool setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool verbatim);
gchar * getTitleOrDesc(gchar const *svg_tagname) const;
SPObject * findFirstChild(gchar const *tagname) const;
GString * textualContent() const;