/** Does the equivalent of what refresh_selected used to do; * looks at each file in a site and rebuilds the tree accordingly. */ void rebuild_node_files(GtkCTreeNode * site_node) { /* Get rid of all the files first */ while (GTK_CTREE_ROW(site_node)->children) { gtk_ctree_remove_node(GTK_CTREE(the_tree), GTK_CTREE_NODE(GTK_CTREE_ROW(site_node)->children)); } NE_DEBUG(DEBUG_GNOME, "Removed all children, freezing CTree...\n"); gtk_clist_freeze(GTK_CLIST(the_tree)); populate_site_node(site_node, selected_site); gtk_clist_thaw(GTK_CLIST(the_tree)); NE_DEBUG(DEBUG_GNOME, "Repopulation complete, CTree thawed.\n"); }
/* Returns TRUE if the entry for the given directory is expanded */ boolean dirtree_entry_expanded( GNode *dnode ) { g_assert( NODE_IS_DIR(dnode) ); return GTK_CTREE_ROW(DIR_NODE_DESC(dnode)->ctnode)->expanded; }
static void dirtree_expand (GtkCTree * tree, GtkCTreeNode * node) { GtkAdjustment *h_adjustment; gfloat row_align; DirTreeNode *dt_node; dt_node = gtk_ctree_node_get_row_data (tree, node); if (dt_node->scanned == FALSE) { tree_expand_node (DIRTREE (tree), node, FALSE); dt_node->scanned = TRUE; } if (parent_class->tree_expand) (*parent_class->tree_expand) (tree, node); h_adjustment = gtk_clist_get_hadjustment (GTK_CLIST (tree)); if (h_adjustment && h_adjustment->upper != 0.0) { row_align = (float) (tree->tree_indent * GTK_CTREE_ROW (node)->level) / h_adjustment->upper; gtk_ctree_node_moveto (tree, node, tree->tree_column, 0, row_align); } }
void dirtree_refresh_node (DirTree * dt, GtkCTreeNode * node) { DirTreeNode *dirnode = NULL; gint has_subdirs; gboolean expanded; dirnode = gtk_ctree_node_get_row_data (GTK_CTREE (dt), node); has_subdirs = tree_is_subdirs (dirnode->path, dt->show_dotfile); if (has_subdirs && GTK_CTREE_ROW (node)->expanded == 1) expanded = TRUE; else expanded = FALSE; if (has_subdirs) gtk_ctree_set_node_info (GTK_CTREE (dt), node, g_basename (dirnode->path), CTREE_SPACING, folder_pixmap, folder_mask, ofolder_pixmap, ofolder_mask, FALSE, expanded); else gtk_ctree_set_node_info (GTK_CTREE (dt), node, g_basename (dirnode->path), CTREE_SPACING, folder_pixmap, folder_mask, ofolder_pixmap, ofolder_mask, TRUE, expanded); }
GtkCTreeNode * dirtree_find_file (DirTree * dt, GtkCTreeNode * parent, char *file_name) { GtkCTreeNode *child; child = GTK_CTREE_ROW (parent)->children; while (child) { if (!strcmp (NODE_TEXT (GTK_CTREE (dt), child), file_name)) return child; child = GTK_CTREE_ROW (child)->sibling; } return NULL; }
static void tree_collapse (GtkCTree * tree, GtkCTreeNode * node) { GtkCTreeNode *child; DIRTREE (tree)->collapse = TRUE; gtk_clist_freeze (GTK_CLIST (tree)); child = GTK_CTREE_ROW (node)->children; while (child) { gtk_ctree_remove_node (GTK_CTREE (tree), child); child = GTK_CTREE_ROW (node)->children; } gtk_clist_thaw (GTK_CLIST (tree)); DIRTREE (tree)->collapse = FALSE; }
/* * Get a child node according to its name. */ static GtkCTreeNode* gdisp_getChildAccordingToItsName ( Kernel_T *kernel, GtkCTreeNode *parentNode, gchar *requestedChildName ) { GtkWidget *cTree = (GtkWidget*)NULL; GtkCTreeRow *parentNodeRow = (GtkCTreeRow*)NULL; GtkCTreeNode *parentChild = (GtkCTreeNode*)NULL; GtkCTreeNode *requestedChild = (GtkCTreeNode*)NULL; gchar *childName = (gchar*)NULL; /* * Deduce node row from node. */ cTree = kernel->widgets.sampledSymbolHTree; parentNodeRow = GTK_CTREE_ROW(parentNode); /* * Loop over all children. */ parentChild = parentNodeRow->children; while (requestedChild == (GtkCTreeNode*)NULL && parentChild != (GtkCTreeNode*)NULL ) { childName = (gchar*)gtk_ctree_node_get_row_data(GTK_CTREE(cTree), parentChild); if (childName != (gchar*)NULL && strcmp(childName,requestedChildName) == 0) { requestedChild = parentChild; } else { parentChild = GTK_CTREE_NODE_NEXT(parentChild); } } return requestedChild; }
/* Adds a new entry to the directory tree */ void dirtree_entry_new( GNode *dnode ) { GtkCTreeNode *parent_ctnode = NULL; const char *name; boolean expanded; g_assert( NODE_IS_DIR(dnode) ); parent_ctnode = DIR_NODE_DESC(dnode->parent)->ctnode; if (strlen( NODE_DESC(dnode)->name ) > 0) name = NODE_DESC(dnode)->name; else name = _("/. (root)"); expanded = g_node_depth( dnode ) <= 2; DIR_NODE_DESC(dnode)->ctnode = gui_ctree_node_add( dir_ctree_w, parent_ctnode, dir_colexp_mini_icons, name, expanded, dnode ); if (parent_ctnode == NULL) { /* First entry was just added. Keep directory tree frozen * most of the time while scanning, otherwise it tends to * flicker annoyingly */ gtk_clist_freeze( GTK_CLIST(dir_ctree_w) ); } else if (GTK_CTREE_ROW(parent_ctnode)->expanded) { /* Pre-update (allow ctree to register new row) */ gtk_clist_thaw( GTK_CLIST(dir_ctree_w) ); gui_update( ); gtk_clist_freeze( GTK_CLIST(dir_ctree_w) ); /* Select last row */ gtk_ctree_select( GTK_CTREE(dir_ctree_w), DIR_NODE_DESC(dnode)->ctnode ); /* Scroll directory tree down to last row */ gui_clist_moveto_row( dir_ctree_w, -1, 0.0 ); /* Post-update (allow ctree to perform select/scroll) */ gtk_clist_thaw( GTK_CLIST(dir_ctree_w) ); gui_update( ); gtk_clist_freeze( GTK_CLIST(dir_ctree_w) ); } }
/* * Refresh provider graphic list. */ void gdisp_refreshSampledSymbolList ( Kernel_T *kernel ) { GList *providerItem = (GList*)NULL; Provider_T *provider = (Provider_T*)NULL; GtkWidget *cTree = (GtkWidget*)NULL; GList *cTreeList = (GList*)NULL; GtkCTreeRow *cTreeRow = (GtkCTreeRow*)NULL; GtkCTreeNode *cTreeNode = (GtkCTreeNode*)NULL; guint cTreeLength = 0; guint cTreeCpt = 0; /* ------------------------ PER PROVIDER ---------------------- */ cTree = kernel->widgets.sampledSymbolHTree; /* * When removing a node, GTK main loop activate the "unselect" * callback, that performs a post recursive action on a node * that has been destroyed. * Avoid that shame by temporarily blocking the signal emission. */ gtk_clist_freeze(GTK_CLIST(cTree)); gtk_signal_handler_block_by_func(GTK_OBJECT(cTree), gdisp_treeUnselectRowCallback, (gpointer)kernel); /* * Remove all top-level node, those that have no parent. * First step : build top-level list. */ cTreeLength = g_list_length(GTK_CTREE(cTree)->clist.row_list); for (cTreeCpt=0; cTreeCpt<cTreeLength; cTreeCpt++) { cTreeNode = gtk_ctree_node_nth(GTK_CTREE(cTree),cTreeCpt); if (cTreeNode != (GtkCTreeNode*)NULL) { cTreeRow = GTK_CTREE_ROW(cTreeNode); if (cTreeRow->parent == (GtkCTreeNode*)NULL) { cTreeList = g_list_append(cTreeList,(gpointer)cTreeNode); } /* node is top-level, ie without parent */ } /* node exists */ } /* loop over all rows */ /* * Second step : remove all top_level nodes. */ cTreeList = g_list_first(cTreeList); while (cTreeList != (GList*)NULL) { gtk_ctree_remove_node(GTK_CTREE(cTree), (GtkCTreeNode*)cTreeList->data); cTreeList = g_list_next(cTreeList); } /* * Loop over all providers. Forget tree node address. */ providerItem = g_list_first(kernel->providerList); while (providerItem != (GList*)NULL) { provider = (Provider_T*)providerItem->data; provider->pNode = (GtkCTreeNode*)NULL; providerItem = g_list_next(providerItem); } /* * Finalise. */ gdisp_finaliseHierarchicalTree(kernel, cTree); /* * Activate again the unselect handler. */ gtk_signal_handler_unblock_by_func(GTK_OBJECT(cTree), gdisp_treeUnselectRowCallback, (gpointer)kernel); gtk_clist_thaw(GTK_CLIST(cTree)); }
gint gtk_dir_tree_open_dir(GtkDirTree *dir_tree, const gchar *path) { GtkCTreeNode *root_node, *node; GtkDirTreeNode *dir_node; DIR *dir; gchar *c; gchar *folder; gint nlen; gint new_path, new_node; gchar *text; gchar root[5], root1[5], root2[5], root3[5], root4[5]; gchar *aux_path, *real_path; if((dir=opendir(path)) == NULL) return FALSE; closedir(dir); /* GET ABSOLUTE PATH */ sprintf(root,"%s",G_DIR_SEPARATOR_S); sprintf(root1,"%s.",G_DIR_SEPARATOR_S); sprintf(root2,"%s..",G_DIR_SEPARATOR_S); sprintf(root3,"%s..%s",G_DIR_SEPARATOR_S,G_DIR_SEPARATOR_S); sprintf(root4,"%s.%s",G_DIR_SEPARATOR_S,G_DIR_SEPARATOR_S); if(path){ gint length; aux_path = g_strdup(path); length = strlen(aux_path); if(strcmp(aux_path + length - 2, root1) == 0){ if(length == 2) { g_free(aux_path); aux_path = g_strdup(root); } else { aux_path[length - 1] = '\0'; } } else if(strcmp(aux_path + length - 3, root2) == 0){ if(length == 3) { g_free(aux_path); aux_path = g_strdup(root); } else { gint i = length - 4; while(i >= 0){ if(aux_path[i] == root[0]){ aux_path[i+1] = '\0'; break; } i--; } } } else if(strcmp(aux_path + length - 4, root3) == 0){ if(length == 4) { g_free(aux_path); aux_path = g_strdup(root); } else { gint i = length - 5; while(i >= 0){ if(aux_path[i] == root[0]){ aux_path[i+1] = '\0'; break; } i--; } } } else if(strcmp(aux_path + length - 3, root4) == 0){ if(length == 3) { g_free(aux_path); aux_path = g_strdup(root); } else { aux_path[length - 2] = '\0'; } } } else aux_path = g_strdup(G_DIR_SEPARATOR_S); real_path = g_strdup(aux_path); g_free(aux_path); c = (gchar *)real_path; folder = NULL; nlen = 0; root_node = gtk_ctree_node_nth(GTK_CTREE(dir_tree), 1); gtk_ctree_expand(GTK_CTREE(dir_tree), root_node); new_path = FALSE; new_node = TRUE; while(*c != '\0' && *c != '\n' && c != NULL){ nlen++; folder = (char *)g_realloc(folder, (nlen+1)*sizeof(char)); folder[nlen-1] = *c; folder[nlen]='\0'; if(*c == G_DIR_SEPARATOR){ if(new_path){ node = GTK_CTREE_ROW(root_node)->children; while(node){ dir_node = gtk_ctree_node_get_row_data(GTK_CTREE(dir_tree), node); text = dir_node->path; if(strcmp(text, folder) == 0){ gtk_ctree_expand(GTK_CTREE(dir_tree), node); root_node = node; break; } node = GTK_CTREE_NODE_NEXT(node); } } else { new_path = TRUE; } new_node = FALSE; } else { new_node = TRUE; } c++; } if(new_node){ nlen++; folder = (char *)g_realloc(folder, (nlen+1)*sizeof(char)); folder[nlen-1] = G_DIR_SEPARATOR; folder[nlen]='\0'; node = GTK_CTREE_ROW(root_node)->children; while(node){ dir_node = gtk_ctree_node_get_row_data(GTK_CTREE(dir_tree), node); text = dir_node->path; if(strcmp(text, folder) == 0){ gtk_ctree_expand(GTK_CTREE(dir_tree), node); root_node = node; break; } node = GTK_CTREE_NODE_NEXT(node); } } g_free(folder); if (gtk_ctree_node_is_visible(GTK_CTREE(dir_tree), root_node) != GTK_VISIBILITY_FULL) { gtk_widget_map(GTK_WIDGET(dir_tree)); gtk_ctree_node_moveto(GTK_CTREE(dir_tree), root_node, 0, 0.5, 0.5); } gtk_ctree_select(GTK_CTREE(dir_tree), root_node); return TRUE; }
void select_ctree_cb(GtkCTree * ctree, GtkCTreeNode * node, gpointer data) { GtkCTreeNode *parent; struct site *current_site; struct site_file *current_file; void *data_to_get; struct ctree_attachment *actual_data; extern GtkWidget *main_area_box, *area_data; /* Make sure that any changes have been confirmed on the selected site, * before selected_site gets changed. This seems to get automatically done * by the signal handler. */ if (GTK_CTREE_ROW(node)->parent == NULL) { /* We're at the top level */ if ((data_to_get = gtk_ctree_node_get_row_data(GTK_CTREE(ctree), GTK_CTREE_NODE(node))) == NULL) { NE_DEBUG(DEBUG_GNOME, "\"Data get\" returned NULL. Oh dear.\n"); } actual_data = (struct ctree_attachment *) data_to_get; if (actual_data->file_or_site != IS_A_SITE) NE_DEBUG(DEBUG_GNOME, "Somehow you've clicked on a site, but ended up with file data!\n"); current_site = (struct site *) actual_data->info_struct; /* Make the data shared */ selected_site = current_site; current_site_node = node; NE_DEBUG (DEBUG_GNOME, "Removing widgets from main data area...\n"); gtk_container_remove(GTK_CONTAINER(main_area_box), area_data); NE_DEBUG (DEBUG_GNOME, "Building site info widgets...\n"); area_data = make_site_info_area(current_site); NE_DEBUG (DEBUG_GNOME, "Adding widgets to main data area..."); gtk_container_add(GTK_CONTAINER(main_area_box), area_data); NE_DEBUG (DEBUG_GNOME, "done.\n"); } else if (GTK_CTREE_ROW(node)->parent != NULL) { parent = GTK_CTREE_ROW(node)->parent; /* Grab the file data from that row */ if ((data_to_get = gtk_ctree_node_get_row_data(GTK_CTREE(ctree), GTK_CTREE_NODE(node))) == NULL) { NE_DEBUG(DEBUG_GNOME, "\"Data get\" for the file returned NULL. Oh dear.\n"); } actual_data = (struct ctree_attachment *) data_to_get; if (actual_data->file_or_site != IS_A_FILE) NE_DEBUG(DEBUG_GNOME, "Somehow you've clicked on a file, but ended up with site data!\n"); current_file = (struct site_file *) actual_data->info_struct; /* Grab the site data from the file's parent */ while (GTK_CTREE_ROW(parent)->parent != NULL) { parent = GTK_CTREE_ROW(parent)->parent; NE_DEBUG(DEBUG_GNOME, "Assigned parent to node->parent.\n"); } if ((data_to_get = gtk_ctree_node_get_row_data(GTK_CTREE(ctree), GTK_CTREE_NODE(parent))) == NULL) { NE_DEBUG(DEBUG_GNOME, "\"Data get\" for the file's parent returned NULL. Oh dear.\n"); } actual_data = (struct ctree_attachment *) data_to_get; if (actual_data->file_or_site != IS_A_SITE) NE_DEBUG(DEBUG_GNOME, "Somehow you've clicked on a file, but it's parent was a file too!?\n"); current_site = (struct site *) actual_data->info_struct; selected_site = current_site; current_site_node = parent; if (current_file == NULL) { gfe_status("Unable to access info about the selected file."); } else { /* This line is causing a mutex to deadlock. why....? */ NE_DEBUG (DEBUG_GNOME, "Removing widgets from main data area...\n"); gtk_container_remove(GTK_CONTAINER(main_area_box), area_data); NE_DEBUG (DEBUG_GNOME, "Making file info area...\n"); area_data = make_file_info_area(current_file); NE_DEBUG (DEBUG_GNOME, "Adding file info area to main area..."); gtk_container_add(GTK_CONTAINER(main_area_box), area_data); NE_DEBUG (DEBUG_GNOME, "done.\n"); } } else { g_warning("If you got to here, something is really buggered, quite frankly.\n"); } }