static void inventory_item_inserted(GwyInventory *inventory, guint pos, GtkTreeStore *store) { GrainValueStorePrivate *priv; GwyGrainValue *gvalue; GwyGrainValueGroup group; GtkTreeIter siter, iter; priv = g_object_get_qdata(G_OBJECT(store), priv_quark); g_return_if_fail(pos >= priv->user_start_pos); siter = priv->user_group_iter; gvalue = gwy_inventory_get_nth_item(inventory, pos); g_return_if_fail(GWY_IS_GRAIN_VALUE(gvalue)); group = gwy_grain_value_get_group(gvalue); g_return_if_fail(group == GWY_GRAIN_VALUE_GROUP_USER); gtk_tree_store_insert(store, &iter, &siter, pos - priv->user_start_pos); gtk_tree_store_set(store, &iter, GWY_GRAIN_VALUE_STORE_COLUMN_ITEM, gvalue, GWY_GRAIN_VALUE_STORE_COLUMN_GROUP, group, -1); }
/** * gwy_grain_value_tree_view_select: * @treeview: A tree view with grain values. * @gvalue: The grain value to select. * * Selects a particular grain value in a grain value tree view. * * If the @gvalue group is currently unexpanded, it will be expanded to * show it, and the tree view may scroll to make it visible. * * Since: 2.8 **/ void gwy_grain_value_tree_view_select(GtkTreeView *treeview, GwyGrainValue *gvalue) { GtkTreeSelection *selection; GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; g_return_if_fail(GTK_IS_TREE_VIEW(treeview)); g_return_if_fail(GWY_IS_GRAIN_VALUE(gvalue)); g_return_if_fail(priv_quark && g_object_get_qdata(G_OBJECT(treeview), priv_quark)); model = gtk_tree_view_get_model(treeview); if (!find_grain_value(model, gvalue, &iter)) { g_warning("Grain value not in tree model."); return; } path = gtk_tree_model_get_path(model, &iter); gtk_tree_view_expand_to_path(treeview, path); gtk_tree_view_scroll_to_cell(treeview, path, NULL, FALSE, 0.0, 0.0); gtk_tree_path_free(path); selection = gtk_tree_view_get_selection(treeview); gtk_tree_selection_select_iter(selection, &iter); }
int main(void) { gwy_type_init(); printf(file_prologue, generated, id, id, title, title); const gchar* const *names = gwy_grain_value_list_builtins(); guint nvalues = g_strv_length((gchar**)names); GwyGrainValue **grainvalues = g_new(GwyGrainValue*, nvalues); for (guint i = 0; i < nvalues; i++) { grainvalues[i] = gwy_grain_value_new(names[i]); g_assert(GWY_IS_GRAIN_VALUE(grainvalues[i])); } qsort(grainvalues, nvalues, sizeof(GwyGrainValue*), compare); GString *str = g_string_new(NULL); const gchar *processing_group = "NONE"; for (guint i = 0; i < nvalues; i++) { GwyGrainValue *grainvalue = grainvalues[i]; const gchar *name = gwy_grain_value_get_name(grainvalue); const gchar *group = gwy_grain_value_get_group(grainvalue); if (!gwy_strequal(group, processing_group)) { if (!gwy_strequal(processing_group, "NONE")) printf(group_epilogue); g_string_assign(str, group); make_id(str); printf(group_prologue, id, str->str, group, group); processing_group = group; } g_string_assign(str, name); make_id(str); printf(value_prologue, id, str->str, name); g_string_assign(str, gwy_grain_value_get_symbol(grainvalue)); convert_pango_to_docbook(str); make_math(str); printf("<entry>%s</entry>\n", str->str); printf("<entry><code>%s</code></entry>", gwy_grain_value_get_ident(grainvalue)); g_string_assign(str, ""); if (gwy_grain_value_needs_same_units(grainvalue)) append_separated(str, "needs same lateral and value units"); if (gwy_grain_value_is_angle(grainvalue)) append_separated(str, "represents angle in radians"); printf("<entry>%s</entry>\n", str->str); printf(value_epilogue); g_object_unref(grainvalue); } if (!gwy_strequal(processing_group, "NONE")) printf(group_epilogue); printf(file_epilogue); return 0; }