Working With Trees



I'm using Glade 2.0 and GTK 2.something to try and write a very simple
file manager, and I can't get the GtkTreeView object to work at all. 
I've looked around, and there doesn't seem to be any docs in regards to
this widget, other than the API, and the examples in the API are garbage
(my apologies to their authors): most of them are referencing variables
that they don't even define.

What I am trying to do at the moment is add an item to the GtkTreeStore,
but it doesn't seem to want to go.  I'm not getting any warnings on the
console about bad types or non-existant objects, or anything else for
that matter, but gtk_tree_model_get just returns garbage.  The code is
below.

  int SetFolders(void)
{
  GtkWidget      *tviewFolders;
  GtkTreeStore    *tstoreFolders;
  GtkTreeIter     iterStore, iterTest;
  char            Test[100];
  gchar *gTest;

  memset(&Test[0], 0, 99);
  strcpy(&Test[0], "testing this for fun");
  printf("Test is %s\n", Test);
  
  // Find the widget for the Folders tree
  tviewFolders = lookup_widget(GTK_WIDGET(winMain), "tviewFolders");
  
  // Create the entries entry
  tstoreFolders = gtk_tree_store_new(1, G_TYPE_STRING);

  gTest = g_strdup_printf("%s", Test);
  printf("Gstring is %s\n", gTest);

  gtk_tree_store_append(GTK_TREE_STORE(tstoreFolders), &iterStore,
NULL);
  gtk_tree_store_set(GTK_TREE_STORE(tstoreFolders), &iterStore, 0,
gTest, -1);
  g_free(gTest);

  // Read the value we just wrote back
  gtk_tree_model_get(GTK_TREE_STORE(tstoreFolders), &iterStore, 0,
&Test[0], -1);
  printf("Test is %s\n", Test);
  
  // Bind the entries to the object
  gtk_tree_view_set_model(GTK_TREE_VIEW(tviewFolders),
GTK_TREE_MODEL(tstoreFolders));
  
  //g_object_unref(tstoreFolders);
  gtk_tree_model_get(tstoreFolders, &iterStore, 0, &Test[0], -1);
  printf("Test is %s\n", Test);
  return 0;
}





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]