Commit fee0eaf0c6b36ab7493b96bd9b948bcc2963c410
1 parent
c2cca166
Exists in
master
and in
4 other branches
Implementing action viewer widget.
Showing
3 changed files
with
81 additions
and
5 deletions
Show diff stats
src/include/pw3270/actions.h
| ... | ... | @@ -262,6 +262,8 @@ |
| 262 | 262 | Pw3270ActionList * pw3270_action_list_new(GtkApplication *application); |
| 263 | 263 | void pw3270_action_list_free(Pw3270ActionList *action_list); |
| 264 | 264 | |
| 265 | + Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view); | |
| 266 | + | |
| 265 | 267 | G_END_DECLS |
| 266 | 268 | |
| 267 | 269 | #endif // PW3270_ACTIONS_H_INCLUDED | ... | ... |
src/objects/actions/view.c
| ... | ... | @@ -43,6 +43,9 @@ |
| 43 | 43 | gchar name[1]; |
| 44 | 44 | }; |
| 45 | 45 | |
| 46 | + static void list_element_free(struct ListElement *element); | |
| 47 | + | |
| 48 | + | |
| 46 | 49 | GtkWidget * pw3270_action_view_new() { |
| 47 | 50 | |
| 48 | 51 | GtkWidget * view = GTK_WIDGET(gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtk_list_store_new(1,G_TYPE_OBJECT)))); |
| ... | ... | @@ -66,6 +69,56 @@ |
| 66 | 69 | return view; |
| 67 | 70 | } |
| 68 | 71 | |
| 72 | + Pw3270ActionList * pw3270_action_list_move_action(Pw3270ActionList *action_list, const gchar *action_name, GtkWidget *view) { | |
| 73 | + | |
| 74 | + GSList * item = (GSList *) action_list; | |
| 75 | + | |
| 76 | + while(item) { | |
| 77 | + | |
| 78 | + struct ListElement * element = (struct ListElement *) item->data; | |
| 79 | + | |
| 80 | + if(!g_ascii_strcasecmp(action_name,element->name)) { | |
| 81 | + | |
| 82 | + size_t ix; | |
| 83 | + | |
| 84 | + struct Properties { | |
| 85 | + const gchar * name; | |
| 86 | + GType g_type; | |
| 87 | + GValue value; | |
| 88 | + } properties[] = { | |
| 89 | + { | |
| 90 | + .name = "label", | |
| 91 | + .g_type = G_TYPE_STRING, | |
| 92 | + .value = G_VALUE_INIT | |
| 93 | + } | |
| 94 | + }; | |
| 95 | + | |
| 96 | + for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { | |
| 97 | + | |
| 98 | + g_value_init(&properties[ix].value, properties[ix].g_type); | |
| 99 | + g_object_get_property(G_OBJECT(element->action), properties[ix].name, &properties[ix].value); | |
| 100 | + | |
| 101 | + } | |
| 102 | + | |
| 103 | + debug("label=\"%s\"",g_value_get_string(&properties[0].value)); | |
| 104 | + | |
| 105 | + | |
| 106 | + for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) { | |
| 107 | + g_value_unset(&properties[ix].value); | |
| 108 | + } | |
| 109 | + | |
| 110 | + list_element_free(element); | |
| 111 | + return (Pw3270ActionList *) g_slist_remove_link(action_list,item); | |
| 112 | + } | |
| 113 | + | |
| 114 | + item = g_slist_next(item); | |
| 115 | + | |
| 116 | + } | |
| 117 | + | |
| 118 | + return action_list; | |
| 119 | + | |
| 120 | + } | |
| 121 | + | |
| 69 | 122 | /* |
| 70 | 123 | void pw3270_action_view_append_application_action(GtkWidget *widget, GAction *action) { |
| 71 | 124 | |
| ... | ... | @@ -85,8 +138,10 @@ |
| 85 | 138 | if(!action) |
| 86 | 139 | return list; |
| 87 | 140 | |
| 88 | - GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(action),"toolbar-icon"); | |
| 141 | + if(!g_object_class_find_property(G_OBJECT_GET_CLASS(action),"label")) | |
| 142 | + return list; | |
| 89 | 143 | |
| 144 | + GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(action),"toolbar-icon"); | |
| 90 | 145 | if(!spec) |
| 91 | 146 | return list; |
| 92 | 147 | |
| ... | ... | @@ -149,7 +204,7 @@ |
| 149 | 204 | return (Pw3270ActionList *) list; |
| 150 | 205 | } |
| 151 | 206 | |
| 152 | - static void free_element(struct ListElement *element) { | |
| 207 | + void list_element_free(struct ListElement *element) { | |
| 153 | 208 | |
| 154 | 209 | if(element->image) { |
| 155 | 210 | g_object_unref(element->image); |
| ... | ... | @@ -161,6 +216,6 @@ |
| 161 | 216 | } |
| 162 | 217 | |
| 163 | 218 | void pw3270_action_list_free(Pw3270ActionList *action_list) { |
| 164 | - g_slist_free_full((GSList *) action_list, (GDestroyNotify) free_element); | |
| 219 | + g_slist_free_full((GSList *) action_list, (GDestroyNotify) list_element_free); | |
| 165 | 220 | } |
| 166 | 221 | ... | ... |
src/objects/toolbar/settings.c
| ... | ... | @@ -39,14 +39,33 @@ |
| 39 | 39 | } ToolbarSettingsPage; |
| 40 | 40 | |
| 41 | 41 | static void load(Pw3270SettingsPage *pg, GtkApplication *application, GSettings *settings) { |
| 42 | + | |
| 43 | + size_t ix; | |
| 44 | + | |
| 42 | 45 | debug("%s",__FUNCTION__); |
| 43 | 46 | |
| 44 | 47 | // Populate views |
| 45 | - Pw3270ActionList * actions = pw3270_action_list_new(application); | |
| 48 | + Pw3270ActionList * action_list = pw3270_action_list_new(application); | |
| 49 | + | |
| 50 | + // Load current values. | |
| 51 | + g_autofree gchar * action_names = g_settings_get_string(settings,"toolbar-action-names"); | |
| 52 | + | |
| 53 | + gchar ** actions = g_strsplit(action_names,",",-1); | |
| 54 | + | |
| 55 | + for(ix = 0; actions[ix]; ix++) { | |
| 46 | 56 | |
| 57 | + if(g_ascii_strcasecmp(actions[ix],"separator")) { | |
| 47 | 58 | |
| 59 | + // It's an action | |
| 60 | + action_list = pw3270_action_list_move_action(action_list,actions[ix],((ToolbarSettingsPage *) pg)->views[0]); | |
| 61 | + | |
| 62 | + } | |
| 63 | + | |
| 64 | + | |
| 65 | + } | |
| 48 | 66 | |
| 49 | - pw3270_action_list_free(actions); | |
| 67 | + g_strfreev(actions); | |
| 68 | + pw3270_action_list_free(action_list); | |
| 50 | 69 | |
| 51 | 70 | |
| 52 | 71 | } | ... | ... |