Add editor_get_calltip_text().

Add tooltips for the symbol list items.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3288 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2008-11-29 12:50:52 +00:00
parent 7589d8a4e5
commit 13682cfd10
6 changed files with 49 additions and 4 deletions

View File

@ -4,6 +4,10 @@
Simplify the tooltips code for the Open Files treeview.
Change the dependency handling for GTK 2.12 for some features
from compile time to run time.
* src/editor.c, src/editor.h, src/symbols.c, src/treeviews.c,
src/treeviews.h:
Add editor_get_calltip_text().
Add tooltips for the symbol list items.
2008-11-28 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

View File

@ -1387,6 +1387,20 @@ gboolean editor_show_calltip(GeanyEditor *editor, gint pos)
}
gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag)
{
GString *str;
g_return_val_if_fail(editor != NULL, NULL);
str = g_string_new(NULL);
if (append_calltip(str, tag, FILETYPE_ID(editor->document->file_type)))
return g_string_free(str, FALSE);
else
return g_string_free(str, TRUE);
}
static void show_autocomplete(ScintillaObject *sci, gint rootlen, const gchar *words)
{
/* store whether a calltip is showing, so we can reshow it after autocompletion */

View File

@ -256,4 +256,6 @@ void editor_set_indentation_guides(GeanyEditor *editor);
void editor_apply_update_prefs(GeanyEditor *editor);
gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag);
#endif

View File

@ -831,8 +831,7 @@ 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 found_parent)
{
gchar *utf8_name;
const gchar *scope = tag->atts.entry.scope;
@ -879,6 +878,22 @@ static const gchar *get_symbol_name(GeanyDocument *doc, const TMTag *tag,
}
static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag)
{
gchar *utf8_name = editor_get_calltip_text(doc->editor, tag);
/* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion
* for None at this point completely */
if (! utils_str_equal(doc->encoding, "UTF-8") && ! utils_str_equal(doc->encoding, "None"))
{
setptr(utf8_name,
encodings_convert_to_utf8_from_charset(utf8_name, -1, doc->encoding, TRUE));
}
return utf8_name;
}
/* find the last word in "foo::bar::blah", e.g. "blah" */
const gchar *get_parent_name(const TMTag *tag, filetype_id ft_id)
{
@ -989,6 +1004,7 @@ static void add_tree_tag(GeanyDocument *doc, const TMTag *tag, GHashTable *paren
{
const gchar *name;
const gchar *parent_name = get_parent_name(tag, ft_id);
gchar *tooltip;
GtkTreeIter iter;
GtkTreeIter *icon_iter = NULL, *child = NULL;
GdkPixbuf *icon = NULL;
@ -1025,11 +1041,15 @@ static void add_tree_tag(GeanyDocument *doc, const TMTag *tag, GHashTable *paren
gtk_tree_store_append(tree_store, child, parent);
name = get_symbol_name(doc, tag, (parent_name != NULL));
tooltip = get_symbol_tooltip(doc, tag);
gtk_tree_store_set(tree_store, child,
SYMBOLS_COLUMN_ICON, icon,
SYMBOLS_COLUMN_NAME, name,
SYMBOLS_COLUMN_TAG, tag, -1);
SYMBOLS_COLUMN_TAG, tag,
SYMBOLS_COLUMN_TOOLTIP, tooltip,
-1);
g_free(tooltip);
if (G_LIKELY(G_IS_OBJECT(icon)))
g_object_unref(icon);
}

View File

@ -122,6 +122,10 @@ static void prepare_taglist(GtkWidget *tree, GtkTreeStore *store)
g_object_set(tree, "show-expanders", interface_prefs.show_symbol_list_expanders, NULL);
if (! interface_prefs.show_symbol_list_expanders)
g_object_set(tree, "level-indentation", 10, NULL);
/* Tooltips */
g_object_set(tree,
"has-tooltip", TRUE,
"tooltip-column", SYMBOLS_COLUMN_TOOLTIP, NULL);
}
/* selection handling */
@ -180,7 +184,7 @@ void treeviews_update_tag_list(GeanyDocument *doc, gboolean update)
if (doc->priv->tag_tree == NULL)
{
doc->priv->tag_store = gtk_tree_store_new(
SYMBOLS_N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
SYMBOLS_N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING);
doc->priv->tag_tree = gtk_tree_view_new();
prepare_taglist(doc->priv->tag_tree, doc->priv->tag_store);
gtk_widget_show(doc->priv->tag_tree);

View File

@ -42,6 +42,7 @@ enum
SYMBOLS_COLUMN_ICON,
SYMBOLS_COLUMN_NAME,
SYMBOLS_COLUMN_TAG,
SYMBOLS_COLUMN_TOOLTIP,
SYMBOLS_N_COLUMNS
};