diff options
| -rw-r--r-- | src/document.cpp | 1 | ||||
| -rw-r--r-- | src/document.h | 5 | ||||
| -rw-r--r-- | src/uri-references.cpp | 39 |
3 files changed, 35 insertions, 10 deletions
diff --git a/src/document.cpp b/src/document.cpp index e56adee68..32a025e87 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -106,6 +106,7 @@ SPDocument::SPDocument() : profileManager(0), // deferred until after other initialization router(new Avoid::Router(Avoid::PolyLineRouting|Avoid::OrthogonalRouting)), _collection_queue(0), + parent_document(NULL), oldSignalsConnected(false), current_persp3d(NULL), current_persp3d_impl(NULL) diff --git a/src/document.h b/src/document.h index cc565e3aa..e804a4980 100644 --- a/src/document.h +++ b/src/document.h @@ -25,6 +25,7 @@ #include "gc-finalized.h" #include "gc-anchored.h" #include <glibmm/ustring.h> +#include <boost/ptr_container/ptr_list.hpp> #include <vector> namespace Avoid { @@ -120,6 +121,10 @@ public: GSList *_collection_queue; + // A list of svg documents being used or shown within this document + boost::ptr_list<SPDocument> child_documents; + SPDocument *parent_document; + bool oldSignalsConnected; /** Returns our SPRoot */ diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 718b2d451..adf948c7b 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -58,17 +58,36 @@ void URIReference::attach(const URI &uri) throw(BadURIException) // The path contains references to seperate document files to load. const char *path = uri.getPath(); - if(path) { - if(document != NULL) { - // Calculate the absolute path from an available document - std::string basePath = std::string( document->getBase() ); - std::string absPath = Glib::build_filename(basePath, std::string( path ) ); - path = absPath.c_str(); + if(path && document != NULL) { + // Calculate the absolute path from an available document + std::string basePath = std::string( document->getBase() ); + std::string absPath = Glib::build_filename(basePath, std::string( path ) ); + path = absPath.c_str(); + + // We look at existing children and parents + SPDocument *parent = document; + SPDocument *original = document; + document = NULL; + + while(parent != NULL) { + boost::ptr_list<SPDocument>::iterator iter; + for (iter = parent->child_documents.begin(); + iter != parent->child_documents.end(); ++iter) { + if(strcmp(iter->getURI(), path)==0) + document = &*iter; + } + parent = parent->parent_document; + } + // Load a fresh document from the svg source. + if(!document) { + document = SPDocument::createNewDoc(path, FALSE); + if(document) { + document->parent_document = original; + original->child_documents.push_back(document); + } else { + g_warning("Could not load svg file: %s", path); + } } - // TODO: This is inefficient because it will load the same svg file - // many times if it's used many times. A global list of documents would - // be useful for tracking linked items. - document = SPDocument::createNewDoc(path, FALSE); } g_return_if_fail(document != NULL); |
