index 0f74c62417200a0dd2794c27cd2c96f11768b92d..2a5ededbb475bf88fd9f0f35b722587cb484a9fd 100644 (file)
-/*
+/**
* Implementation of the file dialog interfaces defined in filedialog.h
*
* Authors:
* Bob Jamison
* Other dudes from The Inkscape Organization
*
* 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 <johan@shouraizou.nl>
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
- * 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
*/
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
+//General includes
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <set>
-
+//Gtk includes
+#include <gtkmm.h>
+#include <glibmm/i18n.h>
+#include <glib/gstdio.h>
//Temporary ugly hack
//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 <gtk/gtkfilechooser.h>
//show() on both classes are fixed
#include <gtk/gtkfilechooser.h>
-
//Another hack
#include <gtk/gtkentry.h>
#include <gtk/gtkexpander.h>
//Another hack
#include <gtk/gtkentry.h>
#include <gtk/gtkexpander.h>
+#ifdef WITH_GNOME_VFS
+# include <libgnomevfs/gnome-vfs-init.h> // gnome_vfs_initialized
+#endif
-#include <unistd.h>
-#include <sys/stat.h>
-#include <glibmm/i18n.h>
-#include <gtkmm/box.h>
-#include <gtkmm/colorbutton.h>
-#include <gtkmm/frame.h>
-#include <gtkmm/filechooserdialog.h>
-#include <gtkmm/menubar.h>
-#include <gtkmm/menu.h>
-#include <gtkmm/entry.h>
-#include <gtkmm/expander.h>
-#include <gtkmm/comboboxtext.h>
-#include <gtkmm/stock.h>
-#include <gdkmm/pixbuf.h>
+
+//Inkscape includes
#include "prefs-utils.h"
#include <dialogs/dialog-events.h>
#include <extension/input.h>
#include "prefs-utils.h"
#include <dialogs/dialog-events.h>
#include <extension/input.h>
#include "ui/widget/scalar-unit.h"
#include "ui/widget/scalar-unit.h"
+//Routines from file.cpp
#undef INK_DUMP_FILENAME_CONV
#ifdef INK_DUMP_FILENAME_CONV
#undef INK_DUMP_FILENAME_CONV
#ifdef INK_DUMP_FILENAME_CONV
void dump_ustr( const Glib::ustring& ustr );
#endif
void dump_ustr( const Glib::ustring& ustr );
#endif
+
+
namespace Inkscape
{
namespace UI
namespace Inkscape
{
namespace UI
return true;
}
return true;
}
+
bool SVGPreview::setFileName(Glib::ustring &theFileName)
{
Glib::ustring fileName = theFileName;
fileName = Glib::filename_to_utf8(fileName);
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;
if (!doc) {
g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
return false;
"<svg\n"
"xmlns=\"http://www.w3.org/2000/svg\"\n"
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
"<svg\n"
"xmlns=\"http://www.w3.org/2000/svg\"\n"
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
- "width=\"%d\" height=\"%d\">\n"
+ "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
"<rect\n"
" style=\"fill:#eeeeee;stroke:none\"\n"
" x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
"<rect\n"
" style=\"fill:#eeeeee;stroke:none\"\n"
" x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
" 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"
" 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</text>\n"
+ " x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE
"</svg>\n\n";
//if (!Glib::get_charset()) //If we are not utf8
"</svg>\n\n";
//if (!Glib::get_charset()) //If we are not utf8
"<svg\n"
"xmlns=\"http://www.w3.org/2000/svg\"\n"
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
"<svg\n"
"xmlns=\"http://www.w3.org/2000/svg\"\n"
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
- "width=\"%d\" height=\"%d\">\n"
+ "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
"<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
"<path\n"
"style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
"<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
"<path\n"
"style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
- "x=\"190\" y=\"240\">%s</text></g>\n"
+ "x=\"190\" y=\"240\">%s</text></g>\n" //# VALUE HERE
"</svg>\n\n";
//Fill in the template
"</svg>\n\n";
//Fill in the template
}
}
+
+/**
+ * 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)
{
void SVGPreview::showTooLarge(long fileLength)
{
"<svg\n"
"xmlns=\"http://www.w3.org/2000/svg\"\n"
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
"<svg\n"
"xmlns=\"http://www.w3.org/2000/svg\"\n"
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
- "width=\"%d\" height=\"%d\">\n"
+ "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
"<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
"<path\n"
"style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
"<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
"<path\n"
"style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
- "x=\"170\" y=\"215\">%5.1f MB</text>\n"
+ "x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE
"<text xml:space=\"preserve\"\n"
"style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
"<text xml:space=\"preserve\"\n"
"style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
- "x=\"180\" y=\"245\">%s</text>\n"
+ "x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE
"</svg>\n\n";
//Fill in the template
"</svg>\n\n";
//Fill in the template
if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
return false;
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();
if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
showNoPreview();
if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))
{
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;
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;
return FALSE;
}
long fileLen = info.st_size;
return FALSE;
}
}
return FALSE;
}
}
-
+
Glib::ustring svg = ".svg";
Glib::ustring svgz = ".svgz";
Glib::ustring svg = ".svg";
Glib::ustring svgz = ".svgz";
/**
*
*/
/**
*
*/
- 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,
/**
*
*/
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();
+ }
/**
*
/**
*
virtual ~FileDialogBase()
{}
virtual ~FileDialogBase()
{}
+protected:
+ void cleanup( bool showConfirmed );
+
+ Glib::ustring preferenceBase;
+ /**
+ * What type of 'open' are we? (open, import, place, etc)
+ */
+ FileDialogType dialogType;
+
+ /**
+ * Our svg preview widget
+ */
+ SVGPreview svgPreview;
+
+ //# Child widgets
+ Gtk::CheckButton previewCheckbox;
+
+private:
+ void internalSetup();
+
+ /**
+ * Callback for user changing preview checkbox
+ */
+ void _previewEnabledCB();
+
+ /**
+ * Callback for seeing if the preview needs to be drawn
+ */
+ void _updatePreviewCallback();
};
};
+void FileDialogBase::internalSetup()
+{
+ bool enablePreview =
+ (bool)prefs_get_int_attribute( preferenceBase.c_str(),
+ "enable_preview", 1 );
+
+ previewCheckbox.set_label( Glib::ustring(_("Enable Preview")) );
+ previewCheckbox.set_active( enablePreview );
+
+ previewCheckbox.signal_toggled().connect(
+ sigc::mem_fun(*this, &FileDialogBase::_previewEnabledCB) );
+
+ //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 FileDialogBase::_updatePreviewCallback()
+{
+ Glib::ustring fileName = get_preview_filename();
+
+#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
/*#########################################################################
### F I L E O P E N
std::vector<Glib::ustring> getFilenames ();
std::vector<Glib::ustring> getFilenames ();
-protected:
-
-
-
private:
private:
-
- /**
- * What type of 'open' are we? (open, import, place, etc)
- */
- FileDialogType dialogType;
-
- /**
- * Our svg preview widget
- */
- SVGPreview svgPreview;
-
- /**
- * Callback for seeing if the preview needs to be drawn
- */
- void updatePreviewCallback();
-
/**
* Create a filter menu for this type of dialog
*/
/**
* Create a filter menu for this type of dialog
*/
-/**
- * Callback for checking if the preview needs to be redrawn
- */
-void FileOpenDialogImpl::updatePreviewCallback()
-{
- Glib::ustring fileName = get_preview_filename();
-#ifdef WITH_GNOME_VFS
- if (fileName.length() < 1)
- fileName = get_preview_uri();
-#endif
- if (fileName.length() < 1)
- return;
- svgPreview.set(fileName, dialogType);
-}
-
-
-
-
-
void FileOpenDialogImpl::createFilterMenu()
void FileOpenDialogImpl::createFilterMenu()
FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title) :
FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title) :
- FileDialogBase(title)
+ FileDialogBase(title, fileTypes, "dialogs.open")
{
{
set_select_multiple(true);
#ifdef WITH_GNOME_VFS
set_select_multiple(true);
#ifdef WITH_GNOME_VFS
- set_local_only(false);
+ if (gnome_vfs_initialized()) {
+ set_local_only(false);
+ }
#endif
/* Initalize to Autodetect */
#endif
/* Initalize to Autodetect */
set_current_folder(udir.c_str());
}
set_current_folder(udir.c_str());
}
+
+ set_extra_widget( previewCheckbox );
+
+
//###### Add the file types menu
createFilterMenu();
//###### 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) );
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));
-
}
}
}
myFilename = get_filename();
#ifdef WITH_GNOME_VFS
}
myFilename = get_filename();
#ifdef WITH_GNOME_VFS
- if (myFilename.length() < 1)
+ if (myFilename.empty() && gnome_vfs_initialized())
myFilename = get_uri();
#endif
myFilename = get_uri();
#endif
+ cleanup( true );
return TRUE;
}
else
{
return TRUE;
}
else
{
+ cleanup( false );
return FALSE;
}
}
return FALSE;
}
}
{
std::vector<Glib::ustring> result = get_filenames();
#ifdef WITH_GNOME_VFS
{
std::vector<Glib::ustring> result = get_filenames();
#ifdef WITH_GNOME_VFS
- if (result.empty())
+ if (result.empty() && gnome_vfs_initialized())
result = get_uris();
#endif
return result;
result = get_uris();
#endif
return result;
Glib::ustring getFilename();
void change_title(const Glib::ustring& title);
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:
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;
/**
* 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
/**
* Allow the specification of the output file type
std::vector<FileType> fileTypes;
//# Child widgets
std::vector<FileType> fileTypes;
//# Child widgets
+ Gtk::HBox childBox;
+ Gtk::VBox checksBox;
+
+ Gtk::CheckButton fileTypeCheckbox;
/**
* Callback for user input into fileNameEntry
/**
* Callback for user input into fileNameEntry
* Filename that was given
*/
Glib::ustring myFilename;
* Filename that was given
*/
Glib::ustring myFilename;
-};
-
+ /**
+ * List of known file extensions.
+ */
+ std::set<Glib::ustring> knownExtensions;
+};
-/**
- * Callback for checking if the preview needs to be redrawn
- */
-void FileSaveDialogImpl::updatePreviewCallback()
-{
- Glib::ustring fileName = get_preview_filename();
-#ifdef WITH_GNOME_VFS
- if (fileName.length() < 1)
- fileName = get_preview_uri();
-#endif
- if (!fileName.c_str())
- return;
- bool retval = svgPreview.set(fileName, dialogType);
- set_preview_widget_active(retval);
-}
-
-
-
/**
* Callback for fileNameEntry widget
*/
/**
* Callback for fileNameEntry widget
*/
filter.add_pattern(type.pattern);
set_filter(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
- }
- }
- }
+ updateNameAndExtension();
}
}
{
Inkscape::Extension::DB::OutputList extension_list;
Inkscape::Extension::db.get_output_list(extension_list);
{
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++)
for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
current_item != extension_list.end(); current_item++)
type.name = (_(omod->get_filetypename()));
type.pattern = "*";
Glib::ustring extension = omod->get_extension();
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);
fileDialogExtensionToPattern (type.pattern, extension);
type.extension= omod;
fileTypeComboBox.append_text(type.name);
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key) :
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")
{
/* One file at a time */
set_select_multiple(false);
#ifdef WITH_GNOME_VFS
{
/* One file at a time */
set_select_multiple(false);
#ifdef WITH_GNOME_VFS
- set_local_only(false);
+ if (gnome_vfs_initialized()) {
+ set_local_only(false);
+ }
#endif
/* Initalize to Autodetect */
#endif
/* Initalize to Autodetect */
//###### Add the file types menu
//createFilterMenu();
//###### 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( (bool)prefs_get_int_attribute("dialogs.save_as",
+ "append_extension", 1) );
+
createFileTypeMenu();
fileTypeComboBox.set_size_request(200,40);
fileTypeComboBox.signal_changed().connect(
sigc::mem_fun(*this, &FileSaveDialogImpl::fileTypeChangedCallback) );
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;
//Let's do some customization
fileNameEntry = NULL;
if (b == Gtk::RESPONSE_OK)
{
if (b == Gtk::RESPONSE_OK)
{
- myFilename = get_filename();
-#ifdef WITH_GNOME_VFS
- if (myFilename.length() < 1)
- myFilename = get_uri();
-#endif
+ updateNameAndExtension();
+
+ // Store changes of the "Append filename automatically" checkbox back to preferences.
+ prefs_set_int_attribute("dialogs.save_as", "append_extension", fileTypeCheckbox.get_active());
+
+ // Store the last used save-as filetype to preferences.
+ prefs_set_string_attribute("dialogs.save_as", "default",
+ ( extension != NULL ? extension->get_id() : "" ));
+
+ cleanup( true );
return TRUE;
}
else
{
return TRUE;
}
else
{
+ cleanup( false );
+
return FALSE;
}
}
return FALSE;
}
}
void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
{
void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )
{
- extension = key;
-
// If no pointer to extension is passed in, look up based on filename extension.
// If no pointer to extension is passed in, look up based on filename extension.
- if ( !extension ) {
+ if ( !key ) {
// Not quite UTF-8 here.
gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
// Not quite UTF-8 here.
gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
- for ( int i = 0; !extension && (i < (int)fileTypes.size()); i++ ) {
+ for ( int i = 0; !key && (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) ) {
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;
+ key = fileTypes[i].extension;
}
g_free(extensionLower);
}
}
g_free(extensionLower);
}
@@ -1469,7 +1491,8 @@ void FileSaveDialogImpl::setSelectionType( Inkscape::Extension::Extension * key
}
// Ensure the proper entry in the combo box is selected.
}
// Ensure the proper entry in the combo box is selected.
- if ( extension ) {
+ if ( key ) {
+ extension = key;
gchar const * extensionID = extension->get_id();
if ( extensionID ) {
for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
gchar const * extensionID = extension->get_id();
if ( extensionID ) {
for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
set_filename(myFilename);
} else {
std::string dirName = Glib::path_get_dirname( myFilename );
set_filename(myFilename);
} else {
std::string dirName = Glib::path_get_dirname( myFilename );
- set_current_folder(dirName);
+ 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());
}
Glib::ustring basename = Glib::path_get_basename(myFilename);
//fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
}
}
}
}
+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<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
+ }
+ }
+}
private:
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;
/**
* 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
//##########################################
//##########################################
//# EXTRA WIDGET -- SOURCE SIDE
//##########################################
-/**
- * Callback for checking if the preview needs to be redrawn
- */
-void FileExportDialogImpl::updatePreviewCallback()
-{
- Glib::ustring fileName = get_preview_filename();
-#ifdef WITH_GNOME_VFS
- if (fileName.length() < 1)
- fileName = get_preview_uri();
-#endif
- if (!fileName.c_str())
- return;
- bool retval = svgPreview.set(fileName, dialogType);
- set_preview_widget_active(retval);
-}
-
-
-
/**
* Callback for fileNameEntry widget
*/
/**
* Callback for fileNameEntry widget
*/
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key) :
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.export"),
sourceX0Spinner("X0", _("Left edge of source")),
sourceY0Spinner("Y0", _("Top edge of source")),
sourceX1Spinner("X1", _("Right edge of source")),
sourceX0Spinner("X0", _("Left edge of source")),
sourceY0Spinner("Y0", _("Top edge of source")),
sourceX1Spinner("X1", _("Right edge of source")),
set_select_multiple(false);
#ifdef WITH_GNOME_VFS
set_select_multiple(false);
#ifdef WITH_GNOME_VFS
- set_local_only(false);
+ if (gnome_vfs_initialized()) {
+ set_local_only(false);
+ }
#endif
/* Initalize to Autodetect */
#endif
/* Initalize to Autodetect */
- //###### 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();
//Let's do some customization
fileNameEntry = NULL;
Gtk::Container *cont = get_toplevel();
}
myFilename = get_filename();
#ifdef WITH_GNOME_VFS
}
myFilename = get_filename();
#ifdef WITH_GNOME_VFS
- if (myFilename.length() < 1)
+ if ( myFilename.empty() && gnome_vfs_initialized() ) {
myFilename = get_uri();
myFilename = get_uri();
+ }
#endif
/*
#endif
/*