Commit 5e08cc14e6c7e9e41cf6fb51768096f2fc555021
1 parent
da55a192
Exists in
master
and in
4 other branches
Fixing toolbar settings.
Showing
3 changed files
with
77 additions
and
23 deletions
Show diff stats
src/include/pw3270/toolbar.h
| ... | ... | @@ -61,7 +61,10 @@ |
| 61 | 61 | GtkWidget * pw3270_toolbar_insert_action_by_name(GtkWidget *toolbar, const gchar *name, gint pos); |
| 62 | 62 | |
| 63 | 63 | void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style); |
| 64 | +// GtkToolbarStyle pw3270_toolbar_toolbar_get_style(GtkToolbar *toolbar); | |
| 65 | + | |
| 64 | 66 | void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size); |
| 67 | +// GtkIconSize pw3270_toolbar_get_icon_size(GtkToolbar *toolbar); | |
| 65 | 68 | |
| 66 | 69 | G_END_DECLS |
| 67 | 70 | ... | ... |
src/objects/toolbar/actions.c
| ... | ... | @@ -48,10 +48,12 @@ |
| 48 | 48 | debug("%s - %s",icon_name,pw3270_action_get_label(action)); |
| 49 | 49 | |
| 50 | 50 | GtkToolItem * item = gtk_tool_button_new( |
| 51 | - gtk_image_new_from_icon_name(icon_name,GTK_ICON_SIZE_LARGE_TOOLBAR), | |
| 51 | + NULL, | |
| 52 | 52 | pw3270_action_get_label(action) |
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | + gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(item),icon_name); | |
| 56 | + | |
| 55 | 57 | const gchar * tooltip = pw3270_action_get_tooltip(action); |
| 56 | 58 | if(tooltip) |
| 57 | 59 | gtk_widget_set_tooltip_markup(GTK_WIDGET(item),tooltip); | ... | ... |
src/objects/toolbar/toolbar.c
| ... | ... | @@ -89,7 +89,11 @@ |
| 89 | 89 | GtkToolbar parent; |
| 90 | 90 | |
| 91 | 91 | /// @brief Popup Menu |
| 92 | - GtkWidget * popup_menu; | |
| 92 | + struct { | |
| 93 | + GtkWidget * menu; | |
| 94 | + GtkWidget * styles[G_N_ELEMENTS(styles)]; | |
| 95 | + GtkWidget * icon_sizes[G_N_ELEMENTS(icon_sizes)]; | |
| 96 | + } popup; | |
| 93 | 97 | |
| 94 | 98 | }; |
| 95 | 99 | |
| ... | ... | @@ -115,47 +119,49 @@ |
| 115 | 119 | static void detacher(GtkWidget *attach_widget, GtkMenu G_GNUC_UNUSED(*menu)) { |
| 116 | 120 | |
| 117 | 121 | pw3270ToolBar * toolbar = PW3270_TOOLBAR(attach_widget); |
| 118 | - toolbar->popup_menu = NULL; | |
| 122 | + toolbar->popup.menu = NULL; | |
| 119 | 123 | |
| 120 | 124 | } |
| 121 | 125 | |
| 122 | - static void set_icon_size(GtkMenuItem *menuitem, GtkWidget *toolbar) { | |
| 126 | + static void set_icon_size(GtkCheckMenuItem *menuitem, GtkWidget *toolbar) { | |
| 123 | 127 | |
| 124 | - const struct icon_size * size = g_object_get_data(G_OBJECT(menuitem),"icon_size"); | |
| 125 | - | |
| 126 | - debug("%s(%d,%s)",__FUNCTION__,(int) size->icon_size, size->label); | |
| 127 | - pw3270_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), size->icon_size); | |
| 128 | + if(gtk_check_menu_item_get_active(menuitem)) { | |
| 129 | + const struct icon_size * size = g_object_get_data(G_OBJECT(menuitem),"icon_size"); | |
| 130 | + pw3270_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), size->icon_size); | |
| 131 | + } | |
| 128 | 132 | |
| 129 | 133 | } |
| 130 | 134 | |
| 131 | - static void set_style(GtkMenuItem *menuitem, GtkWidget *toolbar) { | |
| 132 | - struct toolbar_style * style = g_object_get_data(G_OBJECT(menuitem),"toolbar_style"); | |
| 135 | + static void set_style(GtkCheckMenuItem *menuitem, GtkWidget *toolbar) { | |
| 133 | 136 | |
| 134 | - debug("%s(%d,%s)",__FUNCTION__,(int) style->style, style->label); | |
| 135 | - pw3270_toolbar_toolbar_set_style(GTK_TOOLBAR(toolbar), style->style); | |
| 137 | + if(gtk_check_menu_item_get_active(menuitem)) { | |
| 138 | + struct toolbar_style * style = g_object_get_data(G_OBJECT(menuitem),"toolbar_style"); | |
| 139 | + pw3270_toolbar_toolbar_set_style(GTK_TOOLBAR(toolbar), style->style); | |
| 140 | + } | |
| 136 | 141 | |
| 137 | 142 | } |
| 138 | 143 | |
| 139 | 144 | static void pw3270ToolBar_init(pw3270ToolBar *widget) { |
| 140 | 145 | |
| 141 | - widget->popup_menu = gtk_menu_new(); | |
| 146 | + widget->popup.menu = gtk_menu_new(); | |
| 142 | 147 | |
| 143 | 148 | // Size options |
| 144 | 149 | { |
| 145 | 150 | size_t ix; |
| 146 | 151 | |
| 147 | 152 | GtkWidget * item = gtk_menu_item_new_with_mnemonic( _("Icon _size") ); |
| 148 | - gtk_menu_shell_append(GTK_MENU_SHELL(widget->popup_menu),item); | |
| 153 | + gtk_menu_shell_append(GTK_MENU_SHELL(widget->popup.menu),item); | |
| 149 | 154 | |
| 150 | 155 | GtkWidget * submenu = gtk_menu_new(); |
| 151 | 156 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),submenu); |
| 152 | 157 | |
| 153 | 158 | for(ix = 0; ix < G_N_ELEMENTS(icon_sizes); ix++) { |
| 154 | 159 | |
| 155 | - item = gtk_menu_item_new_with_mnemonic(gettext(icon_sizes[ix].label)); | |
| 160 | + widget->popup.icon_sizes[ix] = item = gtk_check_menu_item_new_with_mnemonic(gettext(icon_sizes[ix].label)); | |
| 161 | + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item),TRUE); | |
| 156 | 162 | |
| 157 | 163 | g_object_set_data(G_OBJECT(item),"icon_size", (gpointer) &icon_sizes[ix]); |
| 158 | - g_signal_connect(item, "activate", G_CALLBACK(set_icon_size), widget); | |
| 164 | + g_signal_connect(item, "toggled", G_CALLBACK(set_icon_size), widget); | |
| 159 | 165 | |
| 160 | 166 | gtk_menu_shell_append(GTK_MENU_SHELL(submenu),item); |
| 161 | 167 | |
| ... | ... | @@ -168,17 +174,18 @@ |
| 168 | 174 | size_t ix; |
| 169 | 175 | |
| 170 | 176 | GtkWidget * item = gtk_menu_item_new_with_mnemonic( _("S_tyle") ); |
| 171 | - gtk_menu_shell_append(GTK_MENU_SHELL(widget->popup_menu),item); | |
| 177 | + gtk_menu_shell_append(GTK_MENU_SHELL(widget->popup.menu),item); | |
| 172 | 178 | |
| 173 | 179 | GtkWidget * submenu = gtk_menu_new(); |
| 174 | 180 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),submenu); |
| 175 | 181 | |
| 176 | 182 | for(ix = 0; ix < G_N_ELEMENTS(styles); ix++) { |
| 177 | 183 | |
| 178 | - item = gtk_menu_item_new_with_mnemonic(gettext(styles[ix].label)); | |
| 184 | + widget->popup.styles[ix] = item = gtk_check_menu_item_new_with_mnemonic(gettext(styles[ix].label)); | |
| 185 | + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item),TRUE); | |
| 179 | 186 | |
| 180 | 187 | g_object_set_data(G_OBJECT(item),"toolbar_style", (gpointer) &styles[ix]); |
| 181 | - g_signal_connect(item, "activate", G_CALLBACK(set_style), widget); | |
| 188 | + g_signal_connect(item, "toggled", G_CALLBACK(set_style), widget); | |
| 182 | 189 | |
| 183 | 190 | gtk_menu_shell_append(GTK_MENU_SHELL(submenu),item); |
| 184 | 191 | |
| ... | ... | @@ -186,9 +193,10 @@ |
| 186 | 193 | |
| 187 | 194 | } |
| 188 | 195 | |
| 196 | + | |
| 189 | 197 | // gtk_container_set_border_width(GTK_CONTAINER(widget->popup_menu),6); |
| 190 | - gtk_widget_show_all(widget->popup_menu); | |
| 191 | - gtk_menu_attach_to_widget(GTK_MENU(widget->popup_menu),GTK_WIDGET(widget),detacher); | |
| 198 | + gtk_widget_show_all(widget->popup.menu); | |
| 199 | + gtk_menu_attach_to_widget(GTK_MENU(widget->popup.menu),GTK_WIDGET(widget),detacher); | |
| 192 | 200 | |
| 193 | 201 | // Bind settings |
| 194 | 202 | GSettings *settings = pw3270_application_get_settings(g_application_get_default()); |
| ... | ... | @@ -253,8 +261,8 @@ |
| 253 | 261 | |
| 254 | 262 | debug("%s button_number=%d",__FUNCTION__,button_number); |
| 255 | 263 | |
| 256 | - if(toolbar->popup_menu) { | |
| 257 | - gtk_menu_popup_at_pointer(GTK_MENU(toolbar->popup_menu),NULL); | |
| 264 | + if(toolbar->popup.menu) { | |
| 265 | + gtk_menu_popup_at_pointer(GTK_MENU(toolbar->popup.menu),NULL); | |
| 258 | 266 | } |
| 259 | 267 | |
| 260 | 268 | return TRUE; |
| ... | ... | @@ -270,10 +278,35 @@ |
| 270 | 278 | else |
| 271 | 279 | gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),style); |
| 272 | 280 | |
| 281 | + // Store value | |
| 273 | 282 | pw3270_settings_set_int("toolbar-style",(int) style); |
| 274 | 283 | |
| 284 | + // Update menu | |
| 285 | + pw3270ToolBar * tb = PW3270_TOOLBAR(toolbar); | |
| 286 | + if(tb && tb->popup.menu) { | |
| 287 | + size_t ix; | |
| 288 | + for(ix = 0; ix < G_N_ELEMENTS(styles); ix++) { | |
| 289 | + | |
| 290 | + gtk_check_menu_item_set_active( | |
| 291 | + GTK_CHECK_MENU_ITEM(tb->popup.styles[ix]), | |
| 292 | + styles[ix].style == style | |
| 293 | + ); | |
| 294 | + } | |
| 295 | + } | |
| 296 | + | |
| 275 | 297 | } |
| 276 | 298 | |
| 299 | + /* | |
| 300 | + static void update_child(GtkToolButton *item, GtkWidget *toolbar) { | |
| 301 | + | |
| 302 | + if(!GTK_IS_TOOL_BUTTON(item)) | |
| 303 | + return; | |
| 304 | + | |
| 305 | + debug("[%s]", gtk_tool_button_get_icon_name(item)); | |
| 306 | + | |
| 307 | + } | |
| 308 | + */ | |
| 309 | + | |
| 277 | 310 | void pw3270_toolbar_set_icon_size(GtkToolbar *toolbar, GtkIconSize icon_size) { |
| 278 | 311 | |
| 279 | 312 | debug("%s(%d)",__FUNCTION__,(int) icon_size); |
| ... | ... | @@ -283,6 +316,22 @@ |
| 283 | 316 | else |
| 284 | 317 | gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar),icon_size); |
| 285 | 318 | |
| 319 | + // Store value | |
| 286 | 320 | pw3270_settings_set_int("toolbar-icon-size", (gint) icon_size); |
| 287 | 321 | |
| 322 | + // Update menu | |
| 323 | + pw3270ToolBar * tb = PW3270_TOOLBAR(toolbar); | |
| 324 | + if(tb && tb->popup.menu) { | |
| 325 | + size_t ix; | |
| 326 | + for(ix = 0; ix < G_N_ELEMENTS(icon_sizes); ix++) { | |
| 327 | + | |
| 328 | + gtk_check_menu_item_set_active( | |
| 329 | + GTK_CHECK_MENU_ITEM(tb->popup.icon_sizes[ix]), | |
| 330 | + icon_sizes[ix].icon_size == icon_size | |
| 331 | + ); | |
| 332 | + } | |
| 333 | + } | |
| 334 | + | |
| 335 | + // gtk_container_foreach(GTK_CONTAINER(toolbar),(GtkCallback) update_child, toolbar); | |
| 336 | + | |
| 288 | 337 | } | ... | ... |