Commit 0af119d4e3b2ca45bc8e51500cb3b4b9e83652ad
1 parent
38e4ce37
Exists in
master
and in
1 other branch
Saving accelerators to keyfile.
Showing
6 changed files
with
88 additions
and
12 deletions
Show diff stats
src/include/v3270/actions.h
| ... | ... | @@ -59,12 +59,18 @@ |
| 59 | 59 | |
| 60 | 60 | LIB3270_EXPORT void v3270_accelerator_map_foreach(GtkWidget *widget,void (*call)(const V3270Accelerator * accel, const char *keys, gpointer ptr), gpointer ptr); |
| 61 | 61 | |
| 62 | + LIB3270_EXPORT void v3270_accelerator_map_to_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name); | |
| 63 | + | |
| 62 | 64 | LIB3270_EXPORT const V3270Accelerator * v3270_get_accelerator(GtkWidget *widget, guint keyval, GdkModifierType state); |
| 63 | 65 | LIB3270_EXPORT void v3270_accelerator_activate(const V3270Accelerator * accel, GtkWidget *terminal); |
| 64 | 66 | LIB3270_EXPORT gboolean v3270_accelerator_compare(const V3270Accelerator * accel, const guint keyval, const GdkModifierType mods); |
| 65 | 67 | LIB3270_EXPORT const gchar * v3270_accelerator_get_name(const V3270Accelerator * accel); |
| 66 | 68 | LIB3270_EXPORT const gchar * v3270_accelerator_get_description(const V3270Accelerator * accel); |
| 67 | 69 | |
| 70 | + /// @brief Converts the accelerator into a string which can be used to represent the accelerator to the user. | |
| 71 | + /// @return A newly-allocated string representing the accelerator. | |
| 72 | + LIB3270_EXPORT gchar * v3270_accelerator_get_label(const V3270Accelerator * accel); | |
| 73 | + | |
| 68 | 74 | G_END_DECLS |
| 69 | 75 | |
| 70 | 76 | #endif // V3270_ACTIONS_H_INCLUDED | ... | ... |
src/terminal/keyboard/accelerator.c
| ... | ... | @@ -142,6 +142,8 @@ |
| 142 | 142 | |
| 143 | 143 | g_autofree gchar * keyname = gtk_accelerator_name(accel->key,accel->mods); |
| 144 | 144 | g_string_append(str,keyname); |
| 145 | + | |
| 146 | + | |
| 145 | 147 | } |
| 146 | 148 | |
| 147 | 149 | accelerator = g_slist_next(accelerator); |
| ... | ... | @@ -154,3 +156,8 @@ |
| 154 | 156 | g_string_free(str,FALSE); |
| 155 | 157 | |
| 156 | 158 | } |
| 159 | + | |
| 160 | + LIB3270_EXPORT gchar * v3270_accelerator_get_label(const V3270Accelerator * accel) | |
| 161 | + { | |
| 162 | + return gtk_accelerator_get_label(accel->key,accel->mods); | |
| 163 | + } | ... | ... |
src/terminal/keyboard/init.c
| ... | ... | @@ -96,13 +96,6 @@ |
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | -#ifdef DEBUG | |
| 100 | - void show_accelerator(const V3270Accelerator * accel, const char *keys, gpointer ptr) | |
| 101 | - { | |
| 102 | - debug("%s=%s",v3270_accelerator_get_name(accel),keys); | |
| 103 | - } | |
| 104 | -#endif // DEBUG | |
| 105 | - | |
| 106 | 99 | void v3270_init_accelerators(v3270 *widget) |
| 107 | 100 | { |
| 108 | 101 | size_t ix; |
| ... | ... | @@ -165,10 +158,6 @@ |
| 165 | 158 | |
| 166 | 159 | v3270_accelerator_map_sort(widget); |
| 167 | 160 | |
| 168 | -#ifdef DEBUG | |
| 169 | - v3270_accelerator_map_foreach(widget,show_accelerator,NULL); | |
| 170 | -#endif // DEBUG | |
| 171 | - | |
| 172 | 161 | } |
| 173 | 162 | |
| 174 | 163 | ... | ... |
| ... | ... | @@ -0,0 +1,68 @@ |
| 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 properties.c 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 <config.h> | |
| 31 | + #include <gtk/gtk.h> | |
| 32 | + #include "private.h" | |
| 33 | + | |
| 34 | + //#include <v3270/actions.h> | |
| 35 | + | |
| 36 | + struct Args | |
| 37 | + { | |
| 38 | + GKeyFile * key_file; | |
| 39 | + const gchar * group_name; | |
| 40 | + }; | |
| 41 | + | |
| 42 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 43 | + | |
| 44 | + static void save_accelerator(const V3270Accelerator * accel, const char *keys, gpointer ptr) | |
| 45 | + { | |
| 46 | + const gchar * key = v3270_accelerator_get_name(accel); | |
| 47 | + if(!key) | |
| 48 | + return; | |
| 49 | + | |
| 50 | + debug("%s=%s",v3270_accelerator_get_name(accel),keys); | |
| 51 | + | |
| 52 | + g_key_file_set_string( | |
| 53 | + ((struct Args *) ptr)->key_file, | |
| 54 | + ((struct Args *) ptr)->group_name, | |
| 55 | + key, | |
| 56 | + keys | |
| 57 | + ); | |
| 58 | + | |
| 59 | + } | |
| 60 | + | |
| 61 | + void v3270_accelerator_map_to_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name) | |
| 62 | + { | |
| 63 | + struct Args args = { key_file, group_name }; | |
| 64 | + | |
| 65 | + g_key_file_remove_group(key_file,group_name,NULL); | |
| 66 | + v3270_accelerator_map_foreach(GTK_WIDGET(widget),save_accelerator,&args); | |
| 67 | + | |
| 68 | + } | ... | ... |
src/testprogram/testprogram.c
| ... | ... | @@ -106,14 +106,17 @@ |
| 106 | 106 | debug("%s: Saving settings for windows %p",__FUNCTION__,window); |
| 107 | 107 | |
| 108 | 108 | GKeyFile * key_file = get_key_file(); |
| 109 | + | |
| 109 | 110 | v3270_to_key_file(terminal,key_file,"terminal"); |
| 111 | + v3270_accelerator_map_to_key_file(terminal, key_file, "accelerators"); | |
| 112 | + | |
| 110 | 113 | g_key_file_save_to_file(key_file,"terminal.conf",NULL); |
| 111 | 114 | g_key_file_free(key_file); |
| 112 | 115 | |
| 113 | 116 | |
| 114 | 117 | } |
| 115 | 118 | |
| 116 | -#endif // _WIN32 | |
| 119 | +#endif // _WIN32 | |
| 117 | 120 | |
| 118 | 121 | |
| 119 | 122 | static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { | ... | ... |
v3270.cbp
| ... | ... | @@ -274,6 +274,9 @@ |
| 274 | 274 | <Unit filename="src/terminal/keyboard/init.c"> |
| 275 | 275 | <Option compilerVar="CC" /> |
| 276 | 276 | </Unit> |
| 277 | + <Unit filename="src/terminal/keyboard/keyfile.c"> | |
| 278 | + <Option compilerVar="CC" /> | |
| 279 | + </Unit> | |
| 277 | 280 | <Unit filename="src/terminal/keyboard/private.h" /> |
| 278 | 281 | <Unit filename="src/terminal/keyfile.c"> |
| 279 | 282 | <Option compilerVar="CC" /> | ... | ... |