[gnumeric] Improve function tooltips and remove some unneccessary tests from configure



commit b0b2e5ba9646a0093af155115052f6e4f05fc9c7
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Mon Jul 19 11:07:35 2010 -0600

    Improve function tooltips and remove some unneccessary tests from configure
    
     2010-07-19 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* dao.c: delete HAVE_G_DATE_SET_TIME_T throughout
    
    2010-07-19  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* configure.in: checks for g_date_set_time_t and g_slice_alloc have
    	  been superceded by the glib 2.12 requirement; check for
    	  g_hash_table_get_keys
    	* src/dependent.c: remove HAVE_G_SLICE_ALLOC throughout
    	* src/func.c (gnm_func_lookup_prefix): new
    	* src/func.h (gnm_func_lookup_prefix): new
    	* src/rendered-value.c: remove HAVE_G_SLICE_ALLOC throughout
    	* src/symbol.c (symbol_names): new
    	* src/symbol.h (symbol_names): new
    	* src/value.c: remove HAVE_G_SLICE_ALLOC throughout
    
    2010-07-19  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* gnumeric-expr-entry.c (gee_set_tooltip): We can have a tooltip without
    	  function descriptor
    	(gee_set_tooltip_completion): new
    	(gee_check_tooltip): if we are typing what might be a function name
    	  provide suggestions

 ChangeLog                              |   14 +++++++
 configure.in                           |    2 +-
 plugins/excelplugins/ExcelTestModule.c |    5 ---
 plugins/excelplugins/excelplugins.c    |    5 ---
 src/dependent.c                        |   12 ------
 src/func.c                             |    8 ++++
 src/func.h                             |    1 +
 src/rendered-value.c                   |    9 -----
 src/symbol.c                           |   17 +++++++++
 src/symbol.h                           |    1 +
 src/tools/ChangeLog                    |    4 ++
 src/tools/dao.c                        |    7 ----
 src/value.c                            |    9 -----
 src/widgets/ChangeLog                  |    8 ++++
 src/widgets/gnumeric-expr-entry.c      |   59 +++++++++++++++++++++++++++++---
 15 files changed, 108 insertions(+), 53 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ae428ce..6815320 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-07-19  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* configure.in: checks for g_date_set_time_t and g_slice_alloc have
+	  been superceded by the glib 2.12 requirement; check for 
+	  g_hash_table_get_keys
+	* src/dependent.c: remove HAVE_G_SLICE_ALLOC throughout
+	* src/func.c (gnm_func_lookup_prefix): new
+	* src/func.h (gnm_func_lookup_prefix): new
+	* src/rendered-value.c: remove HAVE_G_SLICE_ALLOC throughout
+	* src/symbol.c (symbol_names): new
+	* src/symbol.h (symbol_names): new
+	* src/value.c: remove HAVE_G_SLICE_ALLOC throughout
+
+
 2010-07-18  Morten Welinder  <terra gnome org>
 
 	* src/wbc-gtk-edit.c (attrs_at_byte): Fix signedness problem.
diff --git a/configure.in b/configure.in
index 4f2c28d..9ad4eb5 100644
--- a/configure.in
+++ b/configure.in
@@ -687,7 +687,7 @@ SAVE_LIBS=$LIBS
 CFLAGS="$CFLAGS $GNUMERIC_CFLAGS"
 LIBS="$GNUMERIC_LIBS $LIBS"
 
-AC_CHECK_FUNCS(g_date_set_time_t g_slice_alloc g_option_context_set_delocalize)
+AC_CHECK_FUNCS(g_option_context_set_delocalize g_hash_table_get_keys)
 AC_CHECK_FUNCS(pango_font_map_create_context)
 AC_CHECK_FUNCS(gtk_orientable_set_orientation gtk_adjustment_configure gtk_widget_set_visible gtk_widget_get_state gtk_widget_is_toplevel gtk_widget_get_window gsf_open_pkg_foreach_rel gtk_dialog_get_content_area gtk_entry_get_buffer gtk_widget_get_can_focus gtk_entry_get_text_length gtk_entry_set_icon_from_stock gtk_layout_get_bin_window gtk_widget_get_allocation)
 AC_CHECK_FUNCS(gsf_infile_msvba_steal_modules)
diff --git a/plugins/excelplugins/ExcelTestModule.c b/plugins/excelplugins/ExcelTestModule.c
index 55e1d14..26a57ba 100644
--- a/plugins/excelplugins/ExcelTestModule.c
+++ b/plugins/excelplugins/ExcelTestModule.c
@@ -37,14 +37,9 @@
 #include <stdio.h>
 #include <string.h>
 
-#ifdef HAVE_G_SLICE_ALLOC
 #define g_slice_new_array0(T,c) ((T*) g_slice_alloc0 ((sizeof (T))*(c)))
 #define ALLOC_ARRAY(T,c) (g_slice_new_array0 (T,c))
 #define FREE_ARRAY(p,c) (g_slice_free1 (sizeof(*p)*(c),(p)))
-#else
-#define ALLOC_ARRAY(T,c) (g_new0 (T,c))
-#define FREE_ARRAY(p,c)  (g_free ((p)))
-#endif
 
 static char * pascal_string_from_c_string(const char *s){
 	char *o=NULL;
diff --git a/plugins/excelplugins/excelplugins.c b/plugins/excelplugins/excelplugins.c
index 93dd1ef..de53ed5 100644
--- a/plugins/excelplugins/excelplugins.c
+++ b/plugins/excelplugins/excelplugins.c
@@ -50,14 +50,9 @@
 #include <sys/mman.h>
 #endif
 
-#if defined( HAVE_G_SLICE_ALLOC )
 #define g_slice_new_array0(T,c) ((T*) g_slice_alloc0 ((sizeof (T))*(c)))
 #define ALLOC_ARRAY(T,c) ( g_slice_new_array0 (T,c) )
 #define FREE_ARRAY(p,c)  ( g_slice_free1 (sizeof(*p)*(c),(p)) )
-#else
-#define ALLOC_ARRAY(T,c) ( g_new0 (T,c) )
-#define FREE_ARRAY(p,c)  ( g_free ((p)) )
-#endif
 
 GNM_PLUGIN_MODULE_HEADER;
 
diff --git a/src/dependent.c b/src/dependent.c
index 6f5c644..7149ec1 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -52,11 +52,7 @@ static void dependent_changed (GnmDependent *dep);
  */
 
 #ifndef USE_STRING_POOLS
-#ifdef HAVE_G_SLICE_ALLOC
 #define USE_POOLS 0
-#else
-#define USE_POOLS 1
-#endif
 #endif
 
 #if USE_POOLS
@@ -68,19 +64,11 @@ static GOMemChunk *cset_pool;
 #define NEW_FEW CHUNK_ALLOC (gpointer, micro_few_pool)
 #define FREE_FEW(p) CHUNK_FREE (micro_few_pool, p)
 #else
-#ifdef HAVE_G_SLICE_ALLOC
 #define CHUNK_ALLOC(T,c) g_slice_new (T)
 #define CHUNK_FREE(p,v) g_slice_free1 (sizeof(*v),(v))
 #define MICRO_HASH_FEW 4 /* Even and small. */
 #define NEW_FEW (gpointer *)g_slice_alloc (MICRO_HASH_FEW * sizeof (gpointer))
 #define FREE_FEW(p) g_slice_free1 (MICRO_HASH_FEW * sizeof (gpointer), p)
-#else
-#define CHUNK_ALLOC(T,c) g_new (T,1)
-#define CHUNK_FREE(p,v) g_free ((v))
-#define MICRO_HASH_FEW 3 /* Who cares?  */
-#define NEW_FEW g_new (gpointer, MICRO_HASH_FEW)
-#define FREE_FEW(p) CHUNK_FREE (micro_few_pool, p)
-#endif
 #endif
 
 /* ------------------------------------------------------------------------- */
diff --git a/src/func.c b/src/func.c
index 3dd0938..cd74ea3 100644
--- a/src/func.c
+++ b/src/func.c
@@ -963,6 +963,14 @@ gnm_func_lookup (char const *name, Workbook *scope)
 	return g_hash_table_lookup (scope->sheet_local_functions, (gpointer)name);
 }
 
+GSList *
+gnm_func_lookup_prefix   (char const *prefix, Workbook *scope)
+{
+	GSList *list = symbol_names (global_symbol_table, NULL, prefix);
+	
+	return list;
+}
+
 GnmFunc *
 gnm_func_add (GnmFuncGroup *fn_group,
 	      GnmFuncDescriptor const *desc,
diff --git a/src/func.h b/src/func.h
index 1aecd99..7340043 100644
--- a/src/func.h
+++ b/src/func.h
@@ -230,6 +230,7 @@ char const *gnm_func_get_name	     (GnmFunc const *fn_def);
 gpointer    gnm_func_get_user_data   (GnmFunc const *func);
 void        gnm_func_set_user_data   (GnmFunc *func, gpointer user_data);
 GnmFunc	   *gnm_func_lookup	     (char const *name, Workbook *scope);	/* change scope one day */
+GSList	   *gnm_func_lookup_prefix   (char const *prefix, Workbook *scope);
 GnmFunc    *gnm_func_add	     (GnmFuncGroup *group,
 				      GnmFuncDescriptor const *descriptor,
 				      const char *textdomain);
diff --git a/src/rendered-value.c b/src/rendered-value.c
index aad915b..c538bab 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -46,11 +46,7 @@
 #undef DEBUG_BOUNDING_BOX
 
 #ifndef USE_RV_POOLS
-#ifdef HAVE_G_SLICE_ALLOC
 #define USE_RV_POOLS 0
-#else
-#define USE_RV_POOLS 1
-#endif
 #endif
 
 #if USE_RV_POOLS
@@ -61,13 +57,8 @@ static GOMemChunk *rendered_rotated_value_pool;
 #define CHUNK_FREE(p,v) go_mem_chunk_free ((p), (v))
 #else
 static int rv_allocations;
-#ifdef HAVE_G_SLICE_ALLOC
 #define CHUNK_ALLOC(T,c) (rv_allocations++, g_slice_new (T))
 #define CHUNK_FREE(p,v) (rv_allocations--, g_slice_free1 (sizeof(*v),(v)))
-#else
-#define CHUNK_ALLOC(T,c) (rv_allocations++, g_new (T,1))
-#define CHUNK_FREE(p,v) (rv_allocations--, g_free ((v)))
-#endif
 #endif
 
 
diff --git a/src/symbol.c b/src/symbol.c
index af4f596..f30c35e 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -1,3 +1,4 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * Symbol management for the Gnumeric spreadsheet
  *
@@ -30,6 +31,22 @@ symbol_lookup (SymbolTable *st, char const *str)
 	return sym;
 }
 
+GSList *
+symbol_names (SymbolTable *st, GSList *list, char const *prefix)
+{
+#ifdef HAVE_G_HASH_TABLE_GET_KEYS
+	GList *l = g_hash_table_get_keys (st->hash), *lc;
+
+	for (lc = l; lc != NULL; lc = lc->next) {
+		if (g_str_has_prefix (lc->data, prefix))
+			list = g_slist_prepend (list, lc->data);
+	}
+	g_list_free (l);
+#endif
+	return list;
+}
+
+
 /**
  * symbol_install:
  *
diff --git a/src/symbol.h b/src/symbol.h
index d50a119..aba32e9 100644
--- a/src/symbol.h
+++ b/src/symbol.h
@@ -26,6 +26,7 @@ void         symbol_table_destroy  (SymbolTable *st);
 Symbol      *symbol_lookup         (SymbolTable *st, char const *str);
 Symbol      *symbol_install        (SymbolTable *st, char const *str,
 				    SymbolType type, void *data);
+GSList      *symbol_names (SymbolTable *st, GSList *list, char const *prefix);
 
 void         symbol_ref            (Symbol *sym);
 void         symbol_unref          (Symbol *sym);
diff --git a/src/tools/ChangeLog b/src/tools/ChangeLog
index fb3be8e..affbcb0 100644
--- a/src/tools/ChangeLog
+++ b/src/tools/ChangeLog
@@ -1,3 +1,7 @@
+2010-07-19 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dao.c: delete HAVE_G_DATE_SET_TIME_T throughout 
+
 2010-07-12  Jean Brefort  <jean brefort normalesup org>
 
 	* Makefile.am: install a self-consistent headers list.
diff --git a/src/tools/dao.c b/src/tools/dao.c
index 561b267..8e2ff34 100644
--- a/src/tools/dao.c
+++ b/src/tools/dao.c
@@ -974,15 +974,8 @@ dao_append_date (GString *buf)
 	gchar     *tmp;
 	time_t    now;
 
-#ifdef HAVE_G_DATE_SET_TIME_T
 	now = time (NULL);
 	g_date_set_time_t (&date, now);
-#else
-	GTimeVal  t;
-	g_get_current_time (&t);
-	now = t.tv_sec;
-	g_date_set_time (&date, t.tv_sec);
-#endif
 	g_date_to_struct_tm (&date, &tm_s);
 	tm_s.tm_sec  = now % 60;
 	tm_s.tm_min  = (now / 60) % 60;
diff --git a/src/value.c b/src/value.c
index 7f43b64..b537b80 100644
--- a/src/value.c
+++ b/src/value.c
@@ -34,11 +34,7 @@
 #include <string.h>
 
 #ifndef USE_VALUE_POOLS
-#ifdef HAVE_G_SLICE_ALLOC
 #define USE_VALUE_POOLS 0
-#else
-#define USE_VALUE_POOLS 1
-#endif
 #endif
 
 #if USE_VALUE_POOLS
@@ -51,13 +47,8 @@ static GOMemChunk *value_array_pool;
 #define CHUNK_FREE(p,v) go_mem_chunk_free ((p), (v))
 #else
 static int value_allocations = 0;
-#ifdef HAVE_G_SLICE_ALLOC
 #define CHUNK_ALLOC(T,c) (value_allocations++, g_slice_new (T))
 #define CHUNK_FREE(p,v) (value_allocations--, g_slice_free1 (sizeof(*v),(v)))
-#else
-#define CHUNK_ALLOC(T,c) (value_allocations++, g_new (T,1))
-#define CHUNK_FREE(p,v) (value_allocations--, g_free ((v)))
-#endif
 #endif
 
 
diff --git a/src/widgets/ChangeLog b/src/widgets/ChangeLog
index 449992f..0ae341f 100644
--- a/src/widgets/ChangeLog
+++ b/src/widgets/ChangeLog
@@ -1,5 +1,13 @@
 2010-07-19  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* gnumeric-expr-entry.c (gee_set_tooltip): We can have a tooltip without
+	  function descriptor
+	(gee_set_tooltip_completion): new
+	(gee_check_tooltip): if we are typing what might be a function name
+	  provide suggestions
+
+2010-07-19  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* gnumeric-expr-entry.c (gee_check_tooltip): fix the check for unclosed
 	  strings.
 	
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index 7429bbf..0a05dba 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -45,6 +45,7 @@
 #define UNICODE_RIGHT_TRIANGLE "\xe2\x96\xb6"
 #define UNICODE_CROSS_AND_SKULLBONES "\xe2\x98\xa0"
 #define UNICODE_ELLIPSIS "\xe2\x80\xa6"
+#define UNICODE_ELLIPSIS_VERT "\xe2\x8b\xae"
 
 #warning We should replace these token names with the correct values
    enum yytokentype {
@@ -687,12 +688,11 @@ gee_set_tooltip (GnmExprEntry *gee, GnmFunc *fd, gint args, gboolean had_stuff)
 	gnm_func_load_if_stub (fd);
 	function_def_count_args (fd, &min, &max);
 
-	if (gee->tooltip.fd) {
-		if (gee->tooltip.fd == fd && gee->tooltip.args == args
-		    && gee->tooltip.had_stuff == (max == 0 && args == 0 && had_stuff))
+	if ((gee->tooltip.fd) 
+	    && (gee->tooltip.fd == fd && gee->tooltip.args == args
+		&& gee->tooltip.had_stuff == (max == 0 && args == 0 && had_stuff)))
 			return;
-		gee_delete_tooltip (gee);
-	}
+	gee_delete_tooltip (gee);
 
 	gee->tooltip.fd = fd;
 	gnm_func_ref (gee->tooltip.fd);
@@ -753,6 +753,32 @@ gee_set_tooltip (GnmExprEntry *gee, GnmFunc *fd, gint args, gboolean had_stuff)
 }
 
 static void
+gee_set_tooltip_completion (GnmExprEntry *gee, GSList *list)
+{
+	GString *str;
+	guint i = 0;
+	guint max = 10;
+
+	gee_delete_tooltip (gee);
+
+	str = g_string_new (NULL);
+	while (list != NULL) {
+		g_string_append (str, list->data);
+		i++;
+		list = list->next;
+		if (list != NULL) {
+			g_string_append_c (str, '\n');
+			if (i == max) {
+				g_string_append (str, UNICODE_ELLIPSIS_VERT);
+				break;
+			}
+		}
+	}
+	gee->tooltip.tooltip = gee_create_tooltip (gee, str->str);
+	g_string_free (str, TRUE);
+}
+
+static void
 gee_dump_lexer (GnmLexerItem *gli) {
 	g_print ("************\n");
 	do {
@@ -807,6 +833,29 @@ gee_check_tooltip (GnmExprEntry *gee)
 	}
 	gli--;
 
+	/* This creates the completion tooltip */
+	if (gli->start > 0 && gli->token == STRING) {
+		gint start_t = gli->start;
+		gint end_t = gli->end;
+		if (end_t - start_t > 1) {
+			char *prefix = g_strndup (str + start_t, 
+						  end_t - start_t);
+			GSList *list = gnm_func_lookup_prefix 
+				(prefix, gee->sheet->workbook);
+			g_free (prefix);
+			if (list != NULL) {
+				list = g_slist_sort 
+					(list, 
+					 (GCompareFunc)g_utf8_collate);
+				gee_set_tooltip_completion (gee, list);
+				g_slist_free (list);
+				g_free (str);
+				g_free (gli_c);
+				return;
+			}
+		}
+	}
+
 	while (gli->start > 1) {
 		switch (gli->token) {
 		case TOKEN_PARENTHESIS_OPEN:



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