diff options
| author | John Smith <john.smith7545@yahoo.com> | 2012-07-12 08:19:58 +0000 |
|---|---|---|
| committer | John Smith <john.smith7545@yahoo.com> | 2012-07-12 08:19:58 +0000 |
| commit | d9da2a4f178e71f5b33ea158c0631e86220f2e5d (patch) | |
| tree | 5502c8d1addd8f0b270877102185604c103936e8 /src | |
| parent | Fix for 1023655 : IMprovments to Embedded script UI (diff) | |
| download | inkscape-d9da2a4f178e71f5b33ea158c0631e86220f2e5d.tar.gz inkscape-d9da2a4f178e71f5b33ea158c0631e86220f2e5d.zip | |
Fix for 612221 : Add metadata default configuration in the preferences
(bzr r11544)
Diffstat (limited to 'src')
| -rw-r--r-- | src/file.cpp | 2 | ||||
| -rw-r--r-- | src/rdf.cpp | 31 | ||||
| -rw-r--r-- | src/rdf.h | 4 | ||||
| -rw-r--r-- | src/ui/dialog/document-properties.cpp | 31 | ||||
| -rw-r--r-- | src/ui/dialog/document-properties.h | 3 | ||||
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.cpp | 4 | ||||
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.h | 1 | ||||
| -rw-r--r-- | src/ui/widget/entity-entry.cpp | 31 | ||||
| -rw-r--r-- | src/ui/widget/entity-entry.h | 4 |
9 files changed, 110 insertions, 1 deletions
diff --git a/src/file.cpp b/src/file.cpp index b895c6591..fd039323b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -186,10 +186,10 @@ SPDesktop* sp_file_new_default() g_free(foundTemplate); foundTemplate = 0; } + rdf_add_from_preferences( SP_ACTIVE_DOCUMENT ); return desk; } - /*###################### ## D E L E T E ######################*/ diff --git a/src/rdf.cpp b/src/rdf.cpp index 7131874ef..017de42c1 100644 --- a/src/rdf.cpp +++ b/src/rdf.cpp @@ -19,6 +19,7 @@ #include "sp-item-group.h" #include "inkscape.h" #include "sp-root.h" +#include "preferences.h" /* Example RDF XML from various places... @@ -1135,6 +1136,36 @@ void RDFImpl::setDefaults( SPDocument * doc ) } } +/* + * Add the metadata stored in the users preferences to the document if + * a) the preference 'Input/Output->Add default metatdata to new documents' is true, and + * b) there is no metadata already in the file (such as from a template) + */ +void rdf_add_from_preferences(SPDocument *doc) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (!prefs->getBool("/metadata/addToNewFile")) { + return; + } + + // If there is already some metadata in the doc (from a template) dont add default metadata + for (struct rdf_work_entity_t *entity = rdf_work_entities; entity && entity->name; entity++) { + if ( entity->editable == RDF_EDIT_GENERIC && + rdf_get_work_entity (doc, entity)) { + return; + } + } + + // Put the metadata from user preferences into the doc + for (struct rdf_work_entity_t *entity = rdf_work_entities; entity && entity->name; entity++) { + if ( entity->editable == RDF_EDIT_GENERIC ) { + Glib::ustring text = prefs->getString(PREFS_METADATA + Glib::ustring(entity->name)); + if (text.length() > 0) { + rdf_set_work_entity (doc, entity, text.c_str()); + } + } + } +} /* Local Variables: @@ -15,6 +15,8 @@ #include <glibmm/i18n.h> #include "document.h" +#define PREFS_METADATA "/metadata/rdf/" + // yeah, it's not a triple yet... /** * \brief Holds license name/resource doubles for rdf_license_t entries @@ -132,6 +134,8 @@ void rdf_set_license(SPDocument * doc, void rdf_set_defaults ( SPDocument * doc ); +void rdf_add_from_preferences ( SPDocument *doc ); + #endif // SEEN_RDF_H /* diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 0202360d5..71fc3ac1f 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -781,6 +781,20 @@ void DocumentProperties::build_metadata() } } + Gtk::Button *button_save = manage (new Gtk::Button(_("_Save as default"),1)); + button_save->set_tooltip_text(_("Save this metadata as the default metadata")); + Gtk::Button *button_load = manage (new Gtk::Button(_("Use _default"),1)); + button_load->set_tooltip_text(_("Use the previously saved default metadata here")); + Gtk::HButtonBox *box_buttons = manage (new Gtk::HButtonBox); + box_buttons->set_layout(Gtk::BUTTONBOX_END); + box_buttons->set_spacing(4); + box_buttons->pack_start(*button_save, true, true, 6); + box_buttons->pack_start(*button_load, true, true, 6); + _page_metadata1.pack_end(*box_buttons, false, false, 0); + + button_save->signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::save_default_metadata)); + button_load->signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::load_default_metadata)); + _page_metadata2.show(); row = 0; @@ -1257,6 +1271,23 @@ void DocumentProperties::on_response (int id) hide(); } +void DocumentProperties::load_default_metadata() +{ + /* Get the data RDF entities data from preferences*/ + for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); ++it) { + (*it)->load_from_preferences (); + } +} + +void DocumentProperties::save_default_metadata() +{ + /* Save these RDF entities to preferences*/ + for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); ++it) { + (*it)->save_to_preferences (SP_ACTIVE_DOCUMENT); + } +} + + void DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document) { Inkscape::XML::Node *repr = sp_desktop_namedview(desktop)->getRepr(); diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index 90ac6d9f0..5bafddc32 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -20,6 +20,7 @@ #include <gtkmm/comboboxtext.h> #include <gtkmm/liststore.h> #include <gtkmm/notebook.h> +#include <gtkmm/buttonbox.h> #include <gtkmm/textview.h> #include "ui/widget/page-sizer.h" @@ -89,6 +90,8 @@ protected: void editEmbeddedScript(); void external_create_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem); void embedded_create_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem); + void load_default_metadata(); + void save_default_metadata(); void _handleDocumentReplaced(SPDesktop* desktop, SPDocument *document); void _handleActivateDesktop(Inkscape::Application *application, SPDesktop *desktop); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 38fbe63ba..f2de350a0 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -779,6 +779,10 @@ void InkscapePreferences::initPageIO() _page_io.add_line( false, "", _misc_comment, "", _("When on, a comment will be added to the raw print output, marking the rendered output for an object with its label"), true); + _misc_default_metadata.init( _("Add default metadata to new documents"), "/metadata/addToNewFile", false); + _page_io.add_line( false, "", _misc_default_metadata, "", + _("Add default metadata to new documents. Default metadata can be set from Document Properties->Metadata."), true); + // Input devices options _mouse_sens.init ( "/options/cursortolerance/value", 0.0, 30.0, 1.0, 1.0, 8.0, true, false); _page_mouse.add_line( false, _("Grab sensitivity:"), _mouse_sens, _("pixels"), diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 2ff148232..1cf5cc975 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -286,6 +286,7 @@ protected: UI::Widget::PrefCheckButton _font_dialog; UI::Widget::PrefCheckButton _misc_comment; + UI::Widget::PrefCheckButton _misc_default_metadata; UI::Widget::PrefCheckButton _misc_forkvectors; UI::Widget::PrefCheckButton _misc_gradienteditor; UI::Widget::PrefCheckButton _misc_scripts; diff --git a/src/ui/widget/entity-entry.cpp b/src/ui/widget/entity-entry.cpp index 2a6e2bcd0..c622796b2 100644 --- a/src/ui/widget/entity-entry.cpp +++ b/src/ui/widget/entity-entry.cpp @@ -27,6 +27,7 @@ #include "sp-root.h" #include "document-undo.h" #include "document-private.h" +#include "preferences.h" #include "verbs.h" #include "entity-entry.h" @@ -72,6 +73,13 @@ EntityEntry::~EntityEntry() _changed_connection.disconnect(); } +void EntityEntry::save_to_preferences(SPDocument *doc) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + const gchar *text = rdf_get_work_entity (doc, _entity); + prefs->setString(PREFS_METADATA + Glib::ustring(_entity->name), Glib::ustring(text ? text : "")); +} + EntityLineEntry::EntityLineEntry (rdf_work_entity_t* ent, Registry& wr) : EntityEntry (ent, wr) { @@ -97,6 +105,16 @@ void EntityLineEntry::update(SPDocument *doc) static_cast<Gtk::Entry*>(_packable)->set_text (text ? text : ""); } + +void EntityLineEntry::load_from_preferences() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring text = prefs->getString(PREFS_METADATA + Glib::ustring(_entity->name)); + if (text.length() > 0) { + static_cast<Gtk::Entry*>(_packable)->set_text (text.c_str()); + } +} + void EntityLineEntry::on_changed() { @@ -146,6 +164,19 @@ void EntityMultiLineEntry::update(SPDocument *doc) tv->get_buffer()->set_text (text ? text : ""); } + +void EntityMultiLineEntry::load_from_preferences() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring text = prefs->getString(PREFS_METADATA + Glib::ustring(_entity->name)); + if (text.length() > 0) { + Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable); + Gtk::TextView *tv = static_cast<Gtk::TextView*>(s->get_child()); + tv->get_buffer()->set_text (text.c_str()); + } +} + + void EntityMultiLineEntry::on_changed() { diff --git a/src/ui/widget/entity-entry.h b/src/ui/widget/entity-entry.h index 0e031bb0a..09289496d 100644 --- a/src/ui/widget/entity-entry.h +++ b/src/ui/widget/entity-entry.h @@ -31,6 +31,8 @@ public: virtual ~EntityEntry() = 0; virtual void update (SPDocument *doc) = 0; virtual void on_changed() = 0; + virtual void load_from_preferences() = 0; + void save_to_preferences(SPDocument *doc); Gtk::Label _label; Gtk::Widget *_packable; @@ -46,6 +48,7 @@ public: EntityLineEntry (rdf_work_entity_t* ent, Registry& wr); ~EntityLineEntry(); void update (SPDocument *doc); + void load_from_preferences(); protected: virtual void on_changed(); @@ -56,6 +59,7 @@ public: EntityMultiLineEntry (rdf_work_entity_t* ent, Registry& wr); ~EntityMultiLineEntry(); void update (SPDocument *doc); + void load_from_preferences(); protected: virtual void on_changed(); |
