[gnumeric] Implement undo framework for sheet resize (which is still not implemented).



commit 32505d7dba5f696161c9d1d27aa1b5ff1d757a00
Author: Morten Welinder <terra gnome org>
Date:   Tue Apr 21 13:06:07 2009 -0400

    Implement undo framework for sheet resize (which is still not implemented).
---
 ChangeLog                         |    5 ++
 src/commands.c                    |   79 +++++++++++++++++++++++++++++++++++++
 src/commands.h                    |    4 ++
 src/dialogs/dialog-sheet-resize.c |   10 +++--
 src/print-info.h                  |    5 --
 src/sheet.c                       |   14 +++++++
 src/sheet.h                       |    2 +
 7 files changed, 110 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9a80f5f..09ac12b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-04-21  Morten Welinder  <terra gnome org>
 
+	* src/sheet.c (gnm_sheet_resize): Stub.
+
+	* src/commands.c (cmd_resize_sheets): Undo framework for resizing
+	sheets.
+
 	* src/xml-io.c (xml_read_print_repeat_range): Adapt to print-info
 	changes.
 
diff --git a/src/commands.c b/src/commands.c
index d13c92e..8213610 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -4822,6 +4822,85 @@ cmd_rename_sheet (WorkbookControl *wbc,
 
 /******************************************************************/
 
+#define CMD_RESIZE_SHEETS_TYPE        (cmd_resize_sheets_get_type ())
+#define CMD_RESIZE_SHEETS(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), CMD_RESIZE_SHEETS_TYPE, CmdResizeSheets))
+
+typedef struct {
+	GnmCommand cmd;
+	GSList *sheets;
+	int cols, rows;
+	GOUndo *undo;
+} CmdResizeSheets;
+
+MAKE_GNM_COMMAND (CmdResizeSheets, cmd_resize_sheets, NULL)
+
+static gboolean
+cmd_resize_sheets_undo (GnmCommand *cmd, WorkbookControl *wbc)
+{
+	CmdResizeSheets *me = CMD_RESIZE_SHEETS (cmd);
+
+	go_undo_undo (me->undo);
+	g_object_unref (me->undo);
+	me->undo = NULL;
+
+	return FALSE;
+}
+
+static gboolean
+cmd_resize_sheets_redo (GnmCommand *cmd, WorkbookControl *wbc)
+{
+	CmdResizeSheets *me = CMD_RESIZE_SHEETS (cmd);
+	GSList *l;
+
+	for (l = me->sheets; l; l = l->next) {
+		Sheet *sheet = l->data;
+		GOUndo *u = gnm_sheet_resize (sheet, me->cols, me->rows);
+		me->undo = go_undo_combine (me->undo, u);
+	}
+
+	return FALSE;
+}
+
+static void
+cmd_resize_sheets_finalize (GObject *cmd)
+{
+	CmdResizeSheets *me = CMD_RESIZE_SHEETS (cmd);
+
+	g_slist_free (me->sheets);
+	if (me->undo) {
+		g_object_unref (me->undo);
+		me->undo = NULL;
+	}
+
+	gnm_command_finalize (cmd);
+}
+
+gboolean
+cmd_resize_sheets (WorkbookControl *wbc,
+		   GSList *sheets,
+		   int cols, int rows)
+{
+	CmdResizeSheets *me;
+
+	me = g_object_new (CMD_RESIZE_SHEETS_TYPE, NULL);
+	me->sheets = sheets;
+	me->cols = cols;
+	me->rows = rows;
+	me->cmd.sheet = sheets ? sheets->data : NULL;
+	me->cmd.size = 1;
+	me->cmd.cmd_descriptor = _("Resizing sheet");
+
+	if (sheets &&
+	    gnm_sheet_valid_size (cols, rows))
+		return command_push_undo (wbc, G_OBJECT (me));
+
+	/* No change.  */
+	g_object_unref (me);
+	return FALSE;
+}
+
+/******************************************************************/
+
 #define CMD_SET_COMMENT_TYPE        (cmd_set_comment_get_type ())
 #define CMD_SET_COMMENT(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), CMD_SET_COMMENT_TYPE, CmdSetComment))
 
diff --git a/src/commands.h b/src/commands.h
index e9d4b97..a4605d4 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -151,6 +151,10 @@ gboolean cmd_reorganize_sheets  (WorkbookControl *wbc,
 				 WorkbookSheetState *old_state,
 				 Sheet *undo_sheet);
 
+gboolean cmd_resize_sheets      (WorkbookControl *wbc,
+				 GSList *sheets,
+				 int cols, int rows);
+
 gboolean cmd_so_graph_config (WorkbookControl *wbc, SheetObject *sog,
                               GObject *n_graph, GObject *o_graph);
 
diff --git a/src/dialogs/dialog-sheet-resize.c b/src/dialogs/dialog-sheet-resize.c
index df5986a..285dc71 100644
--- a/src/dialogs/dialog-sheet-resize.c
+++ b/src/dialogs/dialog-sheet-resize.c
@@ -32,6 +32,7 @@
 #include <workbook-view.h>
 #include <workbook.h>
 #include <sheet.h>
+#include <commands.h>
 
 #define RESIZE_DIALOG_KEY "sheet-resize-dialog"
 
@@ -108,6 +109,7 @@ cb_ok_clicked (ResizeState *state)
 {
 	GList *sheets, *l;
 	GSList *changed_sheets = NULL;
+	WorkbookControl *wbc;
 	Workbook *wb;
 	gboolean all_sheets;
 	int cols, rows;
@@ -116,7 +118,8 @@ cb_ok_clicked (ResizeState *state)
 	all_sheets = gtk_toggle_button_get_active
 		(GTK_TOGGLE_BUTTON (state->all_sheets_button));
 
-	wb = wb_control_get_workbook (WORKBOOK_CONTROL (state->wbcg));
+	wbc = WORKBOOK_CONTROL (state->wbcg);
+	wb = wb_control_get_workbook (wbc);
 	sheets = workbook_sheets (wb);
 	for (l = sheets; l; l = l->next) {
 		Sheet *this_sheet = l->data;
@@ -132,9 +135,8 @@ cb_ok_clicked (ResizeState *state)
 	}
 	g_list_free (sheets);
 
-	if (changed_sheets) {
-		g_warning ("Changing sheet size is not implemented yet.");
-	}
+	if (changed_sheets)
+		cmd_resize_sheets (wbc, changed_sheets, cols, rows);
 
 	gtk_widget_destroy (state->dialog);
 }
diff --git a/src/print-info.h b/src/print-info.h
index 3feea15..1c291b1 100644
--- a/src/print-info.h
+++ b/src/print-info.h
@@ -18,11 +18,6 @@ typedef struct {
 	char *right_format;
 } PrintHF;
 
-typedef struct {
-	gboolean use;
-	GnmRange range;
-} PrintRepeatRange;
-
 typedef enum {
 	GNM_PAGE_BREAK_MANUAL,
 	GNM_PAGE_BREAK_AUTO,
diff --git a/src/sheet.c b/src/sheet.c
index b11c94c..f5d34fd 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -1085,6 +1085,20 @@ gnm_sheet_suggest_size (int *cols, int *rows)
 	*rows = r;
 }
 
+GOUndo *
+gnm_sheet_resize (Sheet *sheet, int cols, int rows)
+{
+	g_return_val_if_fail (IS_SHEET (sheet), NULL);
+
+	if (gnm_sheet_get_max_cols (sheet) == cols &&
+	    gnm_sheet_get_max_rows (sheet) == rows)
+		return NULL;
+
+	g_warning ("Changing sheet size is not implemented yet.");
+	return NULL;
+}
+
+
 /**
  * sheet_new_with_type :
  * @wb      : #Workbook
diff --git a/src/sheet.h b/src/sheet.h
index 6d64f2f..4ea2098 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -128,6 +128,8 @@ void      sheet_destroy_contents (Sheet *sheet);
 gboolean  gnm_sheet_valid_size   (int cols, int rows);
 void      gnm_sheet_suggest_size (int *cols, int *rows);
 
+GOUndo   *gnm_sheet_resize       (Sheet *sheet, int cols, int rows);
+
 int gnm_sheet_get_max_rows (Sheet const *sheet);
 int gnm_sheet_get_max_cols (Sheet const *sheet);
 #define gnm_sheet_get_last_col(sheet) (gnm_sheet_get_max_cols(sheet) - 1)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]