X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fui%2Fdialog%2Ffiledialog.cpp;h=2a5ededbb475bf88fd9f0f35b722587cb484a9fd;hb=4d79affe53b5c0e7dbc67014aee9be5251dc56df;hp=cf816033ad43c16764c8e3e58d71abb6785e4a80;hpb=3c13b2f0f2d9d6dbac0b76c60937de7bf72a47cd;p=inkscape.git diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp index cf816033a..2a5ededbb 100644 --- a/src/ui/dialog/filedialog.cpp +++ b/src/ui/dialog/filedialog.cpp @@ -1,46 +1,46 @@ -/* +/** * Implementation of the file dialog interfaces defined in filedialog.h * * Authors: * Bob Jamison * Other dudes from The Inkscape Organization * + * Copyright (C) 2004-2007 Bob Jamison * Copyright (C) 2006 Johan Engelen - * Copyright (C) 2004-2006 The Inkscape Organization + * Copyright (C) 2004-2007 The Inkscape Organization * * Released under GNU GPL, read the file 'COPYING' for more information */ + #ifdef HAVE_CONFIG_H # include #endif +//General includes +#include +#include +#include +#include - +//Gtk includes +#include +#include +#include //Temporary ugly hack -//Remove these after the get_filter() calls in +//Remove this after the get_filter() calls in //show() on both classes are fixed #include - //Another hack #include #include +#ifdef WITH_GNOME_VFS +# include // gnome_vfs_initialized +#endif + -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +//Inkscape includes #include "prefs-utils.h" #include #include @@ -55,6 +55,7 @@ #include "ui/widget/scalar-unit.h" +//Routines from file.cpp #undef INK_DUMP_FILENAME_CONV #ifdef INK_DUMP_FILENAME_CONV @@ -62,6 +63,8 @@ void dump_str( const gchar* str, const gchar* prefix ); void dump_ustr( const Glib::ustring& ustr ); #endif + + namespace Inkscape { namespace UI @@ -239,13 +242,18 @@ bool SVGPreview::setDocument(SPDocument *doc) return true; } + bool SVGPreview::setFileName(Glib::ustring &theFileName) { Glib::ustring fileName = theFileName; fileName = Glib::filename_to_utf8(fileName); - SPDocument *doc = sp_document_new (fileName.c_str(), 0); + /** + * I don't know why passing false to keepalive is bad. But it + * prevents the display of an svg with a non-ascii filename + */ + SPDocument *doc = sp_document_new (fileName.c_str(), true); if (!doc) { g_warning("SVGView: error loading document '%s'\n", fileName.c_str()); return false; @@ -331,7 +339,7 @@ void SVGPreview::showImage(Glib::ustring &theFileName) "\n" + "width=\"%d\" height=\"%d\">\n" //# VALUES HERE "\n" @@ -347,7 +355,7 @@ void SVGPreview::showImage(Glib::ustring &theFileName) " style=\"font-size:24.000000;font-style:normal;font-weight:normal;" " fill:#000000;fill-opacity:1.0000000;stroke:none;" " font-family:Bitstream Vera Sans\"\n" - " x=\"10\" y=\"26\">%d x %d\n" + " x=\"10\" y=\"26\">%d x %d\n" //# VALUES HERE "\n\n"; //if (!Glib::get_charset()) //If we are not utf8 @@ -387,7 +395,7 @@ void SVGPreview::showNoPreview() "\n" + "width=\"%d\" height=\"%d\">\n" //# VALUES HERE "\n" "%s\n" + "x=\"190\" y=\"240\">%s\n" //# VALUE HERE "\n\n"; //Fill in the template @@ -466,6 +474,11 @@ void SVGPreview::showNoPreview() } + +/** + * Inform the user that the svg file is too large to be displayed. + * This does not check for sizes of embedded images (yet) + */ void SVGPreview::showTooLarge(long fileLength) { @@ -479,7 +492,7 @@ void SVGPreview::showTooLarge(long fileLength) "\n" + "width=\"%d\" height=\"%d\">\n" //# VALUES HERE "\n" "%5.1f MB\n" + "x=\"170\" y=\"215\">%5.1f MB\n" //# VALUE HERE "%s\n" + "x=\"180\" y=\"245\">%s\n" //# VALUE HERE "\n\n"; //Fill in the template @@ -621,8 +634,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) return false; - gchar *fName = (gchar *)fileName.c_str(); - //g_message("fname:%s\n", fName); + //g_message("fname:%s", fileName.c_str()); if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) { showNoPreview(); @@ -631,9 +643,13 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { + Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName); + gchar *fName = (gchar *)fileNameUtf8.c_str(); struct stat info; - if (stat(fName, &info)) + if (g_stat(fName, &info)) { + g_warning("SVGPreview::set() : %s : %s", + fName, strerror(errno)); return FALSE; } long fileLen = info.st_size; @@ -644,7 +660,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) return FALSE; } } - + Glib::ustring svg = ".svg"; Glib::ustring svgz = ".svgz"; @@ -699,19 +715,25 @@ public: /** * */ - FileDialogBase(const Glib::ustring &title) : - Gtk::FileChooserDialog(title) - { - } + FileDialogBase(const Glib::ustring &title, FileDialogType type, gchar const* preferenceBase) : + Gtk::FileChooserDialog(title), + preferenceBase(preferenceBase ? preferenceBase : "unknown"), + dialogType(type) + { + internalSetup(); + } /** * */ FileDialogBase(const Glib::ustring &title, - Gtk::FileChooserAction dialogType) : - Gtk::FileChooserDialog(title, dialogType) - { - } + Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) : + Gtk::FileChooserDialog(title, dialogType), + preferenceBase(preferenceBase ? preferenceBase : "unknown"), + dialogType(type) + { + internalSetup(); + } /** * @@ -719,42 +741,10 @@ public: virtual ~FileDialogBase() {} -}; - - - -/*######################################################################### -### F I L E O P E N -#########################################################################*/ - -/** - * Our implementation class for the FileOpenDialog interface.. - */ -class FileOpenDialogImpl : public FileOpenDialog, public FileDialogBase -{ -public: - - FileOpenDialogImpl(const Glib::ustring &dir, - FileDialogType fileTypes, - const Glib::ustring &title); - - virtual ~FileOpenDialogImpl(); - - bool show(); - - Inkscape::Extension::Extension *getSelectionType(); - - Glib::ustring getFilename(); - - std::vector getFilenames (); - protected: + void cleanup( bool showConfirmed ); - - -private: - - + Glib::ustring preferenceBase; /** * What type of 'open' are we? (open, import, place, etc) */ @@ -765,120 +755,139 @@ private: */ SVGPreview svgPreview; - /** - * Callback for seeing if the preview needs to be drawn - */ - void updatePreviewCallback(); + //# Child widgets + Gtk::CheckButton previewCheckbox; - /** - * Fix to allow the user to type the file name - */ - Gtk::Entry fileNameEntry; +private: + void internalSetup(); /** - * Create a filter menu for this type of dialog + * Callback for user changing preview checkbox */ - void createFilterMenu(); + void _previewEnabledCB(); /** - * Callback for user input into fileNameEntry + * Callback for seeing if the preview needs to be drawn */ - void fileNameEntryChangedCallback(); + void _updatePreviewCallback(); +}; - /** - * Callback for user changing which item is selected on the list - */ - void fileSelectedCallback(); +void FileDialogBase::internalSetup() +{ + bool enablePreview = + (bool)prefs_get_int_attribute( preferenceBase.c_str(), + "enable_preview", 1 ); - /** - * Filter name->extension lookup - */ - std::map extensionMap; + previewCheckbox.set_label( Glib::ustring(_("Enable Preview")) ); + previewCheckbox.set_active( enablePreview ); - /** - * The extension to use to write this file - */ - Inkscape::Extension::Extension *extension; + previewCheckbox.signal_toggled().connect( + sigc::mem_fun(*this, &FileDialogBase::_previewEnabledCB) ); - /** - * Filename that was given - */ - Glib::ustring myFilename; + //Catch selection-changed events, so we can adjust the text widget + signal_update_preview().connect( + sigc::mem_fun(*this, &FileDialogBase::_updatePreviewCallback) ); -}; + //###### Add a preview widget + set_preview_widget(svgPreview); + set_preview_widget_active( enablePreview ); + set_use_preview_label (false); +} +void FileDialogBase::cleanup( bool showConfirmed ) +{ + if ( showConfirmed ) + prefs_set_int_attribute( preferenceBase.c_str(), + "enable_preview", previewCheckbox.get_active() ); +} + + +void FileDialogBase::_previewEnabledCB() +{ + bool enabled = previewCheckbox.get_active(); + set_preview_widget_active(enabled); + if ( enabled ) { + _updatePreviewCallback(); + } +} + /** * Callback for checking if the preview needs to be redrawn */ -void FileOpenDialogImpl::updatePreviewCallback() +void FileDialogBase::_updatePreviewCallback() { Glib::ustring fileName = get_preview_filename(); - if (fileName.length() < 1) + +#ifdef WITH_GNOME_VFS + if ( fileName.empty() && gnome_vfs_initialized() ) { + fileName = get_preview_uri(); + } +#endif + + if (fileName.empty()) { return; + } + svgPreview.set(fileName, dialogType); } - - +/*######################################################################### +### F I L E O P E N +#########################################################################*/ /** - * Callback for fileNameEntry widget + * Our implementation class for the FileOpenDialog interface.. */ -void FileOpenDialogImpl::fileNameEntryChangedCallback() +class FileOpenDialogImpl : public FileOpenDialog, public FileDialogBase { - Glib::ustring rawFileName = fileNameEntry.get_text(); +public: - Glib::ustring fileName = Glib::filename_from_utf8(rawFileName); + FileOpenDialogImpl(const Glib::ustring &dir, + FileDialogType fileTypes, + const Glib::ustring &title); - //g_message("User hit return. Text is '%s'\n", fileName.c_str()); + virtual ~FileOpenDialogImpl(); - if (!Glib::path_is_absolute(fileName)) { - //try appending to the current path - // not this way: fileName = get_current_folder() + "/" + fName; - std::vector pathSegments; - pathSegments.push_back( get_current_folder() ); - pathSegments.push_back( fileName ); - fileName = Glib::build_filename(pathSegments); - } + bool show(); - //g_message("path:'%s'\n", fName.c_str()); + Inkscape::Extension::Extension *getSelectionType(); - if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) { - set_current_folder(fileName); - } else if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { - //dialog with either (1) select a regular file or (2) cd to dir - //simulate an 'OK' - set_filename(fileName); - response(Gtk::RESPONSE_OK); - } -} + Glib::ustring getFilename(); + std::vector getFilenames (); +private: + /** + * Create a filter menu for this type of dialog + */ + void createFilterMenu(); + + /** + * Filter name->extension lookup + */ + std::map extensionMap; + + /** + * The extension to use to write this file + */ + Inkscape::Extension::Extension *extension; + + /** + * Filename that was given + */ + Glib::ustring myFilename; + +}; -/** - * Callback for fileNameEntry widget - */ -void FileOpenDialogImpl::fileSelectedCallback() -{ - Glib::ustring fileName = get_filename(); - if (!Glib::get_charset()) //If we are not utf8 - fileName = Glib::filename_to_utf8(fileName); - //g_message("User selected '%s'\n", - // filename().c_str()); -#ifdef INK_DUMP_FILENAME_CONV - ::dump_ustr( get_filename() ); -#endif - fileNameEntry.set_text(fileName); -} @@ -942,7 +951,7 @@ void FileOpenDialogImpl::createFilterMenu() FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir, FileDialogType fileTypes, const Glib::ustring &title) : - FileDialogBase(title) + FileDialogBase(title, fileTypes, "dialogs.open") { @@ -950,6 +959,12 @@ FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir, /* And also Multiple Files */ set_select_multiple(true); +#ifdef WITH_GNOME_VFS + if (gnome_vfs_initialized()) { + set_local_only(false); + } +#endif + /* Initalize to Autodetect */ extension = NULL; /* No filename to start out with */ @@ -970,35 +985,16 @@ FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir, set_current_folder(udir.c_str()); } - //###### Add the file types menu - createFilterMenu(); - //###### Add a preview widget - set_preview_widget(svgPreview); - set_preview_widget_active(true); - set_use_preview_label (false); - - //Catch selection-changed events, so we can adjust the text widget - signal_update_preview().connect( - sigc::mem_fun(*this, &FileOpenDialogImpl::updatePreviewCallback) ); + set_extra_widget( previewCheckbox ); - //###### Add a text entry bar, and tie it to file chooser events - fileNameEntry.set_text(get_current_folder()); - set_extra_widget(fileNameEntry); - fileNameEntry.grab_focus(); + //###### Add the file types menu + createFilterMenu(); - //Catch when user hits [return] on the text field - fileNameEntry.signal_activate().connect( - sigc::mem_fun(*this, &FileOpenDialogImpl::fileNameEntryChangedCallback) ); - - //Catch selection-changed events, so we can adjust the text widget - signal_selection_changed().connect( - sigc::mem_fun(*this, &FileOpenDialogImpl::fileSelectedCallback) ); add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); - + set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK)); } @@ -1057,10 +1053,16 @@ FileOpenDialogImpl::show() extension = extensionMap[gtk_file_filter_get_name(filter)]; } myFilename = get_filename(); +#ifdef WITH_GNOME_VFS + if (myFilename.empty() && gnome_vfs_initialized()) + myFilename = get_uri(); +#endif + cleanup( true ); return TRUE; } else { + cleanup( false ); return FALSE; } } @@ -1094,6 +1096,10 @@ FileOpenDialogImpl::getFilename (void) std::vectorFileOpenDialogImpl::getFilenames() { std::vector result = get_filenames(); +#ifdef WITH_GNOME_VFS + if (result.empty() && gnome_vfs_initialized()) + result = get_uris(); +#endif return result; } @@ -1133,41 +1139,21 @@ public: bool show(); Inkscape::Extension::Extension *getSelectionType(); + virtual void setSelectionType( Inkscape::Extension::Extension * key ); Glib::ustring getFilename(); void change_title(const Glib::ustring& title); - void change_path(const Glib::ustring& dir); - + void change_path(const Glib::ustring& path); + void updateNameAndExtension(); private: - /** - * What type of 'open' are we? (save, export, etc) - */ - FileDialogType dialogType; - - /** - * Our svg preview widget - */ - SVGPreview svgPreview; - /** * Fix to allow the user to type the file name */ Gtk::Entry *fileNameEntry; - /** - * Callback for seeing if the preview needs to be drawn - */ - void updatePreviewCallback(); - - - - /** - * Allow the specification of the output file type - */ - Gtk::HBox fileTypeBox; /** * Allow the specification of the output file type @@ -1181,8 +1167,10 @@ private: std::vector fileTypes; //# Child widgets - Gtk::CheckButton fileTypeCheckbox; + Gtk::HBox childBox; + Gtk::VBox checksBox; + Gtk::CheckButton fileTypeCheckbox; /** * Callback for user input into fileNameEntry @@ -1195,8 +1183,6 @@ private: void createFileTypeMenu(); - bool append_extension; - /** * The extension to use to write this file */ @@ -1211,24 +1197,13 @@ private: * Filename that was given */ Glib::ustring myFilename; -}; - - - - + /** + * List of known file extensions. + */ + std::set knownExtensions; +}; -/** - * Callback for checking if the preview needs to be redrawn - */ -void FileSaveDialogImpl::updatePreviewCallback() -{ - Glib::ustring fileName = get_preview_filename(); - if (!fileName.c_str()) - return; - bool retval = svgPreview.set(fileName, dialogType); - set_preview_widget_active(retval); -} @@ -1279,9 +1254,13 @@ void FileSaveDialogImpl::fileTypeChangedCallback() 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); + + updateNameAndExtension(); } @@ -1290,6 +1269,7 @@ void FileSaveDialogImpl::createFileTypeMenu() { Inkscape::Extension::DB::OutputList extension_list; Inkscape::Extension::db.get_output_list(extension_list); + knownExtensions.clear(); for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin(); current_item != extension_list.end(); current_item++) @@ -1303,6 +1283,7 @@ void FileSaveDialogImpl::createFileTypeMenu() type.name = (_(omod->get_filetypename())); type.pattern = "*"; Glib::ustring extension = omod->get_extension(); + knownExtensions.insert( extension.casefold() ); fileDialogExtensionToPattern (type.pattern, extension); type.extension= omod; fileTypeComboBox.append_text(type.name); @@ -1331,14 +1312,17 @@ FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir, FileDialogType fileTypes, const Glib::ustring &title, const Glib::ustring &default_key) : - FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE) + FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as") { - append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", - "append_extension", 1); - /* One file at a time */ set_select_multiple(false); +#ifdef WITH_GNOME_VFS + if (gnome_vfs_initialized()) { + set_local_only(false); + } +#endif + /* Initalize to Autodetect */ extension = NULL; /* No filename to start out with */ @@ -1363,29 +1347,21 @@ FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir, //###### Do we want the .xxx extension automatically added? fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically"))); - fileTypeCheckbox.set_active(append_extension); + fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.save_as", + "append_extension", 1) ); - fileTypeBox.pack_start(fileTypeCheckbox); createFileTypeMenu(); fileTypeComboBox.set_size_request(200,40); fileTypeComboBox.signal_changed().connect( sigc::mem_fun(*this, &FileSaveDialogImpl::fileTypeChangedCallback) ); - fileTypeBox.pack_start(fileTypeComboBox); - - set_extra_widget(fileTypeBox); - //get_vbox()->pack_start(fileTypeBox, false, false, 0); - //get_vbox()->reorder_child(fileTypeBox, 2); - - //###### Add a preview widget - set_preview_widget(svgPreview); - set_preview_widget_active(true); - set_use_preview_label (false); - //Catch selection-changed events, so we can adjust the text widget - signal_update_preview().connect( - sigc::mem_fun(*this, &FileSaveDialogImpl::updatePreviewCallback) ); + childBox.pack_start( checksBox ); + childBox.pack_end( fileTypeComboBox ); + checksBox.pack_start( fileTypeCheckbox ); + checksBox.pack_start( previewCheckbox ); + set_extra_widget( childBox ); //Let's do some customization fileNameEntry = NULL; @@ -1417,7 +1393,7 @@ FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir, // checkbox.set_sensitive(FALSE); add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK)); show_all_children(); } @@ -1464,27 +1440,23 @@ FileSaveDialogImpl::show() 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(); + updateNameAndExtension(); - /* - - // FIXME: Why do we have more code + // Store changes of the "Append filename automatically" checkbox back to preferences. + prefs_set_int_attribute("dialogs.save_as", "append_extension", fileTypeCheckbox.get_active()); - append_extension = checkbox.get_active(); - prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension); + // Store the last used save-as filetype to preferences. prefs_set_string_attribute("dialogs.save_as", "default", - ( extension != NULL ? extension->get_id() : "" )); - */ + ( extension != NULL ? extension->get_id() : "" )); + + cleanup( true ); + return TRUE; } else { + cleanup( false ); + return FALSE; } } @@ -1499,6 +1471,47 @@ FileSaveDialogImpl::getSelectionType() return extension; } +void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key ) +{ + // If no pointer to extension is passed in, look up based on filename extension. + if ( !key ) { + // Not quite UTF-8 here. + gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1); + for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) { + Inkscape::Extension::Output *ext = dynamic_cast(fileTypes[i].extension); + if ( ext && ext->get_extension() ) { + gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 ); + if ( g_str_has_suffix(filenameLower, extensionLower) ) { + key = fileTypes[i].extension; + } + g_free(extensionLower); + } + } + g_free(filenameLower); + } + + // Ensure the proper entry in the combo box is selected. + if ( key ) { + extension = key; + 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] @@ -1528,15 +1541,67 @@ FileSaveDialogImpl::change_path(const Glib::ustring& path) 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 ); + if ( dirName != get_current_folder() ) { + 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 ); + } } } +void FileSaveDialogImpl::updateNameAndExtension() +{ + // Pick up any changes the user has typed in. + Glib::ustring tmp = get_filename(); +#ifdef WITH_GNOME_VFS + if ( tmp.empty() && gnome_vfs_initialized() ) { + tmp = get_uri(); + } +#endif + if ( !tmp.empty() ) { + myFilename = tmp; + } + Inkscape::Extension::Output* newOut = extension ? dynamic_cast(extension) : 0; + if ( fileTypeCheckbox.get_active() && newOut ) { + try { + bool appendExtension = true; + Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename ); + Glib::ustring::size_type pos = utf8Name.rfind('.'); + if ( pos != Glib::ustring::npos ) { + Glib::ustring trail = utf8Name.substr( pos ); + Glib::ustring foldedTrail = trail.casefold(); + if ( (trail == ".") + | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold() + && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) { + utf8Name = utf8Name.erase( pos ); + } else { + appendExtension = false; + } + } + if (appendExtension) { + utf8Name = utf8Name + newOut->get_extension(); + myFilename = Glib::filename_from_utf8( utf8Name ); + change_path(myFilename); + } + } catch ( Glib::ConvertError& e ) { + // ignore + } + } +} @@ -1657,26 +1722,11 @@ public: private: - /** - * What type of 'open' are we? (save, export, etc) - */ - FileDialogType dialogType; - - /** - * Our svg preview widget - */ - SVGPreview svgPreview; - /** * Fix to allow the user to type the file name */ Gtk::Entry *fileNameEntry; - /** - * Callback for seeing if the preview needs to be drawn - */ - void updatePreviewCallback(); - //########################################## //# EXTRA WIDGET -- SOURCE SIDE //########################################## @@ -1776,20 +1826,6 @@ private: -/** - * Callback for checking if the preview needs to be redrawn - */ -void FileExportDialogImpl::updatePreviewCallback() -{ - Glib::ustring fileName = get_preview_filename(); - if (!fileName.c_str()) - return; - bool retval = svgPreview.set(fileName, dialogType); - set_preview_widget_active(retval); -} - - - /** * Callback for fileNameEntry widget */ @@ -1888,22 +1924,28 @@ FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir, FileDialogType fileTypes, const Glib::ustring &title, const Glib::ustring &default_key) : - FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE), - sourceX0Spinner("X0", _("Source left bound")), - sourceY0Spinner("Y0", _("Source top bound")), - sourceX1Spinner("X1", _("Source right bound")), - sourceY1Spinner("Y1", _("Source bottom bound")), + FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"), + sourceX0Spinner("X0", _("Left edge of source")), + sourceY0Spinner("Y0", _("Top edge of source")), + sourceX1Spinner("X1", _("Right edge of source")), + sourceY1Spinner("Y1", _("Bottom edge of source")), sourceWidthSpinner("Width", _("Source width")), sourceHeightSpinner("Height", _("Source height")), destWidthSpinner("Width", _("Destination width")), destHeightSpinner("Height", _("Destination height")), - destDPISpinner("DPI", _("Dots per inch resolution")) + destDPISpinner("DPI", _("Resolution (dots per inch)")) { append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1); /* One file at a time */ set_select_multiple(false); +#ifdef WITH_GNOME_VFS + if (gnome_vfs_initialized()) { + set_local_only(false); + } +#endif + /* Initalize to Autodetect */ extension = NULL; /* No filename to start out with */ @@ -2022,16 +2064,6 @@ FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir, - //###### PREVIEW WIDGET - set_preview_widget(svgPreview); - set_preview_widget_active(true); - set_use_preview_label (false); - - //Catch selection-changed events, so we can adjust the text widget - signal_update_preview().connect( - sigc::mem_fun(*this, &FileExportDialogImpl::updatePreviewCallback) ); - - //Let's do some customization fileNameEntry = NULL; Gtk::Container *cont = get_toplevel(); @@ -2062,7 +2094,7 @@ FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir, // checkbox.set_sensitive(FALSE); add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK)); show_all_children(); } @@ -2119,6 +2151,11 @@ FileExportDialogImpl::show() extension = type.extension; } myFilename = get_filename(); +#ifdef WITH_GNOME_VFS + if ( myFilename.empty() && gnome_vfs_initialized() ) { + myFilename = get_uri(); + } +#endif /*