Skip to content

Commit d5260de

Browse files
committed
commander: show icons
1 parent 1cb36da commit d5260de

File tree

1 file changed

+70
-6
lines changed

1 file changed

+70
-6
lines changed

commander/src/commander-plugin.c

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ enum {
127127
COL_DOCUMENT,
128128
COL_FILE,
129129
COL_LINE,
130+
COL_ICON,
130131
COL_COUNT
131132
};
132133

@@ -624,6 +625,27 @@ fill_store_project_files (GtkListStore *store)
624625
g_queue_free_full (file_queue, (GDestroyNotify) file_queue_item_free);
625626
}
626627

628+
static const gchar *
629+
get_symbol_icon (const TMTag *tag)
630+
{
631+
if (tag->type & tm_tag_struct_t)
632+
return "classviewer-struct";
633+
634+
if (tag->type & (tm_tag_class_t | tm_tag_interface_t))
635+
return "classviewer-class";
636+
637+
if (tag->type & (tm_tag_function_t | tm_tag_function_t))
638+
return "classviewer-method";
639+
640+
if (tag->type & (tm_tag_macro_t | tm_tag_macro_with_arg_t))
641+
return "classviewer-macro";
642+
643+
if (tag->type & tm_tag_variable_t)
644+
return "classviewer-var";
645+
646+
return "classviewer-other";
647+
}
648+
627649
static void
628650
fill_store_symbols (GtkListStore *store)
629651
{
@@ -671,6 +693,7 @@ fill_store_symbols (GtkListStore *store)
671693
COL_TYPE, COL_TYPE_SYMBOL,
672694
COL_FILE, tag->file->file_name,
673695
COL_LINE, tag->line,
696+
COL_ICON, get_symbol_icon (tag),
674697
-1);
675698

676699
g_free (name);
@@ -926,6 +949,37 @@ on_view_row_activated (GtkTreeView *view,
926949
}
927950
}
928951

952+
static void
953+
cell_icon_data (G_GNUC_UNUSED GtkTreeViewColumn *column,
954+
GtkCellRenderer *cell,
955+
GtkTreeModel *model,
956+
GtkTreeIter *iter,
957+
G_GNUC_UNUSED gpointer udata)
958+
{
959+
const gchar *icon_name;
960+
gint type;
961+
962+
gtk_tree_model_get (model, iter, COL_TYPE, &type, -1);
963+
964+
switch (type) {
965+
case COL_TYPE_FILE: {
966+
g_object_set (cell, "icon-name", "text-x-generic", NULL);
967+
break;
968+
}
969+
970+
case COL_TYPE_MENU_ITEM: {
971+
g_object_set (cell, "icon-name", "geany", NULL);
972+
break;
973+
}
974+
975+
case COL_TYPE_SYMBOL: {
976+
gtk_tree_model_get (model, iter, COL_ICON, &icon_name, -1);
977+
g_object_set (cell, "icon-name", icon_name, NULL);
978+
break;
979+
}
980+
}
981+
}
982+
929983
#ifdef DISPLAY_SCORE
930984
static void
931985
score_cell_data (GtkTreeViewColumn *column,
@@ -967,11 +1021,13 @@ score_cell_data (GtkTreeViewColumn *column,
9671021
static void
9681022
create_panel (void)
9691023
{
970-
GtkWidget *frame;
971-
GtkWidget *box;
972-
GtkWidget *scroll;
973-
GtkTreeViewColumn *col;
974-
GtkCellRenderer *cell;
1024+
GtkWidget *frame;
1025+
GtkWidget *box;
1026+
GtkWidget *scroll;
1027+
GtkTreeViewColumn *col_icon;
1028+
GtkTreeViewColumn *col;
1029+
GtkCellRenderer *cell_icon;
1030+
GtkCellRenderer *cell;
9751031

9761032
plugin_data.panel = g_object_new (GTK_TYPE_WINDOW,
9771033
"decorated", FALSE,
@@ -1009,7 +1065,8 @@ create_panel (void)
10091065
GTK_TYPE_WIDGET,
10101066
G_TYPE_POINTER,
10111067
G_TYPE_STRING,
1012-
G_TYPE_ULONG);
1068+
G_TYPE_ULONG,
1069+
G_TYPE_STRING);
10131070

10141071
plugin_data.sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (plugin_data.store));
10151072
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (plugin_data.sort),
@@ -1028,6 +1085,13 @@ create_panel (void)
10281085

10291086
/* eliminates graphic artifacts */
10301087
gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (plugin_data.view), TRUE);
1088+
1089+
cell_icon = gtk_cell_renderer_pixbuf_new ();
1090+
col_icon = gtk_tree_view_column_new_with_attributes (NULL, cell_icon, NULL);
1091+
gtk_tree_view_column_set_cell_data_func (col_icon, cell_icon, cell_icon_data, NULL, NULL);
1092+
gtk_tree_view_column_set_sizing (col_icon, GTK_TREE_VIEW_COLUMN_FIXED);
1093+
gtk_tree_view_append_column (GTK_TREE_VIEW (plugin_data.view), col_icon);
1094+
10311095
#ifdef DISPLAY_SCORE
10321096
cell = gtk_cell_renderer_text_new ();
10331097
col = gtk_tree_view_column_new_with_attributes (NULL, cell, NULL);

0 commit comments

Comments
 (0)