From f6e71416f19343cb97098c175acce52771e5e32b Mon Sep 17 00:00:00 2001 From: MenTaLguY Date: Fri, 23 Mar 2007 05:52:15 +0000 Subject: allow multiple (balanced) calls to add and remove document (bzr r2745) --- src/inkscape.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/inkscape.cpp') 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 { -- cgit v1.2.3