[gnumeric] improve function name completion tooltips
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] improve function name completion tooltips
- Date: Wed, 21 Jul 2010 06:38:01 +0000 (UTC)
commit 5d1eac965dea2a07dee34a974a8e1143cd6f27d0
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Wed Jul 21 00:38:50 2010 -0600
improve function name completion tooltips
2010-07-21 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/func.c (gnm_func_get_description): new
* src/func.h (gnm_func_get_description): new
* src/symbol.c (symbol_names_cb): new
(symbol_names): rewrite to work in gtk 2.12 and to provide more info
2010-07-21 Andreas J. Guelzow <aguelzow pyrshep ca>
* gnumeric-expr-entry.c (gee_create_tooltip): add argument
(gee_set_tooltip_completion): create the tooltip in 2 parts, function
names with description and instructions
(gee_check_tooltip): the list now contains function descriptors
ChangeLog | 8 ++++-
NEWS | 3 +-
src/dialogs/ChangeLog | 1 +
src/func.c | 28 ++++++++++++++++
src/func.h | 1 +
src/symbol.c | 32 +++++++++++++-----
src/widgets/ChangeLog | 7 ++++
src/widgets/gnumeric-expr-entry.c | 64 +++++++++++++++++++++++++-----------
8 files changed, 112 insertions(+), 32 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 861fbd4..38655e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-07-21 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/func.c (gnm_func_get_description): new
+ * src/func.h (gnm_func_get_description): new
+ * src/symbol.c (symbol_names_cb): new
+ (symbol_names): rewrite to work in gtk 2.12 and to provide more info
+
2010-07-20 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/wbc-gtk-actions.c (cb_help_function): use
@@ -21,7 +28,6 @@
* 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/NEWS b/NEWS
index f47b760..6ff7e25 100644
--- a/NEWS
+++ b/NEWS
@@ -40,8 +40,7 @@ Andreas:
* Allow single merge to single merge copying. [#87296]
* Make the font style buttons override the character attributes.
[#163410]
- * Provide completion when entering functions (when using gtk 2.14
- or newer). [#587084]
+ * Provide name completion (F4) when entering functions. [#587084]
* Implement access to the function selector to paste function names
while editing cells (Shift-F4).
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 4a1dec7..34152d5 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -2,6 +2,7 @@
* dialogs.h (dialog_function_select_paste): add arguments
* dialog-function-select.c (dialog_function_select_paste): add arguments
+
2010-07-20 Andreas J. Guelzow <aguelzow pyrshep ca>
* dialog-define-names.c (name_guru_init): set the window title for the
diff --git a/src/func.c b/src/func.c
index cd74ea3..2469351 100644
--- a/src/func.c
+++ b/src/func.c
@@ -1163,6 +1163,34 @@ gnm_func_get_name (GnmFunc const *func)
}
/**
+ * gnm_func_get_description:
+ * @fn_def: the fn defintion
+ *
+ * Return value: the description of the function
+ *
+ **/
+char const*
+gnm_func_get_description (GnmFunc const *fn_def)
+{
+ gint i;
+ g_return_val_if_fail (fn_def != NULL, NULL);
+
+ gnm_func_load_if_stub ((GnmFunc *)fn_def);
+
+ if (fn_def->help != NULL)
+ for (i = 0;
+ fn_def->help[i].type != GNM_FUNC_HELP_END;
+ i++) {
+ if (fn_def->help[i].type == GNM_FUNC_HELP_NAME) {
+ gchar const *desc;
+ desc = strchr (_(fn_def->help[i].text), ':');
+ return desc ? (desc + 1) : "";
+ }
+ }
+ return "";
+}
+
+/**
* function_def_count_args:
* @func: pointer to function definition
* @min: pointer to min. args
diff --git a/src/func.h b/src/func.h
index 7340043..7516b22 100644
--- a/src/func.h
+++ b/src/func.h
@@ -248,6 +248,7 @@ GnmFunc *gnm_func_lookup_or_add_placeholder
gboolean copy_name);
/* TODO */
+char const *gnm_func_get_description (GnmFunc const *fn_def);
void function_def_count_args (GnmFunc const *fn_def,
gint *min, int *max);
char function_def_get_arg_type (GnmFunc const *fn_def,
diff --git a/src/symbol.c b/src/symbol.c
index f30c35e..6d165d4 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -8,6 +8,7 @@
#include <gnumeric-config.h>
#include "gnumeric.h"
#include "symbol.h"
+#include "func.h"
#include "gutils.h"
@@ -31,19 +32,32 @@ symbol_lookup (SymbolTable *st, char const *str)
return sym;
}
+typedef struct {
+ char const *prefix;
+ GSList *list;
+} symbol_names_cb_t;
+
+static void
+symbol_names_cb (char const * key, Symbol *symbol, symbol_names_cb_t *data)
+{
+ if (g_str_has_prefix (key, data->prefix)) {
+ gnm_func_ref ((GnmFunc*)symbol->data);
+ data->list = g_slist_prepend (data->list, symbol->data);
+ }
+}
+
+/* returns a list of reffed GnmFunc* */
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_names_cb_t data;
+
+ data.list = list;
+ data.prefix = prefix;
+ g_hash_table_foreach (st->hash,
+ (GHFunc) symbol_names_cb,
+ &data);
+ return data.list;
}
diff --git a/src/widgets/ChangeLog b/src/widgets/ChangeLog
index 308fa35..bf4fe4d 100644
--- a/src/widgets/ChangeLog
+++ b/src/widgets/ChangeLog
@@ -1,3 +1,10 @@
+2010-07-21 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * gnumeric-expr-entry.c (gee_create_tooltip): add argument
+ (gee_set_tooltip_completion): create the tooltip in 2 parts, function
+ names with description and instructions
+ (gee_check_tooltip): the list now contains function descriptors
+
2010-07-20 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 b9900ad..711bdc9 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -47,6 +47,7 @@
#define UNICODE_CROSS_AND_SKULLBONES "\xe2\x98\xa0"
#define UNICODE_ELLIPSIS "\xe2\x80\xa6"
#define UNICODE_ELLIPSIS_VERT "\xe2\x8b\xae"
+#define UNICODE_ARROW_UP "\xe2\x87\xa7"
#warning We should replace these token names with the correct values
enum yytokentype {
@@ -644,13 +645,15 @@ cb_gee_focus_out_event (GtkWidget *widget,
gpointer user_data);
static GtkWidget *
-gee_create_tooltip (GnmExprEntry *gee, gchar const *str)
+gee_create_tooltip (GnmExprEntry *gee, gchar const *str,
+ gchar const *marked_str)
{
GtkWidget *toplevel, *label, *tip;
gint root_x = 0, root_y = 0;
GtkAllocation allocation;
GdkWindow *gdkw;
- gchar *markup = gnm_func_convert_markup_to_pango (str);
+ gchar *markup = NULL;
+ GString *string;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (gee->entry));
gtk_widget_add_events(toplevel, GDK_FOCUS_CHANGE_MASK);
@@ -662,8 +665,14 @@ gee_create_tooltip (GnmExprEntry *gee, gchar const *str)
label = gnumeric_create_tooltip (toplevel);
tip = gtk_widget_get_toplevel (label);
- gtk_label_set_markup (GTK_LABEL (label), markup);
+ if (str)
+ markup = gnm_func_convert_markup_to_pango (str);
+ string = g_string_new (markup);
+ if (marked_str)
+ g_string_append (string, marked_str);
+ gtk_label_set_markup (GTK_LABEL (label), string->str);
g_free (markup);
+ g_string_free (string, TRUE);
gdkw = gtk_widget_get_window (GTK_WIDGET (gee->entry));
gdk_window_get_origin (gdkw, &root_x, &root_y);
@@ -755,7 +764,7 @@ gee_set_tooltip (GnmExprEntry *gee, GnmFunc *fd, gint args, gboolean had_stuff)
g_free (extra);
}
- gee->tooltip.tooltip = gee_create_tooltip (gee, str->str);
+ gee->tooltip.tooltip = gee_create_tooltip (gee, str->str, NULL);
gee->tooltip.args = args;
gee->tooltip.had_stuff = (max == 0 && args == 0 && had_stuff);
@@ -766,6 +775,7 @@ static void
gee_set_tooltip_completion (GnmExprEntry *gee, GSList *list, guint start, guint end)
{
GString *str;
+ GString *str_marked;
guint i = 0;
guint max = 10;
GSList *list_c = list;
@@ -773,28 +783,35 @@ gee_set_tooltip_completion (GnmExprEntry *gee, GSList *list, guint start, guint
gee_delete_tooltip (gee, TRUE);
str = g_string_new (NULL);
- while (list_c != NULL) {
- g_string_append (str, list_c->data);
- i++;
- list_c = list_c->next;
- if (list_c != NULL) {
- g_string_append_c (str, '\n');
- if (i == max) {
- g_string_append (str, UNICODE_ELLIPSIS_VERT);
- break;
- }
- }
+ for (; list_c != NULL && i < max; list_c = list_c->next, i++) {
+ GnmFunc *fd = list_c->data;
+ /* xgettext: the first %s is a function name and */
+ /* the second %s the function description */
+ g_string_append_printf (str, _("%s : %s\n"),
+ gnm_func_get_name (fd),
+ gnm_func_get_description (fd));
}
+
+ str_marked = g_string_new (NULL);
+ if (i == max)
+ g_string_append (str_marked, UNICODE_ELLIPSIS_VERT "\n");
if (i == 1) {
g_free (gee->tooltip.completion);
- gee->tooltip.completion = g_strdup (list->data);
- }
+ gee->tooltip.completion
+ = g_strdup (gnm_func_get_name (list->data));
+ /*xgettext: short form for: "type F4-key to complete the name"*/
+ g_string_append (str_marked, _("\n<i>F4 to complete</i>"));
+ } else
+ /*xgettext: short form for: "type shift-F4-keys to select the completion"*/
+ g_string_append (str_marked, _("\n<i>" UNICODE_ARROW_UP "F4 to select</i>"));
gee->tooltip.completion_start = start;
gee->tooltip.completion_end = end;
gee->tooltip.completion_se_valid = TRUE;
- gee->tooltip.tooltip = gee_create_tooltip (gee, str->str);
+ gee->tooltip.tooltip = gee_create_tooltip
+ (gee, str->str, str_marked->str);
g_string_free (str, TRUE);
- g_slist_free (list);
+ g_string_free (str_marked, TRUE);
+ go_slist_free_custom (list, (GFreeFunc) gnm_func_unref);
}
static void
@@ -808,6 +825,13 @@ gee_dump_lexer (GnmLexerItem *gli) {
}
+static int
+func_def_cmp (gconstpointer a, gconstpointer b)
+{
+ return g_utf8_collate (gnm_func_get_name (a),
+ gnm_func_get_name (b));
+}
+
static void
gee_check_tooltip (GnmExprEntry *gee)
{
@@ -877,7 +901,7 @@ gee_check_tooltip (GnmExprEntry *gee)
if (list != NULL) {
list = g_slist_sort
(list,
- (GCompareFunc)g_utf8_collate);
+ (GCompareFunc)func_def_cmp);
gee_set_tooltip_completion (gee, list, start_t, end_t);
g_free (str);
g_free (gli_c);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]