summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e83c8c2)
raw | patch | inline | side by side (parent: e83c8c2)
author | bdilly <bdilly@users.sourceforge.net> | |
Thu, 9 Aug 2007 06:39:57 +0000 (06:39 +0000) | ||
committer | bdilly <bdilly@users.sourceforge.net> | |
Thu, 9 Aug 2007 06:39:57 +0000 (06:39 +0000) |
diff --git a/src/file.cpp b/src/file.cpp
index 92df5906529eb7c3bea2116ba297ea93a8a0ad9e..ebeef462e0a8b70e97ea3dff2103066654de3cbc 100644 (file)
--- a/src/file.cpp
+++ b/src/file.cpp
bool
sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow)
{
- //# temp hack for 'doc' until we can switch to this dialog
if (!SP_ACTIVE_DOCUMENT)
return false;
bool success = false;
- static Inkscape::UI::Dialog::FileExportDialog *exportDialogInstance = NULL;
+ static Inkscape::UI::Dialog::FileExportToOCALDialog *exportDialogInstance = NULL;
Inkscape::XML::Node *repr = sp_document_repr_root(doc);
// Verify whether the document is saved, so save this as temporary
export_path = export_path_local;
//# Show the Export To OCAL dialog
- // MADE A CHANGE TO SUBMIT CHANGES. IN THE FUTURE WILL CALL FileExportToOCALDialog
if (!exportDialogInstance)
- exportDialogInstance = Inkscape::UI::Dialog::FileExportDialog::create(
+ exportDialogInstance = Inkscape::UI::Dialog::FileExportToOCALDialog::create(
parentWindow,
- export_path,
Inkscape::UI::Dialog::EXPORT_TYPES,
(char const *) _("Select file to export to"),
default_extension
uri.append(Glib::path_get_basename(fileName));
// Save as a remote file using the dav protocol.
success = file_save_remote(doc, uri, selectionType, FALSE, FALSE);
- //remove(fileName.c_str());
+ remove(fileName.c_str());
if (!success)
g_warning( "Error exporting the document." );
index 2b4dc699b6760a2b4cac5156f884738562cd5f6b..63bb98b4b4b6432b471b348eb582a37f76d6ac62 100644 (file)
/**
* Public factory method. Used in file.cpp
*/
-FileExportDialog *FileExportDialog::create(Gtk::Window& parentWindow,
+ FileExportDialog *FileExportDialog::create(Gtk::Window& parentWindow,
const Glib::ustring &path,
FileDialogType fileTypes,
const Glib::ustring &title,
}
+//########################################################################
+//# F I L E E X P O R T T O O C A L
+//########################################################################
+
+
+/**
+ * Public factory method. Used in file.cpp
+ */
+
+ FileExportToOCALDialog *FileExportToOCALDialog::create(Gtk::Window& parentWindow,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key)
+{
+ FileExportToOCALDialog *dialog = new FileExportToOCALDialogImpl(parentWindow, fileTypes, title, default_key);
+ return dialog;
+}
+
+
} //namespace Dialog
} //namespace UI
index 8551b0eb29379c75c8a8f0583dd708d98eba38b9..06d68fa72e05275ffb85cd71eb6c0cff6e291dc6 100644 (file)
{
+
/**
* Used for setting filters and options, and
* reading them back from user selections.
}; //FileExportDialog
+/**
+ * This class provides an implementation-independent API for
+ * file "ExportToOCAL" dialogs.
+ */
+class FileExportToOCALDialog
+{
+public:
+
+ /**
+ * Constructor. Do not call directly . Use the factory.
+ * @param fileTypes one of FileDialogTypes
+ * @param title the title of the dialog
+ * @param key a list of file types from which the user can select
+ */
+ FileExportToOCALDialog ()
+ {};
+
+ /**
+ * Factory.
+ * @param fileTypes one of FileDialogTypes
+ * @param title the title of the dialog
+ * @param key a list of file types from which the user can select
+ */
+ static FileExportToOCALDialog *create(Gtk::Window& parentWindow,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key);
+
+
+ /**
+ * Destructor.
+ * Perform any necessary cleanups.
+ */
+ virtual ~FileExportToOCALDialog() {};
+
+
+ /**
+ * Show an SaveAs file selector.
+ * @return the selected path if user selected one, else NULL
+ */
+ virtual bool show() =0;
+
+ /**
+ * Return the 'key' (filetype) of the selection, if any
+ * @return a pointer to a string if successful (which must
+ * be later freed with g_free(), else NULL.
+ */
+ virtual Inkscape::Extension::Extension * getSelectionType() = 0;
+
+ virtual void setSelectionType( Inkscape::Extension::Extension * key ) = 0;
+
+ virtual Glib::ustring getFilename () =0;
+
+ /**
+ * Change the window title.
+ */
+ virtual void change_title(const Glib::ustring& title) =0;
+
+
+}; //FileExportToOCAL
+
+
+
} //namespace Dialog
} //namespace UI
} //namespace Inkscape
index 6ed56cefd08fb22fe3bbea52b2a3ab77300a2280..b76772c4056f454f44075dbcc37cbfdb23ce6cb8 100644 (file)
return myFilename;\r
}\r
\r
+\r
+\r
+\r
+//########################################################################\r
+//# F I L E E X P O R T T O O C A L\r
+//########################################################################\r
+\r
+\r
+\r
+/**\r
+ * Callback for fileNameEntry widget\r
+ */\r
+void FileExportToOCALDialogImpl::fileNameEntryChangedCallback()\r
+{\r
+ if (!fileNameEntry)\r
+ return;\r
+\r
+ Glib::ustring fileName = fileNameEntry->get_text();\r
+ if (!Glib::get_charset()) //If we are not utf8\r
+ fileName = Glib::filename_to_utf8(fileName);\r
+\r
+ //g_message("User hit return. Text is '%s'\n", fileName.c_str());\r
+\r
+ myFilename = fileName;\r
+ response(Gtk::RESPONSE_OK);\r
+}\r
+\r
+\r
+\r
+/**\r
+ * Callback for fileNameEntry widget\r
+ */\r
+void FileExportToOCALDialogImpl::fileTypeChangedCallback()\r
+{\r
+ int sel = fileTypeComboBox.get_active_row_number();\r
+ if (sel<0 || sel >= (int)fileTypes.size())\r
+ return;\r
+ FileType type = fileTypes[sel];\r
+\r
+ extension = type.extension;\r
+ updateNameAndExtension();\r
+}\r
+\r
+\r
+\r
+void FileExportToOCALDialogImpl::createFileTypeMenu()\r
+{\r
+ Inkscape::Extension::DB::OutputList extension_list;\r
+ Inkscape::Extension::db.get_output_list(extension_list);\r
+ knownExtensions.clear();\r
+\r
+ for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();\r
+ current_item != extension_list.end(); current_item++)\r
+ {\r
+ Inkscape::Extension::Output * omod = *current_item;\r
+\r
+ // FIXME: would be nice to grey them out instead of not listing them\r
+ if (omod->deactivated()) continue;\r
+\r
+ FileType type;\r
+ type.name = (_(omod->get_filetypename()));\r
+ type.pattern = "*";\r
+ Glib::ustring extension = omod->get_extension();\r
+ knownExtensions.insert( extension.casefold() );\r
+ fileDialogExtensionToPattern (type.pattern, extension);\r
+ type.extension= omod;\r
+ fileTypeComboBox.append_text(type.name);\r
+ fileTypes.push_back(type);\r
+ }\r
+\r
+ //#Let user choose\r
+ FileType guessType;\r
+ guessType.name = _("Guess from extension");\r
+ guessType.pattern = "*";\r
+ guessType.extension = NULL;\r
+ fileTypeComboBox.append_text(guessType.name);\r
+ fileTypes.push_back(guessType);\r
+\r
+\r
+ fileTypeComboBox.set_active(0);\r
+ fileTypeChangedCallback(); //call at least once to set the filter\r
+}\r
+\r
+\r
+\r
+/**\r
+ * Constructor\r
+ */\r
+FileExportToOCALDialogImpl::FileExportToOCALDialogImpl(Gtk::Window &parentWindow,\r
+ FileDialogType fileTypes,\r
+ const Glib::ustring &title,\r
+ const Glib::ustring &default_key) :\r
+ FileDialogExportBase(title)\r
+{\r
+ /*\r
+ * Start Taking the vertical Box and putting a Label\r
+ * and a Entry to take the filename\r
+ * Later put the extension selection and checkbox (?)\r
+ */\r
+ /* Initalize to Autodetect */\r
+ extension = NULL;\r
+ /* No filename to start out with */\r
+ myFilename = "";\r
+\r
+ /* Set our dialog type (save, export, etc...)*/\r
+ dialogType = fileTypes;\r
+ Gtk::VBox *vbox = get_vbox();\r
+ //Gtk::HBox fileBox;\r
+\r
+ Gtk::Label *fileLabel = new Gtk::Label(_("File"));\r
+ \r
+ fileNameEntry = new Gtk::Entry();\r
+ fileNameEntry->set_text(myFilename);\r
+ fileNameEntry->set_max_length(252); // I am giving the extension approach.\r
+ fileBox.pack_start(*fileLabel);\r
+ fileBox.pack_start(*fileNameEntry, Gtk::PACK_EXPAND_WIDGET, 3);\r
+ vbox->pack_start(fileBox);\r
+\r
+ //###### Do we want the .xxx extension automatically added?\r
+ fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));\r
+ fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.export",\r
+ "append_extension", 1) );\r
+\r
+ createFileTypeMenu();\r
+\r
+ fileTypeComboBox.set_size_request(200,40);\r
+ fileTypeComboBox.signal_changed().connect(\r
+ sigc::mem_fun(*this, &FileExportToOCALDialogImpl::fileTypeChangedCallback) );\r
+\r
+ checksBox.pack_start( fileTypeCheckbox );\r
+ vbox->pack_start( checksBox );\r
+ \r
+ vbox->pack_end( fileTypeComboBox );\r
+ \r
+ //Let's do some customization\r
+ fileNameEntry = NULL;\r
+ Gtk::Container *cont = get_toplevel();\r
+ std::vector<Gtk::Entry *> entries;\r
+ findEntryWidgets(cont, entries);\r
+ //g_message("Found %d entry widgets\n", entries.size());\r
+ if (entries.size() >=1 )\r
+ {\r
+ //Catch when user hits [return] on the text field\r
+ fileNameEntry = entries[0];\r
+ fileNameEntry->signal_activate().connect(\r
+ sigc::mem_fun(*this, &FileExportToOCALDialogImpl::fileNameEntryChangedCallback) );\r
+ }\r
+\r
+ //Let's do more customization\r
+ std::vector<Gtk::Expander *> expanders;\r
+ findExpanderWidgets(cont, expanders);\r
+ //g_message("Found %d expander widgets\n", expanders.size());\r
+ if (expanders.size() >=1 )\r
+ {\r
+ //Always show the file list\r
+ Gtk::Expander *expander = expanders[0];\r
+ expander->set_expanded(true);\r
+ }\r
+\r
+\r
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);\r
+ set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));\r
+\r
+ show_all_children();\r
+}\r
+\r
+\r
+\r
+/**\r
+ * Destructor\r
+ */\r
+FileExportToOCALDialogImpl::~FileExportToOCALDialogImpl()\r
+{\r
+}\r
+\r
+\r
+\r
+/**\r
+ * Show this dialog modally. Return true if user hits [OK]\r
+ */\r
+bool\r
+FileExportToOCALDialogImpl::show()\r
+{\r
+ set_modal (TRUE); //Window\r
+ sp_transientize((GtkWidget *)gobj()); //Make transient\r
+ gint b = run(); //Dialog\r
+ hide();\r
+\r
+ if (b == Gtk::RESPONSE_OK)\r
+ {\r
+ updateNameAndExtension();\r
+\r
+ return TRUE;\r
+ }\r
+ else\r
+ {\r
+ return FALSE;\r
+ }\r
+}\r
+\r
+\r
+/**\r
+ * Get the file extension type that was selected by the user. Valid after an [OK]\r
+ */\r
+Inkscape::Extension::Extension *\r
+FileExportToOCALDialogImpl::getSelectionType()\r
+{\r
+ return extension;\r
+}\r
+\r
+void FileExportToOCALDialogImpl::setSelectionType( Inkscape::Extension::Extension * key )\r
+{\r
+ // If no pointer to extension is passed in, look up based on filename extension.\r
+ if ( !key ) {\r
+ // Not quite UTF-8 here.\r
+ gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);\r
+ for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {\r
+ Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);\r
+ if ( ext && ext->get_extension() ) {\r
+ gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );\r
+ if ( g_str_has_suffix(filenameLower, extensionLower) ) {\r
+ key = fileTypes[i].extension;\r
+ }\r
+ g_free(extensionLower);\r
+ }\r
+ }\r
+ g_free(filenameLower);\r
+ }\r
+\r
+ // Ensure the proper entry in the combo box is selected.\r
+ if ( key ) {\r
+ extension = key;\r
+ gchar const * extensionID = extension->get_id();\r
+ if ( extensionID ) {\r
+ for ( int i = 0; i < (int)fileTypes.size(); i++ ) {\r
+ Inkscape::Extension::Extension *ext = fileTypes[i].extension;\r
+ if ( ext ) {\r
+ gchar const * id = ext->get_id();\r
+ if ( id && ( strcmp(extensionID, id) == 0) ) {\r
+ int oldSel = fileTypeComboBox.get_active_row_number();\r
+ if ( i != oldSel ) {\r
+ fileTypeComboBox.set_active(i);\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+\r
+/**\r
+ * Get the file name chosen by the user. Valid after an [OK]\r
+ */\r
+Glib::ustring\r
+FileExportToOCALDialogImpl::getFilename()\r
+{\r
+ myFilename = fileNameEntry->get_text();\r
+ updateNameAndExtension();\r
+ return myFilename;\r
+}\r
+\r
+\r
+void \r
+FileExportToOCALDialogImpl::change_title(const Glib::ustring& title)\r
+{\r
+ this->set_title(title);\r
+}\r
+\r
+void FileExportToOCALDialogImpl::updateNameAndExtension()\r
+{\r
+ // Pick up any changes the user has typed in.\r
+ Glib::ustring tmp = myFilename; // get_filename();\r
+ \r
+ Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;\r
+ if ( fileTypeCheckbox.get_active() && newOut ) {\r
+ try {\r
+ bool appendExtension = true;\r
+ Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );\r
+ Glib::ustring::size_type pos = utf8Name.rfind('.');\r
+ if ( pos != Glib::ustring::npos ) {\r
+ Glib::ustring trail = utf8Name.substr( pos );\r
+ Glib::ustring foldedTrail = trail.casefold();\r
+ if ( (trail == ".") \r
+ | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()\r
+ && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {\r
+ utf8Name = utf8Name.erase( pos );\r
+ } else {\r
+ appendExtension = false;\r
+ }\r
+ }\r
+\r
+ if (appendExtension) {\r
+ utf8Name = utf8Name + newOut->get_extension();\r
+ myFilename = Glib::filename_from_utf8( utf8Name );\r
+\r
+ }\r
+ } catch ( Glib::ConvertError& e ) {\r
+ // ignore\r
+ }\r
+ }\r
+}\r
+\r
+\r
} //namespace Dialog\r
} //namespace UI\r
} //namespace Inkscape\r
index cd9523036cf4190bdb4ef8649f9e8ce25175062f..fa8edda8583a6eeb1088e83a2fb62cc87721f0e6 100644 (file)
Glib::ustring myFilename;\r
};\r
\r
+\r
+\r
+/*#########################################################################\r
+### F I L E D I A L O G E X P O R T B A S E C L A S S\r
+#########################################################################*/\r
+\r
+/**\r
+ * This class is the base implementation for export to OCAL.\r
+ */\r
+class FileDialogExportBase : public Gtk::Dialog\r
+{\r
+public:\r
+\r
+ /**\r
+ *\r
+ */\r
+ FileDialogExportBase(const Glib::ustring &title) : Gtk::Dialog(title,true)\r
+ {}\r
+ /*\r
+ *\r
+ */\r
+ virtual ~FileDialogExportBase()\r
+ {}\r
+\r
+protected:\r
+ void cleanup( bool showConfirmed );\r
+\r
+ //Glib::ustring preferenceBase;\r
+ /**\r
+ * What type of 'open' are we? (open, import, place, etc)\r
+ */\r
+ FileDialogType dialogType;\r
+};\r
+\r
+\r
+\r
+\r
+//########################################################################\r
+//# F I L E E X P O R T T O O C A L\r
+//########################################################################\r
+\r
+\r
+\r
+/**\r
+ * Our implementation of the FileExportToOCALDialog interface.\r
+ */\r
+class FileExportToOCALDialogImpl : public FileExportToOCALDialog, public FileDialogExportBase\r
+{\r
+\r
+public:\r
+ FileExportToOCALDialogImpl(Gtk::Window& parentWindow, \r
+ FileDialogType fileTypes,\r
+ const Glib::ustring &title,\r
+ const Glib::ustring &default_key);\r
+ \r
+ virtual ~FileExportToOCALDialogImpl();\r
+\r
+ bool show();\r
+\r
+ Inkscape::Extension::Extension *getSelectionType();\r
+ virtual void setSelectionType( Inkscape::Extension::Extension * key );\r
+\r
+ Glib::ustring getFilename();\r
+\r
+ Glib::ustring myFilename;\r
+\r
+ void change_title(const Glib::ustring& title);\r
+ void updateNameAndExtension();\r
+\r
+private:\r
+\r
+ /**\r
+ * Fix to allow the user to type the file name\r
+ */\r
+ Gtk::Entry *fileNameEntry;\r
+ \r
+ \r
+ /**\r
+ * Allow the specification of the output file type\r
+ */\r
+ Gtk::ComboBoxText fileTypeComboBox;\r
+\r
+\r
+ /**\r
+ * Data mirror of the combo box\r
+ */\r
+ std::vector<FileType> fileTypes;\r
+\r
+ //# Child widgets\r
+ Gtk::HBox childBox;\r
+ Gtk::VBox checksBox;\r
+ Gtk::HBox fileBox;\r
+\r
+ Gtk::CheckButton fileTypeCheckbox;\r
+\r
+ /**\r
+ * Callback for user input into fileNameEntry\r
+ */\r
+ void fileTypeChangedCallback();\r
+\r
+ /**\r
+ * Create a filter menu for this type of dialog\r
+ */\r
+ void createFileTypeMenu();\r
+\r
+\r
+ /**\r
+ * The extension to use to write this file\r
+ */\r
+ Inkscape::Extension::Extension *extension;\r
+\r
+ /**\r
+ * Callback for user input into fileNameEntry\r
+ */\r
+ void fileNameEntryChangedCallback();\r
+\r
+ /**\r
+ * List of known file extensions.\r
+ */\r
+ std::set<Glib::ustring> knownExtensions;\r
+};\r
+\r
+\r
+\r
}\r
}\r
}\r