diff --git a/src/symbols.c b/src/symbols.c index 58451166eb..0d919dbd96 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -486,7 +486,8 @@ static void hide_empty_rows(GtkTreeStore *store) } -static const gchar *get_symbol_name(GeanyDocument *doc, const TMTag *tag, gboolean found_parent) +static const gchar *get_symbol_name(GeanyDocument *doc, const TMTag *tag, gboolean include_scope, + gboolean include_line) { gchar *utf8_name; const gchar *scope = tag->scope; @@ -517,7 +518,7 @@ static const gchar *get_symbol_name(GeanyDocument *doc, const TMTag *tag, gboole g_string_truncate(buffer, 0); /* check first char of scope is a wordchar */ - if (!found_parent && scope && + if (include_scope && scope && strpbrk(scope, GEANY_WORDCHARS) == scope) { const gchar *sep = tm_parser_scope_separator_printable(tag->lang); @@ -530,14 +531,15 @@ static const gchar *get_symbol_name(GeanyDocument *doc, const TMTag *tag, gboole if (! doc_is_utf8) g_free(utf8_name); - g_string_append_printf(buffer, " [%lu]", tag->line); + if (include_line) + g_string_append_printf(buffer, " [%lu]", tag->line); return buffer->str; } // Returns NULL if the tag is not a variable or callable -static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag) +static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag, gboolean include_scope) { gchar *utf8_name = tm_parser_format_function(tag->lang, tag->name, tag->arglist, tag->var_type, tag->scope); @@ -545,7 +547,8 @@ static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag) if (!utf8_name && tag->var_type && tag->type & (tm_tag_field_t | tm_tag_member_t | tm_tag_variable_t | tm_tag_externvar_t)) { - utf8_name = tm_parser_format_variable(tag->lang, tag->name, tag->var_type); + gchar *scope = include_scope ? tag->scope : NULL; + utf8_name = tm_parser_format_variable(tag->lang, tag->name, tag->var_type, scope); } /* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion @@ -949,8 +952,8 @@ static void update_tree_tags(GeanyDocument *doc, GList **tags) /* only update fields that (can) have changed (name that holds line * number, tooltip, and the tag itself) */ - name = get_symbol_name(doc, found, parent_name != NULL); - tooltip = get_symbol_tooltip(doc, found); + name = get_symbol_name(doc, found, parent_name == NULL, TRUE); + tooltip = get_symbol_tooltip(doc, found, FALSE); gtk_tree_store_set(store, &iter, SYMBOLS_COLUMN_NAME, name, SYMBOLS_COLUMN_TOOLTIP, tooltip, @@ -1006,8 +1009,8 @@ static void update_tree_tags(GeanyDocument *doc, GList **tags) expand = ! gtk_tree_model_iter_has_child(model, parent); /* insert the new element */ - name = get_symbol_name(doc, tag, parent_name != NULL); - tooltip = get_symbol_tooltip(doc, tag); + name = get_symbol_name(doc, tag, parent_name == NULL, TRUE); + tooltip = get_symbol_tooltip(doc, tag, FALSE); gtk_tree_store_insert_with_values(store, &iter, parent, 0, SYMBOLS_COLUMN_NAME, name, SYMBOLS_COLUMN_TOOLTIP, tooltip, @@ -1487,6 +1490,7 @@ static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_b { GtkWidget *first = NULL; GtkWidget *menu; + GtkSizeGroup *group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); GdkEvent *event; GdkEventButton *button_event = NULL; TMTag *tmtag; @@ -1506,24 +1510,36 @@ static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_b { GtkWidget *item; GtkWidget *label; + GtkWidget *box; GtkWidget *image; gchar *fname = short_names[i]; gchar *text; - gchar *sym = get_symbol_tooltip(doc, tmtag); + gchar *tooltip; + gchar *sym = get_symbol_tooltip(doc, tmtag, TRUE); + if (!sym) + sym = g_strdup(get_symbol_name(doc, tmtag, TRUE, FALSE)); if (!sym) sym = g_strdup(""); + if (! first && have_best) - /* For translators: it's the filename and line number of a symbol in the goto-symbol popup menu */ - text = g_markup_printf_escaped(_("%s:%lu: %s"), fname, tmtag->line, sym); + text = g_markup_printf_escaped("%s:%lu", fname, tmtag->line); else - /* For translators: it's the filename and line number of a symbol in the goto-symbol popup menu */ - text = g_markup_printf_escaped(_("%s:%lu: %s"), fname, tmtag->line, sym); + text = g_markup_printf_escaped("%s:%lu", fname, tmtag->line); + + tooltip = g_markup_printf_escaped("%s:%lu\n%s", fname, tmtag->line, sym); - g_free(sym); image = gtk_image_new_from_pixbuf(symbols_icons[get_tag_class(tmtag)].pixbuf); + box = g_object_new(GTK_TYPE_BOX, "orientation", GTK_ORIENTATION_HORIZONTAL, "spacing", 12, NULL); label = g_object_new(GTK_TYPE_LABEL, "label", text, "use-markup", TRUE, "xalign", 0.0, NULL); - item = g_object_new(GTK_TYPE_IMAGE_MENU_ITEM, "image", image, "child", label, "always-show-image", TRUE, NULL); + gtk_size_group_add_widget(group, label); + gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); + g_free(text); + text = g_markup_printf_escaped("%s", sym); + gtk_box_pack_start(GTK_BOX(box), g_object_new(GTK_TYPE_LABEL, "label", text, "use-markup", TRUE, "xalign", 0.0, + "max-width-chars", 80, "ellipsize", PANGO_ELLIPSIZE_END, NULL), FALSE, FALSE, 0); + item = g_object_new(GTK_TYPE_IMAGE_MENU_ITEM, "image", image, "child", box, "always-show-image", TRUE, + "tooltip-markup", tooltip, NULL); g_signal_connect_data(item, "activate", G_CALLBACK(on_goto_popup_item_activate), tm_tag_ref(tmtag), (GClosureNotify) tm_tag_unref, 0); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); @@ -1531,6 +1547,7 @@ static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_b if (! first) first = item; + g_free(sym); g_free(text); g_free(fname); } @@ -1551,6 +1568,8 @@ static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_b button_event ? (GDestroyNotify) gdk_event_free : NULL); ui_menu_popup(GTK_MENU(menu), goto_popup_position_func, doc->editor->sci, button_event ? button_event->button : 0, gtk_get_current_event_time ()); + + g_object_unref(group); } diff --git a/src/tagmanager/tm_parser.c b/src/tagmanager/tm_parser.c index 33465bfae1..5256f91d2b 100644 --- a/src/tagmanager/tm_parser.c +++ b/src/tagmanager/tm_parser.c @@ -1517,21 +1517,33 @@ gboolean tm_parser_enable_kind(TMParserType lang, gchar kind) } -gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type) +gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type, + const gchar *scope) { + gchar *ret, *name_full; + if (!type) return NULL; + if (scope) + name_full = g_strconcat(scope, tm_parser_scope_separator_printable(lang), + name, NULL); + else + name_full = g_strdup(name); + switch (lang) { case TM_PARSER_GO: - return g_strconcat(name, " ", type, NULL); + ret = g_strconcat(name_full, " ", type, NULL); case TM_PARSER_PASCAL: case TM_PARSER_PYTHON: - return g_strconcat(name, ": ", type, NULL); + ret = g_strconcat(name_full, ": ", type, NULL); default: - return g_strconcat(type, " ", name, NULL); + ret = g_strconcat(type, " ", name_full, NULL); } + + g_free(name_full); + return ret; } diff --git a/src/tagmanager/tm_parser.h b/src/tagmanager/tm_parser.h index 0d6e9f5524..64a8f9ff95 100644 --- a/src/tagmanager/tm_parser.h +++ b/src/tagmanager/tm_parser.h @@ -161,7 +161,8 @@ gboolean tm_parser_enable_role(TMParserType lang, gchar kind); gboolean tm_parser_enable_kind(TMParserType lang, gchar kind); -gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type); +gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type, + const gchar *scope); gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gchar *args, const gchar *retval, const gchar *scope);