Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

SPDocument* sp_document_new ( gchar const *  uri,
unsigned int  keepalive,
bool  make_new 
)

Fetches document from URI, or creates new, if NULL; public document appears in document list.

Definition at line 409 of file document.cpp.

References Inkscape::XML::Node::name(), Inkscape::XML::Node::root(), and sp_repr_document_new().

Referenced by Inkscape::UI::ClipboardManagerImpl::_createInternalClipboard(), Inkscape::UI::Dialog::SVGPreview::setFileName(), and sp_file_new().

{
    SPDocument *doc;
    Inkscape::XML::Document *rdoc;
    gchar *base = NULL;
    gchar *name = NULL;

    if (uri) {
        Inkscape::XML::Node *rroot;
        gchar *s, *p;
        /* Try to fetch repr from file */
        rdoc = sp_repr_read_file(uri, SP_SVG_NS_URI);
        /* If file cannot be loaded, return NULL without warning */
        if (rdoc == NULL) return NULL;
        rroot = rdoc->root();
        /* If xml file is not svg, return NULL without warning */
        /* fixme: destroy document */
        if (strcmp(rroot->name(), "svg:svg") != 0) return NULL;
        s = g_strdup(uri);
        p = strrchr(s, '/');
        if (p) {
            name = g_strdup(p + 1);
            p[1] = '\0';
            base = g_strdup(s);
        } else {
            base = NULL;
            name = g_strdup(uri);
        }
        g_free(s);
    } else {
        rdoc = sp_repr_document_new("svg:svg");
    }

    if (make_new) {
        base = NULL;
        uri = NULL;
        name = g_strdup_printf(_("New document %d"), ++doc_count);
    }

    //# These should be set by now
    g_assert(name);

    doc = sp_document_create(rdoc, uri, base, name, keepalive);

    g_free(base);
    g_free(name);

    return doc;
}


Generated by  Doxygen 1.6.0   Back to index