Commit 4a5875a1bd9e7c6a661485ff007225f97b65ce17

Authored by Perry Werneck
1 parent aa4e04a7

Improving header buttons.

pw3270.cbp
... ... @@ -142,6 +142,9 @@
142 142 <Unit filename="src/objects/window/actions/setcolors.c">
143 143 <Option compilerVar="CC" />
144 144 </Unit>
  145 + <Unit filename="src/objects/window/header.c">
  146 + <Option compilerVar="CC" />
  147 + </Unit>
145 148 <Unit filename="src/objects/window/private.h" />
146 149 <Unit filename="src/objects/window/terminal.c">
147 150 <Option compilerVar="CC" />
... ...
src/objects/window/header.c 0 → 100644
... ... @@ -0,0 +1,84 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include "private.h"
  31 + #include <pw3270.h>
  32 + #include <pw3270/toolbar.h>
  33 + #include <pw3270/application.h>
  34 + #include <pw3270/actions.h>
  35 +
  36 + static void on_sensitive(GtkWidget *button, GParamSpec *spec, GtkWidget *widget) {
  37 +
  38 + gboolean sensitive;
  39 + g_object_get(button, "sensitive", &sensitive, NULL);
  40 + gtk_widget_set_visible(button,sensitive);
  41 +
  42 + }
  43 +
  44 + GtkWidget * pw3270_header_button_new_from_builder(GtkWidget *widget, GtkBuilder * builder, const gchar *action_name) {
  45 +
  46 + GtkWidget * button = NULL;
  47 +
  48 + if(g_str_has_prefix(action_name,"menu.")) {
  49 +
  50 + // It's a menu
  51 + g_autofree gchar * icon_name = g_strconcat(action_name+5,"-symbolic",NULL);
  52 + button = pw3270_setup_image_button(gtk_menu_button_new(),icon_name);
  53 + gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(button), G_MENU_MODEL(gtk_builder_get_object(builder, action_name+5)));
  54 + gtk_widget_set_visible(button,TRUE);
  55 +
  56 + } else if(g_str_has_prefix(action_name,"app.")) {
  57 +
  58 + // It's an application action
  59 +
  60 + } else if(g_str_has_prefix(action_name,"win.")) {
  61 +
  62 + // It's a window action.
  63 + GAction * action = g_action_map_lookup_action(G_ACTION_MAP(widget),action_name+4);
  64 + const gchar * icon_name = pw3270_action_get_icon_name(action);
  65 + if(action && icon_name) {
  66 + button = pw3270_setup_image_button(gtk_menu_button_new(),icon_name);
  67 + gtk_actionable_set_action_name(GTK_ACTIONABLE(button),action_name);
  68 + gtk_widget_set_visible(button,g_action_get_enabled(action));
  69 +
  70 +
  71 + }
  72 +
  73 + }
  74 +
  75 + if(button) {
  76 +
  77 + g_signal_connect(button, "notify::sensitive", G_CALLBACK(on_sensitive), widget);
  78 + gtk_widget_set_focus_on_click(button,FALSE);
  79 + gtk_widget_set_can_focus(button,FALSE);
  80 +
  81 + }
  82 +
  83 + return button;
  84 + }
... ...
src/objects/window/private.h
... ... @@ -89,4 +89,7 @@
89 89 G_GNUC_INTERNAL void pw3270_window_open_activated(GSimpleAction * action, GVariant *parameter, gpointer window);
90 90 G_GNUC_INTERNAL void pw3270_window_close_activated(GSimpleAction * action, GVariant *parameter, gpointer window);
91 91  
  92 + // Window widgets & tools.
  93 + G_GNUC_INTERNAL GtkWidget * pw3270_header_button_new_from_builder(GtkWidget *widget, GtkBuilder * builder, const gchar *action_name);
  94 +
92 95 #endif // PRIVATE_H_INCLUDED
... ...
src/objects/window/window.c
... ... @@ -40,7 +40,6 @@
40 40 size_t ix;
41 41 pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget);
42 42  
43   -
44 43 debug("%s(%p)",__FUNCTION__,widget);
45 44  
46 45 // Update actions
... ... @@ -65,7 +64,6 @@
65 64 }
66 65 }
67 66  
68   -
69 67 GTK_WIDGET_CLASS(pw3270ApplicationWindow_parent_class)->destroy(widget);
70 68  
71 69 }
... ... @@ -217,19 +215,39 @@
217 215 else
218 216 gtk_header_bar_set_has_subtitle(header,TRUE);
219 217  
220   - // Create gear button
  218 + // Show the new header
  219 + gtk_widget_show_all(GTK_WIDGET(header));
  220 +
  221 + // Create header's action buttons
221 222 // https://wiki.gnome.org/Initiatives/GnomeGoals/GearIcons
222   - GtkWidget * gear_menu = pw3270_setup_image_button(gtk_menu_button_new(),"open-menu-symbolic");
223   - gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(gear_menu), G_MENU_MODEL(gtk_builder_get_object (builder, "gear-menu")));
224   - gtk_header_bar_pack_end(header, gear_menu);
225 223  
  224 + static const gchar * end_actions[] = {
  225 + "menu.open-menu",
  226 + };
  227 +
  228 + for(ix = 0; ix < G_N_ELEMENTS(end_actions); ix++) {
  229 + gtk_header_bar_pack_end(header, pw3270_header_button_new_from_builder(GTK_WIDGET(window),builder,end_actions[ix]));
  230 + }
  231 +
  232 +
  233 + static const gchar * start_actions[] = {
  234 + "win.disconnect",
  235 + "win.reconnect"
  236 + };
  237 +
  238 + for(ix = 0; ix < G_N_ELEMENTS(start_actions); ix++) {
  239 + gtk_header_bar_pack_start(header, pw3270_header_button_new_from_builder(GTK_WIDGET(window),builder,start_actions[ix]));
  240 + }
  241 +
  242 +
  243 + /*
226 244 // Create "new tab" bar
227 245 GtkWidget * new_tab_button = pw3270_setup_image_button(gtk_button_new(),"tab-new-symbolic");
228 246 gtk_actionable_set_action_name(GTK_ACTIONABLE(new_tab_button),"app.new.tab");
229 247 gtk_header_bar_pack_start(header, new_tab_button);
  248 + gtk_widget_show(new_tab_button);
  249 + */
230 250  
231   - // Show the new header
232   - gtk_widget_show_all(GTK_WIDGET(header));
233 251 }
234 252 break;
235 253  
... ...
ui/window.xml
... ... @@ -30,7 +30,7 @@
30 30 <interface>
31 31  
32 32 <requires lib="gtk+" version="3.0"/>
33   - <menu id="gear-menu">
  33 + <menu id="open-menu">
34 34 <section>
35 35  
36 36 <item>
... ...