Kaydet (Commit) 7d460fdf authored tarafından Enrico Tröger's avatar Enrico Tröger

Show icons in the toolbar editor.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3989 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 59731358
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* src/toolbar.c: * src/toolbar.c:
Display item labels instead of raw names in the toolbar editor. Display item labels instead of raw names in the toolbar editor.
Apply changes in the toolbar editor instantly. Apply changes in the toolbar editor instantly.
Show icons in the toolbar editor.
2009-07-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> 2009-07-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
......
...@@ -548,6 +548,7 @@ enum ...@@ -548,6 +548,7 @@ enum
{ {
TB_EDITOR_COL_ACTION, TB_EDITOR_COL_ACTION,
TB_EDITOR_COL_LABEL, TB_EDITOR_COL_LABEL,
TB_EDITOR_COL_ICON,
TB_EDITOR_COLS_MAX TB_EDITOR_COLS_MAX
}; };
...@@ -591,32 +592,42 @@ static GSList *tb_editor_parse_ui(const gchar *buffer, gssize length, GError **e ...@@ -591,32 +592,42 @@ static GSList *tb_editor_parse_ui(const gchar *buffer, gssize length, GError **e
} }
static gchar *tb_editor_get_action_label(const gchar *action_name) static void tb_editor_set_item_values(const gchar *name, GtkListStore *store, GtkTreeIter *iter)
{ {
gchar *label, *label_clean; gchar *icon = NULL;
gchar *label = NULL;
gchar *label_clean = NULL;
GtkAction *action; GtkAction *action;
action = gtk_action_group_get_action(group, action_name); action = gtk_action_group_get_action(group, name);
if (action == NULL) if (action == NULL)
{ {
if (utils_str_equal(action_name, TB_EDITOR_SEPARATOR)) if (utils_str_equal(name, TB_EDITOR_SEPARATOR))
label = g_strdup(TB_EDITOR_SEPARATOR_LABEL); label_clean = g_strdup(TB_EDITOR_SEPARATOR_LABEL);
else else
return NULL; return;
} }
else else
{ {
g_object_get(action, "label", &label, NULL); g_object_get(action, "icon-name", &icon, NULL);
if (label == NULL) if (icon == NULL)
return NULL; g_object_get(action, "stock-id", &icon, NULL);
}
g_object_get(action, "label", &label, NULL);
if (label != NULL)
/* FIXME strip mnemonics here */ /* FIXME strip mnemonics here */
label_clean = g_strdup(label); label_clean = g_strdup(label);
}
g_free(label); gtk_list_store_set(store, iter,
TB_EDITOR_COL_ACTION, name,
TB_EDITOR_COL_LABEL, label_clean,
TB_EDITOR_COL_ICON, icon,
-1);
return label_clean; g_free(icon);
g_free(label);
g_free(label_clean);
} }
...@@ -643,7 +654,7 @@ static void tb_editor_btn_remove_clicked_cb(GtkWidget *button, TBEditorWidget *t ...@@ -643,7 +654,7 @@ static void tb_editor_btn_remove_clicked_cb(GtkWidget *button, TBEditorWidget *t
GtkTreeModel *model_used; GtkTreeModel *model_used;
GtkTreeSelection *selection_used; GtkTreeSelection *selection_used;
GtkTreeIter iter_used, iter_new; GtkTreeIter iter_used, iter_new;
gchar *action_name, *label; gchar *action_name;
selection_used = gtk_tree_view_get_selection(tbw->tree_used); selection_used = gtk_tree_view_get_selection(tbw->tree_used);
if (gtk_tree_selection_get_selected(selection_used, &model_used, &iter_used)) if (gtk_tree_selection_get_selected(selection_used, &model_used, &iter_used))
...@@ -654,13 +665,9 @@ static void tb_editor_btn_remove_clicked_cb(GtkWidget *button, TBEditorWidget *t ...@@ -654,13 +665,9 @@ static void tb_editor_btn_remove_clicked_cb(GtkWidget *button, TBEditorWidget *t
if (! utils_str_equal(action_name, TB_EDITOR_SEPARATOR)) if (! utils_str_equal(action_name, TB_EDITOR_SEPARATOR))
{ {
label = tb_editor_get_action_label(action_name); gtk_list_store_append(tbw->store_available, &iter_new);
gtk_list_store_insert_with_values(tbw->store_available, &iter_new, 1, tb_editor_set_item_values(action_name, tbw->store_available, &iter_new);
TB_EDITOR_COL_ACTION, action_name,
TB_EDITOR_COL_LABEL, label,
-1);
tb_editor_scroll_to_iter(tbw->tree_available, &iter_new); tb_editor_scroll_to_iter(tbw->tree_available, &iter_new);
g_free(label);
} }
g_free(action_name); g_free(action_name);
...@@ -673,7 +680,7 @@ static void tb_editor_btn_add_clicked_cb(GtkWidget *button, TBEditorWidget *tbw) ...@@ -673,7 +680,7 @@ static void tb_editor_btn_add_clicked_cb(GtkWidget *button, TBEditorWidget *tbw)
GtkTreeModel *model_available; GtkTreeModel *model_available;
GtkTreeSelection *selection_available, *selection_used; GtkTreeSelection *selection_available, *selection_used;
GtkTreeIter iter_available, iter_new, iter_selected; GtkTreeIter iter_available, iter_new, iter_selected;
gchar *action_name, *label; gchar *action_name;
selection_available = gtk_tree_view_get_selection(tbw->tree_available); selection_available = gtk_tree_view_get_selection(tbw->tree_available);
if (gtk_tree_selection_get_selected(selection_available, &model_available, &iter_available)) if (gtk_tree_selection_get_selected(selection_available, &model_available, &iter_available))
...@@ -687,24 +694,14 @@ static void tb_editor_btn_add_clicked_cb(GtkWidget *button, TBEditorWidget *tbw) ...@@ -687,24 +694,14 @@ static void tb_editor_btn_add_clicked_cb(GtkWidget *button, TBEditorWidget *tbw)
} }
selection_used = gtk_tree_view_get_selection(tbw->tree_used); selection_used = gtk_tree_view_get_selection(tbw->tree_used);
label = tb_editor_get_action_label(action_name);
if (gtk_tree_selection_get_selected(selection_used, NULL, &iter_selected)) if (gtk_tree_selection_get_selected(selection_used, NULL, &iter_selected))
{
gtk_list_store_insert_before(tbw->store_used, &iter_new, &iter_selected); gtk_list_store_insert_before(tbw->store_used, &iter_new, &iter_selected);
gtk_list_store_set(tbw->store_used, &iter_new,
TB_EDITOR_COL_ACTION, action_name,
TB_EDITOR_COL_LABEL, label,
-1);
}
else else
gtk_list_store_insert_with_values(tbw->store_used, &iter_new, -1, gtk_list_store_append(tbw->store_used, &iter_new);
TB_EDITOR_COL_ACTION, action_name,
TB_EDITOR_COL_LABEL, label,
-1);
tb_editor_set_item_values(action_name, tbw->store_used, &iter_new);
tb_editor_scroll_to_iter(tbw->tree_used, &iter_new); tb_editor_scroll_to_iter(tbw->tree_used, &iter_new);
g_free(label);
g_free(action_name); g_free(action_name);
} }
} }
...@@ -772,7 +769,6 @@ static void tb_editor_drag_data_rcvd_cb(GtkWidget *widget, GdkDragContext *conte ...@@ -772,7 +769,6 @@ static void tb_editor_drag_data_rcvd_cb(GtkWidget *widget, GdkDragContext *conte
{ {
GtkTreeIter iter, iter_before, *iter_before_ptr; GtkTreeIter iter, iter_before, *iter_before_ptr;
GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(tree)); GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(tree));
gchar *label = tb_editor_get_action_label(text);
if (tbw->last_drag_path != NULL) if (tbw->last_drag_path != NULL)
{ {
...@@ -788,20 +784,12 @@ static void tb_editor_drag_data_rcvd_cb(GtkWidget *widget, GdkDragContext *conte ...@@ -788,20 +784,12 @@ static void tb_editor_drag_data_rcvd_cb(GtkWidget *widget, GdkDragContext *conte
gtk_list_store_insert_before(store, &iter, iter_before_ptr); gtk_list_store_insert_before(store, &iter, iter_before_ptr);
else else
gtk_list_store_insert_after(store, &iter, iter_before_ptr); gtk_list_store_insert_after(store, &iter, iter_before_ptr);
gtk_list_store_set(store, &iter,
TB_EDITOR_COL_ACTION, text,
TB_EDITOR_COL_LABEL, label,
-1);
} }
else else
gtk_list_store_insert_with_values(store, &iter, -1, gtk_list_store_append(store, &iter);
TB_EDITOR_COL_ACTION, text,
TB_EDITOR_COL_LABEL, label,
-1);
tb_editor_set_item_values(text, store, &iter);
tb_editor_scroll_to_iter(tree, &iter); tb_editor_scroll_to_iter(tree, &iter);
g_free(label);
} }
if (tree != tbw->tree_used || ! is_sep) if (tree != tbw->tree_used || ! is_sep)
del = TRUE; del = TRUE;
...@@ -877,7 +865,7 @@ static TBEditorWidget *tb_editor_create_dialog(void) ...@@ -877,7 +865,7 @@ static TBEditorWidget *tb_editor_create_dialog(void)
{ {
GtkWidget *dialog, *vbox, *hbox, *vbox_buttons, *button_add, *button_remove; GtkWidget *dialog, *vbox, *hbox, *vbox_buttons, *button_add, *button_remove;
GtkWidget *swin_available, *swin_used, *tree_available, *tree_used, *label; GtkWidget *swin_available, *swin_used, *tree_available, *tree_used, *label;
GtkCellRenderer *text_renderer; GtkCellRenderer *text_renderer, *icon_renderer;
GtkTreeViewColumn *column; GtkTreeViewColumn *column;
TBEditorWidget *tbw = g_new(TBEditorWidget, 1); TBEditorWidget *tbw = g_new(TBEditorWidget, 1);
...@@ -891,8 +879,10 @@ static TBEditorWidget *tb_editor_create_dialog(void) ...@@ -891,8 +879,10 @@ static TBEditorWidget *tb_editor_create_dialog(void)
gtk_window_set_default_size(GTK_WINDOW(dialog), -1, 400); gtk_window_set_default_size(GTK_WINDOW(dialog), -1, 400);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);
tbw->store_available = gtk_list_store_new(TB_EDITOR_COLS_MAX, G_TYPE_STRING, G_TYPE_STRING); tbw->store_available = gtk_list_store_new(TB_EDITOR_COLS_MAX,
tbw->store_used = gtk_list_store_new(TB_EDITOR_COLS_MAX, G_TYPE_STRING, G_TYPE_STRING); G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
tbw->store_used = gtk_list_store_new(TB_EDITOR_COLS_MAX,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
label = gtk_label_new( label = gtk_label_new(
_("Select items to be displayed on the toolbar. Items can be reordered by drag and drop.")); _("Select items to be displayed on the toolbar. Items can be reordered by drag and drop."));
...@@ -904,6 +894,11 @@ static TBEditorWidget *tb_editor_create_dialog(void) ...@@ -904,6 +894,11 @@ static TBEditorWidget *tb_editor_create_dialog(void)
gtk_tree_sortable_set_sort_column_id( gtk_tree_sortable_set_sort_column_id(
GTK_TREE_SORTABLE(tbw->store_available), TB_EDITOR_COL_LABEL, GTK_SORT_ASCENDING); GTK_TREE_SORTABLE(tbw->store_available), TB_EDITOR_COL_LABEL, GTK_SORT_ASCENDING);
icon_renderer = gtk_cell_renderer_pixbuf_new();
column = gtk_tree_view_column_new_with_attributes(
NULL, icon_renderer, "stock-id", TB_EDITOR_COL_ICON, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree_available), column);
text_renderer = gtk_cell_renderer_text_new(); text_renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes( column = gtk_tree_view_column_new_with_attributes(
_("Available Items"), text_renderer, "text", TB_EDITOR_COL_LABEL, NULL); _("Available Items"), text_renderer, "text", TB_EDITOR_COL_LABEL, NULL);
...@@ -920,6 +915,11 @@ static TBEditorWidget *tb_editor_create_dialog(void) ...@@ -920,6 +915,11 @@ static TBEditorWidget *tb_editor_create_dialog(void)
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree_used), TRUE); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree_used), TRUE);
gtk_tree_view_set_reorderable(GTK_TREE_VIEW(tree_used), TRUE); gtk_tree_view_set_reorderable(GTK_TREE_VIEW(tree_used), TRUE);
icon_renderer = gtk_cell_renderer_pixbuf_new();
column = gtk_tree_view_column_new_with_attributes(
NULL, icon_renderer, "stock-id", TB_EDITOR_COL_ICON, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree_used), column);
text_renderer = gtk_cell_renderer_text_new(); text_renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes( column = gtk_tree_view_column_new_with_attributes(
_("Displayed Items"), text_renderer, "text", TB_EDITOR_COL_LABEL, NULL); _("Displayed Items"), text_renderer, "text", TB_EDITOR_COL_LABEL, NULL);
...@@ -997,10 +997,11 @@ static TBEditorWidget *tb_editor_create_dialog(void) ...@@ -997,10 +997,11 @@ static TBEditorWidget *tb_editor_create_dialog(void)
void toolbar_configure(void) void toolbar_configure(void)
{ {
gchar *markup, *label; gchar *markup;
const gchar *name; const gchar *name;
GSList *sl, *used_items; GSList *sl, *used_items;
GList *l, *all_items; GList *l, *all_items;
GtkTreeIter iter;
GtkTreePath *path; GtkTreePath *path;
TBEditorWidget *tbw; TBEditorWidget *tbw;
...@@ -1023,22 +1024,16 @@ void toolbar_configure(void) ...@@ -1023,22 +1024,16 @@ void toolbar_configure(void)
foreach_list(l, all_items) foreach_list(l, all_items)
{ {
name = gtk_action_get_name(l->data); name = gtk_action_get_name(l->data);
label = tb_editor_get_action_label(name);
if (g_slist_find_custom(used_items, name, (GCompareFunc) strcmp) == NULL) if (g_slist_find_custom(used_items, name, (GCompareFunc) strcmp) == NULL)
gtk_list_store_insert_with_values(tbw->store_available, NULL, -1, {
TB_EDITOR_COL_ACTION, name, gtk_list_store_append(tbw->store_available, &iter);
TB_EDITOR_COL_LABEL, label, tb_editor_set_item_values(name, tbw->store_available, &iter);
-1); }
g_free(label);
} }
foreach_slist(sl, used_items) foreach_slist(sl, used_items)
{ {
label = tb_editor_get_action_label(sl->data); gtk_list_store_append(tbw->store_used, &iter);
gtk_list_store_insert_with_values(tbw->store_used, NULL, -1, tb_editor_set_item_values(sl->data, tbw->store_used, &iter);
TB_EDITOR_COL_ACTION, sl->data,
TB_EDITOR_COL_LABEL, label,
-1);
g_free(label);
} }
/* select first item */ /* select first item */
path = gtk_tree_path_new_from_string("0"); path = gtk_tree_path_new_from_string("0");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment