Logo Search packages:      
Sourcecode: inkscape version File versions

bool sp_file_save_dialog ( Gtk::Window &  parentWindow,
SPDocument doc,
Inkscape::Extension::FileSaveMethod  save_method 
)

Display a SaveAs dialog. Save the document if OK pressed.

Definition at line 704 of file file.cpp.

References Inkscape::UI::Dialog::FileSaveDialog::create(), Inkscape::Extension::db, file_save(), Inkscape::Extension::get_file_save_extension(), Inkscape::Extension::get_file_save_path(), Inkscape::UI::Dialog::FileSaveDialog::getDocTitle(), Inkscape::UI::Dialog::FileSaveDialog::getFilename(), Inkscape::UI::Dialog::FileSaveDialog::getSelectionType(), rdf_find_entity(), rdf_set_work_entity(), SPDocument::root, Inkscape::UI::Dialog::FileSaveDialog::setSelectionType(), Inkscape::UI::Dialog::FileSaveDialog::show(), Inkscape::Extension::store_save_path_in_prefs(), SPObject::title(), and SPDocument::uri.

Referenced by file_save(), SPDesktopWidget::shutdown(), sp_file_save_a_copy(), sp_file_save_as(), and sp_file_save_document().

{
    Inkscape::Extension::Output *extension = 0;
    bool is_copy = (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY);

    // Note: default_extension has the format "org.inkscape.output.svg.inkscape", whereas
    //       filename_extension only uses ".svg"
    Glib::ustring default_extension;
    Glib::ustring filename_extension = ".svg";

    default_extension= Inkscape::Extension::get_file_save_extension(save_method);
    //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension);

    extension = dynamic_cast<Inkscape::Extension::Output *>
        (Inkscape::Extension::db.get(default_extension.c_str()));

    if (extension)
        filename_extension = extension->get_extension();

    Glib::ustring save_path;
    Glib::ustring save_loc;

    save_path = Inkscape::Extension::get_file_save_path(doc, save_method);

    if (!Inkscape::IO::file_test(save_path.c_str(),
          (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
        save_path = "";

    if (save_path.size()<1)
        save_path = g_get_home_dir();

    save_loc = save_path;
    save_loc.append(G_DIR_SEPARATOR_S);

    char formatBuf[256];
    int i = 1;
    if (!doc->uri) {
        // We are saving for the first time; create a unique default filename
        snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
        save_loc.append(formatBuf);

        while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) {
            save_loc = save_path;
            save_loc.append(G_DIR_SEPARATOR_S);
            snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str());
            save_loc.append(formatBuf);
        }
    } else {
        snprintf(formatBuf, 255, _("%s"), Glib::path_get_basename(doc->uri).c_str());
        save_loc.append(formatBuf);
    }

    // convert save_loc from utf-8 to locale
    // is this needed any more, now that everything is handled in
    // Inkscape::IO?
    Glib::ustring save_loc_local = Glib::filename_from_utf8(save_loc);

    if ( save_loc_local.size() > 0)
        save_loc = save_loc_local;

    //# Show the SaveAs dialog
    char const * dialog_title;
    if (is_copy) {
        dialog_title = (char const *) _("Select file to save a copy to");
    } else {
        dialog_title = (char const *) _("Select file to save to");
    }
    gchar* doc_title = doc->root->title();
    Inkscape::UI::Dialog::FileSaveDialog *saveDialog =
        Inkscape::UI::Dialog::FileSaveDialog::create(
            parentWindow,
            save_loc,
            Inkscape::UI::Dialog::SVG_TYPES,
            dialog_title,
            default_extension,
            doc_title ? doc_title : "",
            save_method
            );

    saveDialog->setSelectionType(extension);

    bool success = saveDialog->show();
    if (!success) {
        delete saveDialog;
        return success;
    }

    // set new title here (call RDF to ensure metadata and title element are updated)
    rdf_set_work_entity(doc, rdf_find_entity("title"), saveDialog->getDocTitle().c_str());
    // free up old string
    if(doc_title) g_free(doc_title);

    Glib::ustring fileName = saveDialog->getFilename();
    Inkscape::Extension::Extension *selectionType = saveDialog->getSelectionType();

    delete saveDialog;

    saveDialog = 0;

    if (fileName.size() > 0) {
        Glib::ustring newFileName = Glib::filename_to_utf8(fileName);

        if ( newFileName.size()>0 )
            fileName = newFileName;
        else
            g_warning( "Error converting save filename to UTF-8." );

        // FIXME: does the argument !is_copy really convey the correct meaning here?
        success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy, save_method);

        if (success && SP_DOCUMENT_URI(doc)) {
            sp_file_add_recent(SP_DOCUMENT_URI(doc));
        }

        save_path = Glib::path_get_dirname(fileName);
        Inkscape::Extension::store_save_path_in_prefs(save_path, save_method);

        return success;
    }


    return false;
}


Generated by  Doxygen 1.6.0   Back to index