[gnumeric] Implement access to the function selector to paste function names while editing cells (Shift-F4).



commit 3108f2d42d87c55ccbe3fd47451e1f83051a4660
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Tue Jul 20 12:08:14 2010 -0600

    Implement access to the function selector to paste function names while editing cells (Shift-F4).
    
    2010-07-20  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* gnumeric-expr-entry.c (cb_gee_key_press_event) call
    	  dialog_function_select_paste on Sift-F4
    
    2010-07-20  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* dialog-function-select.c (FunctionSelectState): new fields
    	(cb_dialog_function_select_paste_clicked): new
    	(cb_dialog_function_row_activated): handle paste button
    	(dialog_function_select_init): handle paste button
    	* dialogs.h (dialog_function_select_help): new
    	(dialog_function_select_paste): new
    	* function-select.glade: add paste button
    
    2010-07-20  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/wbc-gtk-actions.c (cb_help_function): use
    	  dialog_function_select_help instead of dialog_function_select

 ChangeLog                            |    5 ++
 NEWS                                 |    2 +
 src/dialogs/ChangeLog                |   11 +++
 src/dialogs/dialog-function-select.c |  126 +++++++++++++++++++++++++++------
 src/dialogs/dialogs.h                |    2 +
 src/dialogs/function-select.glade    |   19 +++++-
 src/wbc-gtk-actions.c                |    2 +-
 src/widgets/ChangeLog                |    5 ++
 src/widgets/gnumeric-expr-entry.c    |    5 ++
 9 files changed, 151 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fa2540f..861fbd4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2010-07-20  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/wbc-gtk-actions.c (cb_help_function): use 
+	  dialog_function_select_help instead of dialog_function_select
+
+2010-07-20  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* src/wbc-gtk-edit.c (wbcg_edit_finish): check whether showed_dialog
 	  is NULL before using it
 
diff --git a/NEWS b/NEWS
index 78376fe..f47b760 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,8 @@ Andreas:
 	  [#163410]
 	* Provide completion when entering functions (when using gtk 2.14 
 	  or newer). [#587084]
+	* Implement access to the function selector to paste function names
+	  while editing cells (Shift-F4).
 
 Jean:
 	* Fix strong/weak cursor display. [#623241]
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 1a76867..b33f995 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,14 @@
+2010-07-20  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dialog-function-select.c (FunctionSelectState): new fields
+	(cb_dialog_function_select_paste_clicked): new
+	(cb_dialog_function_row_activated): handle paste button
+	(dialog_function_select_init): handle paste button
+	* dialogs.h (dialog_function_select_help): new
+	(dialog_function_select_paste): new
+	* function-select.glade: add paste button
+
+
 2010-07-17  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* dialog-function-select.c (cb_dialog_function_row_activated): new
diff --git a/src/dialogs/dialog-function-select.c b/src/dialogs/dialog-function-select.c
index 367eb73..b1db286 100644
--- a/src/dialogs/dialog-function-select.c
+++ b/src/dialogs/dialog-function-select.c
@@ -52,8 +52,15 @@
 
 #define FUNCTION_SELECT_KEY "function-selector-dialog"
 #define FUNCTION_SELECT_HELP_KEY "function-selector-dialog-help-mode"
+#define FUNCTION_SELECT_PASTE_KEY "function-selector-dialog-paste-mode"
 #define FUNCTION_SELECT_DIALOG_KEY "function-selector-dialog"
 
+typedef enum {
+	GURU_MODE = 0,
+	HELP_MODE,
+	PASTE_MODE
+} mode_t;
+
 typedef struct {
 	WBCGtk  *wbcg;
 	Workbook *wb;
@@ -62,6 +69,7 @@ typedef struct {
 	GladeXML  *gui;
 	GtkWidget *dialog;
 	GtkWidget *ok_button;
+	GtkWidget *paste_button;
 	GtkListStore  *model;
 	GtkComboBox   *cb;
 	GtkListStore  *model_functions;
@@ -72,6 +80,7 @@ typedef struct {
 
 	GSList *recent_funcs;
 
+	mode_t      mode;
 	char const *formula_guru_key;
 } FunctionSelectState;
 
@@ -364,6 +373,44 @@ cb_dialog_function_select_ok_clicked (G_GNUC_UNUSED GtkWidget *button,
 	return;
 }
 
+/**
+ * cb_dialog_function_select_paste_clicked:
+ * @button:
+ * @state:
+ *
+ * Close (destroy) the dialog
+ **/
+static void
+cb_dialog_function_select_paste_clicked (G_GNUC_UNUSED GtkWidget *button,
+				      FunctionSelectState *state)
+{
+	GtkTreeIter  iter;
+	GtkTreeModel *model;
+	GnmFunc *func;
+	GtkTreeSelection *the_selection = gtk_tree_view_get_selection (state->treeview);
+
+	if (gtk_tree_selection_get_selected (the_selection, &model, &iter) &&
+	    wbcg_edit_start (state->wbcg, FALSE, FALSE)) {
+		GtkEditable *entry 
+			= GTK_EDITABLE (wbcg_get_entry (state->wbcg));
+		gint position;
+		gtk_tree_model_get (model, &iter,
+				    FUNCTION, &func,
+				    -1);
+		if (func != NULL) {
+			dialog_function_write_recent_func (state, func);
+			gtk_editable_delete_selection (entry);
+			position = gtk_editable_get_position (entry);
+			gtk_editable_insert_text 
+				(entry, func->name, -1, &position);
+			gtk_editable_set_position (entry, position);
+		}
+	}
+
+	gtk_widget_destroy (state->dialog);
+	return;
+}
+
 static void
 cb_dialog_function_row_activated (GtkTreeView *tree_view,
 				  GtkTreePath       *path,
@@ -917,6 +964,7 @@ cb_dialog_function_select_fun_selection_changed (GtkTreeSelection *selection,
 	GnmFunc const *func;
 	GtkTextBuffer *description;
 	GtkTextMark *mark;
+	gboolean active = FALSE;
 
 	description =  gtk_text_view_get_buffer (state->description_view);
 
@@ -936,11 +984,11 @@ cb_dialog_function_select_fun_selection_changed (GtkTreeSelection *selection,
 			gtk_text_buffer_set_text (description, "?", -1);
 		else
 			describe_new_style (description, func, state->sheet);
-
-		gtk_widget_set_sensitive (state->ok_button, TRUE);
-	} else {
-		gtk_widget_set_sensitive (state->ok_button, FALSE);
+		active = TRUE;
 	}
+	gtk_widget_set_sensitive (state->ok_button, active);
+	gtk_widget_set_sensitive (state->paste_button, active);
+	
 }
 
 /**********************************************************************/
@@ -1077,11 +1125,9 @@ dialog_function_select_init (FunctionSelectState *state)
 	GtkCellRenderer *cell;
 	GtkWidget *cancel_button;
 	GtkWidget *close_button;
-	gboolean help_mode;
 
 	g_object_set_data (G_OBJECT (state->dialog), FUNCTION_SELECT_DIALOG_KEY,
 			   state);
-	help_mode = (state->formula_guru_key == NULL);
 
 	/* Set-up combo box */
 	state->cb = GTK_COMBO_BOX 
@@ -1183,7 +1229,7 @@ dialog_function_select_init (FunctionSelectState *state)
 			  "activate",
 			  G_CALLBACK (dialog_function_select_search),
 			  state);
-	if (!help_mode)
+	if (state->mode == GURU_MODE)
 		g_signal_connect (G_OBJECT (state->treeview),
 				  "row-activated",
 				  G_CALLBACK (cb_dialog_function_row_activated),
@@ -1207,6 +1253,11 @@ dialog_function_select_init (FunctionSelectState *state)
 	g_signal_connect (G_OBJECT (state->ok_button),
 		"clicked",
 		G_CALLBACK (cb_dialog_function_select_ok_clicked), state);
+	state->paste_button = glade_xml_get_widget (state->gui, "paste_button");
+	gtk_widget_set_sensitive (state->paste_button, FALSE);
+	g_signal_connect (G_OBJECT (state->paste_button),
+		"clicked",
+		G_CALLBACK (cb_dialog_function_select_paste_clicked), state);
 	cancel_button = glade_xml_get_widget (state->gui, "cancel_button");
 	g_signal_connect (G_OBJECT (cancel_button), "clicked",
 		G_CALLBACK (cb_dialog_function_select_cancel_clicked), state);
@@ -1226,34 +1277,41 @@ dialog_function_select_init (FunctionSelectState *state)
 		(G_OBJECT (state->dialog),
 		 "state", state, 
 		 (GDestroyNotify) cb_dialog_function_select_destroy);
-
-	gtk_widget_set_visible (close_button, help_mode);
+	
+	gtk_widget_set_visible (close_button, state->mode != GURU_MODE);
 	gtk_widget_set_visible (glade_xml_get_widget 
 				(state->gui, "help_button"), 
-				!help_mode);
-	gtk_widget_set_visible (cancel_button, !help_mode);
-	gtk_widget_set_visible (state->ok_button, !help_mode);
+				state->mode == GURU_MODE);
+	gtk_widget_set_visible (cancel_button, state->mode == GURU_MODE);
+	gtk_widget_set_visible (state->ok_button, state->mode == GURU_MODE);
+	gtk_widget_set_visible (state->paste_button, state->mode == PASTE_MODE);
 	gtk_widget_set_visible (glade_xml_get_widget 
 				(state->gui, "title_label"), 
-				!help_mode);
-	gtk_combo_box_set_active (state->cb, help_mode ? 2 : 0);
-	if (help_mode)
+				state->mode == GURU_MODE);
+	gtk_combo_box_set_active (state->cb, state->mode == HELP_MODE ? 2 : 0);
+	switch (state->mode) {
+	case GURU_MODE:
+		break;
+	case HELP_MODE:
 		gtk_window_set_title (GTK_WINDOW (state->dialog),
 				      _("Gnumeric Function Help Browser"));
+		break;
+	case PASTE_MODE:
+		gtk_window_set_title (GTK_WINDOW (state->dialog),
+				      _("Paste Function Name dialog"));
+		break;
+	}
 }
 
-void
-dialog_function_select (WBCGtk *wbcg, char const *key)
+static void
+dialog_function_select_full (WBCGtk *wbcg, char const *guru_key, char const *key, mode_t mode)
 {
 	FunctionSelectState* state;
 	GladeXML  *gui;
 
-	gchar const *our_key = key ? FUNCTION_SELECT_KEY 
-		: FUNCTION_SELECT_HELP_KEY;
-
 	g_return_if_fail (wbcg != NULL);
 
-	if (gnumeric_dialog_raise_if_exists (wbcg, our_key))
+	if (gnumeric_dialog_raise_if_exists (wbcg, key))
 		return;
 	gui = gnm_glade_xml_new (GO_CMD_CONTEXT (wbcg),
 		"function-select.glade", NULL, NULL);
@@ -1266,12 +1324,34 @@ dialog_function_select (WBCGtk *wbcg, char const *key)
 	state->wb    = state->sheet->workbook;
         state->gui   = gui;
         state->dialog = glade_xml_get_widget (state->gui, "selection_dialog");
-	state->formula_guru_key = key;
+	state->formula_guru_key = guru_key;
         state->recent_funcs = NULL;
+	state->mode  = mode;
 
 	dialog_function_select_init (state);
 	gnumeric_keyed_dialog (state->wbcg, GTK_WINDOW (state->dialog),
-			       our_key);
+			       key);
 
 	gtk_widget_show (state->dialog);
 }
+
+void
+dialog_function_select (WBCGtk *wbcg, char const *key)
+{
+	dialog_function_select_full (wbcg, key, 
+				     FUNCTION_SELECT_KEY, GURU_MODE);	
+}
+
+void
+dialog_function_select_help (WBCGtk *wbcg)
+{
+	dialog_function_select_full (wbcg, NULL, 
+				     FUNCTION_SELECT_HELP_KEY, HELP_MODE);
+}
+
+void
+dialog_function_select_paste (WBCGtk *wbcg)
+{
+	dialog_function_select_full (wbcg, NULL, 
+				     FUNCTION_SELECT_PASTE_KEY, PASTE_MODE);
+}
diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h
index eb38c9e..87eb2e9 100644
--- a/src/dialogs/dialogs.h
+++ b/src/dialogs/dialogs.h
@@ -73,6 +73,8 @@ void dialog_tabulate		 (WBCGtk *wbcg, Sheet *sheet);
 void dialog_merge		 (WBCGtk *wbcg);
 
 void dialog_function_select	 (WBCGtk *wbcg, char const *key);
+void dialog_function_select_help	 (WBCGtk *wbcg);
+void dialog_function_select_paste	 (WBCGtk *wbcg);
 
 int dialog_correlation_tool	 (WBCGtk *wbcg, Sheet *sheet);
 int dialog_covariance_tool	 (WBCGtk *wbcg, Sheet *sheet);
diff --git a/src/dialogs/function-select.glade b/src/dialogs/function-select.glade
index d2fe3a3..f1454ba 100644
--- a/src/dialogs/function-select.glade
+++ b/src/dialogs/function-select.glade
@@ -187,6 +187,21 @@
               </packing>
             </child>
             <child>
+              <widget class="GtkButton" id="paste_button">
+                <property name="label">gtk-paste</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
               <widget class="GtkButton" id="cancel_button">
                 <property name="label">gtk-cancel</property>
                 <property name="visible">True</property>
@@ -198,7 +213,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">2</property>
+                <property name="position">3</property>
               </packing>
             </child>
             <child>
@@ -212,7 +227,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">3</property>
+                <property name="position">4</property>
               </packing>
             </child>
           </widget>
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index 72bc895..17e8528 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -1037,7 +1037,7 @@ static GNM_ACTION_DEF (cb_data_show_detail)	{ hide_show_detail (wbcg, TRUE); }
 static GNM_ACTION_DEF (cb_data_group)		{ group_ungroup_colrow (wbcg, TRUE); }
 static GNM_ACTION_DEF (cb_data_ungroup)		{ group_ungroup_colrow (wbcg, FALSE); }
 
-static GNM_ACTION_DEF (cb_help_function)	{ dialog_function_select (wbcg, NULL); }
+static GNM_ACTION_DEF (cb_help_function)	{ dialog_function_select_help (wbcg); }
 static GNM_ACTION_DEF (cb_help_docs)
 {
 	char   *argv[] = { NULL, NULL, NULL };
diff --git a/src/widgets/ChangeLog b/src/widgets/ChangeLog
index 5d4eaf5..e1d0944 100644
--- a/src/widgets/ChangeLog
+++ b/src/widgets/ChangeLog
@@ -1,3 +1,8 @@
+2010-07-20  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* gnumeric-expr-entry.c (cb_gee_key_press_event) call 
+	  dialog_function_select_paste on Sift-F4
+
 2010-07-19  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* gnumeric-expr-entry.c (_GnmExprEntry): add field
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index b346bf6..05c502d 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -34,6 +34,7 @@
 #include <gnm-datetime.h>
 #include <gnumeric-gconf.h>
 #include <dead-kittens.h>
+#include <dialogs/dialogs.h>
 #include <goffice/goffice.h>
 
 #include <gsf/gsf-impl-utils.h>
@@ -1019,6 +1020,10 @@ cb_gee_key_press_event (GtkEntry	*entry,
 		Rangesel *rs = &gee->rangesel;
 		gboolean c, r;
 
+		if (state == GDK_SHIFT_MASK) {
+			dialog_function_select_paste (gee->wbcg);
+			return;
+		}
 		if (gee->tooltip.completion != NULL) {
 			guint start = gee->tooltip.completion_start;
 			guint end = gee->tooltip.completion_end;



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