Commit 29ef0ba70386d7c1b949cd554b24e305028e7a59
1 parent
a49355ab
Exists in
master
and in
5 other branches
Reincluindo suporte básico para scripts
Showing
8 changed files
with
75 additions
and
44 deletions
Show diff stats
src/include/lib3270/action_table.h
| ... | ... | @@ -41,8 +41,6 @@ |
| 41 | 41 | |
| 42 | 42 | /* Keyboard actions */ |
| 43 | 43 | DECLARE_LIB3270_KEY_ACTION( enter ) |
| 44 | - DECLARE_LIB3270_KEY_ACTION( tab ) | |
| 45 | - DECLARE_LIB3270_KEY_ACTION( backtab ) | |
| 46 | 44 | |
| 47 | 45 | DECLARE_LIB3270_FKEY_ACTION( pfkey ) |
| 48 | 46 | DECLARE_LIB3270_FKEY_ACTION( pakey ) |
| ... | ... | @@ -77,6 +75,9 @@ |
| 77 | 75 | DECLARE_LIB3270_ACTION( nextword ) |
| 78 | 76 | DECLARE_LIB3270_ACTION( fieldend ) |
| 79 | 77 | |
| 78 | + DECLARE_LIB3270_ACTION( nextfield ) | |
| 79 | + DECLARE_LIB3270_ACTION( previousfield ) | |
| 80 | + | |
| 80 | 81 | DECLARE_LIB3270_ACTION( attn ) |
| 81 | 82 | DECLARE_LIB3270_ACTION( break ) |
| 82 | 83 | DECLARE_LIB3270_ACTION( pastenext ) | ... | ... |
src/lib3270/kybd.c
| ... | ... | @@ -1394,7 +1394,7 @@ Tab_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params) |
| 1394 | 1394 | } |
| 1395 | 1395 | */ |
| 1396 | 1396 | |
| 1397 | -LIB3270_KEY_ACTION( tab ) | |
| 1397 | +LIB3270_ACTION( nextfield ) | |
| 1398 | 1398 | { |
| 1399 | 1399 | |
| 1400 | 1400 | // reset_idle_timer(); |
| ... | ... | @@ -1407,7 +1407,7 @@ LIB3270_KEY_ACTION( tab ) |
| 1407 | 1407 | status_reset(hSession); |
| 1408 | 1408 | } else |
| 1409 | 1409 | { |
| 1410 | - ENQUEUE_ACTION(lib3270_tab); | |
| 1410 | + ENQUEUE_ACTION(lib3270_nextfield); | |
| 1411 | 1411 | return 0; |
| 1412 | 1412 | } |
| 1413 | 1413 | } |
| ... | ... | @@ -1439,7 +1439,7 @@ LIB3270_EXPORT int lib3270_clear_operator_error(H3270 *hSession) |
| 1439 | 1439 | /* |
| 1440 | 1440 | * Tab backward to previous field. |
| 1441 | 1441 | */ |
| 1442 | -LIB3270_KEY_ACTION( backtab ) | |
| 1442 | +LIB3270_ACTION( previousfield ) | |
| 1443 | 1443 | { |
| 1444 | 1444 | register int baddr, nbaddr; |
| 1445 | 1445 | int sbaddr; |
| ... | ... | @@ -1455,7 +1455,7 @@ LIB3270_KEY_ACTION( backtab ) |
| 1455 | 1455 | } |
| 1456 | 1456 | else |
| 1457 | 1457 | { |
| 1458 | - ENQUEUE_ACTION(lib3270_backtab); | |
| 1458 | + ENQUEUE_ACTION(lib3270_previousfield); | |
| 1459 | 1459 | return 0; |
| 1460 | 1460 | } |
| 1461 | 1461 | } |
| ... | ... | @@ -3020,7 +3020,7 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *session, char *s, int len, int p |
| 3020 | 3020 | case '\r': /* ignored */ |
| 3021 | 3021 | break; |
| 3022 | 3022 | case '\t': |
| 3023 | - lib3270_tab(session); | |
| 3023 | + lib3270_nextfield(session); | |
| 3024 | 3024 | skipped = False; |
| 3025 | 3025 | break; |
| 3026 | 3026 | case '\\': /* backslashes are NOT special when |
| ... | ... | @@ -3106,12 +3106,12 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *session, char *s, int len, int p |
| 3106 | 3106 | break; |
| 3107 | 3107 | |
| 3108 | 3108 | case 't': |
| 3109 | - lib3270_tab(session); | |
| 3109 | + lib3270_nextfield(session); | |
| 3110 | 3110 | skipped = False; |
| 3111 | 3111 | state = BASE; |
| 3112 | 3112 | break; |
| 3113 | 3113 | case 'T': |
| 3114 | - lib3270_tab(session); | |
| 3114 | + lib3270_nextfield(session); | |
| 3115 | 3115 | skipped = False; |
| 3116 | 3116 | state = BASE; |
| 3117 | 3117 | break; | ... | ... |
src/pw3270/actions.c
| ... | ... | @@ -36,6 +36,7 @@ |
| 36 | 36 | #include <lib3270/actions.h> |
| 37 | 37 | #include <lib3270/selection.h> |
| 38 | 38 | #include <lib3270/trace.h> |
| 39 | + #include <lib3270/macros.h> | |
| 39 | 40 | #include <stdlib.h> |
| 40 | 41 | |
| 41 | 42 | #ifdef DEBUG |
| ... | ... | @@ -736,3 +737,47 @@ GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash |
| 736 | 737 | return action; |
| 737 | 738 | } |
| 738 | 739 | |
| 740 | +static void action_text_script(GtkAction *action, GtkWidget *widget) | |
| 741 | +{ | |
| 742 | + gchar **ln = g_strsplit(g_object_get_data(G_OBJECT(action),"script_text"),"\n",-1); | |
| 743 | + int f; | |
| 744 | + H3270 * hSession = v3270_get_session(widget); | |
| 745 | + | |
| 746 | + for(f=0;ln[f];f++) | |
| 747 | + { | |
| 748 | + GError * error = NULL; | |
| 749 | + gint argc = 0; | |
| 750 | + gchar **argv = NULL; | |
| 751 | + | |
| 752 | + if(g_shell_parse_argv(g_strstrip(ln[f]),&argc,&argv,&error)) | |
| 753 | + { | |
| 754 | + gchar *rsp = lib3270_run_macro(hSession,(const gchar **) argv); | |
| 755 | + if(rsp) | |
| 756 | + g_free(rsp); | |
| 757 | + } | |
| 758 | + else | |
| 759 | + { | |
| 760 | + g_warning("Error parsing \"%s\": %s",g_strstrip(ln[f]),error->message); | |
| 761 | + g_error_free(error); | |
| 762 | + } | |
| 763 | + | |
| 764 | + if(argv) | |
| 765 | + g_strfreev(argv); | |
| 766 | + | |
| 767 | + } | |
| 768 | + | |
| 769 | + | |
| 770 | + g_strfreev(ln); | |
| 771 | +} | |
| 772 | + | |
| 773 | +void ui_connect_text_script(GtkWidget *widget, GtkAction *action, const gchar *script_text, GError **error) | |
| 774 | +{ | |
| 775 | + gchar *base = g_strstrip(g_strdup(script_text)); | |
| 776 | + gchar *text = g_strdup(base); | |
| 777 | + g_free(base); | |
| 778 | + | |
| 779 | + gtk_action_set_sensitive(action,TRUE); | |
| 780 | + g_object_set_data_full(G_OBJECT(action),"script_text",text,g_free); | |
| 781 | + g_signal_connect(action,"activate",G_CALLBACK(action_text_script),widget); | |
| 782 | +} | |
| 783 | + | ... | ... |
src/pw3270/uiparser/parser.h
| ... | ... | @@ -56,4 +56,6 @@ |
| 56 | 56 | gboolean ui_get_bool_attribute(const gchar *key, const gchar **name, const gchar **value, gboolean def); |
| 57 | 57 | GtkAction * ui_get_action(GtkWidget *widget, const gchar *name, GHashTable *hash, const gchar **names, const gchar **values, GError **error); |
| 58 | 58 | |
| 59 | + void ui_connect_text_script(GtkWidget *widget, GtkAction *action, const gchar *script_text, GError **error); | |
| 60 | + | |
| 59 | 61 | #endif // UI_PARSER_H_INCLUDED | ... | ... |
src/pw3270/uiparser/private.h
| ... | ... | @@ -54,11 +54,10 @@ |
| 54 | 54 | |
| 55 | 55 | struct parser |
| 56 | 56 | { |
| 57 | -// int disabled; | |
| 58 | 57 | GtkWidget * toplevel; |
| 59 | 58 | GObject * element; |
| 60 | 59 | GtkAction * action; |
| 61 | -// GCallback callback; | |
| 60 | + GtkAction * script_action; | |
| 62 | 61 | GtkWidget * center_widget; |
| 63 | 62 | GtkWidget ** popup; /**< Popup widgets */ |
| 64 | 63 | GStringChunk * strings; | ... | ... |
src/pw3270/uiparser/script.c
| ... | ... | @@ -37,36 +37,21 @@ |
| 37 | 37 | #define trace_action(a,w) /* */ |
| 38 | 38 | #endif // X3270_TRACE |
| 39 | 39 | |
| 40 | -/*--[ Parser struct ]--------------------------------------------------------------------------------*/ | |
| 41 | - | |
| 42 | - | |
| 43 | 40 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 44 | 41 | |
| 45 | - static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, GtkAction *action, GError **error) | |
| 42 | + static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, struct parser *info, GError **error) | |
| 46 | 43 | { |
| 47 | 44 | trace("%s: %s",__FUNCTION__,element_name); |
| 48 | 45 | } |
| 49 | 46 | |
| 50 | - static void element_end(GMarkupParseContext *context, const gchar *element_name, GtkAction *action, GError **error) | |
| 47 | + static void element_end(GMarkupParseContext *context, const gchar *element_name, struct parser *info, GError **error) | |
| 51 | 48 | { |
| 52 | 49 | trace("%s: %s",__FUNCTION__,element_name); |
| 53 | 50 | } |
| 54 | 51 | |
| 55 | - static void text_action(GtkAction *action, const gchar *text) | |
| 56 | - { | |
| 57 | - trace("Script:\n%s\n",text); | |
| 58 | - } | |
| 59 | - | |
| 60 | - static void script_text(GMarkupParseContext *context, const gchar *element_text, gsize text_len, GtkAction *action, GError **error) | |
| 52 | + static void script_text(GMarkupParseContext *context, const gchar *element_text, gsize text_len, struct parser *info, GError **error) | |
| 61 | 53 | { |
| 62 | - gchar *base = g_strstrip(g_strdup(element_text)); | |
| 63 | - gchar *text = g_strdup(base); | |
| 64 | - g_free(base); | |
| 65 | - | |
| 66 | - gtk_action_set_sensitive(action,TRUE); | |
| 67 | - g_object_set_data_full(G_OBJECT(action),"script_text",text,g_free); | |
| 68 | - g_signal_connect(action,"activate",G_CALLBACK(text_action),text); | |
| 69 | - | |
| 54 | + ui_connect_text_script(info->center_widget, info->script_action,element_text,error); | |
| 70 | 55 | } |
| 71 | 56 | |
| 72 | 57 | GObject * ui_create_script(GMarkupParseContext *context,GtkAction *action, struct parser *info, const gchar **names, const gchar **values, GError **error) |
| ... | ... | @@ -91,7 +76,7 @@ |
| 91 | 76 | return NULL; |
| 92 | 77 | } |
| 93 | 78 | |
| 94 | - trace("%s: info->element: %p action: %p",__FUNCTION__,info->element, action); | |
| 79 | +// trace("%s: info->element: %p action: %p",__FUNCTION__,info->element, action); | |
| 95 | 80 | |
| 96 | 81 | if(!(info->element && info->actions)) |
| 97 | 82 | { |
| ... | ... | @@ -99,9 +84,8 @@ |
| 99 | 84 | return NULL; |
| 100 | 85 | } |
| 101 | 86 | |
| 102 | - trace("%s: Parsing script for action %s",__FUNCTION__,gtk_action_get_name(info->action)); | |
| 103 | - | |
| 104 | - g_markup_parse_context_push(context,&parser,info->action); | |
| 87 | + info->script_action = info->action; | |
| 88 | + g_markup_parse_context_push(context,&parser,info); | |
| 105 | 89 | |
| 106 | 90 | return NULL; |
| 107 | 91 | } | ... | ... |
src/pw3270/v3270/keyboard.c
| ... | ... | @@ -95,8 +95,8 @@ |
| 95 | 95 | { GDK_Up, 0, lib3270_cursor_up }, |
| 96 | 96 | { GDK_Right, 0, lib3270_cursor_right }, |
| 97 | 97 | { GDK_Down, 0, lib3270_cursor_down }, |
| 98 | - { GDK_Tab, 0, lib3270_tab }, | |
| 99 | - { GDK_ISO_Left_Tab, GDK_SHIFT_MASK, lib3270_backtab }, | |
| 98 | + { GDK_Tab, 0, lib3270_nextfield }, | |
| 99 | + { GDK_ISO_Left_Tab, GDK_SHIFT_MASK, lib3270_previousfield }, | |
| 100 | 100 | { GDK_KP_Left, 0, lib3270_cursor_left }, |
| 101 | 101 | { GDK_KP_Up, 0, lib3270_cursor_up }, |
| 102 | 102 | { GDK_KP_Right, 0, lib3270_cursor_right }, |
| ... | ... | @@ -199,13 +199,13 @@ |
| 199 | 199 | void v3270_tab(GtkWidget *widget) |
| 200 | 200 | { |
| 201 | 201 | g_return_if_fail(GTK_IS_V3270(widget)); |
| 202 | - lib3270_tab(GTK_V3270(widget)->host); | |
| 202 | + lib3270_nextfield(GTK_V3270(widget)->host); | |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | void v3270_backtab(GtkWidget *widget) |
| 206 | 206 | { |
| 207 | 207 | g_return_if_fail(GTK_IS_V3270(widget)); |
| 208 | - lib3270_backtab(GTK_V3270(widget)->host); | |
| 208 | + lib3270_previousfield(GTK_V3270(widget)->host); | |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | void v3270_set_string(GtkWidget *widget, const gchar *str) | ... | ... |
ui/00default.xml
| ... | ... | @@ -16,8 +16,8 @@ |
| 16 | 16 | obter mais detalhes. |
| 17 | 17 | |
| 18 | 18 | Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este |
| 19 | - programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 20 | - St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 19 | + programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 20 | + St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | Contatos: |
| ... | ... | @@ -184,8 +184,8 @@ |
| 184 | 184 | <menuitem action='print' src='copy'/> |
| 185 | 185 | |
| 186 | 186 | <separator /> |
| 187 | - <menuitem action='backtab' label='Previous field' /> | |
| 188 | - <menuitem action='tab' label='Next field'/> | |
| 187 | + <menuitem action='previousfield' label='Previous field' /> | |
| 188 | + <menuitem action='nextfield' label='Next field'/> | |
| 189 | 189 | <menuitem name="return" action='activate' label='Return' key='Return' /> |
| 190 | 190 | |
| 191 | 191 | <separator /> |
| ... | ... | @@ -232,8 +232,8 @@ |
| 232 | 232 | <accelerator action='move' target='cursor' direction='up' key='Up' group='online' /> |
| 233 | 233 | <accelerator action='move' target='cursor' direction='down' key='Down' group='online' /> |
| 234 | 234 | |
| 235 | - <accelerator action='PreviousField' key='ISO_Left_Tab' group='online' label='Previous field' /> | |
| 236 | - <accelerator action='NextField' key='Tab' group='online' label='Next field'/> | |
| 235 | + <accelerator action='previousfield' key='ISO_Left_Tab' group='online' label='Previous field' /> | |
| 236 | + <accelerator action='nextfield' key='Tab' group='online' label='Next field'/> | |
| 237 | 237 | |
| 238 | 238 | <accelerator action='dup' key='<Shift>KP_Multiply' group='online' /> |
| 239 | 239 | ... | ... |