void gb_project_tree_set_context (GbProjectTree *self, IdeContext *context) { GtkTreeModel *model; GtkTreeIter iter; IdeTreeNode *root; g_return_if_fail (GB_IS_PROJECT_TREE (self)); g_return_if_fail (!context || IDE_IS_CONTEXT (context)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (self)); root = ide_tree_node_new (); ide_tree_node_set_item (root, G_OBJECT (context)); ide_tree_set_root (IDE_TREE (self), root); /* * If we only have one toplevel item (underneath root), expand it. */ if ((gtk_tree_model_iter_n_children (model, NULL) == 1) && gtk_tree_model_get_iter_first (model, &iter)) { g_autoptr(IdeTreeNode) node = NULL; gtk_tree_model_get (model, &iter, 0, &node, -1); if (node != NULL) ide_tree_node_expand (node, FALSE); } }
void gb_project_tree_set_context (GbProjectTree *self, IdeContext *context) { GtkTreeModel *model; GtkTreeIter iter; IdeTreeNode *root; IdeProject *project; IdeVcs *vcs; g_return_if_fail (GB_IS_PROJECT_TREE (self)); g_return_if_fail (IDE_IS_CONTEXT (context)); vcs = ide_context_get_vcs (context); g_signal_connect_object (vcs, "changed", G_CALLBACK (gb_project_tree_vcs_changed), self, G_CONNECT_SWAPPED); project = ide_context_get_project (context); g_signal_connect_object (project, "file-renamed", G_CALLBACK (gb_project_tree_project_file_renamed), self, G_CONNECT_SWAPPED); g_signal_connect_object (project, "file-trashed", G_CALLBACK (gb_project_tree_project_file_trashed), self, G_CONNECT_SWAPPED); model = gtk_tree_view_get_model (GTK_TREE_VIEW (self)); root = ide_tree_node_new (); ide_tree_node_set_item (root, G_OBJECT (context)); ide_tree_set_root (IDE_TREE (self), root); /* * If we only have one toplevel item (underneath root), expand it. */ if ((gtk_tree_model_iter_n_children (model, NULL) == 1) && gtk_tree_model_get_iter_first (model, &iter)) { g_autoptr(IdeTreeNode) node = NULL; gtk_tree_model_get (model, &iter, 0, &node, -1); if (node != NULL) ide_tree_node_expand (node, FALSE); } }