From e5d2a28ac81cd82aac499b2c357f65020be69de1 Mon Sep 17 00:00:00 2001 From: mental Date: Fri, 23 Mar 2007 05:52:15 +0000 Subject: [PATCH] allow multiple (balanced) calls to add and remove document --- src/application/editor.cpp | 12 ++++++++---- src/application/editor.h | 2 ++ src/document.cpp | 4 ---- src/inkscape.cpp | 19 +++++++++++++++---- src/ui/view/view.cpp | 7 +++++++ 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/application/editor.cpp b/src/application/editor.cpp index 1cc45f3c7..56984dcbb 100644 --- a/src/application/editor.cpp +++ b/src/application/editor.cpp @@ -109,15 +109,19 @@ Editor::getActiveDocument() void Editor::addDocument (SPDocument *doc) { - g_assert (!g_slist_find (_instance->_documents, doc)); - _instance->_documents = g_slist_append (_instance->_documents, doc); + if ( _instance->_document_set.find(doc) == _instance->_document_set.end() ) { + _instance->_documents = g_slist_append (_instance->_documents, doc); + } + _instance->_document_set.insert(doc); } void Editor::removeDocument (SPDocument *doc) { - g_assert (g_slist_find (_instance->_documents, doc)); - _instance->_documents = g_slist_remove (_instance->_documents, doc); + _instance->_document_set.erase(doc); + if ( _instance->_document_set.find(doc) == _instance->_document_set.end() ) { + _instance->_documents = g_slist_remove (_instance->_documents, doc); + } } SPDesktop* diff --git a/src/application/editor.h b/src/application/editor.h index 9d2ce493c..a6fe66688 100644 --- a/src/application/editor.h +++ b/src/application/editor.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "app-prototype.h" class SPDesktop; @@ -96,6 +97,7 @@ protected: Editor(Editor const &); Editor& operator=(Editor const &); + std::multiset _document_set; GSList *_documents; GSList *_desktops; gchar *_argv0; diff --git a/src/document.cpp b/src/document.cpp index e66089fed..4dd0f3d21 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -118,8 +118,6 @@ SPDocument::~SPDocument() { collectOrphans(); if (priv) { - inkscape_remove_document(this); - if (priv->partial) { sp_repr_free_log(priv->partial); priv->partial = NULL; @@ -315,7 +313,6 @@ sp_document_create(Inkscape::XML::Document *rdoc, document->_selection_changed_connection = Inkscape::NSApplication::Editor::connectSelectionChanged (sigc::mem_fun (*document, &SPDocument::reset_key)); document->_desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::mem_fun (*document, &SPDocument::reset_key)); } - inkscape_add_document(document); return document; } @@ -402,7 +399,6 @@ sp_document_new_from_mem(gchar const *buffer, gint length, unsigned int keepaliv SPDocument *sp_document_new_dummy() { SPDocument *document = new SPDocument(); - inkscape_add_document(document); return document; } diff --git a/src/inkscape.cpp b/src/inkscape.cpp index be3ff1e7d..799227bf3 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -18,6 +18,7 @@ #endif +#include #include "debug/simple-event.h" #include "debug/event-tracker.h" @@ -109,6 +110,7 @@ static bool inkscape_init_config (Inkscape::XML::Document *doc, const gchar *con struct Inkscape::Application { GObject object; Inkscape::XML::Document *menus; + std::multiset document_set; GSList *documents; GSList *desktops; gchar *argv0; @@ -292,6 +294,8 @@ inkscape_init (SPObject * object) g_assert_not_reached (); } + new (&inkscape->document_set) std::multiset(); + inkscape->menus = sp_repr_read_mem (_(menus_skeleton), MENUS_SKELETON_SIZE, NULL); inkscape->documents = NULL; @@ -321,6 +325,8 @@ inkscape_dispose (GObject *object) inkscape->menus = NULL; } + inkscape->document_set.~multiset(); + G_OBJECT_CLASS (parent_class)->dispose (object); gtk_main_quit (); @@ -1112,8 +1118,11 @@ inkscape_add_document (SPDocument *document) if (!Inkscape::NSApplication::Application::getNewGui()) { - g_assert (!g_slist_find (inkscape->documents, document)); - inkscape->documents = g_slist_append (inkscape->documents, document); + if ( inkscape->document_set.find(document) != inkscape->document_set.end() ) { + + inkscape->documents = g_slist_append (inkscape->documents, document); + } + inkscape->document_set.insert(document); } else { @@ -1130,8 +1139,10 @@ inkscape_remove_document (SPDocument *document) if (!Inkscape::NSApplication::Application::getNewGui()) { - g_assert (g_slist_find (inkscape->documents, document)); - inkscape->documents = g_slist_remove (inkscape->documents, document); + inkscape->document_set.erase(document); + if ( inkscape->document_set.find(document) == inkscape->document_set.end() ) { + inkscape->documents = g_slist_remove (inkscape->documents, document); + } } else { diff --git a/src/ui/view/view.cpp b/src/ui/view/view.cpp index 04158ddbd..6b6e0b8b6 100644 --- a/src/ui/view/view.cpp +++ b/src/ui/view/view.cpp @@ -23,6 +23,7 @@ #include "message-stack.h" #include "message-context.h" #include "verbs.h" +#include "inkscape-private.h" namespace Inkscape { namespace UI { @@ -83,6 +84,9 @@ View::View() */ View::~View() { + if (_doc) { + inkscape_remove_document(_doc); + } _close(); } @@ -138,8 +142,11 @@ void View::setDocument(SPDocument *doc) { if (_doc) { _document_uri_set_connection.disconnect(); _document_resized_connection.disconnect(); + inkscape_remove_document(_doc); } + inkscape_add_document(doc); + _doc = doc; _document_uri_set_connection = _doc->connectURISet(sigc::bind(sigc::ptr_fun(&_onDocumentURISet), this)); -- 2.30.2