diff options
Diffstat (limited to 'src/beaver-settings-page.c')
-rw-r--r-- | src/beaver-settings-page.c | 202 |
1 files changed, 189 insertions, 13 deletions
diff --git a/src/beaver-settings-page.c b/src/beaver-settings-page.c index be5f267..0594ec6 100644 --- a/src/beaver-settings-page.c +++ b/src/beaver-settings-page.c @@ -152,6 +152,129 @@ radio_toggled_cb (GtkToggleButton *toggle, gpointer userdata) gtk_toggle_button_get_active (toggle)); } +/* set_property is a must-to-have call back function used by + * Anjuta custom preference registration function for + * gtk combo_box component. + */ +static void +set_property (AnjutaProperty *prop, const gchar *value) +{ + gchar* values; + gchar **vstr; + gint i; + + /* AnjutaProperty data structure are protected and must use + * its own data field fetch utility functions + */ + GtkWidget *combo_box = anjuta_property_get_widget(prop); + + /* combo_box text values are changed/saved during create_ui, + * poky_mode changes, poky_root changes, poky_sdk changes. Its + * text values is saved and associated with the target combo_box + * component, so that the text values could be fetched and + * saved across different functions. + */ + values = g_object_get_data(G_OBJECT(combo_box), OBJ_PROP_TARGET_ARCHS); + + if (!values || strlen(values) <= 0) + return; + + vstr = g_strsplit (values, ",", 0); + if (vstr) + { + for (i=0; vstr[i] != NULL; i++) + { + if (strcmp(value, vstr[i]) == 0) + { + gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), i); + break; + } + } + g_strfreev(vstr); + } +} + +/* get_property is a must-to-have call back function used by + * Anjuta custom preference registration function for gtk + * combo_box compnent. + */ +static gchar* +get_property(AnjutaProperty *prop) +{ + gchar *values; + gchar **vstr; + gchar *text_value = NULL; + gint idx; + GtkWidget *combo_box = anjuta_property_get_widget(prop); + + values = g_object_get_data(G_OBJECT(combo_box), OBJ_PROP_TARGET_ARCHS); + + if (!values || strlen(values) <= 0) + return text_value; + + vstr = g_strsplit(values, ",", 0); + + if (vstr) + { + idx = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box)); + if (idx < 0) + idx = 0; + + if (vstr[idx] != NULL) + text_value = g_strdup(vstr[idx]); + + g_strfreev(vstr); + } + + return text_value; +} + +/* Note it's weird that this changed callback function is not implemented + * in anjuta preference framework, and property of preference is internal + * protected and can't be fetched outside anjuta preference code, so + * we have to repeat the implementation of get_property, it seems a little + * strange + */ +static void +target_combo_changed (GtkWidget *widget, gpointer user_data) +{ + AnjutaPreferences *pr; + gchar *text_value = NULL; + gint idx; + gchar *values = NULL; + gchar** vstr; + + pr = ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget), + "AnjutaPreferences")); + values = g_object_get_data(G_OBJECT(widget), OBJ_PROP_TARGET_ARCHS); + if (!values || strlen(values) <= 0) + { + anjuta_preferences_set (pr, PREFS_PROP_TRIPLET, NULL); + return; + } + vstr = g_strsplit(values, ",", 0); + if (vstr) + { + idx = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); + //if no items selected, select index 0 as default! + if (idx < 0) + idx = 0; + if (vstr[idx] != NULL) + text_value = g_strdup(vstr[idx]); + g_strfreev(vstr); + } + + /* this combo_changed callback will be called before triplet_changed + * call back if the combo box text items or selected index have any + * changes. We need to update the new triplet value, so that + * triplet_changed could get correct new triplet. If the old selected + * text value equals the newly selected text value, then + * triplet_changed need not be called. + */ + anjuta_preferences_set (pr, PREFS_PROP_TRIPLET, text_value); + g_free (text_value); +} + static void create_ui (BeaverSettingsPage *page) { @@ -176,9 +299,14 @@ create_ui (BeaverSettingsPage *page) GtkWidget *qemu_radio; GtkWidget *device_radio; + GtkWidget *target_combo; + gboolean res; - gchar *filename = NULL; + gchar **vstr; + gchar *cur_target = NULL; + gchar *target_combo_value; + int i; gtk_box_set_spacing (GTK_BOX (page), 6); gtk_box_set_homogeneous (GTK_BOX (page), FALSE); @@ -314,27 +442,75 @@ create_ui (BeaverSettingsPage *page) gtk_box_pack_start (GTK_BOX (inner_vbox), inner_alignment, TRUE, FALSE, 0); /* label */ - label = gtk_label_new (_("Toolchain triplet: ")); + label = gtk_label_new (_("Target Architecture: ")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_size_group_add_widget (opts_labels_group, label); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - /* entry */ - entry = gtk_entry_new (); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - gtk_size_group_add_widget (opts_fields_group, label); + /* available target architecture is stored in a combo_box */ + target_combo = gtk_combo_box_entry_new_text(); + gtk_box_pack_start (GTK_BOX(hbox), target_combo, TRUE, TRUE, 0); + gtk_size_group_add_widget (opts_fields_group, target_combo); - /* register prop */ - res = anjuta_preferences_register_property_raw (priv->prefs, - entry, + /* Note: we need to save target_combo box widget pointer in preferences + * So event change callback functions outside the UI could get the pointer + * and update the combo box related values */ + g_object_set_data(G_OBJECT(priv->prefs), PREFS_PROP_TARGET_COMBO, + target_combo); + + /* Get target arch values from preferences storage, since it's updated + * by several actions. And also, previous launching values are saved in + * this preference storaget too so that users could save this setting */ + target_combo_value = anjuta_preferences_get(priv->prefs, + PREFS_PROP_TARGET_ARCHS); + + /* Save target arch values and made it associated with combo box, since + * get or set combo box property need to use it.*/ + g_object_set_data(G_OBJECT(target_combo), OBJ_PROP_TARGET_ARCHS, + target_combo_value); + + cur_target = anjuta_preferences_get (priv->prefs, PREFS_PROP_TRIPLET); + + g_debug("CUR arch %s of %s when create_ui", cur_target, target_combo_value); + + /* Fill the combo box values according to the available architectures + * under current UI selections + */ + + if (target_combo_value) + { + vstr = g_strsplit (target_combo_value, ",", 0); + if (vstr) + { + for (i = 0; vstr[i]; i++) { + gtk_combo_box_append_text (GTK_COMBO_BOX(target_combo), vstr[i]); + if (cur_target && strcmp(cur_target, vstr[i]) == 0) + gtk_combo_box_set_active(GTK_COMBO_BOX(target_combo), i); + } + } + g_strfreev (vstr); + } + + res = anjuta_preferences_register_property_custom (priv->prefs, + target_combo, PREFS_PROP_TRIPLET, - NULL, + target_combo_value, 0, - ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY, - ANJUTA_PROPERTY_DATA_TYPE_TEXT); + ANJUTA_PROPERTY_DATA_TYPE_TEXT, + set_property, + get_property); if (!res) - g_warning ("Error adding preference for triplet"); + g_warning ("Error while adding preference for target triplet"); + + /* It's weird that below combo box changed callback registration function + * is missing in custom style registration. We need to add it so that when + * combo box selection or text changed, we can updated related triplet + * in the preference storage + */ + + g_signal_connect(G_OBJECT(target_combo), "changed", + G_CALLBACK(target_combo_changed), NULL); /* Frame for target */ frame = gtk_frame_new (_("<b>Target Options</b>")); |