Commit 6fde193e4797b46eb8271ee81258aed9d2108199

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

Adding convenience method for comboboxes.

src/dialogs/settings/clipboard.c
@@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
33 */ 33 */
34 34
35 #include "private.h" 35 #include "private.h"
  36 + #include <terminal.h>
36 #include <v3270/settings.h> 37 #include <v3270/settings.h>
37 #include <lib3270/log.h> 38 #include <lib3270/log.h>
38 39
@@ -319,19 +320,20 @@ GtkWidget * v3270_clipboard_settings_new() { @@ -319,19 +320,20 @@ GtkWidget * v3270_clipboard_settings_new() {
319 320
320 V3270Settings * settings = GTK_V3270_SETTINGS(g_object_new(V3270ClipboardSettings_get_type(), NULL)); 321 V3270Settings * settings = GTK_V3270_SETTINGS(g_object_new(V3270ClipboardSettings_get_type(), NULL));
321 322
322 - settings->title = _("Cut & Paste settings"); 323 + settings->title = _("Clipboard properties");
323 settings->label = _("Clipboard"); 324 settings->label = _("Clipboard");
324 325
325 return GTK_WIDGET(settings); 326 return GTK_WIDGET(settings);
326 } 327 }
327 328
328 -static void load(GtkWidget *w, GtkWidget *terminal) { 329 +static void load(GtkWidget *w, GtkWidget *t) {
329 330
330 size_t ix; 331 size_t ix;
331 332
332 V3270ClipboardSettings *widget = (V3270ClipboardSettings *) w; 333 V3270ClipboardSettings *widget = (V3270ClipboardSettings *) w;
  334 + v3270 *terminal = GTK_V3270(t);
333 335
334 - v3270_settings_load_toggle_buttons(toggles, G_N_ELEMENTS(toggles), terminal, widget->input.toggles); 336 + v3270_settings_load_toggle_buttons(toggles, G_N_ELEMENTS(toggles), t, widget->input.toggles);
335 337
336 // HTML Font combo 338 // HTML Font combo
337 { 339 {
@@ -358,7 +360,7 @@ static void load(GtkWidget *w, GtkWidget *terminal) { @@ -358,7 +360,7 @@ static void load(GtkWidget *w, GtkWidget *terminal) {
358 360
359 PangoFontFamily **families; 361 PangoFontFamily **families;
360 gint n_families; 362 gint n_families;
361 - pango_context_list_families(gtk_widget_get_pango_context(terminal),&families, &n_families); 363 + pango_context_list_families(gtk_widget_get_pango_context(t),&families, &n_families);
362 364
363 for(ix=0; ((gint) ix) < n_families; ix++) { 365 for(ix=0; ((gint) ix) < n_families; ix++) {
364 366
@@ -377,6 +379,8 @@ static void load(GtkWidget *w, GtkWidget *terminal) { @@ -377,6 +379,8 @@ static void load(GtkWidget *w, GtkWidget *terminal) {
377 379
378 } 380 }
379 381
  382 + gtk_combo_box_select_column_uint(widget->input.combos[2],1,((terminal->selection.options & V3270_SELECTION_PLAIN_TEXT) ? 0 : 1));
  383 +
380 } 384 }
381 385
382 static void apply(GtkWidget *w, GtkWidget *terminal) { 386 static void apply(GtkWidget *w, GtkWidget *terminal) {
src/dialogs/settings/private.h
@@ -34,6 +34,8 @@ @@ -34,6 +34,8 @@
34 #include <lib3270/toggle.h> 34 #include <lib3270/toggle.h>
35 #include <v3270/settings.h> 35 #include <v3270/settings.h>
36 36
  37 + G_GNUC_INTERNAL void gtk_combo_box_select_column_uint(GtkComboBox * combo_box, gint column, guint value);
  38 +
37 /// @brief Toggle button factory. 39 /// @brief Toggle button factory.
38 struct ToggleButtonDefinition { 40 struct ToggleButtonDefinition {
39 gint left; 41 gint left;
src/dialogs/settings/tools.c
@@ -131,4 +131,54 @@ @@ -131,4 +131,54 @@
131 131
132 } 132 }
133 133
  134 + struct combo_select_uint {
  135 + GtkComboBox * combo_box;
  136 + gint column;
  137 + guint new_value;
  138 + };
  139 +
  140 + static gboolean test_combo_select_uint(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, struct combo_select_uint *arg) {
  141 +
  142 + // Get value
  143 + GValue value = { 0, };
  144 + gtk_tree_model_get_value(model,iter,arg->column,&value);
  145 + guint row_value = g_value_get_uint(&value);
  146 + g_value_unset(&value);
  147 +
  148 + if(row_value == arg->new_value) {
  149 + gtk_combo_box_set_active_iter(arg->combo_box,iter);
  150 + return TRUE;
  151 + }
  152 +
  153 + return FALSE;
  154 + }
  155 +
  156 + void gtk_combo_box_select_column_uint(GtkComboBox * combo_box, gint column, guint new_value) {
  157 +
  158 + GtkTreeIter iter;
  159 + GtkListStore * list = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box)));
  160 +
  161 + // Is the value already selected?
  162 + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo_box),&iter)) {
  163 +
  164 + GValue value = { 0, };
  165 + gtk_tree_model_get_value(GTK_TREE_MODEL(list),&iter,column,&value);
  166 + guint active = g_value_get_uint(&value);
  167 + g_value_unset(&value);
  168 +
  169 + if(active == new_value)
  170 + return;
  171 +
  172 + }
  173 +
  174 + // No, it's not, find one.
  175 + struct combo_select_uint arg = {
  176 + .combo_box = combo_box,
  177 + .column = column,
  178 + .new_value = new_value
  179 + };
  180 +
  181 + gtk_tree_model_foreach(GTK_TREE_MODEL(list),(GtkTreeModelForeachFunc) test_combo_select_uint, &arg);
  182 + }
  183 +
134 184