index a1773d39a317c36775d91815e5fe0141a5e62cf5..749589900a2716f5c9c183d83e1144a964b038ac 100644 (file)
*
* Copyright (C) 2004-2007 Bob Jamison
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
+ * 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
*/
}
-
-/**
- * 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<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(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::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats();
- for (unsigned int i=0; i<formats.size(); i++)
- {
- Gdk::PixbufFormat format = formats[i];
- std::vector<Glib::ustring>extensions = format.get_extensions();
- for (unsigned int j=0; j<extensions.size(); j++)
- {
- Glib::ustring ext = extensions[j];
- if (hasSuffix(fileName, ext))
- return true;
- }
- }
- return false;
-}
-
bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
{
return;
}
- svgPreview.set(fileName, dialogType);
+ svgPreview.set(fileName, _dialogType);
}
const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title) :
- FileDialogBaseGtk(parentWindow, title, fileTypes, "dialogs.open")
+ FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_OPEN, fileTypes, "dialogs.open")
{
myFilename = "";
/* Set our dialog type (open, import, etc...)*/
- dialogType = fileTypes;
+ _dialogType = fileTypes;
/* Set the pwd and/or the filename */
add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
-
- //###### Allow easy access to our examples folder
- if(Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR,
- (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
- {
+
+ //###### Allow easy access to our examples folder
+ if ( Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_EXISTS)
+ && Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_IS_DIR)
+ && g_path_is_absolute(INKSCAPE_EXAMPLESDIR)
+ )
+ {
add_shortcut_folder(INKSCAPE_EXAMPLESDIR);
}
}
Glib::ustring
FileOpenDialogImplGtk::getFilename (void)
{
- return g_strdup(myFilename.c_str());
+ return myFilename;
}
return result;
}
-
+Glib::ustring FileOpenDialogImplGtk::getCurrentDirectory()
+{
+ return get_current_folder();
+}
myFilename = "";
/* Set our dialog type (save, export, etc...)*/
- dialogType = fileTypes;
+ _dialogType = fileTypes;
/* Set the pwd and/or the filename */
if (dir.size() > 0)
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);
@@ -1179,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.
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);
Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(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);
}
}
myFilename = "";
/* Set our dialog type (save, export, etc...)*/
- dialogType = fileTypes;
+ _dialogType = fileTypes;
/* Set the pwd and/or the filename */
if (dir.size()>0)