summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d8c91d1)
raw | patch | inline | side by side (parent: d8c91d1)
author | joncruz <joncruz@users.sourceforge.net> | |
Sat, 3 Mar 2007 20:51:35 +0000 (20:51 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Sat, 3 Mar 2007 20:51:35 +0000 (20:51 +0000) |
src/ui/dialog/filedialog.cpp | patch | blob | history |
index 894129795fc885e40b72de19b79bff1c8e29df44..454a356c7aa1faaa28827c36d632e70471b7f39c 100644 (file)
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:
std::vector<FileType> fileTypes;
//# Child widgets
+ Gtk::CheckButton fileTypeCheckbox;
/**
* Callback for user input into fileNameEntry
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;
- bool appendExtension = true;
- if ( newOut ) {
- try {
- Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
- size_t 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
- }
- }
+ updateNameAndExtension();
}
//###### 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) );
+
+ fileTypeBox.pack_start(fileTypeCheckbox);
createFileTypeMenu();
fileTypeComboBox.set_size_request(200,40);
fileTypeComboBox.signal_changed().connect(
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() : "" ));
return TRUE;
}
}
}
+void FileSaveDialogImpl::updateNameAndExtension()
+{
+ // 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 ( fileTypeCheckbox.get_active() && newOut ) {
+ try {
+ bool appendExtension = true;
+ Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
+ size_t 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
+ }
+ }
+}