Commit b6e8a273 authored by Jon K Hellan's avatar Jon K Hellan Committed by Jon Kåre Hellan

Add scrolled window

2000-02-14  Jon K Hellan  <hellan@acm.org>

        * src/dialogs/import.glade: Add scrolled window

	* src/file.c (workbook_read, workbook_import, workbook_save_as,
	workbook_save): Use error message template.

	* src/command-context.h (struct _CommandContext): Add
	template_list member.
	(struct CommandContextClass): Call message parameter to methods
	"message".
	(command_context_push_template, command_context_pop_template):
	Declare.

	* src/command-context.c (command_context_push_template): New
	function. Push a printf template for error messages to stack.
	(command_context_pop_template): New function. Pop current template
	from stack.
	(format_message): New function. Format a message using template on
	stack.
	(gnumeric_error_plugin_problem, gnumeric_error_read,
	gnumeric_error_save): Use format_message.

	* src/command-context-corba.c (ccc_error_plugin_problem,
	ccc_error_read, ccc_error_save): Call message parameter
	"message".

	* src/command-context-gui.c (ccg_error_plugin_problem,
	ccg_error_read, ccg_error_save): Ditto.
parent dc482c29
2000-02-14 Jon K Hellan <hellan@acm.org>
* src/dialogs/import.glade: Add scrolled window
* src/file.c (workbook_read, workbook_import, workbook_save_as,
workbook_save): Use error message template.
* src/command-context.h (struct _CommandContext): Add
template_list member.
(struct CommandContextClass): Call message parameter to methods
"message".
(command_context_push_template, command_context_pop_template):
Declare.
* src/command-context.c (command_context_push_template): New
function. Push a printf template for error messages to stack.
(command_context_pop_template): New function. Pop current template
from stack.
(format_message): New function. Format a message using template on
stack.
(gnumeric_error_plugin_problem, gnumeric_error_read,
gnumeric_error_save): Use format_message.
* src/command-context-corba.c (ccc_error_plugin_problem,
ccc_error_read, ccc_error_save): Call message parameter
"message".
* src/command-context-gui.c (ccg_error_plugin_problem,
ccg_error_read, ccg_error_save): Ditto.
2000-02-14 Jody Goldberg <jgoldberg@home.com>
* src/cell-draw.c (cell_draw) : Cells can span in either direction.
......
2000-02-14 Jon K Hellan <hellan@acm.org>
* src/dialogs/import.glade: Add scrolled window
* src/file.c (workbook_read, workbook_import, workbook_save_as,
workbook_save): Use error message template.
* src/command-context.h (struct _CommandContext): Add
template_list member.
(struct CommandContextClass): Call message parameter to methods
"message".
(command_context_push_template, command_context_pop_template):
Declare.
* src/command-context.c (command_context_push_template): New
function. Push a printf template for error messages to stack.
(command_context_pop_template): New function. Pop current template
from stack.
(format_message): New function. Format a message using template on
stack.
(gnumeric_error_plugin_problem, gnumeric_error_read,
gnumeric_error_save): Use format_message.
* src/command-context-corba.c (ccc_error_plugin_problem,
ccc_error_read, ccc_error_save): Call message parameter
"message".
* src/command-context-gui.c (ccg_error_plugin_problem,
ccg_error_read, ccg_error_save): Ditto.
2000-02-14 Jody Goldberg <jgoldberg@home.com>
* src/cell-draw.c (cell_draw) : Cells can span in either direction.
......
......@@ -16,19 +16,19 @@
#define CCG_CLASS(o) CMD_CONTEXT_CORBA_CLASS (GTK_OBJECT (o)->klass)
static void
ccc_error_plugin_problem (CommandContext *context, char const * const app_ver)
ccc_error_plugin_problem (CommandContext *context, char const * const message)
{
/* FIXME set exception */
}
static void
ccc_error_read (CommandContext *context, char const * const app_ver)
ccc_error_read (CommandContext *context, char const * const message)
{
/* FIXME set exception */
}
static void
ccc_error_save (CommandContext *context, char const * const app_ver)
ccc_error_save (CommandContext *context, char const * const message)
{
/* FIXME set exception */
}
......
......@@ -16,27 +16,27 @@
#define CCG_CLASS(o) CMD_CONTEXT_GUI_CLASS (GTK_OBJECT (o)->klass)
static void
ccg_error_plugin_problem (CommandContext *context, char const * const app_ver)
ccg_error_plugin_problem (CommandContext *context, char const * const message)
{
CommandContextGui *ccg = COMMAND_CONTEXT_GUI (context);
gnumeric_notice (ccg->wb, GNOME_MESSAGE_BOX_ERROR, app_ver);
gnumeric_notice (ccg->wb, GNOME_MESSAGE_BOX_ERROR, message);
}
static void
ccg_error_read (CommandContext *context, char const * const app_ver)
ccg_error_read (CommandContext *context, char const * const message)
{
CommandContextGui *ccg = COMMAND_CONTEXT_GUI (context);
gnumeric_notice (ccg->wb, GNOME_MESSAGE_BOX_ERROR, app_ver);
gnumeric_notice (ccg->wb, GNOME_MESSAGE_BOX_ERROR, message);
}
static void
ccg_error_save (CommandContext *context, char const * const app_ver)
ccg_error_save (CommandContext *context, char const * const message)
{
CommandContextGui *ccg = COMMAND_CONTEXT_GUI (context);
gnumeric_notice (ccg->wb, GNOME_MESSAGE_BOX_ERROR, app_ver);
gnumeric_notice (ccg->wb, GNOME_MESSAGE_BOX_ERROR, message);
}
static void
......
......@@ -14,34 +14,96 @@
#define CC_CLASS(o) COMMAND_CONTEXT_CLASS (GTK_OBJECT (o)->klass)
/**
* command_context_push_template
* @template: printf template to display message
*
* Push a printf template to the stack. The template is used to provide
* context for error messages. E.g.: "Could not read file: %s"
*/
void
command_context_push_template (CommandContext *context, const char *template)
{
context->template_list = g_slist_prepend(context->template_list,
g_strdup(template));
}
/**
* command_context_pop_template:
*
* Call this routine to remove the current template from the stack.
*/
void
command_context_pop_template (CommandContext *context)
{
if(context->template_list) {
GSList *tlist = context->template_list;
g_free(context->template_list->data);
context->template_list = context->template_list->next;
g_slist_free_1(tlist);
}
}
/**
* command_context_format_message:
*
* Format a message using the template on the stack (if any).
* The caller must free the returned message.
* FIXME: Make it accept varargs.
*/
static char *
format_message (CommandContext *context, char const * const message)
{
GSList *tlist = context->template_list;
char const * const msg = message ? message : "";
if (tlist)
return g_strdup_printf ((char *) (tlist->data), msg);
else
return g_strdup (msg);
}
void
gnumeric_error_plugin_problem (CommandContext *context,
char const * const message)
{
char *fmessage;
g_return_if_fail (context != NULL);
g_return_if_fail (IS_COMMAND_CONTEXT (context));
fmessage = format_message (context, message);
CC_CLASS (context)->error_plugin_problem (context, message);
g_free (fmessage);
}
void
gnumeric_error_read (CommandContext *context,
char const * const message)
{
char *fmessage;
g_return_if_fail (context != NULL);
g_return_if_fail (IS_COMMAND_CONTEXT (context));
CC_CLASS (context)->error_read (context, message);
fmessage = format_message (context, message);
CC_CLASS (context)->error_read (context, fmessage);
g_free (fmessage);
}
void
gnumeric_error_save (CommandContext *context,
char const * const message)
{
char *fmessage;
g_return_if_fail (context != NULL);
g_return_if_fail (IS_COMMAND_CONTEXT (context));
CC_CLASS (context)->error_save (context, message);
fmessage = format_message (context, message);
CC_CLASS (context)->error_save (context, fmessage);
g_free (fmessage);
}
void
......
......@@ -13,21 +13,30 @@
struct _CommandContext {
GtkObject parent;
GSList *template_list;
};
typedef struct {
GtkObjectClass parent_class;
void (*error_plugin_problem) (CommandContext *context,
char const * const app_ver);
char const * const message);
void (*error_read) (CommandContext *context,
char const * const app_ver);
char const * const message);
void (*error_save) (CommandContext *context,
char const * const app_ver);
char const * const message);
void (*error_splits_array) (CommandContext *context);
} CommandContextClass;
GtkType command_context_get_type (void);
/* Push a printf template to the list. The template is used to provide
* context for error messages. E.g.: "Could not read file: %s". */
void
command_context_push_template (CommandContext *context, const char *template);
void
command_context_pop_template (CommandContext *context);
/*
* These routines should be part of the eventual worbook-view
* structure. They represent the exceptions that can arise.
......
......@@ -80,16 +80,12 @@
</widget>
<widget>
<class>GtkCList</class>
<name>import-clist</name>
<height>113</height>
<can_focus>True</can_focus>
<has_focus>True</has_focus>
<columns>1</columns>
<column_widths>80</column_widths>
<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
<show_titles>False</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
<class>GtkScrolledWindow</class>
<name>scrolledwindow1</name>
<hscrollbar_policy>GTK_POLICY_NEVER</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy>
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
<vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
<child>
<padding>0</padding>
<expand>True</expand>
......@@ -97,16 +93,29 @@
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label2</name>
<label>label2</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<class>GtkCList</class>
<name>import-clist</name>
<height>113</height>
<can_focus>True</can_focus>
<has_focus>True</has_focus>
<columns>1</columns>
<column_widths>80</column_widths>
<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
<show_titles>False</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label2</name>
<label>label2</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
</widget>
</widget>
</widget>
......
......@@ -227,18 +227,23 @@ Workbook *
workbook_read (CommandContext *context, const char *filename)
{
Workbook *wb = NULL;
char * template;
g_return_val_if_fail (filename != NULL, NULL);
if (!g_file_exists (filename)) {
if (g_file_exists (filename)) {
template = g_strdup_printf (_("Could not read file %s\n%%s"),
filename);
command_context_push_template (context, template);
wb = workbook_try_read (context, filename);
command_context_pop_template (context);
g_free (template);
} else {
wb = workbook_new_with_sheets (1);
workbook_set_filename (wb, filename);
return wb;
}
/* FIXME: We used to display "Could not read file <filename>" */
return workbook_try_read (context, filename);
return wb;
}
/*
......@@ -303,13 +308,19 @@ workbook_import (CommandContext *context, Workbook *parent,
if (ret == 0 && clist->selection) {
FileOpener *fo;
int sel_row;
char * template;
sel_row = GPOINTER_TO_INT (clist->selection->data);
fo = gtk_clist_get_row_data (clist, sel_row);
wb = workbook_new ();
template = g_strdup_printf (_("Could not import file %s\n%%s"),
filename);
command_context_push_template (context, template);
ret = fo->open (context, wb, filename);
command_context_pop_template (context);
g_free (template);
if (ret != 0) {
#ifdef ENABLE_BONOBO
bonobo_object_destroy (BONOBO_OBJECT (wb));
......@@ -317,9 +328,6 @@ workbook_import (CommandContext *context, Workbook *parent,
gtk_object_destroy (GTK_OBJECT (wb));
#endif
wb = NULL;
/* FIXME: Here's where we used to display
* "Could not import file <fname>" unless this
* was a cancel. */
} else {
workbook_mark_clean (wb);
/* We will want to change the name before saving */
......@@ -507,6 +515,7 @@ workbook_save_as (CommandContext *context, Workbook *wb)
if (accepted) {
char *name = gtk_file_selection_get_filename (fsel);
char *template;
if (name [strlen (name)-1] != '/') {
char *base = g_basename (name);
......@@ -521,6 +530,11 @@ workbook_save_as (CommandContext *context, Workbook *wb)
} else
name = g_strdup (name);
template = g_strdup_printf
(_("Could not save to file %s\n%%s"),
name);
command_context_push_template
(context, template);
/* Files are expected to be in standard C format. */
if (current_saver->save (context, wb, name)
== 0) {
......@@ -528,10 +542,9 @@ workbook_save_as (CommandContext *context, Workbook *wb)
workbook_mark_clean (wb);
success = TRUE;
}
/* FIXME: On failure, we used to
display "Could not save to file
<name>" */
command_context_pop_template (context);
g_free (template);
g_free (name);
}
}
......@@ -544,20 +557,25 @@ workbook_save_as (CommandContext *context, Workbook *wb)
gboolean
workbook_save (CommandContext *context, Workbook *wb)
{
char *template;
gboolean ret;
g_return_val_if_fail (wb != NULL, FALSE);
if (wb->needs_name)
return workbook_save_as (context, wb);
if (gnumeric_xml_write_workbook (context, wb, wb->filename) == 0) {
template = g_strdup_printf (_("Could not save to file %s\n%%s"),
wb->filename);
command_context_push_template (context, template);
ret = (gnumeric_xml_write_workbook (context, wb, wb->filename) == 0);
if (ret == TRUE)
workbook_mark_clean (wb);
return TRUE;
} else {
/* FIXME: On failure, we used to display "Could not save to
file <filename>" */
return FALSE;
}
command_context_pop_template (context);
g_free (template);
return ret;
}
char *
......
......@@ -21,6 +21,11 @@ gnumeric_no_modify_array_notice (Workbook *wb)
_("You cannot change part of an array."));
}
/*
* TODO:
* Get rid of trailing newlines /whitespace.
* Wrap overlong lines.
*/
void
gnumeric_notice (Workbook *wb, const char *type, const char *str)
{
......
......@@ -21,6 +21,11 @@ gnumeric_no_modify_array_notice (Workbook *wb)
_("You cannot change part of an array."));
}
/*
* TODO:
* Get rid of trailing newlines /whitespace.
* Wrap overlong lines.
*/
void
gnumeric_notice (Workbook *wb, const char *type, const char *str)
{
......
......@@ -16,19 +16,19 @@
#define CCG_CLASS(o) CMD_CONTEXT_CORBA_CLASS (GTK_OBJECT (o)->klass)
static void
ccc_error_plugin_problem (CommandContext *context, char const * const app_ver)
ccc_error_plugin_problem (CommandContext *context, char const * const message)
{
/* FIXME set exception */
}
static void
ccc_error_read (CommandContext *context, char const * const app_ver)
ccc_error_read (CommandContext *context, char const * const message)
{
/* FIXME set exception */
}
static void
ccc_error_save (CommandContext *context, char const * const app_ver)
ccc_error_save (CommandContext *context, char const * const message)
{
/* FIXME set exception */
}
......
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