From: mental Date: Tue, 15 Jan 2008 05:08:28 +0000 (+0000) Subject: stop toggling insensitive state for modification flag updates (fixes critical bug... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1e595ddc34dd7090b285ed9f6fc8e125b9a264d9;p=inkscape.git stop toggling insensitive state for modification flag updates (fixes critical bug #182401) In order to do this, I got rid of sodipodi:modified in favor of a simple flag in SPDocument, also renaming SPDocument::{set,is}Modified to SPDocument::{set,is}ModifiedSinceSave --- diff --git a/src/dialogs/export.cpp b/src/dialogs/export.cpp index d664ef729..14d338ed5 100644 --- a/src/dialogs/export.cpp +++ b/src/dialogs/export.cpp @@ -1235,10 +1235,11 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi); modified = true; } - - if (modified) - doc->setModified(); sp_document_set_undo_sensitive(doc, saved); + + if (modified) { + doc->setModifiedSinceSave(); + } break; } case SELECTION_SELECTION: { @@ -1275,12 +1276,11 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) modified = true; } } + sp_document_set_undo_sensitive(doc, saved); if (modified) { - doc->setModified(); + doc->setModifiedSinceSave(); } - - sp_document_set_undo_sensitive(doc, saved); break; } default: diff --git a/src/document-undo.cpp b/src/document-undo.cpp index 2acd740f2..7df4943b7 100644 --- a/src/document-undo.cpp +++ b/src/document-undo.cpp @@ -66,15 +66,6 @@ #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 @@ -208,7 +199,7 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev doc->actionkey = key; doc->virgin = FALSE; - doc->setModified(); + doc->setModifiedSinceSave(); sp_repr_begin_transaction (doc->rdoc); @@ -274,7 +265,7 @@ sp_document_undo (SPDocument *doc) sp_repr_undo_log (log->event); doc->priv->redo = g_slist_prepend (doc->priv->redo, log); - doc->setModified(); + doc->setModifiedSinceSave(); doc->priv->undoStackObservers.notifyUndoEvent(log); ret = TRUE; @@ -320,7 +311,7 @@ sp_document_redo (SPDocument *doc) sp_repr_replay_log (log->event); doc->priv->undo = g_slist_prepend (doc->priv->undo, log); - doc->setModified(); + doc->setModifiedSinceSave(); doc->priv->undoStackObservers.notifyRedoEvent(log); ret = TRUE; diff --git a/src/document.h b/src/document.h index 6c9ea570d..8a4e65bb3 100644 --- a/src/document.h +++ b/src/document.h @@ -81,6 +81,7 @@ struct SPDocument : public Inkscape::GC::Managed<>, unsigned int keepalive : 1; unsigned int virgin : 1; ///< Has the document never been touched? + unsigned int modified_since_save : 1; Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document @@ -140,8 +141,10 @@ 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); + bool isModifiedSinceSave() const { return modified_since_save; } + void setModifiedSinceSave(bool modified=true) { + modified_since_save = modified; + } private: SPDocument(SPDocument const &); // no copy diff --git a/src/event-log.cpp b/src/event-log.cpp index 54e58678a..82de44696 100644 --- a/src/event-log.cpp +++ b/src/event-log.cpp @@ -364,10 +364,7 @@ void EventLog::checkForVirginity() { g_return_if_fail (_document); if (_curr_event == _last_saved) { - bool saved = sp_document_get_undo_sensitive(_document); - sp_document_set_undo_sensitive(_document, false); - _document->setModified(false); - sp_document_set_undo_sensitive(_document, saved); + _document->setModifiedSinceSave(false); } } diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 9b0c99010..b9976595a 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -104,10 +104,7 @@ 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 */ - bool saved = sp_document_get_undo_sensitive(doc); - sp_document_set_undo_sensitive(doc, false); - doc->setModified(false); - sp_document_set_undo_sensitive(doc, saved); + doc->setModifiedSinceSave(false); sp_document_set_uri(doc, filename); @@ -253,7 +250,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, gchar *saved_dataloss = NULL; gchar *saved_uri = NULL; if (!official) { - saved_modified = doc->isModified(); + saved_modified = doc->isModifiedSinceSave(); if (repr->attribute("inkscape:output_extension")) { saved_output_extension = g_strdup(repr->attribute("inkscape:output_extension")); } @@ -268,7 +265,6 @@ 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); - doc->setModified(false); // save the filename for next use sp_document_set_uri(doc, fileName); // also save the extension for next use @@ -279,6 +275,7 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, repr->setAttribute("inkscape:dataloss", "true"); } sp_document_set_undo_sensitive (doc, saved); + doc->setModifiedSinceSave(false); omod->save(doc, fileName); @@ -286,11 +283,11 @@ 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); - 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); + doc->setModifiedSinceSave(saved_modified); } if (saved_output_extension) g_free(saved_output_extension); diff --git a/src/file.cpp b/src/file.cpp index 58ca463bf..c3e7e7583 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -249,7 +249,7 @@ sp_file_revert_dialog() } bool do_revert = true; - if (doc->isModified()) { + if (doc->isModifiedSinceSave()) { 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,7 +771,7 @@ sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc) { bool success = true; - if (doc->isModified()) { + if (doc->isModifiedSinceSave()) { Inkscape::XML::Node *repr = sp_document_repr_root(doc); if ( doc->uri == NULL || repr->attribute("inkscape:output_extension") == NULL ) @@ -1186,7 +1186,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) Inkscape::XML::Node *repr = sp_document_repr_root(doc); - if (!doc->uri && !doc->isModified()) + if (!doc->uri && !doc->isModifiedSinceSave()) return false; // Get the default extension name diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 4f831e629..cd176c0cf 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 (doc->isModified()) { + if (doc->isModifiedSinceSave()) { 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 0368262dc..481f201cd 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -881,11 +881,10 @@ void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr) bool saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive(doc, false); - sp_repr_set_boolean(repr, "showguides", v); - - doc->setModified(); sp_document_set_undo_sensitive(doc, saved); + + doc->setModifiedSinceSave(); } void sp_namedview_show_grids(SPNamedView * namedview, bool show, bool dirty_document) @@ -897,15 +896,14 @@ void sp_namedview_show_grids(SPNamedView * namedview, bool show, bool dirty_docu bool saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive(doc, false); - sp_repr_set_boolean(repr, "showgrid", namedview->grids_visible); + sp_document_set_undo_sensitive(doc, saved); /* 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->setModified(); + doc->setModifiedSinceSave(); } - sp_document_set_undo_sensitive(doc, saved); } gchar const *SPNamedView::getName() const diff --git a/src/ui/view/edit-widget.cpp b/src/ui/view/edit-widget.cpp index 78cf76096..9ac6aeefd 100644 --- a/src/ui/view/edit-widget.cpp +++ b/src/ui/view/edit-widget.cpp @@ -1203,7 +1203,7 @@ EditWidget::shutdown() return false; SPDocument *doc = _desktop->doc(); - if (doc->isModified()) { + if (doc->isModifiedSinceSave()) { 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 84d53663b..1364e5a2a 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -67,11 +67,10 @@ RegisteredWidget::write_to_xml(const char * svgstr) bool saved = sp_document_get_undo_sensitive (local_doc); sp_document_set_undo_sensitive (local_doc, false); - if (!write_undo) local_repr->setAttribute(_key.c_str(), svgstr); - local_doc->setModified(); - sp_document_set_undo_sensitive (local_doc, saved); + + local_doc->setModifiedSinceSave(); if (write_undo) { local_repr->setAttribute(_key.c_str(), svgstr); sp_document_done (local_doc, event_type, event_description); @@ -378,8 +377,9 @@ 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->setModified(); sp_document_set_undo_sensitive (local_doc, saved); + + local_doc->setModifiedSinceSave(); 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 1c5f9b521..0110a6c4c 100644 --- a/src/ui/widget/tolerance-slider.cpp +++ b/src/ui/widget/tolerance-slider.cpp @@ -179,8 +179,9 @@ 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->setModified(); sp_document_set_undo_sensitive (doc, saved); + + doc->setModifiedSinceSave(); _wr->setUpdating (false); } diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index ca1121152..4d44b1b26 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 (doc->isModified()) { + if (doc->isModifiedSinceSave()) { GtkWidget *dialog; /** \todo