Commit 8e33538613b9659a7f933bf71468688cb1dfe8ea

Authored by Perry Werneck
1 parent 101ba80b
Exists in master and in 1 other branch develop

Fixing accelerator settings dialog.

src/dialogs/settings/accelerator.c
@@ -111,6 +111,8 @@ @@ -111,6 +111,8 @@
111 111
112 static void V3270AcceleratorSettings_init(V3270AcceleratorSettings *widget) 112 static void V3270AcceleratorSettings_init(V3270AcceleratorSettings *widget)
113 { 113 {
  114 + size_t ix;
  115 +
114 // Create description list 116 // Create description list
115 GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new(); 117 GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new();
116 118
@@ -171,8 +173,8 @@ @@ -171,8 +173,8 @@
171 NULL 173 NULL
172 ); 174 );
173 175
174 - gtk_tree_view_column_set_resizable(column, TRUE);  
175 gtk_tree_view_column_set_min_width(column, 500); 176 gtk_tree_view_column_set_min_width(column, 500);
  177 + gtk_tree_view_column_set_resizable(column, TRUE);
176 178
177 gtk_tree_view_insert_column( 179 gtk_tree_view_insert_column(
178 GTK_TREE_VIEW(view), 180 GTK_TREE_VIEW(view),
@@ -201,6 +203,13 @@ @@ -201,6 +203,13 @@
201 NULL 203 NULL
202 ); 204 );
203 205
  206 + for(ix = 1; ix < 3; ix++)
  207 + {
  208 + GtkTreeViewColumn * column = gtk_tree_view_get_column(GTK_TREE_VIEW(view), ix);
  209 + gtk_tree_view_column_set_min_width(column, 200);
  210 + gtk_tree_view_column_set_resizable(column, TRUE);
  211 + }
  212 +
204 // Create scroller view 213 // Create scroller view
205 { 214 {
206 GtkWidget * box = gtk_scrolled_window_new(NULL,NULL); 215 GtkWidget * box = gtk_scrolled_window_new(NULL,NULL);
@@ -405,7 +414,7 @@ static void accel_edited(GtkCellRendererAccel G_GNUC_UNUSED(*accel), gchar *path @@ -405,7 +414,7 @@ static void accel_edited(GtkCellRendererAccel G_GNUC_UNUSED(*accel), gchar *path
405 change_accel(widget, path, accel_key, mask, MAIN_VALUE, MAIN_MASK); 414 change_accel(widget, path, accel_key, mask, MAIN_VALUE, MAIN_MASK);
406 } 415 }
407 416
408 -static void alternative_edited(GtkCellRendererAccel G_GNUC_UNUSED(*accel), gchar *path, guint accel_key, GdkModifierType mask, guint G_GNUC_UNUSED(hardware_keycode), V3270AcceleratorSettings *widget) 417 +static void alternative_edited(GtkCellRendererAccel G_GNUC_UNUSED(*renderer), gchar *path, guint accel_key, GdkModifierType mask, guint G_GNUC_UNUSED(hardware_keycode), V3270AcceleratorSettings *widget)
409 { 418 {
410 #ifdef DEBUG 419 #ifdef DEBUG
411 { 420 {
@@ -413,6 +422,43 @@ static void alternative_edited(GtkCellRendererAccel G_GNUC_UNUSED(*accel), gchar @@ -413,6 +422,43 @@ static void alternative_edited(GtkCellRendererAccel G_GNUC_UNUSED(*accel), gchar
413 debug("%s(%s) = %u/%d (%s)",__FUNCTION__,path,accel_key,mask,keyname); 422 debug("%s(%s) = %u/%d (%s)",__FUNCTION__,path,accel_key,mask,keyname);
414 } 423 }
415 #endif // DEBUG 424 #endif // DEBUG
  425 +
  426 + // Check for "single-accel" actions
  427 + V3270Accelerator *accel = NULL;
  428 + GtkTreePath * tree_path = gtk_tree_path_new_from_string(path);
  429 + GtkTreeIter iter;
  430 + if(gtk_tree_model_get_iter(GTK_TREE_MODEL(widget->store),&iter,tree_path))
  431 + {
  432 + GValue value;
  433 + memset(&value,0,sizeof(value));
  434 + gtk_tree_model_get_value(GTK_TREE_MODEL(widget->store), &iter, ACTION, &value);
  435 + accel = (V3270Accelerator *) g_value_get_pointer(&value);
  436 + g_value_unset(&value);
  437 + }
  438 + gtk_tree_path_free(tree_path);
  439 +
  440 + if(accel && accel->type == V3270_ACCELERATOR_TYPE_PFKEY)
  441 + {
  442 + GtkWidget * dialog =
  443 + gtk_message_dialog_new_with_markup(
  444 + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))),
  445 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  446 + GTK_MESSAGE_ERROR,
  447 + GTK_BUTTONS_CANCEL,
  448 + _( "The action \"%s\" can't manage alternative keys" ),
  449 + v3270_accelerator_get_description(accel)
  450 + );
  451 +
  452 + gtk_window_set_title(GTK_WINDOW(dialog),_("Rejected by action"));
  453 + gtk_widget_show_all(dialog);
  454 +
  455 + g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL);
  456 + g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL);
  457 +
  458 + return;
  459 + }
  460 +
  461 + // Call the common validation.
416 change_accel(widget, path, accel_key, mask, ALTERNATIVE_VALUE, ALTERNATIVE_MASK); 462 change_accel(widget, path, accel_key, mask, ALTERNATIVE_VALUE, ALTERNATIVE_MASK);
417 } 463 }
418 464
src/dialogs/settings/host.c
@@ -626,7 +626,7 @@ LIB3270_EXPORT void v3270_select_host(GtkWidget *widget) @@ -626,7 +626,7 @@ LIB3270_EXPORT void v3270_select_host(GtkWidget *widget)
626 g_return_if_fail(GTK_IS_V3270(widget)); 626 g_return_if_fail(GTK_IS_V3270(widget));
627 627
628 GtkWidget * dialog = v3270_settings_dialog_new(); 628 GtkWidget * dialog = v3270_settings_dialog_new();
629 - GtkWidget * settings = v3270_host_select_new(); 629 + GtkWidget * settings = v3270_host_settings_new();
630 630
631 gtk_window_set_title(GTK_WINDOW(dialog), v3270_settings_get_title(settings)); 631 gtk_window_set_title(GTK_WINDOW(dialog), v3270_settings_get_title(settings));
632 gtk_container_add(GTK_CONTAINER(dialog), settings); 632 gtk_container_add(GTK_CONTAINER(dialog), settings);
src/include/internals.h
@@ -176,6 +176,7 @@ @@ -176,6 +176,7 @@
176 { 176 {
177 struct _V3270Accelerator parent; 177 struct _V3270Accelerator parent;
178 const gchar *name; 178 const gchar *name;
  179 + const gchar *description;
179 unsigned short keycode; 180 unsigned short keycode;
180 } V3270PFKeyAccelerator; 181 } V3270PFKeyAccelerator;
181 182
src/terminal/keyboard/accelerator.c
@@ -40,16 +40,28 @@ @@ -40,16 +40,28 @@
40 { 40 {
41 V3270Accelerator * rc = NULL; 41 V3270Accelerator * rc = NULL;
42 42
43 - if(accel->type == V3270_ACCELERATOR_TYPE_CUSTOM)  
44 - {  
45 - V3270CustomAccelerator * customAccel = g_new0(V3270CustomAccelerator,1);  
46 - *customAccel = *((V3270CustomAccelerator *) accel);  
47 - rc = (V3270Accelerator *) customAccel;  
48 - }  
49 - else  
50 - { 43 + switch(accel->type)
  44 + {
  45 + case V3270_ACCELERATOR_TYPE_CUSTOM:
  46 + {
  47 + V3270CustomAccelerator * customAccel = g_new0(V3270CustomAccelerator,1);
  48 + *customAccel = *((V3270CustomAccelerator *) accel);
  49 + rc = (V3270Accelerator *) customAccel;
  50 + }
  51 + break;
  52 +
  53 + case V3270_ACCELERATOR_TYPE_PFKEY:
  54 + {
  55 + V3270PFKeyAccelerator * customAccel = g_new0(V3270PFKeyAccelerator,1);
  56 + *customAccel = *((V3270PFKeyAccelerator *) accel);
  57 + rc = (V3270Accelerator *) customAccel;
  58 + }
  59 + break;
  60 +
  61 + default:
51 rc = g_new0(V3270Accelerator,1); 62 rc = g_new0(V3270Accelerator,1);
52 *rc = *accel; 63 *rc = *accel;
  64 +
53 } 65 }
54 66
55 return rc; 67 return rc;
@@ -174,6 +186,9 @@ @@ -174,6 +186,9 @@
174 186
175 case V3270_ACCELERATOR_TYPE_PFKEY: 187 case V3270_ACCELERATOR_TYPE_PFKEY:
176 188
  189 + if( ((V3270PFKeyAccelerator *)accel)->description )
  190 + return ((V3270PFKeyAccelerator *)accel)->description;
  191 +
177 if( ((V3270PFKeyAccelerator *)accel)->name ) 192 if( ((V3270PFKeyAccelerator *)accel)->name )
178 return ((V3270PFKeyAccelerator *)accel)->name; 193 return ((V3270PFKeyAccelerator *)accel)->name;
179 194
@@ -200,6 +215,9 @@ @@ -200,6 +215,9 @@
200 case V3270_ACCELERATOR_TYPE_CUSTOM: 215 case V3270_ACCELERATOR_TYPE_CUSTOM:
201 return ((V3270CustomAccelerator *) accel)->name; 216 return ((V3270CustomAccelerator *) accel)->name;
202 217
  218 + case V3270_ACCELERATOR_TYPE_PFKEY:
  219 + return ((V3270PFKeyAccelerator *) accel)->name;
  220 +
203 } 221 }
204 222
205 return NULL; 223 return NULL;
src/terminal/keyboard/init.c
@@ -143,7 +143,6 @@ @@ -143,7 +143,6 @@
143 // Create accelerators for lib3270 toggles. 143 // Create accelerators for lib3270 toggles.
144 { 144 {
145 const LIB3270_TOGGLE * toggles = lib3270_get_toggles(); 145 const LIB3270_TOGGLE * toggles = lib3270_get_toggles();
146 - size_t ix;  
147 146
148 for(ix = 0; toggles[ix].name; ix++) 147 for(ix = 0; toggles[ix].name; ix++)
149 { 148 {
@@ -164,8 +163,6 @@ @@ -164,8 +163,6 @@
164 163
165 // Create accelerators for internal actions. 164 // Create accelerators for internal actions.
166 { 165 {
167 - size_t ix;  
168 -  
169 const V3270_ACTION * actions = v3270_get_actions(); 166 const V3270_ACTION * actions = v3270_get_actions();
170 167
171 for(ix = 0 ; actions[ix].name; ix++) 168 for(ix = 0 ; actions[ix].name; ix++)
@@ -183,6 +180,51 @@ @@ -183,6 +180,51 @@
183 } 180 }
184 } 181 }
185 182
  183 + // Create PF-Key accelerators
  184 + {
  185 + static const struct
  186 + {
  187 + guint key;
  188 + GdkModifierType mods;
  189 + const gchar * name;
  190 + const gchar * description;
  191 + unsigned short pfkey;
  192 + } accels[] =
  193 + {
  194 + {
  195 + .key = GDK_Page_Up,
  196 + .name = "page-up",
  197 + .description = N_( "Previous page" ),
  198 + .pfkey = 7
  199 + },
  200 + {
  201 + .key = GDK_Page_Down,
  202 + .name = "page-down",
  203 + .description = N_( "Next page" ),
  204 + .pfkey = 8
  205 + }
  206 + };
  207 +
  208 + for(ix = 0 ; ix < G_N_ELEMENTS(accels); ix++)
  209 + {
  210 + V3270PFKeyAccelerator * accelerator = g_new0(V3270PFKeyAccelerator,1);
  211 +
  212 + accelerator->keycode = accels[ix].pfkey;
  213 + accelerator->name = accels[ix].name;
  214 + accelerator->description = accels[ix].description;
  215 + accelerator->parent.type = V3270_ACCELERATOR_TYPE_PFKEY;
  216 + accelerator->parent.key = accels[ix].key;
  217 + accelerator->parent.mods = accels[ix].mods;
  218 + accelerator->parent.arg = (gconstpointer) accelerator;
  219 + accelerator->parent.activate = G_CALLBACK(fire_pfkey_action);
  220 +
  221 + debug("****************************%p [%s]",accelerator,accelerator->name);
  222 + widget->accelerators = g_slist_prepend(widget->accelerators,accelerator);
  223 +
  224 + }
  225 +
  226 + }
  227 +
186 v3270_accelerator_map_sort(widget); 228 v3270_accelerator_map_sort(widget);
187 229
188 } 230 }
src/terminal/keyboard/keyfile.c
@@ -49,12 +49,12 @@ @@ -49,12 +49,12 @@
49 // It's a PF-Key action! 49 // It's a PF-Key action!
50 g_autofree gchar * key = g_strdup_printf("pf%u",((V3270PFKeyAccelerator *)accel)->keycode); 50 g_autofree gchar * key = g_strdup_printf("pf%u",((V3270PFKeyAccelerator *)accel)->keycode);
51 51
52 - debug("%s=%s",((V3270PFKeyAccelerator *)accel)->name,key); 52 + debug("%p %s=%s",accel,v3270_accelerator_get_name(accel),key);
53 53
54 g_key_file_set_string( 54 g_key_file_set_string(
55 ((struct Args *) ptr)->key_file, 55 ((struct Args *) ptr)->key_file,
56 ((struct Args *) ptr)->group_name, 56 ((struct Args *) ptr)->group_name,
57 - ((V3270PFKeyAccelerator *)accel)->name, 57 + v3270_accelerator_get_name(accel),
58 key 58 key
59 ); 59 );
60 60
@@ -86,7 +86,7 @@ @@ -86,7 +86,7 @@
86 86
87 } 87 }
88 88
89 - static int fire_pfkey_action(GtkWidget *widget, V3270PFKeyAccelerator *accel) 89 + int fire_pfkey_action(GtkWidget *widget, V3270PFKeyAccelerator *accel)
90 { 90 {
91 return lib3270_pfkey(v3270_get_session(widget),(int) accel->keycode); 91 return lib3270_pfkey(v3270_get_session(widget),(int) accel->keycode);
92 } 92 }
@@ -126,61 +126,64 @@ @@ -126,61 +126,64 @@
126 126
127 if(!accel) 127 if(!accel)
128 { 128 {
129 - // Is a special PFKey action? 129 + g_warning("Can't parse accelerator %s",name);
  130 + return;
  131 + }
130 132
131 - // Page_Down=pf8 133 + debug("Recreating accelerators for action \"%s\"",v3270_accelerator_get_name(accel));
132 134
133 - unsigned int pfkey = 0; 135 + {
  136 + size_t ix;
  137 + gchar ** keycodes = g_strsplit(keys," ",-1);
134 138
135 - if(sscanf(keys,"pf%u",&pfkey) == 1) 139 + for(ix=0;keycodes[ix];ix++)
136 { 140 {
137 - guint key;  
138 - GdkModifierType mods;  
139 141
140 - debug("Creating special accelerator for PF%u",pfkey);  
141 -  
142 - gtk_accelerator_parse(name,&key,&mods);  
143 -  
144 - if(!key) 142 + if(accel->type == V3270_ACCELERATOR_TYPE_PFKEY)
145 { 143 {
146 - g_warning("Can't parse accelerator %s",name);  
147 - return;  
148 - } 144 + unsigned int pfkey = 0;
149 145
150 - // Remap PFKey accelerator  
151 - V3270PFKeyAccelerator *pfAccel = g_new0(V3270PFKeyAccelerator,1); 146 + if(sscanf(keycodes[ix],"pf%u",&pfkey) != 1)
  147 + {
  148 + g_warning("Can't parse accelerator %s",keys);
  149 + return;
  150 + }
152 151
153 - pfAccel->keycode = (unsigned short) pfkey;  
154 - pfAccel->name = g_intern_string(name);  
155 - pfAccel->parent.type = V3270_ACCELERATOR_TYPE_PFKEY;  
156 - pfAccel->parent.key = key;  
157 - pfAccel->parent.mods = mods;  
158 - pfAccel->parent.arg = (gconstpointer) pfAccel;  
159 - pfAccel->parent.activate = G_CALLBACK(fire_pfkey_action); 152 + // It's a PFKey redirector
  153 + guint key;
  154 + GdkModifierType mods;
160 155
161 - terminal->accelerators = g_slist_prepend(terminal->accelerators,pfAccel); 156 + debug("Creating special accelerator %s",v3270_accelerator_get_name(accel));
  157 + gtk_accelerator_parse(keycodes[ix],&key,&mods);
162 158
163 - }  
164 - else  
165 - {  
166 - debug("Can't find accelerator \"%s\"",name);  
167 - g_warning("Can't find accelerator \"%s\"",name);  
168 - } 159 + if(!key)
  160 + {
  161 + g_warning("Can't parse accelerator %s",v3270_accelerator_get_name(accel));
  162 + return;
  163 + }
169 164
170 - return;  
171 - } 165 + // Remap PFKey accelerator
  166 + V3270PFKeyAccelerator *pfAccel = g_new0(V3270PFKeyAccelerator,1);
172 167
173 - debug("Recreating accelerators for action \"%s\"",v3270_accelerator_get_name(accel)); 168 + pfAccel->keycode = (unsigned short) pfkey;
  169 + pfAccel->name = ((V3270PFKeyAccelerator *) accel)->name;
  170 + pfAccel->parent.type = V3270_ACCELERATOR_TYPE_PFKEY;
  171 + pfAccel->parent.key = key;
  172 + pfAccel->parent.mods = mods;
  173 + pfAccel->parent.arg = (gconstpointer) pfAccel;
  174 + pfAccel->parent.activate = G_CALLBACK(fire_pfkey_action);
174 175
175 - {  
176 - size_t ix;  
177 - gchar ** keycodes = g_strsplit(keys," ",-1); 176 + terminal->accelerators = g_slist_prepend(terminal->accelerators,pfAccel);
  177 +
  178 + }
  179 + else
  180 + {
  181 + // Standard accelerator.
  182 + V3270Accelerator * acc = v3270_accelerator_copy(accel);
  183 + gtk_accelerator_parse(keycodes[ix],&acc->key,&acc->mods);
  184 + terminal->accelerators = g_slist_prepend(terminal->accelerators,acc);
  185 + }
178 186
179 - for(ix=0;keycodes[ix];ix++)  
180 - {  
181 - V3270Accelerator * acc = v3270_accelerator_copy(accel);  
182 - gtk_accelerator_parse(keycodes[ix],&acc->key,&acc->mods);  
183 - terminal->accelerators = g_slist_prepend(terminal->accelerators,acc);  
184 } 187 }
185 188
186 g_strfreev(keycodes); 189 g_strfreev(keycodes);
src/terminal/keyboard/private.h
@@ -32,5 +32,7 @@ @@ -32,5 +32,7 @@
32 #include <v3270/actions.h> 32 #include <v3270/actions.h>
33 #include <internals.h> 33 #include <internals.h>
34 34
  35 + G_GNUC_INTERNAL int fire_pfkey_action(GtkWidget *widget, V3270PFKeyAccelerator *accel);
  36 +
35 37
36 38