X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fui%2Fdialog%2Ffiledialogimpl-gtkmm.cpp;h=749589900a2716f5c9c183d83e1144a964b038ac;hb=ba885512446fff2803585a4aaec34e7742841f05;hp=5dd8e66f23164ab2f3fae3adcc5f81f0bea98fca;hpb=ab5f33e91458710ed8dd2b2a1b3a53e4227d4856;p=inkscape.git diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 5dd8e66f2..749589900 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -9,8 +9,8 @@ * * Copyright (C) 2004-2007 Bob Jamison * Copyright (C) 2006 Johan Engelen + * Copyright (C) 2007-2008 Joel Holdsworth * Copyright (C) 2004-2007 The Inkscape Organization - * Copyright (C) 2007 Joel Holdsworth * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -209,16 +209,21 @@ void SVGPreview::showImage(Glib::ustring &theFileName) try { img = Gdk::Pixbuf::create_from_file(fileName); } - catch (Glib::FileError & e) + catch (const Glib::FileError & e) { g_message("caught Glib::FileError in SVGPreview::showImage"); return; } - catch (Gdk::PixbufError & e) + catch (const Gdk::PixbufError & e) { g_message("Gdk::PixbufError in SVGPreview::showImage"); return; } + catch (...) + { + g_message("Caught ... in SVGPreview::showImage"); + return; + } gint imgWidth = img->get_width(); gint imgHeight = img->get_height(); @@ -490,55 +495,6 @@ void SVGPreview::showTooLarge(long fileLength) } - -/** - * Return true if the string ends with the given suffix - */ -static bool -hasSuffix(Glib::ustring &str, Glib::ustring &ext) -{ - int strLen = str.length(); - int extLen = ext.length(); - if (extLen > strLen) - return false; - int strpos = strLen-1; - for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--) - { - Glib::ustring::value_type ch = str[strpos]; - if (ch != ext[extpos]) - { - if ( ((ch & 0xff80) != 0) || - static_cast( g_ascii_tolower( static_cast(0x07f & ch) ) ) != ext[extpos] ) - { - return false; - } - } - } - return true; -} - - -/** - * Return true if the image is loadable by Gdk, else false - */ -static bool -isValidImageFile(Glib::ustring &fileName) -{ - std::vectorformats = Gdk::Pixbuf::get_formats(); - for (unsigned int i=0; iextensions = format.get_extensions(); - for (unsigned int j=0; jFileOpenDialogImplGtk::getFilenames() return result; } - +Glib::ustring FileOpenDialogImplGtk::getCurrentDirectory() +{ + return get_current_folder(); +} @@ -910,7 +871,7 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow, myFilename = ""; /* Set our dialog type (save, export, etc...)*/ - dialogType = fileTypes; + _dialogType = fileTypes; /* Set the pwd and/or the filename */ if (dir.size() > 0) @@ -969,6 +930,17 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow, expander->set_expanded(true); } + // allow easy access to the user's own templates folder + gchar *templates = profile_path ("templates"); + if ( Inkscape::IO::file_test(templates, G_FILE_TEST_EXISTS) + && Inkscape::IO::file_test(templates, G_FILE_TEST_IS_DIR) + && g_path_is_absolute(templates) + ) + { + add_shortcut_folder(templates); + } + g_free (templates); + //if (extension == NULL) // checkbox.set_sensitive(FALSE); @@ -1174,22 +1146,17 @@ void FileSaveDialogImplGtk::setSelectionType( Inkscape::Extension::Extension * k } } - -/** - * Get the file name chosen by the user. Valid after an [OK] - */ -Glib::ustring -FileSaveDialogImplGtk::getFilename() +Glib::ustring FileSaveDialogImplGtk::getCurrentDirectory() { - return myFilename; + return get_current_folder(); } -void +/*void FileSaveDialogImplGtk::change_title(const Glib::ustring& title) { - this->set_title(title); -} + set_title(title); +}*/ /** * Change the default save path location. @@ -1198,6 +1165,7 @@ void FileSaveDialogImplGtk::change_path(const Glib::ustring& path) { myFilename = path; + if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) { //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str()); set_current_folder(myFilename); @@ -1238,30 +1206,8 @@ void FileSaveDialogImplGtk::updateNameAndExtension() 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 - } + // Append the file extension if it's not already present + appendExtension(myFilename, newOut); } } @@ -1397,7 +1343,7 @@ FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow, myFilename = ""; /* Set our dialog type (save, export, etc...)*/ - dialogType = fileTypes; + _dialogType = fileTypes; /* Set the pwd and/or the filename */ if (dir.size()>0)