summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4c82feb)
raw | patch | inline | side by side (parent: 4c82feb)
author | joncruz <joncruz@users.sourceforge.net> | |
Fri, 2 Mar 2007 05:06:08 +0000 (05:06 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Fri, 2 Mar 2007 05:06:08 +0000 (05:06 +0000) |
src/file.cpp | patch | blob | history | |
src/ui/dialog/filedialog.cpp | patch | blob | history | |
src/ui/dialog/filedialog.h | patch | blob | history |
diff --git a/src/file.cpp b/src/file.cpp
index 8f4b2a9c1faf2d9b470c3aba37b12b7185160b6c..f4630719b27eb88f0343c1f25c6d3a6814c99483 100644 (file)
--- a/src/file.cpp
+++ b/src/file.cpp
try {
Inkscape::Extension::save(key, doc, uri.c_str(),
- saveas && prefs_get_int_attribute("dialogs.save_as", "append_extension", 1),
+ false,
saveas, official);
} catch (Inkscape::Extension::Output::no_extension_found &e) {
gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
-static Inkscape::UI::Dialog::FileSaveDialog *saveDialogInstance = NULL;
-
/**
* Display a SaveAs dialog. Save the document if OK pressed.
*
Inkscape::XML::Node *repr = sp_document_repr_root(doc);
- Inkscape::Extension::Output *extension;
+ Inkscape::Extension::Output *extension = 0;
//# Get the default extension name
Glib::ustring default_extension;
} else {
dialog_title = (char const *) _("Select file to save to");
}
- if (!saveDialogInstance)
- saveDialogInstance =
- Inkscape::UI::Dialog::FileSaveDialog::create(
- save_loc,
- Inkscape::UI::Dialog::SVG_TYPES,
- (char const *) _("Select file to save to"),
- default_extension
+ Inkscape::UI::Dialog::FileSaveDialog *saveDialog =
+ Inkscape::UI::Dialog::FileSaveDialog::create(
+ save_loc,
+ Inkscape::UI::Dialog::SVG_TYPES,
+ (char const *) _("Select file to save to"),
+ default_extension
);
- else
- saveDialogInstance->change_path(save_loc);
- saveDialogInstance->change_title(dialog_title);
-
- bool success = saveDialogInstance->show();
- if (!success)
- return success;
- Glib::ustring fileName = saveDialogInstance->getFilename();
+ saveDialog->change_title(dialog_title);
+ saveDialog->setSelectionType(extension);
- Inkscape::Extension::Extension *selectionType =
- saveDialogInstance->getSelectionType();
+ bool success = saveDialog->show();
+ if (!success) {
+ delete saveDialog;
+ return success;
+ }
+
+ 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);
index b51793d126b884356f275a61c381164bbf1d8af6..0f74c62417200a0dd2794c27cd2c96f11768b92d 100644 (file)
bool show();
Inkscape::Extension::Extension *getSelectionType();
+ virtual void setSelectionType( Inkscape::Extension::Extension * key );
Glib::ustring getFilename();
std::vector<FileType> fileTypes;
//# Child widgets
- Gtk::CheckButton fileTypeCheckbox;
-
/**
* Callback for user input into fileNameEntry
void createFileTypeMenu();
- bool append_extension;
-
/**
* The extension to use to write this file
*/
return;
FileType type = fileTypes[sel];
//g_message("selected: %s\n", type.name.c_str());
+
+ extension = type.extension;
Gtk::FileFilter filter;
filter.add_pattern(type.pattern);
set_filter(filter);
+
+ // Pick up any changes the user has typed in.
+ Glib::ustring tmp = get_filename();
+#ifdef WITH_GNOME_VFS
+ if ( tmp.empty() ) {
+ tmp = get_uri();
+ }
+#endif
+ if ( !tmp.empty() ) {
+ myFilename = tmp;
+ }
+
+ Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
+ if ( newOut ) {
+ size_t pos = myFilename.rfind('.');
+ if ( pos != Glib::ustring::npos ) {
+ Glib::ustring trail = myFilename.substr( pos );
+ try {
+ Glib::ustring trailUtf8 = Glib::filename_to_utf8( trail );
+ if ( trailUtf8.casefold() != Glib::ustring( newOut->get_extension() ).casefold() ) {
+ myFilename = myFilename.erase( pos ) + newOut->get_extension();
+ change_path(myFilename);
+ }
+ } catch ( Glib::ConvertError& e ) {
+ // ignore
+ }
+ }
+ }
}
const Glib::ustring &default_key) :
FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE)
{
- append_extension = (bool)prefs_get_int_attribute("dialogs.save_as",
- "append_extension", 1);
-
/* One file at a time */
set_select_multiple(false);
//###### Add the file types menu
//createFilterMenu();
- //###### Do we want the .xxx extension automatically added?
- fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
- fileTypeCheckbox.set_active(append_extension);
-
- fileTypeBox.pack_start(fileTypeCheckbox);
createFileTypeMenu();
fileTypeComboBox.set_size_request(200,40);
fileTypeComboBox.signal_changed().connect(
if (b == Gtk::RESPONSE_OK)
{
- int sel = fileTypeComboBox.get_active_row_number ();
- if (sel>=0 && sel< (int)fileTypes.size())
- {
- FileType &type = fileTypes[sel];
- extension = type.extension;
- }
myFilename = get_filename();
#ifdef WITH_GNOME_VFS
if (myFilename.length() < 1)
myFilename = get_uri();
#endif
- /*
-
- // FIXME: Why do we have more code
-
- append_extension = checkbox.get_active();
- prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);
- prefs_set_string_attribute("dialogs.save_as", "default",
- ( extension != NULL ? extension->get_id() : "" ));
- */
return TRUE;
}
else
return extension;
}
+void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
+{
+ extension = key;
+
+ // If no pointer to extension is passed in, look up based on filename extension.
+ if ( !extension ) {
+ // Not quite UTF-8 here.
+ gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
+ for ( int i = 0; !extension && (i < (int)fileTypes.size()); i++ ) {
+ Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
+ if ( ext && ext->get_extension() ) {
+ gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
+ if ( g_str_has_suffix(filenameLower, extensionLower) ) {
+ extension = fileTypes[i].extension;
+ }
+ g_free(extensionLower);
+ }
+ }
+ g_free(filenameLower);
+ }
+
+ // Ensure the proper entry in the combo box is selected.
+ if ( extension ) {
+ gchar const * extensionID = extension->get_id();
+ if ( extensionID ) {
+ for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
+ Inkscape::Extension::Extension *ext = fileTypes[i].extension;
+ if ( ext ) {
+ gchar const * id = ext->get_id();
+ if ( id && ( strcmp(extensionID, id) == 0) ) {
+ int oldSel = fileTypeComboBox.get_active_row_number();
+ if ( i != oldSel ) {
+ fileTypeComboBox.set_active(i);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
/**
* Get the file name chosen by the user. Valid after an [OK]
set_current_folder(myFilename);
} else {
//fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
- set_filename(myFilename);
+ if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
+ set_filename(myFilename);
+ } else {
+ std::string dirName = Glib::path_get_dirname( myFilename );
+ set_current_folder(dirName);
+ }
Glib::ustring basename = Glib::path_get_basename(myFilename);
//fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
- set_current_name(basename);
+ try {
+ set_current_name( Glib::filename_to_utf8(basename) );
+ } catch ( Glib::ConvertError& e ) {
+ g_warning( "Error converting save filename to UTF-8." );
+ // try a fallback.
+ set_current_name( basename );
+ }
}
}
index 508c72997cd2bc120e7cc8d53c6bcfddfc6c4727..c573dbe5dd337886faed11afd13091685f08cd0b 100644 (file)
*/
virtual Inkscape::Extension::Extension * getSelectionType() = 0;
+ virtual void setSelectionType( Inkscape::Extension::Extension * key ) = 0;
+
virtual Glib::ustring getFilename () =0;
/**