Commit 308ecd304d70dfac595b3caa64cbf4c9c6e3b5e2

Authored by Perry Werneck
1 parent b77fc6d1

Adding available actions for toolbar edit.

src/include/pw3270/actions.h
@@ -261,6 +261,7 @@ @@ -261,6 +261,7 @@
261 GtkWidget * pw3270_action_view_new(); 261 GtkWidget * pw3270_action_view_new();
262 Pw3270ActionList * pw3270_action_list_new(GtkApplication *application); 262 Pw3270ActionList * pw3270_action_list_new(GtkApplication *application);
263 void pw3270_action_list_free(Pw3270ActionList *action_list); 263 void pw3270_action_list_free(Pw3270ActionList *action_list);
  264 + void pw3270_action_view_set_actions(GtkWidget *view, Pw3270ActionList *list);
264 265
265 Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view); 266 Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view);
266 267
src/objects/actions/view.c
@@ -51,7 +51,6 @@ @@ -51,7 +51,6 @@
51 51
52 static void list_element_free(struct ListElement *element); 52 static void list_element_free(struct ListElement *element);
53 53
54 -  
55 GtkWidget * pw3270_action_view_new() { 54 GtkWidget * pw3270_action_view_new() {
56 55
57 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)))); 56 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 @@ @@ -60,7 +59,6 @@
60 gtk_widget_set_vexpand(view,TRUE); 59 gtk_widget_set_vexpand(view,TRUE);
61 gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(view),FALSE); 60 gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(view),FALSE);
62 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view),FALSE); 61 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view),FALSE);
63 - gtk_tree_view_set_reorderable(GTK_TREE_VIEW(view),TRUE);  
64 62
65 // Create Renderers 63 // Create Renderers
66 GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new(); 64 GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new();
@@ -87,54 +85,73 @@ @@ -87,54 +85,73 @@
87 return view; 85 return view;
88 } 86 }
89 87
90 - Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view) { 88 + static void pw3270_action_view_append_element(GtkListStore * store, struct ListElement * element) {
91 89
92 - GSList * item = (GSList *) action_list;  
93 - GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view))); 90 + size_t ix;
94 91
95 - while(item) { 92 + struct Properties {
  93 + const gchar * name;
  94 + GType g_type;
  95 + GValue value;
  96 + } properties[] = {
  97 + {
  98 + .name = "label",
  99 + .g_type = G_TYPE_STRING,
  100 + .value = G_VALUE_INIT
  101 + }
  102 + };
96 103
97 - struct ListElement * element = (struct ListElement *) item->data; 104 + for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) {
98 105
99 - if(!g_ascii_strcasecmp(action_name,element->name)) { 106 + g_value_init(&properties[ix].value, properties[ix].g_type);
  107 + g_object_get_property(G_OBJECT(element->action), properties[ix].name, &properties[ix].value);
100 108
101 - size_t ix; 109 + }
102 110
103 - struct Properties {  
104 - const gchar * name;  
105 - GType g_type;  
106 - GValue value;  
107 - } properties[] = {  
108 - {  
109 - .name = "label",  
110 - .g_type = G_TYPE_STRING,  
111 - .value = G_VALUE_INIT  
112 - }  
113 - }; 111 + // Remove "_"
  112 + g_autofree gchar * label = g_strdup(g_value_get_string(&properties[0].value));
114 113
115 - for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { 114 + if(label) {
116 115
117 - g_value_init(&properties[ix].value, properties[ix].g_type);  
118 - g_object_get_property(G_OBJECT(element->action), properties[ix].name, &properties[ix].value); 116 + gchar *from, *to;
119 117
  118 + for(from=to=label;*from;from++) {
  119 + if(*from != '_') {
  120 + *(to++) = *from;
120 } 121 }
  122 + }
  123 + *to = 0;
121 124
122 - debug("label=\"%s\"",g_value_get_string(&properties[0].value)); 125 + }
123 126
124 - GtkTreeIter iter;  
125 - gtk_list_store_append(store, &iter);  
126 - gtk_list_store_set(  
127 - store,  
128 - &iter,  
129 - COLUMN_PIXBUF, element->pixbuf,  
130 - COLUMN_LABEL, g_value_get_string(&properties[0].value),  
131 - -1  
132 - ); 127 + GtkTreeIter iter;
  128 + gtk_list_store_append(store, &iter);
  129 + gtk_list_store_set(
  130 + store,
  131 + &iter,
  132 + COLUMN_PIXBUF, element->pixbuf,
  133 + COLUMN_LABEL, (label ? label : g_action_get_name(element->action)),
  134 + -1
  135 + );
133 136
134 - for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) {  
135 - g_value_unset(&properties[ix].value);  
136 - } 137 + for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) {
  138 + g_value_unset(&properties[ix].value);
  139 + }
  140 +
  141 + }
137 142
  143 + Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view) {
  144 +
  145 + GSList * item = (GSList *) action_list;
  146 + GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view)));
  147 +
  148 + while(item) {
  149 +
  150 + struct ListElement * element = (struct ListElement *) item->data;
  151 +
  152 + if(!g_ascii_strcasecmp(action_name,element->name)) {
  153 +
  154 + pw3270_action_view_append_element(store, element);
138 list_element_free(element); 155 list_element_free(element);
139 return (Pw3270ActionList *) g_slist_remove_link(action_list,item); 156 return (Pw3270ActionList *) g_slist_remove_link(action_list,item);
140 } 157 }
@@ -147,19 +164,18 @@ @@ -147,19 +164,18 @@
147 164
148 } 165 }
149 166
150 - /*  
151 - void pw3270_action_view_append_application_action(GtkWidget *widget, GAction *action) { 167 + void pw3270_action_view_set_actions(GtkWidget *view, Pw3270ActionList *list) {
152 168
153 - g_return_if_fail(PW3270_IS_ACTION(action)); 169 + GSList *item;
  170 + GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view)));
154 171
155 - GtkListStore * store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget)));  
156 - GtkTreeIter iter; 172 + for(item = (GSList *) list; item; item = g_slist_next(item)) {
157 173
158 - gtk_list_store_append(store, &iter);  
159 - gtk_list_store_set(store, &iter, 0, action); 174 + pw3270_action_view_append_element(store, (struct ListElement *) item->data);
  175 +
  176 + }
160 177
161 } 178 }
162 - */  
163 179
164 static GSList * append_action(GSList * list, const gchar *type, GAction *action) { 180 static GSList * append_action(GSList * list, const gchar *type, GAction *action) {
165 181
src/objects/toolbar/settings.c
@@ -65,6 +65,10 @@ @@ -65,6 +65,10 @@
65 } 65 }
66 66
67 g_strfreev(actions); 67 g_strfreev(actions);
  68 +
  69 + // Load available actions.
  70 + pw3270_action_view_set_actions(((ToolbarSettingsPage *) pg)->views[1], action_list);
  71 +
68 pw3270_action_list_free(action_list); 72 pw3270_action_list_free(action_list);
69 73
70 74
@@ -116,6 +120,8 @@ @@ -116,6 +120,8 @@
116 120
117 } 121 }
118 122
  123 + gtk_tree_view_set_reorderable(GTK_TREE_VIEW(page->views[0]),TRUE);
  124 +
119 // Create buttons 125 // Create buttons
120 static const gchar * icon_names[G_N_ELEMENTS(page->buttons)] = { 126 static const gchar * icon_names[G_N_ELEMENTS(page->buttons)] = {
121 "go-next", 127 "go-next",