file.cpp revision 83965d687aa02620e79151c91948d313bda9cbf1
871fccc39b870543073d7015a9d8c701252b68f9joncruz * File/Print operations
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Lauris Kaplinski <lauris@kaplinski.com>
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Chema Celorio <chema@celorio.com>
871fccc39b870543073d7015a9d8c701252b68f9joncruz * bulia byak <buliabyak@users.sf.net>
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Bruno Dilly <bruno.dilly@gmail.com>
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Copyright (C) 1999-2005 Authors
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Copyright (C) 2004 David Turner
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Copyright (C) 2001-2002 Ximian, Inc.
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Released under GNU GPL, read the file 'COPYING' for more information
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Note: This file needs to be cleaned up extensively.
871fccc39b870543073d7015a9d8c701252b68f9joncruz * What it probably needs is to have one .h file for
871fccc39b870543073d7015a9d8c701252b68f9joncruz * the API, and two or more .cpp files for the implementations.
871fccc39b870543073d7015a9d8c701252b68f9joncruz/* #include "extension/menu.h" */
871fccc39b870543073d7015a9d8c701252b68f9joncruz//#define INK_DUMP_FILENAME_CONV 1
871fccc39b870543073d7015a9d8c701252b68f9joncruz//#define INK_DUMP_FOPEN 1
871fccc39b870543073d7015a9d8c701252b68f9joncruzvoid dump_str(gchar const *str, gchar const *prefix);
871fccc39b870543073d7015a9d8c701252b68f9joncruz/*######################
871fccc39b870543073d7015a9d8c701252b68f9joncruz######################*/
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Create a blank document and add it to the desktop
871fccc39b870543073d7015a9d8c701252b68f9joncruz SPDocument *doc = sp_document_new(templName, TRUE, true);
871fccc39b870543073d7015a9d8c701252b68f9joncruz if (Inkscape::NSApplication::Application::getNewGui())
871fccc39b870543073d7015a9d8c701252b68f9joncruz dt = Inkscape::NSApplication::Editor::createDesktop (doc);
871fccc39b870543073d7015a9d8c701252b68f9joncruz SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
d703e5d08553a3dd5eb4f0a11040de79071bdcfbKrzysztof Kosiński sp_namedview_update_layers_from_document(dt);
871fccc39b870543073d7015a9d8c701252b68f9joncruz sources.push_back( profile_path("templates") ); // first try user's local dir
26b62dfb088a00b6debad350538a64c2af145f50johanengelen sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir
871fccc39b870543073d7015a9d8c701252b68f9joncruz if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) {
871fccc39b870543073d7015a9d8c701252b68f9joncruz // TRANSLATORS: default.svg is localizable - this is the name of the default document
871fccc39b870543073d7015a9d8c701252b68f9joncruz // template. This way you can localize the default pagesize, translate the name of
871fccc39b870543073d7015a9d8c701252b68f9joncruz // the default layer, etc. If you wish to localize this file, please create a
871fccc39b870543073d7015a9d8c701252b68f9joncruz // localized share/templates/default.xx.svg file, where xx is your language code.
871fccc39b870543073d7015a9d8c701252b68f9joncruz char *default_template = g_build_filename(dirname, _("default.svg"), NULL);
871fccc39b870543073d7015a9d8c701252b68f9joncruz if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) {
c97348400fa86585534b463cc1a3f70ecd9f4c72scislac/*######################
c97348400fa86585534b463cc1a3f70ecd9f4c72scislac## D E L E T E
871fccc39b870543073d7015a9d8c701252b68f9joncruz######################*/
871fccc39b870543073d7015a9d8c701252b68f9joncruz * Perform document closures preceding an exit()
00cd8cdd29c4bcef32835fb75ed803cefeec6d10theAdib // no need to call inkscape_exit here; last document being closed will take care of that
00cd8cdd29c4bcef32835fb75ed803cefeec6d10theAdib/*######################
00cd8cdd29c4bcef32835fb75ed803cefeec6d10theAdib######################*/
00cd8cdd29c4bcef32835fb75ed803cefeec6d10theAdib * Open a file, add the document to the desktop
00cd8cdd29c4bcef32835fb75ed803cefeec6d10theAdib * \param replace_empty if true, and the current desktop is empty, this document
00cd8cdd29c4bcef32835fb75ed803cefeec6d10theAdib * will replace the empty one.
00cd8cdd29c4bcef32835fb75ed803cefeec6d10theAdib } catch (Inkscape::Extension::Input::no_extension_found &e) {
00cd8cdd29c4bcef32835fb75ed803cefeec6d10theAdib } catch (Inkscape::Extension::Input::open_failed &e) {
b0a706debff59200299511d55822722c5cb3e15fbuliabyak SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL;
871fccc39b870543073d7015a9d8c701252b68f9joncruz if (existing && existing->virgin && replace_empty) {
871fccc39b870543073d7015a9d8c701252b68f9joncruz // If the current desktop is empty, open the document there
871fccc39b870543073d7015a9d8c701252b68f9joncruz sp_document_resized_signal_emit (doc, sp_document_width(doc), sp_document_height(doc));
871fccc39b870543073d7015a9d8c701252b68f9joncruz if (!Inkscape::NSApplication::Application::getNewGui()) {
871fccc39b870543073d7015a9d8c701252b68f9joncruz // create a whole new desktop and window
871fccc39b870543073d7015a9d8c701252b68f9joncruz SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
871fccc39b870543073d7015a9d8c701252b68f9joncruz desktop = Inkscape::NSApplication::Editor::createDesktop (doc);
if (add_to_recent) {
return TRUE;
return FALSE;
if (!uri) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved yet. Cannot revert."));
bool do_revert = true;
gchar *text = g_strdup_printf(_("Changes will be lost! Are you sure you want to reload document %s?"), uri);
if (!response) {
do_revert = false;
bool reverted;
if (do_revert) {
reverted = false;
if (reverted) {
for (unsigned i = 0; i < total; i++) {
if (i < dataLen) {
if (i < byteLen) {
if ( i < cstrLen ) {
if (attr)
if (!openDialogInstance) {
if (!success)
#ifdef INK_DUMP_FILENAME_CONV
if (diff > 0) {
diff),
diff);
gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s). This may have been caused by an unknown filename extension."), safeUri);
return FALSE;
return FALSE;
#ifdef WITH_GNOME_VFS
result = gnome_vfs_create (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
if (!attr)
if (attr)
if (extension)
if (attr)
char const * dialog_title;
if (is_copy) {
if (!success) {
delete saveDialog;
return success;
delete saveDialog;
saveDialog = 0;
if (success)
return success;
bool success = true;
SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved."));
return success;
if (!SP_ACTIVE_DOCUMENT)
if (!SP_ACTIVE_DOCUMENT)
if (!SP_ACTIVE_DOCUMENT)
// FIXME: in case of id conflict, newly added thing will be re-ided and thus likely break a reference to it from imported stuff
items_count ++;
for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc)); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (desktop) {
for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc)); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (desktop) {
if (sel_bbox) {
if (!doc)
if (!importDialogInstance) {
if (!success)
#ifdef NEW_EXPORT_DIALOG
if (!attr)
if (attr)
if (extension)
if (attr)
if (!exportDialogInstance)
if (!success)
return success;
if (success)
return success;
if (!SP_ACTIVE_DOCUMENT)
bool success = false;
static bool gotSuccess = false;
if (!exportDialogInstance)
if (!success)
return success;
if (!success){
return success;
if(!gotSuccess)
if (!success)
return success;
if (!success)
gchar *text = g_strdup_printf(_("Error exporting the document. Verify if the server name, username and password are correct. If the server have support for webdav and verify if you didn't forget to choose a license too."));
gotSuccess = true;
return success;
if (!SP_ACTIVE_DOCUMENT)
if (success)
if (!doc)
if (!importDialogInstance) {
if (!success)
if (doc)
if (doc)
if (doc)
"foo.svg",
"file:foo.svg",
"bar\xe1\x84\x92.svg",
for ( int i = 0; things[i]; i++ )
things[i],
str );
things[i],
str );