Commit 9306acb35298ee66b252826f577fdcb952904776
1 parent
3881b3c9
Exists in
master
and in
4 other branches
Adding methods to get/set toolbar action names.
Showing
3 changed files
with
63 additions
and
21 deletions
Show diff stats
src/include/pw3270/toolbar.h
@@ -59,6 +59,8 @@ | @@ -59,6 +59,8 @@ | ||
59 | GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos); | 59 | GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos); |
60 | GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, const gchar *name, gint pos); | 60 | GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, const gchar *name, gint pos); |
61 | 61 | ||
62 | + void pw3270_toolbar_set_actions(GtkWidget *toolbar, const gchar *action_names); | ||
63 | + | ||
62 | void pw3270_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style); | 64 | void pw3270_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style); |
63 | void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size); | 65 | void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size); |
64 | 66 |
src/objects/toolbar/toolbar.c
@@ -336,3 +336,56 @@ | @@ -336,3 +336,56 @@ | ||
336 | // gtk_container_foreach(GTK_CONTAINER(toolbar),(GtkCallback) update_child, toolbar); | 336 | // gtk_container_foreach(GTK_CONTAINER(toolbar),(GtkCallback) update_child, toolbar); |
337 | 337 | ||
338 | } | 338 | } |
339 | + | ||
340 | + void pw3270_toolbar_clear(GtkWidget *toolbar) { | ||
341 | + | ||
342 | + GList * children = gtk_container_get_children(GTK_CONTAINER(toolbar)); | ||
343 | + GList * item; | ||
344 | + | ||
345 | + for(item = children;item;item = g_list_next(item)) { | ||
346 | + gtk_container_remove(GTK_CONTAINER(toolbar),GTK_WIDGET(item->data)); | ||
347 | + } | ||
348 | + | ||
349 | + g_list_free(children); | ||
350 | + } | ||
351 | + | ||
352 | + void pw3270_toolbar_set_actions(GtkWidget *toolbar, const gchar *action_names) { | ||
353 | + | ||
354 | + gchar ** actions = g_strsplit(action_names,",",-1); | ||
355 | + size_t ix; | ||
356 | + | ||
357 | + pw3270_toolbar_clear(toolbar); | ||
358 | + | ||
359 | + for(ix = 0; actions[ix]; ix++) { | ||
360 | + pw3270_toolbar_insert_action(toolbar,actions[ix],-1); | ||
361 | + } | ||
362 | + | ||
363 | + g_strfreev(actions); | ||
364 | + | ||
365 | + } | ||
366 | + | ||
367 | + gchar * pw3270_toolbar_get_actions(GtkWidget *toolbar) { | ||
368 | + | ||
369 | + GString * str = g_string_new(""); | ||
370 | + | ||
371 | + GList * children = gtk_container_get_children(GTK_CONTAINER(toolbar)); | ||
372 | + GList * item; | ||
373 | + | ||
374 | + for(item = children;item;item = g_list_next(item)) { | ||
375 | + | ||
376 | + if(*str->str) | ||
377 | + g_string_append(str,","); | ||
378 | + | ||
379 | + if(GTK_IS_SEPARATOR_TOOL_ITEM(item->data)) { | ||
380 | + g_string_append(str,"separator"); | ||
381 | + } else if(GTK_IS_TOOL_BUTTON(item->data)) { | ||
382 | + g_string_append(str,gtk_actionable_get_action_name(GTK_ACTIONABLE(item->data))); | ||
383 | + } | ||
384 | + | ||
385 | + } | ||
386 | + | ||
387 | + g_list_free(children); | ||
388 | + | ||
389 | + | ||
390 | + return g_string_free(str,FALSE); | ||
391 | + } |
src/objects/window/window.c
@@ -151,29 +151,13 @@ | @@ -151,29 +151,13 @@ | ||
151 | // | 151 | // |
152 | // Setup toolbar | 152 | // Setup toolbar |
153 | // | 153 | // |
154 | - { | ||
155 | - static const gchar *actions[] = { | ||
156 | - | ||
157 | - "win.copy", | ||
158 | - "win.paste", | ||
159 | - "win.select-all", | ||
160 | - "separator", | ||
161 | - "win.connect", | ||
162 | - "win.disconnect", | ||
163 | - "separator", | ||
164 | - "win.set.colors", | ||
165 | - "win.session.properties", | ||
166 | - "win.file.transfer", | ||
167 | - "win.print", | ||
168 | - "app.quit" | ||
169 | - | ||
170 | - }; | ||
171 | 154 | ||
172 | - size_t ix; | 155 | + { |
173 | 156 | ||
174 | - for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { | ||
175 | - pw3270_toolbar_insert_action(GTK_WIDGET(widget->toolbar),actions[ix],-1); | ||
176 | - } | 157 | + pw3270_toolbar_set_actions( |
158 | + GTK_WIDGET(widget->toolbar), | ||
159 | + "win.copy,win.paste,win.select-all,separator,win.connect,win.disconnect,separator,win.session.properties,win.file.transfer,win.print,app.quit" | ||
160 | + ); | ||
177 | 161 | ||
178 | g_action_map_add_action( | 162 | g_action_map_add_action( |
179 | G_ACTION_MAP(widget), | 163 | G_ACTION_MAP(widget), |
@@ -185,6 +169,9 @@ | @@ -185,6 +169,9 @@ | ||
185 | G_ACTION(g_property_action_new("menubar", widget, "show-menubar")) | 169 | G_ACTION(g_property_action_new("menubar", widget, "show-menubar")) |
186 | ); | 170 | ); |
187 | 171 | ||
172 | + g_autofree gchar * action_names = pw3270_toolbar_get_actions(GTK_WIDGET(widget->toolbar)); | ||
173 | + debug("[%s]",action_names); | ||
174 | + | ||
188 | } | 175 | } |
189 | 176 | ||
190 | } | 177 | } |