Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / ui / widget / entity-entry.cpp
index cc38de24fb495e93f3573755c4b9331fbdc42a6d..e191a93605cd82c582dbad1f415138b83378d37e 100644 (file)
@@ -6,6 +6,8 @@
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   Jon Phillips <jon@rejon.org>
  *   Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2000 - 2005 Authors
  *
@@ -20,6 +22,7 @@
 #include <gtkmm/entry.h>
 
 #include "inkscape.h"
+#include "sp-object.h"
 #include "rdf.h"
 #include "ui/widget/registry.h"
 
@@ -56,7 +59,7 @@ EntityEntry::create (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
 }
 
 EntityEntry::EntityEntry (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
-: _label(Glib::ustring(_(ent->title))+":", 1.0, 0.5), _packable(0), 
+: _label(Glib::ustring(_(ent->title)), 1.0, 0.5), _packable(0), 
   _entity(ent), _tt(&tt), _wr(&wr)
 {
 }
@@ -80,10 +83,14 @@ EntityLineEntry::~EntityLineEntry()
     delete static_cast<Gtk::Entry*>(_packable);
 }
 
-void 
-EntityLineEntry::update (SPDocument *doc)
+void EntityLineEntry::update(SPDocument *doc)
 {
     const char *text = rdf_get_work_entity (doc, _entity);
+    // If RDF title is not set, get the document's <title> and set the RDF:
+    if ( !text && !strcmp(_entity->name, "title") && doc->root ) {
+        text = doc->root->title();
+        rdf_set_work_entity(doc, _entity, text);
+    }
     static_cast<Gtk::Entry*>(_packable)->set_text (text ? text : "");
 }
 
@@ -95,9 +102,10 @@ EntityLineEntry::on_changed()
     _wr->setUpdating (true);
     SPDocument *doc = SP_ACTIVE_DOCUMENT;
     Glib::ustring text = static_cast<Gtk::Entry*>(_packable)->get_text();
-    if (rdf_set_work_entity (doc, _entity, text.c_str()))
-        SPDocumentUndo::done (doc, SP_VERB_NONE, 
-                          /* TODO: annotate */ "entity-entry.cpp:101");
+    if (rdf_set_work_entity (doc, _entity, text.c_str())) {
+        DocumentUndo::done(doc, SP_VERB_NONE, 
+                           /* TODO: annotate */ "entity-entry.cpp:101");
+    }
     _wr->setUpdating (false);
 }
 
@@ -121,10 +129,14 @@ EntityMultiLineEntry::~EntityMultiLineEntry()
     delete static_cast<Gtk::ScrolledWindow*>(_packable);
 }
 
-void 
-EntityMultiLineEntry::update (SPDocument *doc)
+void EntityMultiLineEntry::update(SPDocument *doc)
 {
     const char *text = rdf_get_work_entity (doc, _entity);
+    // If RDF title is not set, get the document's <title> and set the RDF:
+    if ( !text && !strcmp(_entity->name, "title") && doc->root ) {
+        text = doc->root->title();
+        rdf_set_work_entity(doc, _entity, text);
+    }
     Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable);
     Gtk::TextView *tv = static_cast<Gtk::TextView*>(s->get_child());
     tv->get_buffer()->set_text (text ? text : "");
@@ -140,9 +152,10 @@ EntityMultiLineEntry::on_changed()
     Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable);
     Gtk::TextView *tv = static_cast<Gtk::TextView*>(s->get_child());
     Glib::ustring text = tv->get_buffer()->get_text();
-    if (rdf_set_work_entity (doc, _entity, text.c_str()))
-        SPDocumentUndo::done (doc, SP_VERB_NONE, 
-                          /* TODO: annotate */ "entity-entry.cpp:146");
+    if (rdf_set_work_entity (doc, _entity, text.c_str())) {
+        DocumentUndo::done(doc, SP_VERB_NONE, 
+                            /* TODO: annotate */ "entity-entry.cpp:146");
+    }
     _wr->setUpdating (false);
 }