Commit 80157a40582f1bd40b2eaa1f25109d415523f4bc
1 parent
20603bd1
Exists in
master
and in
2 other branches
Refactoring action list editor on a more standard way.
Showing
7 changed files
with
268 additions
and
31 deletions
Show diff stats
pw3270.cbp
... | ... | @@ -136,6 +136,9 @@ |
136 | 136 | <Unit filename="src/objects/os/windows/savedesktopicon.c"> |
137 | 137 | <Option compilerVar="CC" /> |
138 | 138 | </Unit> |
139 | + <Unit filename="src/objects/settings/actionview.c"> | |
140 | + <Option compilerVar="CC" /> | |
141 | + </Unit> | |
139 | 142 | <Unit filename="src/objects/settings/dialog.c"> |
140 | 143 | <Option compilerVar="CC" /> |
141 | 144 | </Unit> | ... | ... |
src/include/pw3270/actions.h
... | ... | @@ -104,7 +104,7 @@ |
104 | 104 | void pw3270_action_view_move_selected(GtkWidget *from, GtkWidget *to); |
105 | 105 | void pw3270_action_view_append(GtkWidget *widget, const gchar *label, GdkPixbuf *pixbuf, const gchar *action_name, const PW3270ActionViewFlag flags); |
106 | 106 | gchar * pw3270_action_view_get_action_names(GtkWidget *widget); |
107 | - GtkWidget * pw3270_action_view_extract_button_new(GtkWidget *widget, const gchar *icon_name); | |
107 | + GtkWidget * pw3270_action_view_move_button_new(GtkWidget *from, GtkWidget *to, const gchar *icon_name); | |
108 | 108 | |
109 | 109 | Pw3270ActionList * pw3270_action_list_new(GtkApplication *application); |
110 | 110 | Pw3270ActionList * pw3270_action_list_append(Pw3270ActionList *action_list, const gchar *label, GdkPixbuf *pixbuf, const gchar *action_name, const PW3270ActionViewFlag flags); | ... | ... |
src/include/pw3270/settings.h
... | ... | @@ -36,6 +36,7 @@ |
36 | 36 | #endif // _WIN32 |
37 | 37 | |
38 | 38 | #include <gtk/gtk.h> |
39 | + #include <pw3270/actions.h> | |
39 | 40 | |
40 | 41 | G_BEGIN_DECLS |
41 | 42 | |
... | ... | @@ -91,4 +92,18 @@ |
91 | 92 | |
92 | 93 | G_END_DECLS |
93 | 94 | |
95 | +/*--[ PW3270 Action List Editor ]--------------------------------------------------------------------*/ | |
96 | + | |
97 | + #define GTK_TYPE_PW3270_SETTINGS_ACTIONS (PW3270SettingsActions_get_type()) | |
98 | + | |
99 | + typedef struct _PW3270SettingsActions PW3270SettingsActions; | |
100 | + typedef struct _PW3270SettingsActionsClass PW3270SettingsActionsClass; | |
101 | + | |
102 | + GType PW3270SettingsActions_get_type(void); | |
103 | + GtkWidget * pw3270_settings_actions_new(); | |
104 | + Pw3270ActionList * pw3270_settings_action_load(GtkWidget *widget, Pw3270ActionList *available, const gchar *value); | |
105 | + | |
106 | + G_END_DECLS | |
107 | + | |
108 | + | |
94 | 109 | #endif // V3270SETTINGS_H_INCLUDED | ... | ... |
src/objects/actions/view.c
... | ... | @@ -436,16 +436,18 @@ |
436 | 436 | |
437 | 437 | } |
438 | 438 | |
439 | - GtkWidget * pw3270_action_view_extract_button_new(GtkWidget *widget, const gchar *icon_name) { | |
439 | + GtkWidget * pw3270_action_view_move_button_new(GtkWidget *from, GtkWidget *to, const gchar *icon_name) { | |
440 | 440 | |
441 | 441 | GtkWidget * button = gtk_button_new_from_icon_name(icon_name,GTK_ICON_SIZE_DND); |
442 | 442 | |
443 | 443 | gtk_widget_set_focus_on_click(button,FALSE); |
444 | 444 | gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE); |
445 | 445 | gtk_widget_set_sensitive(button,FALSE); |
446 | + gtk_widget_set_hexpand(button,FALSE); | |
447 | + gtk_widget_set_vexpand(button,FALSE); | |
446 | 448 | |
447 | 449 | g_signal_connect( |
448 | - gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)), | |
450 | + gtk_tree_view_get_selection(GTK_TREE_VIEW(from)), | |
449 | 451 | "changed", |
450 | 452 | G_CALLBACK(selection_changed), |
451 | 453 | button | ... | ... |
... | ... | @@ -0,0 +1,216 @@ |
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 | +#ifdef _WIN32 | |
31 | + #include <winsock2.h> | |
32 | + #include <windows.h> | |
33 | +#endif // _WIN32 | |
34 | + | |
35 | + #include <pw3270.h> | |
36 | + #include <pw3270/settings.h> | |
37 | + #include <lib3270.h> | |
38 | + #include <lib3270/log.h> | |
39 | + #include <pw3270/actions.h> | |
40 | + | |
41 | + struct _PW3270SettingsActions { | |
42 | + GtkGrid parent; | |
43 | + GtkWidget * views[3]; | |
44 | + GtkTreeModel * model; | |
45 | + }; | |
46 | + | |
47 | + struct _PW3270SettingsActionsClass { | |
48 | + GtkGridClass parent; | |
49 | + | |
50 | + int dunno; | |
51 | + }; | |
52 | + | |
53 | + G_DEFINE_TYPE(PW3270SettingsActions, PW3270SettingsActions, GTK_TYPE_GRID); | |
54 | + | |
55 | + static void PW3270SettingsActions_class_init(PW3270SettingsActionsClass *klass) { | |
56 | + | |
57 | + } | |
58 | + | |
59 | + static void PW3270SettingsActions_init(PW3270SettingsActions *grid) { | |
60 | + | |
61 | + size_t ix; | |
62 | + | |
63 | + static const struct View { | |
64 | + const gchar *label; | |
65 | + const gchar *tooltip; | |
66 | + } views[G_N_ELEMENTS(grid->views)] = { | |
67 | + { | |
68 | + .label = N_("Start"), | |
69 | + .tooltip = N_("Items packed from the start to the end") | |
70 | + }, | |
71 | + | |
72 | + { | |
73 | + .label = N_("Available"), | |
74 | + .tooltip = N_("List of the available and unpacked actions") | |
75 | + }, | |
76 | + | |
77 | + { | |
78 | + .label = N_("End"), | |
79 | + .tooltip = N_("Items packed from the end to the start") | |
80 | + } | |
81 | + }; | |
82 | + | |
83 | + gtk_grid_set_row_homogeneous(GTK_GRID(grid),FALSE); | |
84 | + gtk_grid_set_row_spacing(GTK_GRID(grid),12); | |
85 | + gtk_grid_set_column_spacing(GTK_GRID(grid),6); | |
86 | + | |
87 | + { | |
88 | + // Create views | |
89 | + GtkTreeSelection * selection; | |
90 | + GtkWidget *box; | |
91 | + | |
92 | + for(ix = 0; ix < G_N_ELEMENTS(grid->views); ix++) { | |
93 | + | |
94 | + // Create label. | |
95 | + GtkWidget * label = gtk_label_new(gettext(views[ix].label)); | |
96 | + gtk_widget_set_tooltip_markup(label,gettext(views[ix].tooltip)); | |
97 | + //gtk_label_set_xalign(GTK_LABEL(label),0); | |
98 | + gtk_widget_set_hexpand(label,TRUE); | |
99 | + gtk_widget_set_vexpand(label,FALSE); | |
100 | + | |
101 | + gtk_grid_attach( | |
102 | + GTK_GRID(grid), | |
103 | + label, | |
104 | + (ix*2),0, | |
105 | + 1,1 | |
106 | + ); | |
107 | + | |
108 | + // Create view | |
109 | + grid->views[ix] = pw3270_action_view_new(); | |
110 | + gtk_widget_set_hexpand(grid->views[ix],TRUE); | |
111 | + gtk_widget_set_vexpand(grid->views[ix],TRUE); | |
112 | + | |
113 | + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(grid->views[ix])); | |
114 | + gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); | |
115 | + | |
116 | + GtkWidget * box = gtk_scrolled_window_new(NULL,NULL); | |
117 | + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(box),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); | |
118 | + gtk_container_add(GTK_CONTAINER(box),grid->views[ix]); | |
119 | + | |
120 | + gtk_grid_attach( | |
121 | + GTK_GRID(grid), | |
122 | + box, | |
123 | + (ix*2),1, | |
124 | + 1,4 | |
125 | + ); | |
126 | + | |
127 | + } | |
128 | + | |
129 | + } | |
130 | + | |
131 | + // Create buttons | |
132 | + { | |
133 | + GtkWidget *buttons[] = { | |
134 | + pw3270_action_view_move_button_new(grid->views[1],grid->views[0],"go-previous"), | |
135 | + pw3270_action_view_move_button_new(grid->views[1],grid->views[2],"go-next"), | |
136 | + pw3270_action_view_move_button_new(grid->views[0],grid->views[1],"go-next"), | |
137 | + pw3270_action_view_move_button_new(grid->views[2],grid->views[1],"go-previous") | |
138 | + }; | |
139 | + | |
140 | + gtk_grid_attach(GTK_GRID(grid),buttons[0],1,1,1,1); | |
141 | + gtk_grid_attach(GTK_GRID(grid),buttons[1],3,1,1,1); | |
142 | + | |
143 | + gtk_grid_attach(GTK_GRID(grid),buttons[2],1,2,1,1); | |
144 | + gtk_grid_attach(GTK_GRID(grid),buttons[3],3,2,1,1); | |
145 | + | |
146 | + } | |
147 | + | |
148 | + } | |
149 | + | |
150 | + GtkWidget * pw3270_settings_actions_new() { | |
151 | + | |
152 | + return GTK_WIDGET(g_object_new( | |
153 | + GTK_TYPE_PW3270_SETTINGS_ACTIONS, | |
154 | + NULL | |
155 | + )); | |
156 | + | |
157 | + } | |
158 | + | |
159 | + Pw3270ActionList * pw3270_settings_action_load(GtkWidget *widget, Pw3270ActionList *action_list, const gchar *action_names) { | |
160 | + | |
161 | + PW3270SettingsActions *editor = (PW3270SettingsActions *) widget; | |
162 | + | |
163 | + static const unsigned short columns[] = { 0, 2 }; | |
164 | + unsigned short column; | |
165 | + size_t action; | |
166 | + | |
167 | + gchar **views = g_strsplit(action_names,":",-1); | |
168 | + | |
169 | + for(column = 0; column < G_N_ELEMENTS(columns); column++) { | |
170 | + | |
171 | + if(!views[column]) | |
172 | + break; | |
173 | + | |
174 | + gchar ** actions = g_strsplit(views[column],",",-1); | |
175 | + | |
176 | + for(action = 0; actions[action];action++) { | |
177 | + action_list = pw3270_action_list_move_action( | |
178 | + action_list, | |
179 | + actions[action], | |
180 | + editor->views[columns[column]] | |
181 | + ); | |
182 | + } | |
183 | + | |
184 | + g_strfreev(actions); | |
185 | + } | |
186 | + | |
187 | + g_strfreev(views); | |
188 | + | |
189 | + pw3270_action_view_set_actions(editor->views[1], action_list); | |
190 | + | |
191 | + return action_list; | |
192 | + } | |
193 | + | |
194 | + /* | |
195 | + static void remove_from_left(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
196 | + debug("%s(%p)",__FUNCTION__,settings); | |
197 | + pw3270_action_view_move_selected(settings->views[0],settings->views[2]); | |
198 | + } | |
199 | + | |
200 | + static void add_to_left(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
201 | + debug("%s(%p)",__FUNCTION__,settings); | |
202 | + pw3270_action_view_move_selected(settings->views[2],settings->views[0]); | |
203 | + } | |
204 | + | |
205 | + static void remove_from_right(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
206 | + debug("%s(%p)",__FUNCTION__,settings); | |
207 | + pw3270_action_view_move_selected(settings->views[1],settings->views[2]); | |
208 | + } | |
209 | + | |
210 | + static void add_to_right(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
211 | + debug("%s(%p)",__FUNCTION__,settings); | |
212 | + pw3270_action_view_move_selected(settings->views[2],settings->views[1]); | |
213 | + } | |
214 | + | |
215 | + | |
216 | +*/ | ... | ... |
src/objects/toolbar/settings.c
... | ... | @@ -59,7 +59,7 @@ |
59 | 59 | |
60 | 60 | struct _PW3270SettingsPrivate { |
61 | 61 | GtkWidget * views[2]; |
62 | - GtkWidget * buttons[2]; | |
62 | +// GtkWidget * buttons[2]; | |
63 | 63 | GtkTreeModel * models[2]; |
64 | 64 | GtkWidget * combos[G_N_ELEMENTS(comboboxes)]; |
65 | 65 | }; |
... | ... | @@ -150,6 +150,7 @@ |
150 | 150 | gtk_widget_set_hexpand(box,FALSE); |
151 | 151 | gtk_widget_set_vexpand(box,FALSE); |
152 | 152 | |
153 | + /* | |
153 | 154 | page->buttons[0] = pw3270_action_view_extract_button_new(page->views[0],"go-next"), |
154 | 155 | page->buttons[1] = pw3270_action_view_extract_button_new(page->views[1],"go-previous"), |
155 | 156 | |
... | ... | @@ -169,6 +170,7 @@ |
169 | 170 | G_CALLBACK(toolbar_insert), |
170 | 171 | page |
171 | 172 | ); |
173 | + */ | |
172 | 174 | |
173 | 175 | gtk_grid_attach( |
174 | 176 | grid, | ... | ... |
src/objects/window/header-settings.c
... | ... | @@ -40,10 +40,14 @@ |
40 | 40 | /*--[ Constants ]------------------------------------------------------------------------------------*/ |
41 | 41 | |
42 | 42 | struct _PW3270SettingsPrivate { |
43 | + GtkWidget * editor; | |
44 | + /* | |
43 | 45 | GtkWidget * views[3]; |
44 | 46 | GtkTreeModel * model; |
47 | + */ | |
45 | 48 | }; |
46 | 49 | |
50 | + /* | |
47 | 51 | static const struct _views { |
48 | 52 | const char * label; |
49 | 53 | gint left; |
... | ... | @@ -69,29 +73,10 @@ |
69 | 73 | .height = 10 |
70 | 74 | } |
71 | 75 | }; |
76 | + */ | |
72 | 77 | |
73 | 78 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
74 | 79 | |
75 | - static void remove_from_left(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
76 | - debug("%s(%p)",__FUNCTION__,settings); | |
77 | - pw3270_action_view_move_selected(settings->views[0],settings->views[2]); | |
78 | - } | |
79 | - | |
80 | - static void add_to_left(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
81 | - debug("%s(%p)",__FUNCTION__,settings); | |
82 | - pw3270_action_view_move_selected(settings->views[2],settings->views[0]); | |
83 | - } | |
84 | - | |
85 | - static void remove_from_right(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
86 | - debug("%s(%p)",__FUNCTION__,settings); | |
87 | - pw3270_action_view_move_selected(settings->views[1],settings->views[2]); | |
88 | - } | |
89 | - | |
90 | - static void add_to_right(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
91 | - debug("%s(%p)",__FUNCTION__,settings); | |
92 | - pw3270_action_view_move_selected(settings->views[2],settings->views[1]); | |
93 | - } | |
94 | - | |
95 | 80 | GtkWidget * pw3270_header_settings_new() { |
96 | 81 | |
97 | 82 | size_t ix; |
... | ... | @@ -106,6 +91,15 @@ |
106 | 91 | // Create private data. |
107 | 92 | PW3270SettingsPrivate * page = settings->settings = g_new0(PW3270SettingsPrivate,1); |
108 | 93 | |
94 | + page->editor = pw3270_settings_actions_new(); | |
95 | + | |
96 | + gtk_grid_attach( | |
97 | + GTK_GRID(settings), | |
98 | + v3270_dialog_section_new(_("Title bar actions"), _("Change the position of the title bar icons"), page->editor), | |
99 | + 0,0,4,3 | |
100 | + ); | |
101 | + | |
102 | + /* | |
109 | 103 | // Create dialog grid |
110 | 104 | GtkGrid * grid = GTK_GRID(gtk_grid_new()); |
111 | 105 | gtk_grid_set_row_homogeneous(grid,FALSE); |
... | ... | @@ -222,7 +216,7 @@ |
222 | 216 | } |
223 | 217 | |
224 | 218 | } |
225 | - | |
219 | + */ | |
226 | 220 | |
227 | 221 | gtk_widget_show_all(GTK_WIDGET(settings)); |
228 | 222 | return GTK_WIDGET(settings); |
... | ... | @@ -230,11 +224,10 @@ |
230 | 224 | |
231 | 225 | void load(GtkWidget *widget, PW3270SettingsPrivate *page) { |
232 | 226 | |
233 | - size_t view, action; | |
234 | - g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); | |
227 | + g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); | |
235 | 228 | |
236 | - // Populate views | |
237 | - Pw3270ActionList * action_list = pw3270_action_list_new(GTK_APPLICATION(g_application_get_default())); | |
229 | + // Get avaliable actions. | |
230 | + Pw3270ActionList * action_list = pw3270_action_list_new(GTK_APPLICATION(g_application_get_default())); | |
238 | 231 | |
239 | 232 | // Add standard menus |
240 | 233 | { |
... | ... | @@ -283,6 +276,10 @@ |
283 | 276 | |
284 | 277 | // Load settings |
285 | 278 | g_autofree gchar * action_names = g_settings_get_string(settings,"header-action-names"); |
279 | + | |
280 | + action_list = pw3270_settings_action_load(page->editor, action_list, action_names); | |
281 | + | |
282 | + /* | |
286 | 283 | gchar **views = g_strsplit(action_names,":",-1); |
287 | 284 | |
288 | 285 | for(view = 0; view < 2; view++) { |
... | ... | @@ -303,12 +300,14 @@ |
303 | 300 | |
304 | 301 | pw3270_action_view_set_actions(page->views[2], action_list); |
305 | 302 | |
306 | - pw3270_action_list_free(action_list); | |
303 | + */ | |
307 | 304 | |
305 | + pw3270_action_list_free(action_list); | |
308 | 306 | } |
309 | 307 | |
310 | 308 | void apply(GtkWidget *widget, PW3270SettingsPrivate *page) { |
311 | 309 | |
310 | + /* | |
312 | 311 | g_autofree gchar * left_names = pw3270_action_view_get_action_names(page->views[0]); |
313 | 312 | g_autofree gchar * right_names = pw3270_action_view_get_action_names(page->views[1]); |
314 | 313 | g_autofree gchar * action_names = g_strconcat(left_names,":",right_names,NULL); |
... | ... | @@ -317,6 +316,6 @@ |
317 | 316 | |
318 | 317 | g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); |
319 | 318 | g_settings_set_string(settings,"header-action-names",action_names); |
320 | - | |
319 | + */ | |
321 | 320 | } |
322 | 321 | ... | ... |