From 308ecd304d70dfac595b3caa64cbf4c9c6e3b5e2 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 20 Dec 2019 16:49:29 -0300 Subject: [PATCH] Adding available actions for toolbar edit. --- src/include/pw3270/actions.h | 1 + src/objects/actions/view.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------- src/objects/toolbar/settings.c | 6 ++++++ 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/src/include/pw3270/actions.h b/src/include/pw3270/actions.h index a47f6d8..a125a28 100644 --- a/src/include/pw3270/actions.h +++ b/src/include/pw3270/actions.h @@ -261,6 +261,7 @@ GtkWidget * pw3270_action_view_new(); Pw3270ActionList * pw3270_action_list_new(GtkApplication *application); void pw3270_action_list_free(Pw3270ActionList *action_list); + void pw3270_action_view_set_actions(GtkWidget *view, Pw3270ActionList *list); Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view); diff --git a/src/objects/actions/view.c b/src/objects/actions/view.c index 1735a3e..35bc199 100644 --- a/src/objects/actions/view.c +++ b/src/objects/actions/view.c @@ -51,7 +51,6 @@ static void list_element_free(struct ListElement *element); - GtkWidget * pw3270_action_view_new() { GtkWidget * view = GTK_WIDGET(gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtk_list_store_new(3,G_TYPE_OBJECT,G_TYPE_STRING,G_TYPE_STRING)))); @@ -60,7 +59,6 @@ gtk_widget_set_vexpand(view,TRUE); gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(view),FALSE); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view),FALSE); - gtk_tree_view_set_reorderable(GTK_TREE_VIEW(view),TRUE); // Create Renderers GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new(); @@ -87,54 +85,73 @@ return view; } - Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view) { + static void pw3270_action_view_append_element(GtkListStore * store, struct ListElement * element) { - GSList * item = (GSList *) action_list; - GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view))); + size_t ix; - while(item) { + struct Properties { + const gchar * name; + GType g_type; + GValue value; + } properties[] = { + { + .name = "label", + .g_type = G_TYPE_STRING, + .value = G_VALUE_INIT + } + }; - struct ListElement * element = (struct ListElement *) item->data; + for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { - if(!g_ascii_strcasecmp(action_name,element->name)) { + g_value_init(&properties[ix].value, properties[ix].g_type); + g_object_get_property(G_OBJECT(element->action), properties[ix].name, &properties[ix].value); - size_t ix; + } - struct Properties { - const gchar * name; - GType g_type; - GValue value; - } properties[] = { - { - .name = "label", - .g_type = G_TYPE_STRING, - .value = G_VALUE_INIT - } - }; + // Remove "_" + g_autofree gchar * label = g_strdup(g_value_get_string(&properties[0].value)); - for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { + if(label) { - g_value_init(&properties[ix].value, properties[ix].g_type); - g_object_get_property(G_OBJECT(element->action), properties[ix].name, &properties[ix].value); + gchar *from, *to; + for(from=to=label;*from;from++) { + if(*from != '_') { + *(to++) = *from; } + } + *to = 0; - debug("label=\"%s\"",g_value_get_string(&properties[0].value)); + } - GtkTreeIter iter; - gtk_list_store_append(store, &iter); - gtk_list_store_set( - store, - &iter, - COLUMN_PIXBUF, element->pixbuf, - COLUMN_LABEL, g_value_get_string(&properties[0].value), - -1 - ); + GtkTreeIter iter; + gtk_list_store_append(store, &iter); + gtk_list_store_set( + store, + &iter, + COLUMN_PIXBUF, element->pixbuf, + COLUMN_LABEL, (label ? label : g_action_get_name(element->action)), + -1 + ); - for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { - g_value_unset(&properties[ix].value); - } + for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { + g_value_unset(&properties[ix].value); + } + + } + Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view) { + + GSList * item = (GSList *) action_list; + GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view))); + + while(item) { + + struct ListElement * element = (struct ListElement *) item->data; + + if(!g_ascii_strcasecmp(action_name,element->name)) { + + pw3270_action_view_append_element(store, element); list_element_free(element); return (Pw3270ActionList *) g_slist_remove_link(action_list,item); } @@ -147,19 +164,18 @@ } - /* - void pw3270_action_view_append_application_action(GtkWidget *widget, GAction *action) { + void pw3270_action_view_set_actions(GtkWidget *view, Pw3270ActionList *list) { - g_return_if_fail(PW3270_IS_ACTION(action)); + GSList *item; + GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view))); - GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); - GtkTreeIter iter; + for(item = (GSList *) list; item; item = g_slist_next(item)) { - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, 0, action); + pw3270_action_view_append_element(store, (struct ListElement *) item->data); + + } } - */ static GSList * append_action(GSList * list, const gchar *type, GAction *action) { diff --git a/src/objects/toolbar/settings.c b/src/objects/toolbar/settings.c index c2f5230..7c8e2a1 100644 --- a/src/objects/toolbar/settings.c +++ b/src/objects/toolbar/settings.c @@ -65,6 +65,10 @@ } g_strfreev(actions); + + // Load available actions. + pw3270_action_view_set_actions(((ToolbarSettingsPage *) pg)->views[1], action_list); + pw3270_action_list_free(action_list); @@ -116,6 +120,8 @@ } + gtk_tree_view_set_reorderable(GTK_TREE_VIEW(page->views[0]),TRUE); + // Create buttons static const gchar * icon_names[G_N_ELEMENTS(page->buttons)] = { "go-next", -- libgit2 0.21.2