index 5dd8e66f23164ab2f3fae3adcc5f81f0bea98fca..749589900a2716f5c9c183d83e1144a964b038ac 100644 (file)
*
* Copyright (C) 2004-2007 Bob Jamison
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
*
* 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) 2004-2007 The Inkscape Organization
- * Copyright (C) 2007 Joel Holdsworth
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
try {
img = Gdk::Pixbuf::create_from_file(fileName);
}
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;
}
{
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;
}
{
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();
gint imgWidth = img->get_width();
gint imgHeight = img->get_height();
}
}
-
-/**
- * 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)
{
bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
{
return;
}
return;
}
- svgPreview.set(fileName, dialogType);
+ svgPreview.set(fileName, _dialogType);
}
}
const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title) :
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...)*/
myFilename = "";
/* Set our dialog type (open, import, etc...)*/
- dialogType = fileTypes;
+ _dialogType = fileTypes;
/* Set the pwd and/or the filename */
/* 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));
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);
}
}
add_shortcut_folder(INKSCAPE_EXAMPLESDIR);
}
}
Glib::ustring
FileOpenDialogImplGtk::getFilename (void)
{
Glib::ustring
FileOpenDialogImplGtk::getFilename (void)
{
- return g_strdup(myFilename.c_str());
+ return myFilename;
}
}
return result;
}
return result;
}
-
+Glib::ustring FileOpenDialogImplGtk::getCurrentDirectory()
+{
+ return get_current_folder();
+}
myFilename = "";
/* Set our dialog type (save, export, etc...)*/
myFilename = "";
/* Set our dialog type (save, export, etc...)*/
- dialogType = fileTypes;
+ _dialogType = fileTypes;
/* Set the pwd and/or the filename */
if (dir.size() > 0)
/* Set the pwd and/or the filename */
if (dir.size() > 0)
expander->set_expanded(true);
}
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);
//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)
{
FileSaveDialogImplGtk::change_title(const Glib::ustring& title)
{
- this->set_title(title);
-}
+ set_title(title);
+}*/
/**
* Change the default save path location.
/**
* Change the default save path location.
FileSaveDialogImplGtk::change_path(const Glib::ustring& path)
{
myFilename = path;
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);
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 ) {
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...)*/
myFilename = "";
/* Set our dialog type (save, export, etc...)*/
- dialogType = fileTypes;
+ _dialogType = fileTypes;
/* Set the pwd and/or the filename */
if (dir.size()>0)
/* Set the pwd and/or the filename */
if (dir.size()>0)