Commit c7e7774e authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

add missing break.


2002-06-26  Jody Goldberg <jody@gnome.org>

	* src/expr.c (do_gnm_expr_unref) : add missing break.

2002-06-26  Jody Goldberg <jody@gnome.org>

	* src/gui-util.c (gui_file_open) : move the magic directory selector
	  for here.
	(gnumeric_dialog_file_selection) : to here, so that it works for other
	  situations too.
parent 8e593507
......@@ -12,7 +12,8 @@ Release Critical
- 3D reference fixes on sheet deletion
- Dependencies for constructed ranges
- Finish support for named ranges in applix.
- mps importer fails to import the mps sample files afiro.mps and blend.mps
- range sel for expressions that start with +
- 'discard' for invalid expressions enters text as string
1.2 Targets
-----------
......
2002-06-26 Jody Goldberg <jody@gnome.org>
* src/expr.c (do_gnm_expr_unref) : add missing break.
2002-06-26 Jody Goldberg <jody@gnome.org>
* src/gui-util.c (gui_file_open) : move the magic directory selector
for here.
(gnumeric_dialog_file_selection) : to here, so that it works for other
situations too.
2002-06-26 Jon K Hellan <hellan@acm.org>
* GNOME_Gnumeric.server.in.in: Add mime types for lotus, applix,
......
2002-06-26 Jody Goldberg <jody@gnome.org>
* src/expr.c (do_gnm_expr_unref) : add missing break.
2002-06-26 Jody Goldberg <jody@gnome.org>
* src/gui-util.c (gui_file_open) : move the magic directory selector
for here.
(gnumeric_dialog_file_selection) : to here, so that it works for other
situations too.
2002-06-26 Jon K Hellan <hellan@acm.org>
* GNOME_Gnumeric.server.in.in: Add mime types for lotus, applix,
......
2002-06-26 Jody Goldberg <jody@gnome.org>
* src/expr.c (do_gnm_expr_unref) : add missing break.
2002-06-26 Jody Goldberg <jody@gnome.org>
* src/gui-util.c (gui_file_open) : move the magic directory selector
for here.
(gnumeric_dialog_file_selection) : to here, so that it works for other
situations too.
2002-06-26 Jon K Hellan <hellan@acm.org>
* GNOME_Gnumeric.server.in.in: Add mime types for lotus, applix,
......
......@@ -368,7 +368,7 @@ do_gnm_expr_unref (GnmExpr const *expr)
value_release (expr->array.corner.value);
do_gnm_expr_unref (expr->array.corner.expr);
}
break;
case GNM_EXPR_OP_SET:
gnm_expr_list_unref (expr->set.set);
......
......@@ -53,7 +53,6 @@ typedef enum {
* GnumFileOpener
*/
typedef struct _GnumFileOpener GnumFileOpener;
typedef struct _GnumFileOpenerClass GnumFileOpenerClass;
#define TYPE_GNUM_FILE_OPENER (gnum_file_opener_get_type ())
......
......@@ -24,6 +24,7 @@ typedef struct _SolverParameters SolverParameters;
typedef struct _SheetObject SheetObject;
typedef struct _SheetObjectAnchor SheetObjectAnchor;
typedef struct _GnmDepContainer GnmDepContainer;
typedef struct _Dependent Dependent;
typedef struct _Cell Cell;
typedef struct _CellComment CellComment;
......@@ -88,7 +89,7 @@ typedef struct _ErrorInfo ErrorInfo;
typedef struct _PrintInformation PrintInformation;
typedef struct _String String;
typedef struct _GnmDepContainer GnmDepContainer;
typedef struct _GnumFileOpener GnumFileOpener; /* TODO rename to GnmFileFormatReader */
typedef struct _StyleFormat StyleFormat;
typedef struct _StyleFont StyleFont;
......
......@@ -78,6 +78,42 @@ make_format_chooser (GList *list, GtkOptionMenu *omenu)
return (GTK_WIDGET (box));
}
gboolean
gui_file_read (WorkbookControlGUI *wbcg, char const *file_name,
GnumFileOpener const *optional_format)
{
IOContext *io_context;
WorkbookView *wbv;
wb_control_set_sensitive (WORKBOOK_CONTROL (wbcg), FALSE);
io_context = gnumeric_io_context_new (COMMAND_CONTEXT (wbcg));
wbv = wb_view_new_from_file (file_name, optional_format, io_context);
if (gnumeric_io_error_occurred (io_context))
gnumeric_io_error_display (io_context);
g_object_unref (G_OBJECT (io_context));
wb_control_set_sensitive (WORKBOOK_CONTROL (wbcg), TRUE);
if (wbv != NULL) {
Workbook *tmp_wb = wb_control_workbook (WORKBOOK_CONTROL (wbcg));
if (workbook_is_pristine (tmp_wb)) {
g_object_ref (G_OBJECT (wbcg));
workbook_unref (tmp_wb);
workbook_control_set_view (WORKBOOK_CONTROL (wbcg), wbv, NULL);
workbook_control_init_state (WORKBOOK_CONTROL (wbcg));
} else
(void) wb_control_wrapper_new (WORKBOOK_CONTROL (wbcg), wbv, NULL);
workbook_recalc (wb_view_workbook (wbv));
g_return_val_if_fail (!workbook_is_dirty (wb_view_workbook (wbv)), FALSE);
sheet_update (wb_view_cur_sheet (wbv));
return TRUE;
}
return FALSE;
}
/*
* Lets the user choose an import filter for selected file, and
* uses that to load the file.
......@@ -124,7 +160,7 @@ gui_file_import (WorkbookControlGUI *wbcg)
fo = g_list_nth_data (importers, gnumeric_option_menu_get_selected_index (omenu));
file_name = gtk_file_selection_get_filename (fsel);
if (fo != NULL)
wb_view_open (file_name, WORKBOOK_CONTROL (wbcg), TRUE, fo);
gui_file_read (wbcg, file_name, fo);
gtk_object_destroy (GTK_OBJECT (fsel));
g_list_free (importers);
......@@ -303,29 +339,12 @@ void
gui_file_open (WorkbookControlGUI *wbcg)
{
GtkFileSelection *fsel;
WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
Workbook *wb;
const gchar *wb_file_name;
fsel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Load file")));
gtk_file_selection_hide_fileop_buttons (fsel);
/* Select current directory if we have one */
wb = wb_control_workbook (wbc);
wb_file_name = wb != NULL ? workbook_get_filename (wb) : NULL;
if (wb_file_name != NULL && strchr (wb_file_name, G_DIR_SEPARATOR) != NULL) {
gchar *tmp, *dir_name;
tmp = g_dirname (wb_file_name);
dir_name = g_strconcat (tmp, G_DIR_SEPARATOR_S, NULL);
gtk_file_selection_set_filename (fsel, dir_name);
g_free (dir_name);
g_free (tmp);
}
if (gnumeric_dialog_file_selection (wbcg, fsel))
wb_view_open (gtk_file_selection_get_filename (fsel),
wbc, TRUE, NULL);
gui_file_read (wbcg, gtk_file_selection_get_filename (fsel), NULL);
gtk_widget_destroy (GTK_WIDGET (fsel));
}
......
......@@ -10,6 +10,8 @@ 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);
gboolean gui_file_read (WorkbookControlGUI *wbcg, char const *file_name,
GnumFileOpener const *optional_format);
#ifdef WITH_BONOBO
void gui_file_save_to_stream (BonoboStream *stream, WorkbookControlGUI *wbcg,
......
......@@ -166,6 +166,19 @@ gboolean
gnumeric_dialog_file_selection (WorkbookControlGUI *wbcg, GtkFileSelection *fsel)
{
gboolean result = FALSE;
Workbook *wb;
const gchar *wb_file_name;
/* Select current directory if we have one */
wb = wb_control_workbook (WORKBOOK_CONTROL (wbcg));
wb_file_name = (wb != NULL) ? workbook_get_filename (wb) : NULL;
if (wb_file_name != NULL && strchr (wb_file_name, G_DIR_SEPARATOR) != NULL) {
gchar *tmp = g_dirname (wb_file_name);
gchar *dir_name = g_strconcat (tmp, G_DIR_SEPARATOR_S, NULL);
gtk_file_selection_set_filename (fsel, dir_name);
g_free (dir_name);
g_free (tmp);
}
gtk_window_set_modal (GTK_WINDOW (fsel), TRUE);
gnumeric_set_transient (wbcg, GTK_WINDOW (fsel));
......
......@@ -10,6 +10,7 @@
#include "history.h"
#include "application.h"
#include "gui-file.h"
#include "workbook-control-gui-priv.h"
#include "workbook-view.h"
#include "workbook.h"
......@@ -31,7 +32,7 @@ static void
file_history_cmd (GtkWidget *widget, WorkbookControlGUI *wbcg)
{
char *filename = gtk_object_get_data (GTK_OBJECT (widget), UGLY_GNOME_UI_KEY);
wb_view_open (filename, WORKBOOK_CONTROL (wbcg), TRUE, NULL);
gui_file_read (wbcg, filename, NULL);
}
#else
......@@ -42,7 +43,7 @@ file_history_cmd (BonoboUIComponent *uic, WorkbookControlGUI *wbcg, const char *
char *filename = bonobo_ui_component_get_prop (wbcg->uic, fullpath,
"tip", NULL);
wb_view_open (filename, WORKBOOK_CONTROL (wbcg), TRUE, NULL);
gui_file_read (wbcg, filename, NULL);
g_free (filename);
g_free (fullpath);
}
......
......@@ -41,7 +41,6 @@ void gnumeric_io_error_display (IOContext *context);
void gnumeric_io_clear_error (IOContext *context);
gboolean gnumeric_io_error_occurred (IOContext *context);
gboolean gnumeric_io_error_occurred (IOContext *context);
void io_progress_message (IOContext *io_context, const gchar *msg);
void io_progress_update (IOContext *io_context, gdouble f);
......
......@@ -154,7 +154,8 @@ main (int argc, char *argv [])
if (startup_files) {
int i;
for (i = 0; startup_files [i] && !initial_workbook_open_complete ; i++) {
if (wb_view_open (startup_files[i], wbc, TRUE, NULL))
if (gui_file_read (WORKBOOK_CONTROL_GUI (wbc),
startup_files[i], NULL))
opened_workbook = TRUE;
/* cheesy attempt to keep the ui from freezing during load */
......
......@@ -81,7 +81,7 @@ workbook_persist_file_load (BonoboPersistFile *ps, const CORBA_char *filename,
{
WorkbookView *wbv = closure;
return wb_view_open (filename, /* FIXME */ NULL, FALSE, NULL) ? 0 : -1;
return wb_view_open_file (filename, /* FIXME */ NULL, FALSE, NULL) ? 0 : -1;
}
static int
......
......@@ -600,121 +600,109 @@ wb_view_save (WorkbookView *wbv, CommandContext *context)
return !error;
}
/**
* wb_view_open :
* @file_name : File name
* @wbc : Workbook Control
* @display_errors :
* @fo : Optional GnumFileOpener
*
* Reads @file_name file using given file opener @fo, or probes for a valid
* possibility if @fo is NULL.
*
* Return value: TRUE if file was successfully read and FALSE otherwise.
*/
gboolean
wb_view_open (char const *file_name,
WorkbookControl *wbc,
gboolean display_errors,
GnumFileOpener const *fo)
WorkbookView *
wb_view_new_from_input (GsfInput *input,
GnumFileOpener const *optional_fmt,
IOContext *io_context)
{
Workbook *new_wb = NULL;
WorkbookView *new_wbv = NULL;
GsfInput *input;
GError *err = NULL;
g_return_val_if_fail (file_name != NULL, FALSE);
g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbc), FALSE);
g_return_val_if_fail (fo == NULL || IS_GNUM_FILE_OPENER (fo), FALSE);
/* Only report error if stdio fails too */
input = gsf_input_mmap_new (file_name, NULL);
if (input == NULL)
input = gsf_input_stdio_new (file_name, &err);
g_return_val_if_fail (GSF_IS_INPUT(input), NULL);
g_return_val_if_fail (optional_fmt == NULL ||
IS_GNUM_FILE_OPENER (optional_fmt), NULL);
/* NOTE : we could support gzipped anything here if we wanted to
* by adding a wrapper, but there is no framework for remembering that
* the file was gzipped so lets not just yet.
*/
if (input != NULL) {
IOContext *io_context = gnumeric_io_context_new (COMMAND_CONTEXT (wbc));
wb_control_set_sensitive (wbc, FALSE);
/* Search for an applicable opener */
if (fo == NULL) {
FileProbeLevel pl;
GList *l;
for (pl = FILE_PROBE_FILE_NAME; pl < FILE_PROBE_LAST && fo == NULL; pl++) {
for (l = get_file_openers (); l != NULL; l = l->next) {
GnumFileOpener const *tmp_fo = GNUM_FILE_OPENER (l->data);
if (gnum_file_opener_probe (tmp_fo, input, pl)) {
fo = tmp_fo;
break;
}
/* Search for an applicable opener */
if (optional_fmt == NULL) {
FileProbeLevel pl;
GList *l;
for (pl = FILE_PROBE_FILE_NAME; pl < FILE_PROBE_LAST && optional_fmt == NULL; pl++) {
for (l = get_file_openers (); l != NULL; l = l->next) {
GnumFileOpener const *tmp_fo = GNUM_FILE_OPENER (l->data);
if (gnum_file_opener_probe (tmp_fo, input, pl)) {
optional_fmt = tmp_fo;
break;
}
}
}
}
if (fo != NULL) {
gboolean old;
if (optional_fmt != NULL) {
Workbook *new_wb;
gboolean old;
new_wbv = workbook_view_new (NULL);
new_wb = wb_view_workbook (new_wbv);
new_wbv = workbook_view_new (NULL);
new_wb = wb_view_workbook (new_wbv);
/* disable recursive dirtying while loading */
old = workbook_enable_recursive_dirty (new_wb, FALSE);
gnum_file_opener_open (fo, io_context, new_wbv, input);
workbook_enable_recursive_dirty (new_wb, old);
/* disable recursive dirtying while loading */
old = workbook_enable_recursive_dirty (new_wb, FALSE);
gnum_file_opener_open (optional_fmt, io_context, new_wbv, input);
workbook_enable_recursive_dirty (new_wb, old);
if (!gnumeric_io_error_occurred (io_context) &&
workbook_sheet_count (new_wb) == 0)
gnumeric_io_error_read (io_context, _("No sheets in workbook."));
if (!gnumeric_io_error_occurred (io_context) &&
workbook_sheet_count (new_wb) == 0)
gnumeric_io_error_read (io_context, _("No sheets in workbook."));
if (!gnumeric_io_error_occurred (io_context)) {
workbook_set_dirty (new_wb, FALSE);
} else {
g_object_unref (G_OBJECT (new_wb));
new_wb = NULL;
new_wbv = NULL;
}
if (gnumeric_io_error_occurred (io_context)) {
g_object_unref (G_OBJECT (new_wb));
new_wbv = NULL;
} else
gnumeric_io_error_read (io_context, _("Unsupported file format."));
if (gnumeric_io_error_occurred (io_context))
gnumeric_io_error_display (io_context);
wb_control_set_sensitive (wbc, TRUE);
g_object_unref (G_OBJECT (io_context));
} else {
new_wb = workbook_new_with_sheets (1);
new_wbv = workbook_view_new (new_wb);
workbook_set_saveinfo (new_wb, file_name, FILE_FL_NEW, NULL);
}
workbook_set_dirty (new_wb, FALSE);
} else
gnumeric_io_error_read (io_context, _("Unsupported file format."));
if (new_wbv != NULL) {
Workbook *old_wb;
if (gnumeric_io_error_occurred (io_context))
gnumeric_io_error_display (io_context);
g_return_val_if_fail (new_wb != NULL, FALSE);
return new_wbv;
}
old_wb = wb_control_workbook (wbc);
if (workbook_is_pristine (old_wb)) {
g_object_ref (G_OBJECT (wbc));
workbook_unref (old_wb);
workbook_control_set_view (wbc, new_wbv, NULL);
workbook_control_init_state (wbc);
} else
(void) wb_control_wrapper_new (wbc, new_wbv, NULL);
/**
* wb_view_new_from_file :
* @file_name : File name
* @optional_fmt : Optional GnumFileOpener
* @io_context : Optional context to display errors.
*
* Reads @file_name file using given file opener @optional_fmt, or probes for a valid
* possibility if @optional_fmt is NULL. Reports problems to @io_context.
*
* Return value: TRUE if file was successfully read and FALSE otherwise.
*/
WorkbookView *
wb_view_new_from_file (char const *file_name,
GnumFileOpener const *optional_fmt,
IOContext *io_context)
{
GError *err = NULL;
char *msg = NULL;
GsfInput *input;
workbook_recalc (new_wb);
/* Only report error if stdio fails too */
input = gsf_input_mmap_new (file_name, NULL);
if (input == NULL)
input = gsf_input_stdio_new (file_name, &err);
g_return_val_if_fail (!workbook_is_dirty (new_wb), FALSE);
if (input != NULL) {
WorkbookView *res = wb_view_new_from_input (input,
optional_fmt, io_context);
g_object_unref (G_OBJECT (input));
return res;
}
sheet_update (wb_view_cur_sheet (new_wbv));
return TRUE;
} else {
g_return_val_if_fail (new_wb == NULL, FALSE);
return FALSE;
if (err != NULL) {
if (err->message != NULL)
msg = g_strdup (err->message);
g_error_free (err);
}
if (msg == NULL)
msg = g_strdup_printf (_("An unexplained error happened while opening '%s'"),
file_name);
gnumeric_io_error_read (io_context, msg);
return NULL;
}
......@@ -82,15 +82,12 @@ gboolean wb_view_save_as (WorkbookView *wbv, GnumFileSaver *fs,
char const *file_name, CommandContext *context);
gboolean wb_view_save (WorkbookView *wbv, CommandContext *context);
gboolean wb_view_open_input (GsfInput *input,
WorkbookControl *wbc,
gboolean display_errors,
GnumFileOpener const *fo);
/* convenience wrapper */
gboolean wb_view_open (char const *file_name,
WorkbookControl *wbc,
gboolean display_errors,
GnumFileOpener const *fo);
WorkbookView *wb_view_new_from_input (GsfInput *input,
GnumFileOpener const *optional_format,
IOContext *io_context);
WorkbookView *wb_view_new_from_file (char const *file_name,
GnumFileOpener const *optional_format,
IOContext *io_context);
#define WORKBOOK_VIEW_FOREACH_CONTROL(wbv, control, code) \
do { \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment