Commit 67b9abffefbad0c42047ed13996d2eab15e3de58

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

Isolating charset widget.

src/dialogs/save/save.c
... ... @@ -61,18 +61,6 @@
61 61 }
62 62 };
63 63  
64   - static const struct _charsets
65   - {
66   - const gchar *name;
67   - const gchar *description;
68   - } charsets[] =
69   - {
70   - // http://en.wikipedia.org/wiki/Character_encoding
71   - { "UTF-8", N_( "UTF-8" ) },
72   - { "ISO-8859-1", N_( "Western Europe (ISO 8859-1)" ) },
73   - { "CP1252", N_( "Windows Western languages (CP1252)" ) },
74   - };
75   -
76 64 /*--[ Implement ]------------------------------------------------------------------------------------*/
77 65  
78 66 /*
... ... @@ -224,43 +212,14 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
224 212  
225 213 // Charset drop-down
226 214 {
227   - size_t ix;
228   - const gchar * scharset = NULL;
229   -
230 215 widget = gtk_label_new_with_mnemonic (_("C_haracter Coding"));
231 216 gtk_widget_set_halign(widget,GTK_ALIGN_END);
232 217 gtk_widget_set_valign(widget,GTK_ALIGN_CENTER);
233 218 gtk_grid_attach(grid,widget,0,1,1,1);
234 219  
235   - dialog->charset = gtk_combo_box_text_new();
236   -
237   - g_get_charset(&scharset);
238   -
239   - g_autofree gchar * text = g_strdup_printf(_("Current (%s)"),scharset);
240   - gtk_combo_box_text_insert(
241   - GTK_COMBO_BOX_TEXT(dialog->charset),
242   - 0,
243   - scharset,
244   - text
245   - );
246   -
247   - gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->charset),0);
248   -
  220 + dialog->charset = v3270_charset_combo_box_new();
249 221 gtk_grid_attach(grid,dialog->charset,1,1,1,1);
250 222  
251   - for(ix=0;ix<G_N_ELEMENTS(charsets);ix++)
252   - {
253   - if(g_ascii_strcasecmp(charsets[ix].name,scharset))
254   - {
255   - gtk_combo_box_text_insert(
256   - GTK_COMBO_BOX_TEXT(dialog->charset),
257   - ix+1,
258   - charsets[ix].name,
259   - gettext(charsets[ix].description)
260   - );
261   - }
262   - }
263   -
264 223 }
265 224  
266 225 // Format drop-down
... ...
src/dialogs/tools.c
... ... @@ -124,3 +124,52 @@
124 124 }
125 125  
126 126 #endif //! GTK 3.16
  127 +
  128 + GtkWidget * v3270_charset_combo_box_new()
  129 + {
  130 + static const struct _charsets
  131 + {
  132 + const gchar *name;
  133 + const gchar *description;
  134 + } charsets[] =
  135 + {
  136 + // http://en.wikipedia.org/wiki/Character_encoding
  137 + { "UTF-8", N_( "UTF-8" ) },
  138 + { "ISO-8859-1", N_( "Western Europe (ISO 8859-1)" ) },
  139 + { "CP1252", N_( "Windows Western languages (CP1252)" ) },
  140 + };
  141 +
  142 + size_t ix;
  143 + const gchar * scharset = NULL;
  144 + GtkWidget * widget = gtk_combo_box_text_new();
  145 +
  146 + g_get_charset(&scharset);
  147 +
  148 + g_autofree gchar * text = g_strdup_printf(_("Current (%s)"),scharset);
  149 + gtk_combo_box_text_insert(
  150 + GTK_COMBO_BOX_TEXT(widget),
  151 + 0,
  152 + scharset,
  153 + text
  154 + );
  155 +
  156 + gtk_combo_box_set_active(GTK_COMBO_BOX(widget),0);
  157 +
  158 + for(ix=0;ix<G_N_ELEMENTS(charsets);ix++)
  159 + {
  160 + if(g_ascii_strcasecmp(charsets[ix].name,scharset))
  161 + {
  162 + gtk_combo_box_text_insert(
  163 + GTK_COMBO_BOX_TEXT(widget),
  164 + ix+1,
  165 + charsets[ix].name,
  166 + gettext(charsets[ix].description)
  167 + );
  168 + }
  169 + }
  170 +
  171 + return widget;
  172 +
  173 + }
  174 +
  175 +
... ...
src/include/internals.h
... ... @@ -108,6 +108,8 @@
108 108 G_GNUC_INTERNAL void v3270_dialog_close(GtkDialog *dialog, gpointer user_data);
109 109  
110 110  
  111 +/*--[ Internal Widgets & Tools ]---------------------------------------------------------------------*/
  112 +
111 113 #if GTK_CHECK_VERSION(3,12,0)
112 114 G_GNUC_INTERNAL GtkHeaderBar * v3270_dialog_get_header_bar(GtkWidget * widget);
113 115 G_GNUC_INTERNAL void v3270_dialog_cancel(GtkButton G_GNUC_UNUSED(*button), GtkWidget *dialog);
... ... @@ -135,11 +137,14 @@
135 137  
136 138 G_GNUC_INTERNAL gchar * v3270_select_file(GtkWidget *widget, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename, const gchar *filter, ... ) G_GNUC_NULL_TERMINATED;
137 139  
138   - #if ! GTK_CHECK_VERSION(3,16,0)
139   -
  140 +#if ! GTK_CHECK_VERSION(3,16,0)
140 141 G_GNUC_INTERNAL void gtk_text_view_set_monospace (GtkTextView *text_view, gboolean monospace);
  142 +#endif //! GTK 3.16
  143 +
  144 + G_GNUC_INTERNAL GtkWidget * v3270_charset_combo_box_new();
  145 +
  146 +/*--[ Internal Methods ]-----------------------------------------------------------------------------*/
141 147  
142   - #endif //! GTK 3.16
143 148  
144 149 const GtkWidgetClass * v3270_get_parent_class(void);
145 150  
... ...