Commit 51e7bf1e authored by Lutz Müller's avatar Lutz Müller Committed by Lutz Müller

Add a menu item "Send" to the file menu. If this one is clicked, pop up an

2001-07-10  Lutz Müller <urc8@rz.uni-karlsruhe.de>

        * src/workbook-control-gui.c: Add a menu item "Send" to the file menu.
        If this one is clicked, pop up an Evolution-Composer with current
        workbook attached.
        * src/file-priv.h: New virtual function for GnumFileSaver:
        save_to_stream.
        Introduce GnumFileSaverSaveToStreamFunc. Keep a mime type.
        * src/file.[c,h]: Implement save_to_stream and mime_type detection.
        * src/gui-file.[c,h]: Reduce copy & paste by introducing
        (make_format_chooser) and (check_multiple_sheet_support_if_needed).
        New function: (gui_file_save_to_stream) which asks for the desired
        mime type.
        * src/bonobo-io.c: This file saver doesn't support save_to_stream.
        * src/stf.c: This one either.
        * src/xml-io.[c,h]: Implement save_to_stream.
        * src/plugin-service.c: Pass NULL for save_to_stream.
parent bb46688c
2001-07-10 Lutz Mller <urc8@rz.uni-karlsruhe.de>
* src/workbook-control-gui.c: Add a menu item "Send" to the file menu.
If this one is clicked, pop up an Evolution-Composer with current
workbook attached.
* src/file-priv.h: New virtual function for GnumFileSaver:
save_to_stream.
Introduce GnumFileSaverSaveToStreamFunc. Keep a mime type.
* src/file.[c,h]: Implement save_to_stream and mime_type detection.
* src/gui-file.[c,h]: Reduce copy & paste by introducing
(make_format_chooser) and (check_multiple_sheet_support_if_needed).
New function: (gui_file_save_to_stream) which asks for the desired
mime type.
* src/bonobo-io.c: This file saver doesn't support save_to_stream.
* src/stf.c: This one either.
* src/xml-io.[c,h]: Implement save_to_stream.
* src/plugin-service.c: Pass NULL for save_to_stream.
2001-07-09 Lutz Mller <urc8@rz.uni-karlsruhe.de>
* acconfig.h: #undef ENABLE_EVOLUTION
......
2001-07-10 Lutz Mller <urc8@rz.uni-karlsruhe.de>
* src/workbook-control-gui.c: Add a menu item "Send" to the file menu.
If this one is clicked, pop up an Evolution-Composer with current
workbook attached.
* src/file-priv.h: New virtual function for GnumFileSaver:
save_to_stream.
Introduce GnumFileSaverSaveToStreamFunc. Keep a mime type.
* src/file.[c,h]: Implement save_to_stream and mime_type detection.
* src/gui-file.[c,h]: Reduce copy & paste by introducing
(make_format_chooser) and (check_multiple_sheet_support_if_needed).
New function: (gui_file_save_to_stream) which asks for the desired
mime type.
* src/bonobo-io.c: This file saver doesn't support save_to_stream.
* src/stf.c: This one either.
* src/xml-io.[c,h]: Implement save_to_stream.
* src/plugin-service.c: Pass NULL for save_to_stream.
2001-07-09 Lutz Mller <urc8@rz.uni-karlsruhe.de>
* acconfig.h: #undef ENABLE_EVOLUTION
......
2001-07-10 Lutz Mller <urc8@rz.uni-karlsruhe.de>
* src/workbook-control-gui.c: Add a menu item "Send" to the file menu.
If this one is clicked, pop up an Evolution-Composer with current
workbook attached.
* src/file-priv.h: New virtual function for GnumFileSaver:
save_to_stream.
Introduce GnumFileSaverSaveToStreamFunc. Keep a mime type.
* src/file.[c,h]: Implement save_to_stream and mime_type detection.
* src/gui-file.[c,h]: Reduce copy & paste by introducing
(make_format_chooser) and (check_multiple_sheet_support_if_needed).
New function: (gui_file_save_to_stream) which asks for the desired
mime type.
* src/bonobo-io.c: This file saver doesn't support save_to_stream.
* src/stf.c: This one either.
* src/xml-io.[c,h]: Implement save_to_stream.
* src/plugin-service.c: Pass NULL for save_to_stream.
2001-07-09 Lutz Mller <urc8@rz.uni-karlsruhe.de>
* acconfig.h: #undef ENABLE_EVOLUTION
......
2001-07-10 Lutz Mller <urc8@rz.uni-karlsruhe.de>
* src/workbook-control-gui.c: Add a menu item "Send" to the file menu.
If this one is clicked, pop up an Evolution-Composer with current
workbook attached.
* src/file-priv.h: New virtual function for GnumFileSaver:
save_to_stream.
Introduce GnumFileSaverSaveToStreamFunc. Keep a mime type.
* src/file.[c,h]: Implement save_to_stream and mime_type detection.
* src/gui-file.[c,h]: Reduce copy & paste by introducing
(make_format_chooser) and (check_multiple_sheet_support_if_needed).
New function: (gui_file_save_to_stream) which asks for the desired
mime type.
* src/bonobo-io.c: This file saver doesn't support save_to_stream.
* src/stf.c: This one either.
* src/xml-io.[c,h]: Implement save_to_stream.
* src/plugin-service.c: Pass NULL for save_to_stream.
2001-07-09 Lutz Mller <urc8@rz.uni-karlsruhe.de>
* acconfig.h: #undef ENABLE_EVOLUTION
......
......@@ -528,7 +528,11 @@ gnumeric_bonobo_io_init (void)
gnumeric_bonobo_read_workbook);
gnumeric_bonobo_saver = gnum_file_saver_new (
NULL, "efs", desc, FILE_FL_AUTO,
#ifdef ENABLE_BONOBO
gnumeric_bonobo_write_workbook, NULL);
#else
gnumeric_bonobo_write_workbook);
#endif
register_file_opener (gnumeric_bonobo_opener, 100);
register_file_saver (gnumeric_bonobo_saver);
}
......@@ -50,21 +50,32 @@ void gnum_file_opener_setup (GnumFileOpener *fo, const gchar *id,
struct _GnumFileSaverClass {
GtkObjectClass parent_class;
void (*save) (GnumFileSaver const *fs,
IOContext *io_context,
WorkbookView *wbv,
const gchar *file_name);
void (*save) (GnumFileSaver const *fs,
IOContext *io_context,
WorkbookView *wbv,
const gchar *file_name);
#ifdef ENABLE_BONOBO
void (*save_to_stream) (GnumFileSaver const *fs,
IOContext *io_context,
WorkbookView *wbv,
BonoboStream *stream,
CORBA_Environment *ev);
#endif
};
struct _GnumFileSaver {
GtkObject parent;
gchar *id;
const gchar *mime_type;
gchar *extension;
gchar *description;
FileFormatLevel format_level;
FileSaveScope save_scope;
GnumFileSaverSaveFunc save_func;
FileFormatLevel format_level;
FileSaveScope save_scope;
GnumFileSaverSaveFunc save_func;
#ifdef ENABLE_BONOBO
GnumFileSaverSaveToStreamFunc save_to_stream_func;
#endif
};
void gnum_file_saver_setup (GnumFileSaver *fs,
......@@ -72,6 +83,11 @@ void gnum_file_saver_setup (GnumFileSaver *fs,
const gchar *extension,
const gchar *description,
FileFormatLevel level,
#ifdef ENABLE_BONOBO
GnumFileSaverSaveFunc save_func,
GnumFileSaverSaveToStreamFunc save_to_stream_func);
#else
GnumFileSaverSaveFunc save_func);
#endif
#endif /* GNUMERIC_FILE_PRIV_H */
......@@ -9,6 +9,9 @@
#include <string.h>
#include <libgnome/libgnome.h>
#include <gal/util/e-util.h>
#ifdef ENABLE_BONOBO
#include <bonobo/bonobo-exception.h>
#endif
#include "file.h"
#include "io-context.h"
#include "command-context.h"
......@@ -204,6 +207,7 @@ gnum_file_saver_init (GnumFileSaver *fs)
{
fs->id = NULL;
fs->extension = NULL;
fs->mime_type = NULL;
fs->description = NULL;
fs->format_level = FILE_FL_NEW;
fs->save_scope = FILE_SAVE_WORKBOOK;
......@@ -237,12 +241,40 @@ gnum_file_saver_save_real (GnumFileSaver const *fs, IOContext *io_context,
fs->save_func (fs, io_context, wbv, file_name);
}
#ifdef ENABLE_BONOBO
static void
gnum_file_saver_save_to_stream_real (GnumFileSaver const *fs,
IOContext *io_context,
WorkbookView *wbv,
BonoboStream *stream,
CORBA_Environment *ev)
{
if (fs->save_to_stream_func == NULL) {
gnumeric_io_error_unknown (io_context);
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Bonobo_Stream_NotSupported, NULL);
return;
}
fs->save_to_stream_func (fs, io_context, wbv, stream, ev);
}
gboolean
gnum_file_saver_supports_save_to_stream (GnumFileSaver const *fs)
{
return (fs->save_to_stream_func != NULL);
}
#endif
static void
gnum_file_saver_class_init (GnumFileSaverClass *klass)
{
GTK_OBJECT_CLASS (klass)->destroy = gnum_file_saver_destroy;
klass->save = gnum_file_saver_save_real;
#ifdef ENABLE_BONOBO
klass->save_to_stream = gnum_file_saver_save_to_stream_real;
#endif
}
E_MAKE_TYPE (gnum_file_saver, "GnumFileSaver", GnumFileSaver, \
......@@ -257,6 +289,9 @@ E_MAKE_TYPE (gnum_file_saver, "GnumFileSaver", GnumFileSaver, \
* @description : Description of supported file format
* @level : File format level
* @save_func : Pointer to "save" function
#ifdef ENABLE_BONOBO
* @save_to_stream_func: Pointer to "save to stream" function
#endif
*
* Sets up GnumFileSaver object, newly created with gtk_type_new function.
* This is intended to be used only by GnumFileSaver derivates.
......@@ -267,15 +302,29 @@ gnum_file_saver_setup (GnumFileSaver *fs, const gchar *id,
const gchar *extension,
const gchar *description,
FileFormatLevel level,
#ifdef ENABLE_BONOBO
GnumFileSaverSaveFunc save_func,
GnumFileSaverSaveToStreamFunc save_to_stream_func)
#else
GnumFileSaverSaveFunc save_func)
#endif
{
gchar *tmp;
g_return_if_fail (IS_GNUM_FILE_SAVER (fs));
fs->id = g_strdup (id);
tmp = g_strdup_printf ("SomeFile.%s", extension);
fs->mime_type = gnome_mime_type_or_default (tmp,
"application/application/x-gnumeric");
g_free (tmp);
fs->extension = g_strdup (extension);
fs->description = g_strdup (description);
fs->format_level = level;
fs->save_func = save_func;
#ifdef ENABLE_BONOBO
fs->save_to_stream_func = save_to_stream_func;
#endif
}
/**
......@@ -285,6 +334,9 @@ gnum_file_saver_setup (GnumFileSaver *fs, const gchar *id,
* @description : Description of supported file format
* @level : File format level
* @save_func : Pointer to "save" function
#ifdef ENABLE_BONOBO
* @save_to_stream_func: Pointer to "save to stream" function
#endif
*
* Creates new GnumFileSaver object. Optional @id will be used
* after registering it with register_file_saver or
......@@ -297,12 +349,21 @@ gnum_file_saver_new (const gchar *id,
const gchar *extension,
const gchar *description,
FileFormatLevel level,
#ifdef ENABLE_BONOBO
GnumFileSaverSaveFunc save_func,
GnumFileSaverSaveToStreamFunc save_to_stream_func)
#else
GnumFileSaverSaveFunc save_func)
#endif
{
GnumFileSaver *fs;
fs = GNUM_FILE_SAVER (gtk_type_new (TYPE_GNUM_FILE_SAVER));
#ifdef ENABLE_BONOBO
gnum_file_saver_setup (fs, id, extension, description, level, save_func, save_to_stream_func);
#else
gnum_file_saver_setup (fs, id, extension, description, level, save_func);
#endif
return fs;
}
......@@ -332,6 +393,14 @@ gnum_file_saver_get_id (GnumFileSaver const *fs)
return fs->id;
}
const gchar *
gnum_file_saver_get_mime_type (GnumFileSaver const *fs)
{
g_return_val_if_fail (IS_GNUM_FILE_SAVER (fs), FALSE);
return fs->mime_type;
}
const gchar *
gnum_file_saver_get_extension (GnumFileSaver const *fs)
{
......@@ -379,6 +448,31 @@ gnum_file_saver_save (GnumFileSaver const *fs, IOContext *io_context,
GNUM_FILE_SAVER_METHOD (fs, save) (fs, io_context, wbv, file_name);
}
#ifdef ENABLE_BONOBO
/**
* gnum_file_saver_save_to_stream:
* @fs : GnumFileSaver object
* @io_context : Context for i/o operation
* @wbv : Workbook View
* @stream : Bonobo Stream
* @ev : CORBA Environment
*
* Saves @wbv and workbook it's attached to into the stream. Results are
* reported through the environment variable, the i/o context is used only
* for updating the progress bar.
*/
void
gnum_file_saver_save_to_stream (GnumFileSaver const *fs, IOContext *io_context,
WorkbookView *wbv, BonoboStream *stream,
CORBA_Environment *ev)
{
bonobo_return_if_fail (IS_GNUM_FILE_SAVER (fs), ev);
GNUM_FILE_SAVER_METHOD (fs, save_to_stream) (fs, io_context, wbv,
stream, ev);
}
#endif
/**
* gnum_file_saver_fix_file_name:
* @fs : GnumFileSaver object
......@@ -714,6 +808,28 @@ get_default_file_saver (void)
return ((DefaultFileSaver *) default_file_saver_list->data)->saver;
}
/**
* get_file_saver_for_mime_type:
* @mime_type: A mime type
*
* Returns a file saver that claims to save files with given mime type.
*
* Return value: GnumFileSaver object or NULL if no suitable file saver could
* be found.
*/
GnumFileSaver *
get_file_saver_for_mime_type (const gchar *mime_type)
{
GList *l;
for (l = file_saver_list; l != NULL; l = l->next) {
if (!strcmp (gnum_file_saver_get_mime_type (l->data), mime_type)) {
return (l->data);
}
}
return (NULL);
}
/**
* get_file_opener_by_id:
* @id : File opener's ID
......
......@@ -3,6 +3,9 @@
#include <gtk/gtktypeutils.h>
#include "gnumeric.h"
#ifdef ENABLE_BONOBO
#include <bonobo/bonobo-stream.h>
#endif
/*
* File format levels. They are ordered. When we save a file, we
......@@ -95,6 +98,13 @@ typedef void (*GnumFileSaverSaveFunc) (GnumFileSaver const *fs,
IOContext *io_context,
WorkbookView *wbv,
const gchar *file_name);
#ifdef ENABLE_BONOBO
typedef void (*GnumFileSaverSaveToStreamFunc) (GnumFileSaver const *fs,
IOContext *io_context,
WorkbookView *wbv,
BonoboStream *stream,
CORBA_Environment *ev);
#endif
GtkType gnum_file_saver_get_type (void);
......@@ -102,17 +112,31 @@ GnumFileSaver *gnum_file_saver_new (const gchar *id,
const gchar *extension,
const gchar *description,
FileFormatLevel level,
#ifdef ENABLE_BONOBO
GnumFileSaverSaveFunc save_func,
GnumFileSaverSaveToStreamFunc save_to_stream_func);
#else
GnumFileSaverSaveFunc save_func);
#endif
void gnum_file_saver_set_save_scope (GnumFileSaver *fs, FileSaveScope scope);
FileSaveScope gnum_file_saver_get_save_scope (GnumFileSaver *fs);
void gnum_file_saver_save (GnumFileSaver const *fs, IOContext *io_context,
WorkbookView *wbv, const gchar *file_name);
#ifdef ENABLE_BONOBO
void gnum_file_saver_save_to_stream (GnumFileSaver const *fs,
IOContext *io_context,
WorkbookView *wbv,
BonoboStream *stream,
CORBA_Environment *ev);
gboolean gnum_file_saver_supports_save_to_stream (GnumFileSaver const *fs);
#endif
gchar *gnum_file_saver_fix_file_name (GnumFileSaver const *fs,
const gchar *file_name);
const gchar *gnum_file_saver_get_id (GnumFileSaver const *fs);
const gchar *gnum_file_saver_get_extension (GnumFileSaver const *fs);
const gchar *gnum_file_saver_get_mime_type (GnumFileSaver const *fs);
const gchar *gnum_file_saver_get_description (GnumFileSaver const *fs);
FileFormatLevel gnum_file_saver_get_format_level (GnumFileSaver const *fs);
......@@ -129,6 +153,7 @@ void register_file_saver_as_default (GnumFileSaver *fs, gint priority);
void unregister_file_saver (GnumFileSaver *fs);
GnumFileSaver *get_default_file_saver (void);
GnumFileSaver *get_file_saver_for_mime_type (const gchar *mime_type);
GnumFileOpener *get_file_opener_by_id (const gchar *id);
GnumFileSaver *get_file_saver_by_id (const gchar *id);
......
......@@ -40,6 +40,38 @@ file_saver_description_cmp (gconstpointer a, gconstpointer b)
gnum_file_saver_get_description (fs_b));
}
static GtkWidget *
make_format_chooser (GList *list, GtkOptionMenu *omenu)
{
GList *l;
GtkBox *box;
GtkMenu *menu;
/* Make format chooser */
box = GTK_BOX (gtk_hbox_new (0, GNOME_PAD));
menu = GTK_MENU (gtk_menu_new ());
for (l = list; l != NULL; l = l->next) {
GtkWidget *item;
const gchar *descr;
if IS_GNUM_FILE_OPENER (l->data)
descr = gnum_file_opener_get_description (
GNUM_FILE_OPENER (l->data));
else
descr = gnum_file_saver_get_description (
GNUM_FILE_SAVER (l->data));
item = gtk_menu_item_new_with_label (descr);
gtk_widget_show (item);
gtk_menu_append (menu, item);
}
gtk_option_menu_set_menu (omenu, GTK_WIDGET (menu));
gtk_box_pack_start (box, gtk_label_new (_("File format:")),
FALSE, FALSE, GNOME_PAD);
gtk_box_pack_start (box, GTK_WIDGET (omenu), FALSE, TRUE, GNOME_PAD);
return (GTK_WIDGET (box));
}
/*
* Lets the user choose an import filter for selected file, and
* uses that to load the file.
......@@ -47,11 +79,10 @@ file_saver_description_cmp (gconstpointer a, gconstpointer b)
void
gui_file_import (WorkbookControlGUI *wbcg)
{
GList *importers, *l;
GList *importers;
GtkFileSelection *fsel;
GtkBox *box;
GtkOptionMenu *omenu;
GtkMenu *menu;
GtkWidget *format_chooser;
GnumFileOpener *fo = NULL;
gchar *file_name;
......@@ -65,26 +96,13 @@ gui_file_import (WorkbookControlGUI *wbcg)
importers = g_list_sort (importers, file_opener_description_cmp);
/* Make format chooser */
box = GTK_BOX (gtk_hbox_new (0, GNOME_PAD));
omenu = GTK_OPTION_MENU (gtk_option_menu_new ());
menu = GTK_MENU (gtk_menu_new ());
for (l = importers; l != NULL; l = l->next) {
GnumFileOpener *fo = l->data;
GtkWidget *item;
item = gtk_menu_item_new_with_label (gnum_file_opener_get_description (fo));
gtk_widget_show (item);
gtk_menu_append (menu, item);
}
gtk_option_menu_set_menu (omenu, GTK_WIDGET (menu));
gtk_box_pack_start (box, gtk_label_new (_("File format:")),
FALSE, FALSE, GNOME_PAD);
gtk_box_pack_start (box, GTK_WIDGET (omenu), FALSE, TRUE, GNOME_PAD);
format_chooser = make_format_chooser (importers, omenu);
/* Pack it into file selector */
fsel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Import file")));
gtk_file_selection_hide_fileop_buttons (fsel);
gtk_box_pack_start (GTK_BOX (fsel->action_area), GTK_WIDGET (box),
gtk_box_pack_start (GTK_BOX (fsel->action_area), format_chooser,
FALSE, TRUE, 0);
/* Show file selector */
......@@ -147,6 +165,31 @@ can_try_save_to (WorkbookControlGUI *wbcg, const char *name)
return result;
}
static gboolean
check_multiple_sheet_support_if_needed (GnumFileSaver *fs,
WorkbookControlGUI *wbcg,
WorkbookView *wb_view)
{
gboolean ret_val = TRUE;
if (gnum_file_saver_get_save_scope (fs) == FILE_SAVE_SHEET &&
gnome_config_get_bool_with_default ("Gnumeric/File/AskBeforeSavingOneSheet=true", NULL)) {
GList *sheets;
gchar *msg = _("Selected file format doesn't support "
"saving multiple sheets in one file.\n"
"If you want to save all sheets, save them "
"in separate files or select different file format.\n"
"Do you want to save only current sheet?");
sheets = workbook_sheets (wb_view_workbook (wb_view));
if (g_list_length (sheets) > 1) {
ret_val = gnumeric_dialog_question_yes_no (wbcg, msg, TRUE);
}
g_list_free (sheets);
}
return (ret_val);
}
static gboolean
do_save_as (WorkbookControlGUI *wbcg, WorkbookView *wb_view,
GnumFileSaver *fs, const char *name)
......@@ -169,25 +212,10 @@ do_save_as (WorkbookControlGUI *wbcg, WorkbookView *wb_view,
wb_view_preferred_size (wb_view, GTK_WIDGET (wbcg->notebook)->allocation.width,
GTK_WIDGET (wbcg->notebook)->allocation.height);
if (gnum_file_saver_get_save_scope (fs) == FILE_SAVE_SHEET &&
gnome_config_get_bool_with_default ("Gnumeric/File/AskBeforeSavingOneSheet=true", NULL)) {
gboolean accepted = TRUE;
GList *sheets;
gchar *msg = _("Selected file format doesn't support "
"saving multiple sheets in one file.\n"
"If you want to save all sheets, save them "
"in separate files or select different file format.\n"
"Do you want to save only current sheet?");
sheets = workbook_sheets (wb_view_workbook (wb_view));
if (g_list_length (sheets) > 1) {
accepted = gnumeric_dialog_question_yes_no (wbcg, msg, TRUE);
}
g_list_free (sheets);
if (!accepted) {
g_free (filename);
return FALSE;
}
success = check_multiple_sheet_support_if_needed (fs, wbcg, wb_view);
if (!success) {
g_free (filename);
return (FALSE);
}
success = wb_view_save_as (wb_view, WORKBOOK_CONTROL (wbcg), fs, filename);
......@@ -198,11 +226,10 @@ do_save_as (WorkbookControlGUI *wbcg, WorkbookView *wb_view,
gboolean
gui_file_save_as (WorkbookControlGUI *wbcg, WorkbookView *wb_view)
{
GList *savers, *l;
GList *savers;
GtkFileSelection *fsel;
GtkBox *box;
GtkOptionMenu *omenu;
GtkMenu *menu;
GtkWidget *format_chooser;
GnumFileSaver *fs;
gboolean success = FALSE;
const gchar *wb_file_name;
......@@ -213,25 +240,12 @@ gui_file_save_as (WorkbookControlGUI *wbcg, WorkbookView *wb_view)
savers = g_list_sort (savers, file_saver_description_cmp);
/* Make format chooser */
box = GTK_BOX (gtk_hbox_new (0, GNOME_PAD));
omenu = GTK_OPTION_MENU (gtk_option_menu_new ());
menu = GTK_MENU (gtk_menu_new ());
for (l = savers; l != NULL; l = l->next) {
GnumFileSaver *fs = l->data;
GtkWidget *item;
item = gtk_menu_item_new_with_label (gnum_file_saver_get_description (fs));
gtk_widget_show (item);
gtk_menu_append (menu, item);
}
gtk_option_menu_set_menu (omenu, GTK_WIDGET (menu));
gtk_box_pack_start (box, gtk_label_new (_("File format:")),
FALSE, FALSE, GNOME_PAD);
gtk_box_pack_start (box, GTK_WIDGET (omenu), FALSE, TRUE, GNOME_PAD);
format_chooser = make_format_chooser (savers, omenu);
/* Pack it into file selector */
fsel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Save workbook as")));
gtk_box_pack_start (GTK_BOX (fsel->action_area), GTK_WIDGET (box),
gtk_box_pack_start (GTK_BOX (fsel->action_area), format_chooser,
FALSE, TRUE, 0);
/* Set default file saver */
......@@ -324,3 +338,99 @@ gui_file_save (WorkbookControlGUI *wbcg, WorkbookView *wb_view)
return wb_view_save (wb_view, WORKBOOK_CONTROL (wbcg));
}
}
#ifdef ENABLE_BONOBO
static GnumFileSaver *
ask_for_file_saver (WorkbookControlGUI *wbcg, WorkbookView *wb_view)
{
GtkWidget *dialog;
GtkWidget *format_chooser;
GtkOptionMenu *omenu;
GList *savers, *l;
GnumFileSaver *fs;
const gchar *buttons[] = {GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL, NULL};
dialog = gnome_message_box_newv (_("Which file format would you like?"),
GNOME_MESSAGE_BOX_QUESTION, buttons);
gnome_dialog_set_close (GNOME_DIALOG (dialog), FALSE);
/* Add the format chooser */
savers = NULL;
for (l = get_file_savers (); l != NULL; l = l->next) {
if (gnum_file_saver_supports_save_to_stream (l->data)) {
savers = g_list_append (savers, l->data);
}
}
savers = g_list_sort (savers, file_saver_description_cmp);
omenu = GTK_OPTION_MENU (gtk_option_menu_new ());
format_chooser = make_format_chooser (savers, omenu);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
format_chooser, FALSE, FALSE, 0);
/* Set default file saver */
fs = wbcg->current_saver;
if (fs == NULL) {
fs = (GnumFileSaver *) workbook_get_file_saver (
wb_view_workbook (wb_view));
}
if (fs == NULL || g_list_find (savers, fs) == NULL) {
fs = get_default_file_saver ();
}
gtk_option_menu_set_history (omenu, g_list_index (savers, fs));
gtk_widget_show_all (dialog);
switch (gnome_dialog_run (GNOME_DIALOG (dialog))) {
case 0: /* Ok */
fs = g_list_nth_data (savers,
gnumeric_option_menu_get_selected_index (omenu));
break;
default: /* Cancel */
fs = NULL;
break;
}
gnome_dialog_close (GNOME_DIALOG (dialog));
g_list_free (savers);
return (fs);
}
void gui_file_save_to_stream (BonoboStream *stream, WorkbookControlGUI *wbcg,
WorkbookView *wb_view, const gchar *mime_type,
CORBA_Environment *ev)
{
GnumFileSaver *fs = NULL;
IOContext *io_context;
/* If no mime type is given, we need to ask. */
if (!mime_type) {
fs = ask_for_file_saver (wbcg, wb_view);
if (!fs) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Bonobo_IOError, NULL);
return;
}
} else {
fs = get_file_saver_for_mime_type (mime_type);
if (!fs) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Bonobo_Stream_NotSupported,
NULL);
return;
}
}
if (!check_multiple_sheet_support_if_needed (fs, wbcg, wb_view)) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Bonobo_IOError, NULL);
return;
}
io_context = gnumeric_io_context_new (WORKBOOK_CONTROL (wbcg));
gnum_file_saver_save_to_stream (fs, io_context, wb_view, stream, ev);
gtk_object_destroy (GTK_OBJECT (io_context));
}
#endif
......@@ -2,10 +2,19 @@
#define GNUMERIC_GUI_FILE_H
#include "gui-gnumeric.h"
#ifdef ENABLE_BONOBO
#include <bonobo/bonobo-stream.h>
#endif
gboolean gui_file_save_as (WorkbookControlGUI *wbcg, WorkbookView *);
gboolean gui_file_save (WorkbookControlGUI *wbcg, WorkbookView *);
void gui_file_import (WorkbookControlGUI *wbcg);
void gui_file_open (WorkbookControlGUI *wbcg);
#ifdef ENABLE_BONOBO
void gui_file_save_to_stream (BonoboStream *stream, WorkbookControlGUI *wbcg,
WorkbookView *wb_view, const gchar *mime_type,
CORBA_Environment *ev);
#endif
#endif /* GNUMERIC_GUI_FILE_H */
......@@ -619,7 +619,11 @@ gnum_plugin_file_saver_new (PluginService *service)
service_file_saver->file_extension,
service_file_saver->description,
service_file_saver->format_level,
NULL);
#ifdef ENABLE_BONOBO
NULL, NULL);
#else
NULL);
#endif
gnum_file_saver_set_save_scope (GNUM_FILE_SAVER (fs),
service_file_saver->save_scope);
fs->service = service;
......
......@@ -332,5 +332,10 @@ stf_init (void)
register_file_saver (gnum_file_saver_new (
"Gnumeric_stf:stf", "csv",
_("Text File Export (*.csv)"),
FILE_FL_MANUAL, stf_write_workbook));