[gnumeric] Have the formula guru auto-quote unparsable expressions. [#442941]



commit 32d00c809892a8acbcf02366e05680826418a6d4
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Tue Dec 29 00:22:20 2009 -0700

    Have the formula guru auto-quote unparsable expressions. [#442941]
    
    2009-12-29 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* formula-guru.glade: add quote button
    	* dialog-formula-guru.c (dialog_formula_guru_update_this_parent):
    	  check for unparsable expressions
    	(dialog_formula_guru_init): set up quote button
    	(dialog_formula_guru): initialize GnmParsePos

 NEWS                              |    3 +-
 src/dialogs/ChangeLog             |    8 ++++++
 src/dialogs/dialog-formula-guru.c |   45 +++++++++++++++++++++++++++++-------
 src/dialogs/formula-guru.glade    |   21 +++++++++++++++++
 4 files changed, 67 insertions(+), 10 deletions(-)
---
diff --git a/NEWS b/NEWS
index ab8e421..0d5ecf1 100644
--- a/NEWS
+++ b/NEWS
@@ -16,7 +16,8 @@ Andreas:
 	* Fix empty cell handling of the advanced filter. [#599064]
 	* Fix scroll bar problem with large frozen panes. [#68603]
 	* Singleton selections now cause the sort buttons to sort the
-	  whole sheet below teh selection. [#141313]
+	  whole sheet below the selection. [#141313]
+	* Have the formula guru auto-quote unparsable expressions. [#442941]
 
 Jean
 	* Fix import export of line type in scatter plots. [#605043]
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index bd68070..b2686e5 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,11 @@
+2009-12-29 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* formula-guru.glade: add quote button
+	* dialog-formula-guru.c (dialog_formula_guru_update_this_parent):
+	  check for unparsable expressions
+	(dialog_formula_guru_init): set up quote button
+	(dialog_formula_guru): initialize GnmParsePos
+
 2009-12-28 Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* dialog-sheetobject-size.c (dialog_so_size_button_sensitivity):
diff --git a/src/dialogs/dialog-formula-guru.c b/src/dialogs/dialog-formula-guru.c
index 0395dbb..17fa7ee 100644
--- a/src/dialogs/dialog-formula-guru.c
+++ b/src/dialogs/dialog-formula-guru.c
@@ -39,6 +39,7 @@
 #include <cell.h>
 #include <expr.h>
 #include <expr-impl.h>
+#include <expr-name.h>
 #include <func.h>
 #include <gnm-format.h>
 #include <goffice/goffice.h>
@@ -68,6 +69,7 @@ typedef struct
 	GtkWidget *zoom_button;
 	GtkWidget *array_button;
 	GtkWidget *main_button_area;
+	GtkWidget *quote_button;
 	GtkTreePath* active_path;
 	char * prefix;
 	char * suffix;
@@ -179,8 +181,28 @@ dialog_formula_guru_update_this_parent (GtkTreeIter *parent, FormulaGuruState *s
 				}
 				gtk_tree_path_free (b);
 			}
-			if (argument && strlen (argument) > 0)
-				text = g_string_append (text, argument);
+			if (argument && strlen (argument) > 0) {
+				GnmExprTop const *texpr = gnm_expr_parse_str 
+					(argument, state->pos, 
+					 GNM_EXPR_PARSE_DEFAULT,
+					 sheet_get_conventions (state->pos->sheet), 
+					 NULL);
+				if (texpr == NULL) {
+					text = g_string_append_c (text, '"');
+					text = g_string_append (text, argument);
+					text = g_string_append_c (text, '"');
+				} else {
+					if ((GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_NAME) 
+					    && expr_name_is_placeholder (texpr->expr->name.name)
+					    && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state->quote_button))) {
+						text = g_string_append_c (text, '"');
+						text = g_string_append (text, argument);
+						text = g_string_append_c (text, '"');
+					} else
+						text = g_string_append (text, argument);
+					gnm_expr_top_unref (texpr);
+				}
+			}
 			g_free (argument);
 			not_first = TRUE;
 			arg_num++;
@@ -851,10 +873,11 @@ dialog_formula_guru_init (FormulaGuruState *state)
 
 	g_signal_connect (state->treeview,
 			  "button_press_event",
-			  G_CALLBACK (start_editing_cb), state),
-
+			  G_CALLBACK (start_editing_cb), state);
 	/* Finished set-up of treeview */
 
+	state->quote_button = glade_xml_get_widget (state->gui,
+						    "quote-button");
 	state->array_button = glade_xml_get_widget (state->gui,
 						    "array_button");
 	gtk_widget_set_sensitive (state->array_button, TRUE);
@@ -970,12 +993,17 @@ dialog_formula_guru (WBCGtk *wbcg, GnmFunc const *fd)
 	state->wb    = wb_control_get_workbook (WORKBOOK_CONTROL (wbcg));
 	state->gui   = gui;
 	state->active_path = NULL;
-	state->pos = NULL;
+	state->pos = g_new (GnmParsePos, 1);
 
 	sv = wb_control_cur_sheet_view (WORKBOOK_CONTROL (wbcg));
 	cell = sheet_cell_get (sv_sheet (sv), sv->edit_pos.col, sv->edit_pos.row);
-	if (cell != NULL && gnm_cell_has_expr (cell))
-		expr = gnm_expr_top_first_funcall (cell->base.texpr);
+	if (cell != NULL) {
+		parse_pos_init_cell (state->pos, cell);
+		if (gnm_cell_has_expr (cell))
+			expr = gnm_expr_top_first_funcall (cell->base.texpr);
+	} else
+		parse_pos_init_editpos (state->pos, sv);
+	
 
 	if (expr == NULL) {
 		wbcg_edit_start (wbcg, TRUE, TRUE);
@@ -986,9 +1014,8 @@ dialog_formula_guru (WBCGtk *wbcg, GnmFunc const *fd)
 		char const *full_str = gtk_entry_get_text (wbcg_get_entry (wbcg));
 		char *func_str;
 
-		state->pos = g_new (GnmParsePos, 1);
 		func_str = gnm_expr_as_string (expr,
-			 parse_pos_init_cell (state->pos, cell),
+			 state->pos,
 			 sheet_get_conventions (sv_sheet (sv)));
 
 		wbcg_edit_start (wbcg, FALSE, TRUE);
diff --git a/src/dialogs/formula-guru.glade b/src/dialogs/formula-guru.glade
index e653990..13a1091 100644
--- a/src/dialogs/formula-guru.glade
+++ b/src/dialogs/formula-guru.glade
@@ -176,6 +176,9 @@
 		</packing>
 	      </child>
 
+            <child>
+              <widget class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
 	      <child>
 	        <widget class="GtkCheckButton" id="array_button">
 	          <property name="visible">True</property>
@@ -188,6 +191,24 @@
 		  <property name="inconsistent">False</property>
 		  <property name="draw_indicator">True</property>
 		</widget>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="quote-button">
+                    <property name="label" translatable="yes">Quote unknown names</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
 		<packing>
 		<property name="left_attach">0</property>
 		<property name="right_attach">2</property>



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