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

Undo for - Renaming a sheet - Inserting current date/time - Simplify

Undo for
- Renaming a sheet
- Inserting current date/time
- Simplify wording for translators.

2000-01-09  Jody Goldberg <jgoldberg@home.com>

	* src/commands.c (cmd_insert_cols) : Be kinder to translators.
	(cmd_insert_rows) : Ditto.
	(cmd_rename_sheet) : Implement.
	(cmd_set_date_time_{undo,redo,destroy}) : Implement.
	(cmd_set_date_time) : Implement.

	* src/workbook.c (sheet_label_text_changed_signal) : Use
	  cmd_rename_sheet.
	(insert_at_cursor) : Delete.
	(insert_current_time_cmd) : Use cmd_set_date_time.
	(insert_current_date_cmd) : Use cmd_set_date_time.
parent 2b8f3bee
2000-01-09 Jody Goldberg <jgoldberg@home.com>
* src/commands.c (cmd_insert_cols) : Be kinder to translators.
(cmd_insert_rows) : Ditto.
(cmd_rename_sheet) : Implement.
(cmd_set_date_time_{undo,redo,destroy}) : Implement.
(cmd_set_date_time) : Implement.
* src/workbook.c (sheet_label_text_changed_signal) : Use
cmd_rename_sheet.
(insert_at_cursor) : Delete.
(insert_current_time_cmd) : Use cmd_set_date_time.
(insert_current_date_cmd) : Use cmd_set_date_time.
2000-01-08 Jody Goldberg <jgoldberg@home.com>
* src/gnumeric-util.c (gnumeric_char_start_expr_p) : new function.
......
2000-01-09 Jody Goldberg <jgoldberg@home.com>
* src/commands.c (cmd_insert_cols) : Be kinder to translators.
(cmd_insert_rows) : Ditto.
(cmd_rename_sheet) : Implement.
(cmd_set_date_time_{undo,redo,destroy}) : Implement.
(cmd_set_date_time) : Implement.
* src/workbook.c (sheet_label_text_changed_signal) : Use
cmd_rename_sheet.
(insert_at_cursor) : Delete.
(insert_current_time_cmd) : Use cmd_set_date_time.
(insert_current_date_cmd) : Use cmd_set_date_time.
2000-01-08 Jody Goldberg <jgoldberg@home.com>
* src/gnumeric-util.c (gnumeric_char_start_expr_p) : new function.
......
......@@ -252,10 +252,7 @@ Office 2000 and 'explorer' compatibility.
* have a 'user-set' feature for 'merge cells'
* Calculation
* Rework dependencies to only supply one level of indirection.
* Rework 'Name' dependencies so we can re-express names.
* Think about allowing a formula to specify that it does not depend on the
contents of a reference, only the adress (ie the AREAS function)
* Dependancies for - CELL functions.
- Sheet objects
* Teach dependencies about implicit intersections
......
......@@ -574,8 +574,10 @@ gboolean
cmd_insert_cols (CommandContext *context,
Sheet *sheet, int start_col, int count)
{
char *mesg = g_strdup_printf (_("Inserting %d column%s at %s"), count,
(count > 1) ? "s" : "", col_name(start_col));
char *mesg = g_strdup_printf ((count > 1)
? _("Inserting %d columns before %s")
: _("Inserting %d column before %s"), count,
col_name(start_col));
return cmd_ins_del_row_col (context, sheet, TRUE, TRUE, mesg,
start_col, count);
}
......@@ -584,8 +586,10 @@ gboolean
cmd_insert_rows (CommandContext *context,
Sheet *sheet, int start_row, int count)
{
char *mesg = g_strdup_printf (_("Inserting %d row%s at %d"), count,
(count > 1) ? "s" : "", start_row+1);
char *mesg = g_strdup_printf ((count > 1)
? _("Inserting %d rows before %d")
: _("Inserting %d row before %d"),
count, start_row+1);
return cmd_ins_del_row_col (context, sheet, FALSE, TRUE, mesg,
start_row, count);
}
......@@ -861,7 +865,8 @@ typedef struct
{
GnumericCommand parent;
char *name;
Workbook *wb;
char *old_name, *new_name;
} CmdRenameSheet;
GNUMERIC_MAKE_COMMAND (CmdRenameSheet, cmd_rename_sheet);
......@@ -873,8 +878,7 @@ cmd_rename_sheet_undo (GnumericCommand *cmd, CommandContext *context)
g_return_val_if_fail (me != NULL, TRUE);
/* FIXME : Fill in */
return FALSE;
return !workbook_rename_sheet (me->wb, me->new_name, me->old_name);
}
static gboolean
......@@ -884,15 +888,16 @@ cmd_rename_sheet_redo (GnumericCommand *cmd, CommandContext *context)
g_return_val_if_fail (me != NULL, TRUE);
/* FIXME : Fill in */
return FALSE;
return !workbook_rename_sheet (me->wb, me->old_name, me->new_name);
}
static void
cmd_rename_sheet_destroy (GtkObject *cmd)
{
CmdRenameSheet *me = CMD_RENAME_SHEET(cmd);
g_free (me->name);
me->wb = NULL;
g_free (me->old_name);
g_free (me->new_name);
gnumeric_command_destroy (cmd);
}
......@@ -900,8 +905,160 @@ gboolean
cmd_rename_sheet (CommandContext *context,
Workbook *wb, const char *old_name, const char *new_name)
{
/* FIXME : Finish */
return workbook_rename_sheet (wb, old_name, new_name);
GtkObject *obj;
CmdRenameSheet *me;
gboolean trouble;
g_return_val_if_fail (wb != NULL, TRUE);
obj = gtk_type_new (CMD_RENAME_SHEET_TYPE);
me = CMD_RENAME_SHEET (obj);
/* Store the specs for the object */
me->wb = wb;
me->old_name = g_strdup (old_name);
me->new_name = g_strdup (new_name);
me->parent.cmd_descriptor =
g_strdup_printf (_("Rename sheet '%s' '%s'"), old_name, new_name);
trouble = cmd_rename_sheet_redo (GNUMERIC_COMMAND(me), context);
/* Register the command object */
return command_push_undo (wb, obj, trouble);
}
/******************************************************************/
#define CMD_SET_DATE_TIME_TYPE (cmd_set_date_time_get_type ())
#define CMD_SET_DATE_TIME(o) (GTK_CHECK_CAST ((o), CMD_SET_DATE_TIME_TYPE, CmdSetDateTime))
typedef struct
{
GnumericCommand parent;
gboolean is_date;
EvalPosition pos;
gchar *contents;
} CmdSetDateTime;
GNUMERIC_MAKE_COMMAND (CmdSetDateTime, cmd_set_date_time);
static gboolean
cmd_set_date_time_undo (GnumericCommand *cmd, CommandContext *context)
{
CmdSetDateTime *me = CMD_SET_DATE_TIME(cmd);
Cell *cell;
g_return_val_if_fail (me != NULL, TRUE);
/* Get the cell */
cell = sheet_cell_fetch (me->pos.sheet, me->pos.eval.col, me->pos.eval.row);
g_return_val_if_fail (cell != NULL, TRUE);
/* Restore the old value (possibly empty) */
if (me->contents != NULL) {
cell_set_text (cell, me->contents);
g_free (me->contents);
me->contents = NULL;
} else
cell_set_value (cell, value_new_empty ());
return FALSE;
}
static gboolean
cmd_set_date_time_redo (GnumericCommand *cmd, CommandContext *context)
{
CmdSetDateTime *me = CMD_SET_DATE_TIME(cmd);
Value *v;
Cell *cell;
char const * prefered_format;
g_return_val_if_fail (me != NULL, TRUE);
g_return_val_if_fail (me->contents == NULL, TRUE);
if (me->is_date) {
int n;
GDate *date = g_date_new();
g_date_set_time (date, time (NULL));
n = g_date_serial (date);
g_date_free( date );
v = value_new_int (n);
/* TODO : why do we need the '>' ? */
prefered_format = _(">mm/dd/yyyy");
} else {
time_t t = time (NULL);
struct tm *tm = localtime (&t);
float_t serial = (tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec)/(24*3600.0);
v = value_new_float (serial);
/* TODO : why do we need the '>' ? */
prefered_format = _(">hh:mm");
}
/* Get the cell (creating it if needed) */
cell = sheet_cell_fetch (me->pos.sheet, me->pos.eval.col, me->pos.eval.row);
/* Ensure that we are not breaking part of an array */
if (cell->parsed_node != NULL && cell->parsed_node->oper == OPER_ARRAY &&
(cell->parsed_node->u.array.rows != 1 ||
cell->parsed_node->u.array.cols != 1)) {
gnumeric_error_splits_array (context);
return TRUE;
}
/* Save contents */
me->contents = (cell->value) ? cell_get_text (cell) : NULL;
cell_set_value (cell, v);
cell_set_format (cell, prefered_format+1);
workbook_recalc (me->pos.sheet->workbook);
return FALSE;
}
static void
cmd_set_date_time_destroy (GtkObject *cmd)
{
CmdSetDateTime *me = CMD_SET_DATE_TIME(cmd);
if (me->contents)
g_free (me->contents);
gnumeric_command_destroy (cmd);
}
gboolean
cmd_set_date_time (CommandContext *context, gboolean is_date,
Sheet *sheet, int col, int row)
{
GtkObject *obj;
CmdSetDateTime *me;
gboolean trouble;
g_return_val_if_fail (sheet != NULL, TRUE);
obj = gtk_type_new (CMD_SET_DATE_TIME_TYPE);
me = CMD_SET_DATE_TIME (obj);
/* Store the specs for the object */
me->pos.sheet = sheet;
me->pos.eval.col = col;
me->pos.eval.row = row;
me->is_date = is_date;
me->contents = NULL;
me->parent.cmd_descriptor =
g_strdup_printf (is_date
? _("Setting current date in %s")
: _("Setting current time in %s"),
cell_name(col, row));
trouble = cmd_set_date_time_redo (GNUMERIC_COMMAND(me), context);
/* Register the command object */
return command_push_undo (sheet->workbook, obj, trouble);
}
/******************************************************************/
......@@ -911,5 +1068,4 @@ cmd_rename_sheet (CommandContext *context,
* - Autofill
* - Array formula creation.
* - Row/Col size changes
* - insert data/time
*/
......@@ -15,6 +15,9 @@ gboolean cmd_set_text (CommandContext *context,
char const * const new_text,
String const * const old_text);
gboolean cmd_set_date_time (CommandContext *context, gboolean is_date,
Sheet *sheet, int col, int row);
gboolean cmd_insert_cols (CommandContext *context,
Sheet *sheet, int start_col, int count);
gboolean cmd_insert_rows (CommandContext *context,
......
......@@ -134,7 +134,7 @@ Workbook_sheet_rename (PortableServer_Servant servant,
{
Workbook *workbook = workbook_from_servant (servant);
return workbook_rename_sheet (workbook, old_name, new_name);
return cmd_rename_sheet (workbook, old_name, new_name);
}
static void
......
......@@ -16,6 +16,7 @@
#include "workbook-cmd-format.h"
#include "dialogs.h"
#include "format.h"
#include "commands.h"
void
workbook_cmd_format_column_auto_fit (GtkWidget *widget, Workbook *wb)
......@@ -196,7 +197,8 @@ workbook_cmd_format_sheet_change_name (GtkWidget *widget, Workbook *wb)
if (!new_name)
return;
workbook_rename_sheet (wb, sheet->name, new_name);
cmd_rename_sheet (workbook_command_context_gui (wb),
wb, sheet->name, new_name);
g_free (new_name);
}
......
......@@ -859,46 +859,20 @@ recalc_cmd (GtkWidget *widget, Workbook *wb)
workbook_recalc_all (wb);
}
static void
insert_at_cursor (Sheet *sheet, Value *value, const char *format)
{
Cell *cell;
cell = sheet_cell_fetch (sheet, sheet->cursor_col, sheet->cursor_row);
cell_set_value (cell, value);
cell_set_format (cell, format);
workbook_recalc (sheet->workbook);
}
static void
insert_current_date_cmd (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = workbook_get_current_sheet (wb);
const char *preferred_date_format = _(">mm/dd/yyyy");
int n;
GDate *date = g_date_new();
g_date_set_time (date, time (NULL));
n = g_date_serial (date);
g_date_free( date );
insert_at_cursor (sheet, value_new_int (n), preferred_date_format+1);
cmd_set_date_time (workbook_command_context_gui (wb), TRUE,
sheet, sheet->cursor_col, sheet->cursor_row);
}
static void
insert_current_time_cmd (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = workbook_get_current_sheet (wb);
time_t t = time (NULL);
struct tm *tm = localtime (&t);
const char *preferred_time_format = _(">hh:mm");
float_t serial;
serial = (tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec)/(24*3600.0);
insert_at_cursor (sheet, value_new_float (serial), preferred_time_format);
cmd_set_date_time (workbook_command_context_gui (wb), TRUE,
sheet, sheet->cursor_col, sheet->cursor_row);
}
static void
......@@ -2285,12 +2259,16 @@ sheet_label_text_changed_signal (EditableLabel *el, const char *new_name, Workbo
{
gboolean ans;
/* FIXME : Why do we care ?
* Why are the tests here ?
*/
if (strchr (new_name, '"'))
return FALSE;
if (strchr (new_name, '\''))
return FALSE;
ans = workbook_rename_sheet (wb, el->text, new_name);
ans = cmd_rename_sheet (workbook_command_context_gui (wb),
wb, el->text, new_name);
workbook_focus_current_sheet (wb);
return ans;
......@@ -2381,7 +2359,9 @@ sheet_action_rename_sheet (GtkWidget *widget, Sheet *current_sheet)
if (!new_name)
return;
workbook_rename_sheet (wb, current_sheet->name, new_name);
/* We do not care if it fails */
(void) cmd_rename_sheet (workbook_command_context_gui (wb),
wb, current_sheet->name, new_name);
g_free (new_name);
}
......
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