[gnumeric] Make changing the scope of a named expression undoable.



commit ed4571fd6c5f50bde4366a09b8e6c991ad8f0a2a
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Jun 3 16:47:13 2010 -0600

    Make changing the scope of a named expression undoable.
    
    2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/commands.h (cmd_rescope_name): new
    	* src/commands.c (cmd_rescope_name): new
    	(cmd_rescope_name_*): new
    
    2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* dialog-define-names.c (cb_name_guru_switch_scope): use
    	 cmd_rescope_name

 ChangeLog                         |    6 +++
 NEWS                              |    1 +
 src/commands.c                    |   69 +++++++++++++++++++++++++++++++++++++
 src/commands.h                    |    2 +
 src/dialogs/ChangeLog             |    5 +++
 src/dialogs/dialog-define-names.c |   12 ++++--
 6 files changed, 91 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bb30673..d1742f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/commands.h (cmd_rescope_name): new
+	* src/commands.c (cmd_rescope_name): new
+	(cmd_rescope_name_*): new
+
+2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* configure.in: check for gtk_entry_get_text_length
 
 2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/NEWS b/NEWS
index 1c03fb7..9349ab9 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Andreas:
 	* Fix spin button handling in various tool dialogs. [#619971]
 	* Redesign define-named-expressions dialog. [#465840] 
 	* Add paste-names dialog. [#613325]
+	* Make changing the scope of a named expression undoable.
 
 Jean:
 	* Do not ungrab a not grabbed item. [#620369]
diff --git a/src/commands.c b/src/commands.c
index 326617b..e5ed0a8 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -5985,6 +5985,75 @@ cmd_remove_name (WorkbookControl *wbc, GnmNamedExpr *nexpr)
 
 /******************************************************************/
 
+#define CMD_RESCOPE_NAME_TYPE        (cmd_rescope_name_get_type ())
+#define CMD_RESCOPE_NAME(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), CMD_RESCOPE_NAME_TYPE, CmdRescopeName))
+
+typedef struct {
+	GnmCommand cmd;
+	GnmNamedExpr *nexpr;
+	Sheet *scope;
+} CmdRescopeName;
+
+MAKE_GNM_COMMAND (CmdRescopeName, cmd_rescope_name, NULL)
+
+static gboolean
+cmd_rescope_name_redo (GnmCommand *cmd, G_GNUC_UNUSED WorkbookControl *wbc)
+{
+	CmdRescopeName *me = CMD_RESCOPE_NAME (cmd);
+	Sheet *old_scope = me->nexpr->pos.sheet;
+	
+	expr_name_set_scope (me->nexpr, me->scope);
+
+	me->scope = old_scope;
+	return FALSE;
+}
+
+static gboolean
+cmd_rescope_name_undo (GnmCommand *cmd, WorkbookControl *wbc)
+{
+	return cmd_rescope_name_redo (cmd, wbc);
+}
+
+
+static void
+cmd_rescope_name_finalize (GObject *cmd)
+{
+	CmdRescopeName *me = CMD_RESCOPE_NAME (cmd);
+
+	expr_name_unref (me->nexpr);
+	gnm_command_finalize (cmd);
+}
+
+/**
+ * cmd_rescope_name :
+ * @wbc :
+ * @nexpr : name to rescope.
+ *
+ * Returns TRUE on error
+ **/
+gboolean
+cmd_rescope_name (WorkbookControl *wbc, GnmNamedExpr *nexpr, Sheet *scope)
+{
+	CmdRescopeName *me;
+
+	g_return_val_if_fail (wbc != NULL, TRUE);
+	g_return_val_if_fail (nexpr != NULL, TRUE);
+	g_return_val_if_fail (!expr_name_is_placeholder (nexpr), TRUE);
+
+	expr_name_ref (nexpr);
+
+	me = g_object_new (CMD_RESCOPE_NAME_TYPE, NULL);
+	me->nexpr = nexpr;
+	me->scope = scope;
+	me->cmd.sheet = wb_control_cur_sheet (wbc);
+	me->cmd.size = 1;
+	me->cmd.cmd_descriptor = g_strdup_printf (_("Change Scope of Name %s"),
+						  expr_name_name (nexpr));
+
+	return gnm_command_push_undo (wbc, G_OBJECT (me));
+}
+/******************************************************************/
+
 #define CMD_SCENARIO_ADD_TYPE (cmd_scenario_add_get_type ())
 #define CMD_SCENARIO_ADD(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), CMD_SCENARIO_ADD_TYPE, CmdScenarioAdd))
 
diff --git a/src/commands.h b/src/commands.h
index 95c442c..0c047a3 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -111,6 +111,8 @@ gboolean cmd_define_name	(WorkbookControl *wbc, char const *name,
 				 GnmExprTop const *texpr,
 				 char const *descriptor);
 gboolean cmd_remove_name        (WorkbookControl *wbc, GnmNamedExpr *nexpr);
+gboolean cmd_rescope_name       (WorkbookControl *wbc, GnmNamedExpr *nexpr, 
+				 Sheet *scope);
 
 gboolean cmd_scenario_add (WorkbookControl *wbc, GnmScenario *s, Sheet *sheet);
 gboolean cmd_scenario_mngr (WorkbookControl *wbc, GnmScenario *sc,
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 289a7d2..2d8f681 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,5 +1,10 @@
 2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* dialog-define-names.c (cb_name_guru_switch_scope): use
+	 cmd_rescope_name
+
+2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* dialog-define-names.c: add #define for gtk 2.12
 
 2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/src/dialogs/dialog-define-names.c b/src/dialogs/dialog-define-names.c
index bb4bf19..c9b03e8 100644
--- a/src/dialogs/dialog-define-names.c
+++ b/src/dialogs/dialog-define-names.c
@@ -623,8 +623,10 @@ cb_name_guru_switch_scope (G_GNUC_UNUSED GtkCellRendererToggle *cell,
 
 		switch (type) {
 		case item_type_available_wb_name:
-#warning make undoable		       
-			expr_name_set_scope (nexpr, state->sheet);
+			if (cmd_rescope_name 
+			    (WORKBOOK_CONTROL (state->wbcg), 
+			     nexpr, state->sheet))
+				return;
 			new_path  = "1"; 
 			new_type  = item_type_available_sheet_name;
 			break;
@@ -633,8 +635,10 @@ cb_name_guru_switch_scope (G_GNUC_UNUSED GtkCellRendererToggle *cell,
 			new_type  = item_type_new_unsaved_sheet_name;
 			break;
 		case item_type_available_sheet_name:
-#warning make undoable		       
-			expr_name_set_scope (nexpr, NULL);
+			if (cmd_rescope_name 
+			    (WORKBOOK_CONTROL (state->wbcg), 
+			     nexpr, NULL))
+				return;
 			new_path  = "0"; 
 			new_type  = item_type_available_wb_name;
 			break;



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