From: mental Date: Tue, 15 Jan 2008 04:27:00 +0000 (+0000) Subject: abstract use of sodipodi:modified X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7348bd1fda2f0fd2297788a486bf2eaa9b5650cc;p=inkscape.git abstract use of sodipodi:modified --- diff --git a/src/dialogs/export.cpp b/src/dialogs/export.cpp index d26a5cde1..d664ef729 100644 --- a/src/dialogs/export.cpp +++ b/src/dialogs/export.cpp @@ -1237,7 +1237,7 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) } if (modified) - repr->setAttribute("sodipodi:modified", "TRUE"); + doc->setModified(); sp_document_set_undo_sensitive(doc, saved); break; } @@ -1277,8 +1277,7 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) } if (modified) { - Inkscape::XML::Node * repr = sp_document_repr_root(doc); - repr->setAttribute("sodipodi:modified", "TRUE"); + doc->setModified(); } sp_document_set_undo_sensitive(doc, saved); diff --git a/src/document-undo.cpp b/src/document-undo.cpp index 7556d2e8f..2acd740f2 100644 --- a/src/document-undo.cpp +++ b/src/document-undo.cpp @@ -66,6 +66,15 @@ #include "debug/timestamp.h" #include "event.h" +bool SPDocument::isModified() const { + return rroot ? rroot->attribute("sodipodi:modified") != NULL : false; +} +void SPDocument::setModified(bool modified) { + if (rroot) { + rroot->setAttribute("sodipodi:modified", "true"); + } +} + /* * Undo & redo @@ -199,9 +208,7 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev doc->actionkey = key; doc->virgin = FALSE; - if (!doc->rroot->attribute("sodipodi:modified")) { - doc->rroot->setAttribute("sodipodi:modified", "true"); - } + doc->setModified(); sp_repr_begin_transaction (doc->rdoc); @@ -267,7 +274,7 @@ sp_document_undo (SPDocument *doc) sp_repr_undo_log (log->event); doc->priv->redo = g_slist_prepend (doc->priv->redo, log); - doc->rroot->setAttribute("sodipodi:modified", "true"); + doc->setModified(); doc->priv->undoStackObservers.notifyUndoEvent(log); ret = TRUE; @@ -313,7 +320,7 @@ sp_document_redo (SPDocument *doc) sp_repr_replay_log (log->event); doc->priv->undo = g_slist_prepend (doc->priv->undo, log); - doc->rroot->setAttribute("sodipodi:modified", "true"); + doc->setModified(); doc->priv->undoStackObservers.notifyRedoEvent(log); ret = TRUE; diff --git a/src/document.h b/src/document.h index 462d2a15a..6c9ea570d 100644 --- a/src/document.h +++ b/src/document.h @@ -140,6 +140,9 @@ sigc::connection connectCommit(CommitSignal::slot_type slot); /// Are we currently in a transition between two "known good" states of the document? bool isSeeking() const; + bool isModified() const; + void setModified(bool modified=true); + private: SPDocument(SPDocument const &); // no copy void operator=(SPDocument const &); // no assign diff --git a/src/event-log.cpp b/src/event-log.cpp index 4c2ef9c7a..54e58678a 100644 --- a/src/event-log.cpp +++ b/src/event-log.cpp @@ -364,10 +364,9 @@ void EventLog::checkForVirginity() { g_return_if_fail (_document); if (_curr_event == _last_saved) { - Inkscape::XML::Node *repr = sp_document_repr_root(_document); bool saved = sp_document_get_undo_sensitive(_document); sp_document_set_undo_sensitive(_document, false); - repr->setAttribute("sodipodi:modified", NULL); + _document->setModified(false); sp_document_set_undo_sensitive(_document, saved); } } diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 0372e4aa0..9b0c99010 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -104,10 +104,9 @@ open(Extension *key, gchar const *filename) /* This kinda overkill as most of these are already set, but I want to make sure for this release -- TJG */ - Inkscape::XML::Node *repr = sp_document_repr_root(doc); bool saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive(doc, false); - repr->setAttribute("sodipodi:modified", NULL); + doc->setModified(false); sp_document_set_undo_sensitive(doc, saved); sp_document_set_uri(doc, filename); @@ -249,14 +248,12 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, Inkscape::XML::Node *repr = sp_document_repr_root(doc); // remember attributes in case this is an unofficial save - gchar *saved_sodipodi_modified = NULL; + bool saved_modified = false; gchar *saved_output_extension = NULL; gchar *saved_dataloss = NULL; gchar *saved_uri = NULL; if (!official) { - if (repr->attribute("sodipodi:modified")) { - saved_sodipodi_modified = g_strdup(repr->attribute("sodipodi:modified")); - } + saved_modified = doc->isModified(); if (repr->attribute("inkscape:output_extension")) { saved_output_extension = g_strdup(repr->attribute("inkscape:output_extension")); } @@ -271,7 +268,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, // update attributes: bool saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive (doc, false); - repr->setAttribute("sodipodi:modified", NULL); + doc->setModified(false); // save the filename for next use sp_document_set_uri(doc, fileName); // also save the extension for next use @@ -289,14 +286,13 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, if ( !official) { saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive (doc, false); - repr->setAttribute("sodipodi:modified", saved_sodipodi_modified); + doc->setModified(saved_modified); repr->setAttribute("inkscape:output_extension", saved_output_extension); repr->setAttribute("inkscape:dataloss", saved_dataloss); sp_document_set_uri(doc, saved_uri); sp_document_set_undo_sensitive (doc, saved); } - if (saved_sodipodi_modified) g_free(saved_sodipodi_modified); if (saved_output_extension) g_free(saved_output_extension); if (saved_dataloss) g_free(saved_dataloss); if (saved_uri) g_free(saved_uri); diff --git a/src/file.cpp b/src/file.cpp index 355b1c50a..58ca463bf 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -249,7 +249,7 @@ sp_file_revert_dialog() } bool do_revert = true; - if (repr->attribute("sodipodi:modified") != NULL) { + if (doc->isModified()) { gchar *text = g_strdup_printf(_("Changes will be lost! Are you sure you want to reload document %s?"), uri); bool response = desktop->warnDialog (text); @@ -771,16 +771,14 @@ sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc) { bool success = true; - Inkscape::XML::Node *repr = sp_document_repr_root(doc); - - gchar const *fn = repr->attribute("sodipodi:modified"); - if (fn != NULL) { + if (doc->isModified()) { + Inkscape::XML::Node *repr = sp_document_repr_root(doc); if ( doc->uri == NULL || repr->attribute("inkscape:output_extension") == NULL ) { return sp_file_save_dialog(parentWindow, doc, FALSE); } else { - fn = g_strdup(doc->uri); + gchar const *fn = g_strdup(doc->uri); gchar const *ext = repr->attribute("inkscape:output_extension"); success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE); g_free((void *) fn); @@ -1187,13 +1185,11 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) static bool gotSuccess = false; Inkscape::XML::Node *repr = sp_document_repr_root(doc); - // Verify whether the document is saved, so save this as temporary - char *str = (char *) repr->attribute("sodipodi:modified"); - if ((!doc->uri) && (!str)) + if (!doc->uri && !doc->isModified()) return false; - // Get the default extension name + // Get the default extension name Glib::ustring default_extension = "org.inkscape.output.svg.inkscape"; char formatBuf[256]; diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 8b84416aa..4f831e629 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -431,7 +431,7 @@ inkscape_crash_handler (int /*signum*/) Inkscape::XML::Node *repr; doc = (SPDocument *) l->data; repr = sp_document_repr_root (doc); - if (repr->attribute("sodipodi:modified")) { + if (doc->isModified()) { const gchar *docname, *d0, *d; gchar n[64], c[1024]; FILE *file; diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index f738828e5..0368262dc 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -884,7 +884,7 @@ void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr) sp_repr_set_boolean(repr, "showguides", v); - doc->rroot->setAttribute("sodipodi:modified", "true"); + doc->setModified(); sp_document_set_undo_sensitive(doc, saved); } @@ -903,7 +903,7 @@ void sp_namedview_show_grids(SPNamedView * namedview, bool show, bool dirty_docu /* we don't want the document to get dirty on startup; that's when we call this function with dirty_document = false */ if (dirty_document) { - doc->rroot->setAttribute("sodipodi:modified", "true"); + doc->setModified(); } sp_document_set_undo_sensitive(doc, saved); } diff --git a/src/ui/view/edit-widget.cpp b/src/ui/view/edit-widget.cpp index ff8b288fd..78cf76096 100644 --- a/src/ui/view/edit-widget.cpp +++ b/src/ui/view/edit-widget.cpp @@ -1203,8 +1203,7 @@ EditWidget::shutdown() return false; SPDocument *doc = _desktop->doc(); - if (sp_document_repr_root(doc)->attribute("sodipodi:modified") != NULL) - { + if (doc->isModified()) { gchar *markup; /// \todo FIXME !!! obviously this will have problems if the document /// name contains markup characters diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index aac9ff25c..84d53663b 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -69,7 +69,7 @@ RegisteredWidget::write_to_xml(const char * svgstr) sp_document_set_undo_sensitive (local_doc, false); if (!write_undo) local_repr->setAttribute(_key.c_str(), svgstr); - local_doc->rroot->setAttribute("sodipodi:modified", "true"); + local_doc->setModified(); sp_document_set_undo_sensitive (local_doc, saved); if (write_undo) { @@ -378,7 +378,7 @@ RegisteredColorPicker::on_changed (guint32 rgba) sp_document_set_undo_sensitive (local_doc, false); local_repr->setAttribute(_ckey.c_str(), c); sp_repr_set_css_double(local_repr, _akey.c_str(), (rgba & 0xff) / 255.0); - local_doc->rroot->setAttribute("sodipodi:modified", "true"); + local_doc->setModified(); sp_document_set_undo_sensitive (local_doc, saved); sp_document_done (local_doc, SP_VERB_NONE, /* TODO: annotate */ "registered-widget.cpp: RegisteredColorPicker::on_changed"); diff --git a/src/ui/widget/tolerance-slider.cpp b/src/ui/widget/tolerance-slider.cpp index 4db82d880..1c5f9b521 100644 --- a/src/ui/widget/tolerance-slider.cpp +++ b/src/ui/widget/tolerance-slider.cpp @@ -179,7 +179,7 @@ ToleranceSlider::update (double val) sp_document_set_undo_sensitive (doc, false); Inkscape::XML::Node *repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); repr->setAttribute(_key.c_str(), os.str().c_str()); - doc->rroot->setAttribute("sodipodi:modified", "true"); + doc->setModified(); sp_document_set_undo_sensitive (doc, saved); _wr->setUpdating (false); diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 4c2ebf21c..ca1121152 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -807,7 +807,7 @@ SPDesktopWidget::shutdown() if (inkscape_is_sole_desktop_for_document(*desktop)) { SPDocument *doc = desktop->doc(); - if (sp_document_repr_root(doc)->attribute("sodipodi:modified") != NULL) { + if (doc->isModified()) { GtkWidget *dialog; /** \todo