Commit ff7cf8af authored by Andreas J. Guelzow's avatar Andreas J. Guelzow

/home/aguelzow/tmp/cvsXdLl7i

parent 8bf194a8
......@@ -62,14 +62,12 @@
#include "style-color.h"
#include "summary.h"
#include "tools/dao.h"
#include "gnumeric-gconf.h"
#include <libgnome/gnome-i18n.h>
#include <gal/util/e-util.h>
#include <ctype.h>
#define MAX_DESCRIPTOR_WIDTH 15
#define GNUMERIC_GCONF_UNDO_SIZE "/apps/gnumeric/core/undosize"
/*
* There are several distinct stages to wrapping each command.
*
......@@ -97,7 +95,6 @@
*
* FIXME: Filter the list of commands when a sheet is deleted.
*
* TODO : Add user preference for undo buffer size limit
* TODO : Possibly clear lists on save.
*
* TODO : Reqs for selective undo
......@@ -178,6 +175,67 @@ static E_MAKE_TYPE (func, #type, type, \
/******************************************************************/
/**
* returns the range name depending on the preference setting
*
* char const *undo_global_range_name
*
* @pos: CellPos
*
* Returns :
*/
static char *
undo_global_range_name (Sheet *sheet, Range const * const range)
{
gboolean show_sheet_name;
GConfClient *client;
GError *err = NULL;
client = application_get_gconf_client ();
show_sheet_name = gconf_client_get_bool (client,
GNUMERIC_GCONF_UNDO_SHOW_SHEET_NAME, &err);
if (err)
show_sheet_name = FALSE;
return global_range_name (show_sheet_name ? sheet : NULL, range);
}
/**
* returns the cell position name depending on the preference setting
*
* char *cmd_cell_pos_name_utility
*
* @pos: CellPos
*
* Returns :
*/
char *
cmd_cell_pos_name_utility (Sheet *sheet, CellPos const *pos)
{
Range range;
range.start = *pos;
range.end = *pos;
return undo_global_range_name (sheet, &range);
}
static guint
max_descriptor_width (void)
{
guint max_width;
GConfClient *client;
GError *err = NULL;
client = application_get_gconf_client ();
max_width = (guint) gconf_client_get_int (client,
GNUMERIC_GCONF_UNDO_MAX_DESCRIPTOR_WIDTH, &err);
if (err)
max_width = 10;
return max_width;
}
/**
* get_menu_label : Utility routine to get the descriptor associated
* with a list of commands.
......@@ -230,19 +288,21 @@ update_after_action (Sheet *sheet)
}
/*
* range_list_to_string: Convert a list of ranges into a string.
* cmd_range_list_to_string_utility: Convert a list of ranges into a string.
* (The result will be something like :
* "A1:C3, D4:E5"). The string will be
* automatically truncated to MAX_DESCRIPTOR_WIDTH.
* automatically truncated to max_descriptor_width ().
* The caller should free the GString that is returned.
*
* @ranges : GSList containing Range *'s
*/
static GString *
range_list_to_string (GSList const *ranges)
GString *
cmd_range_list_to_string_utility (Sheet *sheet, GSList const *ranges)
{
GString *names;
GSList const *l;
char *name;
guint max_width;
g_return_val_if_fail (ranges != NULL, NULL);
......@@ -250,8 +310,9 @@ range_list_to_string (GSList const *ranges)
for (l = ranges; l != NULL; l = l->next) {
Range const * const r = l->data;
/* No need to free range_name, uses static buffer */
g_string_append (names, range_name (r));
name = undo_global_range_name (sheet , r);
g_string_append (names, name);
g_free (name);
if (l->next)
g_string_append (names, ", ");
......@@ -261,9 +322,11 @@ range_list_to_string (GSList const *ranges)
* There is no need to do this for "types", because that
* will never grow indefinitely
*/
if (strlen (names->str) > MAX_DESCRIPTOR_WIDTH) {
g_string_truncate (names, MAX_DESCRIPTOR_WIDTH - 3);
g_string_append (names, "...");
max_width = max_descriptor_width ();
if (strlen (names->str) > max_width) {
/* FIXME: this does not look right for UTF8 !!*/
g_string_truncate (names, max_width - 3);
g_string_append (names, _("..."));
}
return names;
......@@ -668,6 +731,8 @@ cmd_set_text (WorkbookControl *wbc,
const gchar *pad = "";
gchar *text, *corrected_text, *tmp, c = '\0';
Cell const *cell;
guint max_width;
char *where;
g_return_val_if_fail (IS_SHEET (sheet), TRUE);
g_return_val_if_fail (new_text != NULL, TRUE);
......@@ -703,18 +768,20 @@ cmd_set_text (WorkbookControl *wbc,
}
/* Limit the size of the descriptor to something reasonable */
if (strlen (corrected_text) > MAX_DESCRIPTOR_WIDTH || c != '\0') {
max_width = max_descriptor_width ();
if (strlen (corrected_text) > max_width || c != '\0') {
pad = "..."; /* length of 3 */
text = g_strndup (corrected_text,
MAX_DESCRIPTOR_WIDTH - 3);
max_width - 3);
} else
text = corrected_text;
me->parent.sheet = sheet;
me->parent.size = 1;
where = cmd_cell_pos_name_utility (sheet, pos);
me->parent.cmd_descriptor =
g_strdup_printf (_("Typing \"%s%s\" in %s"), text, pad,
cell_pos_name (pos));
g_strdup_printf (_("Typing \"%s%s\" in %s"), text, pad, where);
g_free (where);
if (text != corrected_text)
g_free (text);
......@@ -866,6 +933,7 @@ cmd_area_set_text (WorkbookControl *wbc, ParsePos const *pos,
CmdAreaSetText *me;
gchar *text;
const gchar *pad = "";
guint max_width;
obj = g_object_new (CMD_AREA_SET_TEXT_TYPE, NULL);
me = CMD_AREA_SET_TEXT (obj);
......@@ -877,10 +945,11 @@ cmd_area_set_text (WorkbookControl *wbc, ParsePos const *pos,
me->selection = selection_get_ranges (pos->sheet, FALSE /* No intersection */);
me->old_content = NULL;
if (strlen (new_text) > MAX_DESCRIPTOR_WIDTH) {
max_width = max_descriptor_width ();
if (strlen (new_text) > max_width) {
pad = "..."; /* length of 3 */
text = g_strndup (new_text,
MAX_DESCRIPTOR_WIDTH - 3);
max_width - 3);
} else
text = (gchar *) new_text;
......@@ -1354,7 +1423,7 @@ cmd_clear_selection (WorkbookControl *wbc, Sheet *sheet, int clear_flags)
* need to truncate the "types" list because it will not grow
* indefinitely
*/
names = range_list_to_string (me->selection);
names = cmd_range_list_to_string_utility (sheet, me->selection);
me->parent.cmd_descriptor = g_strdup_printf (_("Clearing %s in %s"), types->str, names->str);
g_string_free (names, TRUE);
......@@ -1548,7 +1617,7 @@ cmd_format (WorkbookControl *wbc, Sheet *sheet,
me->borders = NULL;
if (opt_translated_name == NULL) {
GString *names = range_list_to_string (me->selection);
GString *names = cmd_range_list_to_string_utility (sheet, me->selection);
me->parent.cmd_descriptor = g_strdup_printf (_("Changing format of %s"), names->str);
g_string_free (names, TRUE);
......@@ -1633,6 +1702,7 @@ cmd_resize_colrow (WorkbookControl *wbc, Sheet *sheet,
CmdResizeColRow *me;
GString *list;
gboolean is_single;
guint max_width;
g_return_val_if_fail (IS_SHEET (sheet), TRUE);
......@@ -1651,8 +1721,9 @@ cmd_resize_colrow (WorkbookControl *wbc, Sheet *sheet,
list = colrow_index_list_to_string (selection, is_cols, &is_single);
/* Make sure the string doesn't get overly wide */
if (strlen (list->str) > MAX_DESCRIPTOR_WIDTH) {
g_string_truncate (list, MAX_DESCRIPTOR_WIDTH - 3);
max_width = max_descriptor_width ();
if (strlen (list->str) > max_width) {
g_string_truncate (list, max_width - 3);
g_string_append (list, "...");
}
......@@ -2263,6 +2334,7 @@ cmd_paste_cut (WorkbookControl *wbc, GnmExprRelocateInfo const *info,
GObject *obj;
CmdPasteCut *me;
Range r;
char *where;
g_return_val_if_fail (info != NULL, TRUE);
......@@ -2272,9 +2344,10 @@ cmd_paste_cut (WorkbookControl *wbc, GnmExprRelocateInfo const *info,
return TRUE;
/* FIXME: Do we want to show the destination range as well ? */
where = undo_global_range_name (info->origin_sheet, &info->origin);
if (descriptor == NULL)
descriptor = g_strdup_printf (_("Moving %s"),
range_name (&info->origin));
descriptor = g_strdup_printf (_("Moving %s"), where);
g_free (where);
g_return_val_if_fail (info != NULL, TRUE);
......@@ -2840,7 +2913,7 @@ cmd_autoformat (WorkbookControl *wbc, Sheet *sheet, FormatTemplate *ft)
me->parent.sheet = sheet;
me->parent.size = 1; /* FIXME? */
names = range_list_to_string (me->selection);
names = cmd_range_list_to_string_utility (sheet, me->selection);
me->parent.cmd_descriptor = g_strdup_printf (_("Autoformatting %s"),
names->str);
g_string_free (names, TRUE);
......@@ -2950,7 +3023,7 @@ cmd_unmerge_cells (WorkbookControl *wbc, Sheet *sheet, GSList const *selection)
me->parent.sheet = sheet;
me->parent.size = 1;
names = range_list_to_string (selection);
names = cmd_range_list_to_string_utility (sheet, selection);
me->parent.cmd_descriptor = g_strdup_printf (_("Unmerging %s"), names->str);
g_string_free (names, TRUE);
......@@ -3088,7 +3161,7 @@ cmd_merge_cells (WorkbookControl *wbc, Sheet *sheet, GSList const *selection)
me->parent.sheet = sheet;
me->parent.size = 1;
names = range_list_to_string (selection);
names = cmd_range_list_to_string_utility (sheet, selection);
me->parent.cmd_descriptor = g_strdup_printf (_("Merging %s"),
names->str);
g_string_free (names, TRUE);
......@@ -3731,6 +3804,7 @@ cmd_zoom (WorkbookControl *wbc, GSList *sheets, double factor)
GString *namelist;
GSList *l;
int i;
guint max_width;
g_return_val_if_fail (wbc != NULL, TRUE);
g_return_val_if_fail (sheets != NULL, TRUE);
......@@ -3756,8 +3830,9 @@ cmd_zoom (WorkbookControl *wbc, GSList *sheets, double factor)
}
/* Make sure the string doesn't get overly wide */
if (strlen (namelist->str) > MAX_DESCRIPTOR_WIDTH) {
g_string_truncate (namelist, MAX_DESCRIPTOR_WIDTH - 3);
max_width = max_descriptor_width ();
if (strlen (namelist->str) > max_width) {
g_string_truncate (namelist, max_width - 3);
g_string_append (namelist, "...");
}
......@@ -4316,6 +4391,7 @@ cmd_set_comment (WorkbookControl *wbc,
GObject *obj;
CmdSetComment *me;
CellComment *comment;
char *where;
g_return_val_if_fail (IS_SHEET (sheet), TRUE);
g_return_val_if_fail (new_text != NULL, TRUE);
......@@ -4329,11 +4405,13 @@ cmd_set_comment (WorkbookControl *wbc,
me->new_text = NULL;
else
me->new_text = g_strdup (new_text);
where = cmd_cell_pos_name_utility (sheet, pos);
me->parent.cmd_descriptor =
g_strdup_printf (me->new_text == NULL ?
_("Clearing comment of %s") :
_("Setting comment of %s"),
cell_pos_name (pos));
where);
g_free (where);
me->old_text = NULL;
me->pos = *pos;
me->sheet = sheet;
......
......@@ -12,6 +12,9 @@ void command_redo (WorkbookControl *wbc);
void command_setup_combos (WorkbookControl *wbc);
void command_list_release (GSList *cmds);
GString *cmd_range_list_to_string_utility (Sheet *sheet, GSList const *ranges);
char *cmd_cell_pos_name_utility (Sheet *sheet, CellPos const *pos);
gboolean cmd_set_text (WorkbookControl *wbc, Sheet *sheet,
CellPos const *pos, const char *new_text);
......
2002-04-13 Andreas J. Guelzow <aguelzow@taliesin.ca>
* dialog-function-select.c : move defines into gnumeric-gconf.h
* dialog-preferences.c : add `undo'-preferences page
2002-04-12 Jon K Hellan <hellan@acm.org>
* dialog-preferences.c: Replace Gnome stock text/italic pixmap
......
......@@ -33,6 +33,7 @@
#include <str.h>
#include <workbook-edit.h>
#include <application.h>
#include <gnumeric-gconf.h>
#include <ctype.h>
#include <glade/glade.h>
......@@ -44,9 +45,6 @@
#define FUNCTION_SELECT_KEY "function-selector-dialog"
#define FUNCTION_SELECT_DIALOG_KEY "function-selector-dialog"
#define FUNCTION_SELECT_GCONF_RECENT "/apps/gnumeric/functionselector/recentfunctions"
#define FUNCTION_SELECT_GCONF_NUM_OF_RECENT "/apps/gnumeric/functionselector/num-of-recent"
typedef struct {
WorkbookControlGUI *wbcg;
Workbook *wb;
......
......@@ -32,6 +32,7 @@
#include "number-match.h"
#include "widgets/widget-font-selector.h"
#include "widgets/gnumeric-cell-renderer-text.h"
#include "gnumeric-gconf.h"
#include <gui-util.h>
#include <libgnome/gnome-i18n.h>
......@@ -95,6 +96,14 @@ dialog_pref_load_description_from_schema (PrefState *state, char const *schema_p
gconf_schema_free (the_schema);
}
static void
dialog_pref_load_description (PrefState *state, char const *text)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer (state->description);
gtk_text_buffer_set_text (buffer, text, -1);
}
/*******************************************************************************************/
/* Tree View of selected configuration variables */
/*******************************************************************************************/
......@@ -123,8 +132,8 @@ typedef struct {
static pref_tree_data_t pref_tree_data[] = {
{"/apps/gnumeric/functionselector/num-of-recent", NULL, "/schemas/apps/gnumeric/functionselector/num-of-recent"},
{"/apps/gnumeric/core/undosize", NULL, "/schemas/apps/gnumeric/core/undosize"},
{FUNCTION_SELECT_GCONF_NUM_OF_RECENT, NULL,
"/schemas" FUNCTION_SELECT_GCONF_NUM_OF_RECENT},
{NULL, NULL, NULL}
};
......@@ -465,12 +474,185 @@ GtkWidget *pref_font_initializer (PrefState *state, gpointer data,
return page;
}
/*******************************************************************************************/
/* Undo Preferences Page */
/*******************************************************************************************/
#define GCONF_FONT_NAME "/apps/gnumeric/core/defaultfont/name"
#define GCONF_FONT_SIZE "/apps/gnumeric/core/defaultfont/size"
#define GCONF_FONT_BOLD "/apps/gnumeric/core/defaultfont/bold"
#define GCONF_FONT_ITALIC "/apps/gnumeric/core/defaultfont/italic"
static void
pref_undo_page_open (PrefState *state, gpointer data,
GtkNotebook *notebook, gint page_num)
{
dialog_pref_load_description (state,
_("The items on this page customize the "
"behaviour of the undo/redo system."));
}
static void
cb_pref_undo_set_sheet_name (GConfClient *gconf, guint cnxn_id, GConfEntry *entry,
GtkToggleButton *button)
{
gboolean is_set_gconf = gconf_client_get_bool (gconf,
GNUMERIC_GCONF_UNDO_SHOW_SHEET_NAME,
NULL);
gboolean is_set_button = gtk_toggle_button_get_active (button);
if (is_set_gconf != is_set_button)
gtk_toggle_button_set_active (button, is_set_gconf);
}
static void
cb_pref_undo_sheet_name_toggled (GtkToggleButton *button, PrefState *state)
{
gconf_client_set_bool (state->gconf,
GNUMERIC_GCONF_UNDO_SHOW_SHEET_NAME,
gtk_toggle_button_get_active (button),
NULL);
}
static void
cb_pref_undo_set_max_descriptor_width (GConfClient *gconf, guint cnxn_id, GConfEntry *entry,
GtkSpinButton *button)
{
gint int_in_gconf = gconf_client_get_int (gconf,
GNUMERIC_GCONF_UNDO_MAX_DESCRIPTOR_WIDTH,
NULL);
gint int_in_button = gtk_spin_button_get_value_as_int (button);
if (int_in_gconf != int_in_button)
gtk_spin_button_set_value (button, (gdouble) int_in_gconf);
}
static void
cb_pref_undo_max_descriptor_width_changed (GtkSpinButton *button, PrefState *state)
{
gconf_client_set_int (state->gconf,
GNUMERIC_GCONF_UNDO_MAX_DESCRIPTOR_WIDTH,
gtk_spin_button_get_value_as_int (button),
NULL);
}
static void
cb_pref_undo_set_size (GConfClient *gconf, guint cnxn_id, GConfEntry *entry,
GtkSpinButton *button)
{
gint int_in_gconf = gconf_client_get_int (gconf,
GNUMERIC_GCONF_UNDO_SIZE,
NULL);
gint int_in_button = gtk_spin_button_get_value_as_int (button);
if (int_in_gconf != int_in_button)
gtk_spin_button_set_value (button, (gdouble) int_in_gconf);
}
static void
cb_pref_undo_size_changed (GtkSpinButton *button, PrefState *state)
{
gconf_client_set_int (state->gconf,
GNUMERIC_GCONF_UNDO_SIZE,
gtk_spin_button_get_value_as_int (button),
NULL);
}
static
GtkWidget *pref_undo_page_initializer (PrefState *state, gpointer data,
GtkNotebook *notebook, gint page_num)
{
GtkWidget *page = gtk_table_new (3, 2, FALSE);
guint notif;
GtkWidget *item;
GConfSchema *the_schema;
GtkTooltips *the_tip;
/* Sheet name check box */
the_schema = gconf_client_get_schema (state->gconf,
"/schemas" GNUMERIC_GCONF_UNDO_SHOW_SHEET_NAME,
NULL);
item = gtk_check_button_new_with_label (gconf_schema_get_short_desc (the_schema));
cb_pref_undo_set_sheet_name (state->gconf, 0, NULL, GTK_TOGGLE_BUTTON (item));
notif = gconf_client_notify_add (state->gconf, GNUMERIC_GCONF_UNDO_SHOW_SHEET_NAME,
(GConfClientNotifyFunc) cb_pref_undo_set_sheet_name,
item, NULL, NULL);
g_signal_connect (G_OBJECT (page),
"destroy",
G_CALLBACK (cb_pref_notification_destroy), GINT_TO_POINTER (notif));
g_signal_connect (G_OBJECT (item),
"toggled",
G_CALLBACK (cb_pref_undo_sheet_name_toggled), state);
gtk_table_attach (GTK_TABLE (page), item, 0, 2, 0, 1, GTK_FILL | GTK_SHRINK,
GTK_FILL | GTK_SHRINK, 5, 5);
the_tip = gtk_tooltips_new ();
gtk_tooltips_set_tip (the_tip, item, gconf_schema_get_long_desc (the_schema), NULL);
gconf_schema_free (the_schema);
/* Descriptor Width Spin Button */
the_schema = gconf_client_get_schema (state->gconf,
"/schemas" GNUMERIC_GCONF_UNDO_MAX_DESCRIPTOR_WIDTH,
NULL);
item = gtk_label_new (gconf_schema_get_short_desc (the_schema));
gtk_label_set_justify (GTK_LABEL (item), GTK_JUSTIFY_LEFT);
gtk_table_attach (GTK_TABLE (page), item, 0, 1, 1, 2, 0,
GTK_FILL | GTK_SHRINK, 5, 5);
item = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (5,
5, 200, 1, 1, 1)),
1, 0);
cb_pref_undo_set_max_descriptor_width (state->gconf, 0, NULL, GTK_SPIN_BUTTON (item));
notif = gconf_client_notify_add (state->gconf, GNUMERIC_GCONF_UNDO_MAX_DESCRIPTOR_WIDTH,
(GConfClientNotifyFunc) cb_pref_undo_set_max_descriptor_width,
item, NULL, NULL);
g_signal_connect (G_OBJECT (page),
"destroy",
G_CALLBACK (cb_pref_notification_destroy), GINT_TO_POINTER (notif));
g_signal_connect (G_OBJECT (item),
"value-changed",
G_CALLBACK (cb_pref_undo_max_descriptor_width_changed), state);
gtk_table_attach (GTK_TABLE (page), item, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND,
GTK_FILL | GTK_SHRINK, 5, 5);
the_tip = gtk_tooltips_new ();
gtk_tooltips_set_tip (the_tip, item, gconf_schema_get_long_desc (the_schema), NULL);
gconf_schema_free (the_schema);
/* Undo Size Spin Button */
the_schema = gconf_client_get_schema (state->gconf,
"/schemas" GNUMERIC_GCONF_UNDO_SIZE,
NULL);
item = gtk_label_new (gconf_schema_get_short_desc (the_schema));
gtk_label_set_justify (GTK_LABEL (item), GTK_JUSTIFY_LEFT);
gtk_table_attach (GTK_TABLE (page), item, 0, 1, 2, 3, 0,
GTK_FILL | GTK_SHRINK, 5, 5);
item = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (1000,
0, 30000, 100,
1000, 1000)),
1, 0);
cb_pref_undo_set_size (state->gconf, 0, NULL, GTK_SPIN_BUTTON (item));
notif = gconf_client_notify_add (state->gconf, GNUMERIC_GCONF_UNDO_SIZE,
(GConfClientNotifyFunc) cb_pref_undo_set_size,
item, NULL, NULL);
g_signal_connect (G_OBJECT (page),
"destroy",
G_CALLBACK (cb_pref_notification_destroy), GINT_TO_POINTER (notif));
g_signal_connect (G_OBJECT (item),
"value-changed",
G_CALLBACK (cb_pref_undo_size_changed), state);
gtk_table_attach (GTK_TABLE (page), item, 1, 2, 2, 3, GTK_FILL | GTK_EXPAND,
GTK_FILL | GTK_SHRINK, 5, 5);
the_tip = gtk_tooltips_new ();
gtk_tooltips_set_tip (the_tip, item, gconf_schema_get_long_desc (the_schema), NULL);
gconf_schema_free (the_schema);
gtk_widget_show_all (page);
return page;
}
/*******************************************************************************************/
/* General Preference Dialog Routines */
/*******************************************************************************************/
static page_info_t page_info[] = {
{NULL, GTK_STOCK_ITALIC, pref_font_initializer, pref_font_page_open, NULL},
{NULL, GTK_STOCK_UNDO, pref_undo_page_initializer, pref_undo_page_open, NULL},
{NULL, GTK_STOCK_PREFERENCES, pref_tree_initializer, pref_tree_page_open, pref_tree_data},
{NULL, NULL, NULL, NULL, NULL},
};
......
#ifndef GNUMERIC_GCONF_H
#define GNUMERIC_GCONF_H
#define GNUMERIC_GCONF_UNDO_SIZE "/apps/gnumeric/undo/size"
#define GNUMERIC_GCONF_UNDO_SHOW_SHEET_NAME "/apps/gnumeric/undo/show_sheet_name"
#define GNUMERIC_GCONF_UNDO_MAX_DESCRIPTOR_WIDTH "/apps/gnumeric/undo/max_descriptor_width"
#define FUNCTION_SELECT_GCONF_RECENT "/apps/gnumeric/functionselector/recentfunctions"
#define FUNCTION_SELECT_GCONF_NUM_OF_RECENT "/apps/gnumeric/functionselector/num-of-recent"
#endif /* GNUMERIC_GRAPH_H */
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