From 2c04c48dfc5de6fc1086a25760da83fd88b9a7a1 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 27 Nov 1998 03:37:45 +0000 Subject: [PATCH] add xpm files --- gnome/dir-close.xpm | 24 +++++++++++ gnome/dir-open.xpm | 28 +++++++++++++ gnome/gtree.c | 97 ++++++++++++++++++++++++++++++++++++++++++--- gnome/gtree.h | 6 +-- 4 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 gnome/dir-close.xpm create mode 100644 gnome/dir-open.xpm diff --git a/gnome/dir-close.xpm b/gnome/dir-close.xpm new file mode 100644 index 000000000..a89fada29 --- /dev/null +++ b/gnome/dir-close.xpm @@ -0,0 +1,24 @@ +static char *DIRECTORY_CLOSE_XPM[] = { +"16 16 6 1", +" c None s None", +". c #808080", +"X c #c0c0c0", +"o c #ffff00", +"O c black", +"# c white", +" ", +" ..... ", +" .ooooo. ", +".ooooooo...... ", +".############.O ", +".#ooooooooooo.O ", +".#ooooooooooo.O ", +".#ooooooooooo.O ", +".#ooooooooooo.O ", +".#ooooooooooo.O ", +".#ooooooooooo.O ", +".#ooooooooooo.O ", +"..............O ", +" OOOOOOOOOOOOOO ", +" ", +" "}; diff --git a/gnome/dir-open.xpm b/gnome/dir-open.xpm new file mode 100644 index 000000000..10ceaf2b6 --- /dev/null +++ b/gnome/dir-open.xpm @@ -0,0 +1,28 @@ +static char *DIRECTORY_OPEN_XPM[] = { +/* width height num_colors chars_per_pixel */ +" 16 16 6 1", +/* colors */ +" c None s None", +". c black", +"# c #808080", +"g c white", +"h c #c0c0c0", +"j c yellow", +/* pixels */ +" ", +" ##### ", +" #ggggg# ", +" #ghjhjhg###### ", +" #gjjjjjjggggg#.", +" #gjjjjjjjjjjj#.", +"#############j#.", +"#gggggggggg#.j#.", +"#gjjjjjjjjjj.##.", +" #gjjjjjjjjj#.#.", +" #gjjjjjjjjjj.#.", +" #gjjjjjjjjj#..", +" ############..", +" .............", +" ", +" ", +}; diff --git a/gnome/gtree.c b/gnome/gtree.c index 7aa6b6c15..26bb66a6f 100644 --- a/gnome/gtree.c +++ b/gnome/gtree.c @@ -37,11 +37,15 @@ gtk_dtree_get_row_path (GtkCTree *ctree, GtkCTreeNode *row, gint column) path = g_strdup (""); do { char *new_path; + int val; - gtk_ctree_node_get_pixtext ( + val = gtk_ctree_node_get_pixtext ( ctree, row, column, &node_text, NULL, NULL, NULL); + if (!val) + return path; + new_path = g_concat_dir_and_file (node_text, path); g_free (path); path = new_path; @@ -84,8 +88,7 @@ gtk_dtree_load_path (GtkDTree *dtree, char *path, GtkCTreeNode *parent, int leve full_name = g_concat_dir_and_file (path, dirent->d_name); res = stat (full_name, &s); - printf ("Statting %s\n", full_name); - + if (res == -1){ g_free (full_name); continue; @@ -124,7 +127,6 @@ gtk_dtree_select_row (GtkCTree *ctree, GtkCTreeNode *row, gint column) parent_class->tree_select_row (ctree, row, column); - gtk_clist_freeze (GTK_CLIST (ctree)); while (row == dtree->root_node) return; @@ -133,7 +135,10 @@ gtk_dtree_select_row (GtkCTree *ctree, GtkCTreeNode *row, gint column) dtree->last_node = row; - path = gtk_dtree_get_row_path (ctree, row, column); + gtk_clist_freeze (GTK_CLIST (ctree)); + path = gtk_dtree_get_row_path (ctree, row, 0); + printf ("Selected: %s\n", path); + if (dtree->current_path) g_free (dtree->current_path); @@ -159,6 +164,88 @@ gtk_dtree_select_row (GtkCTree *ctree, GtkCTreeNode *row, gint column) gtk_clist_thaw (GTK_CLIST (ctree)); } +static GtkCTreeNode * +gtk_dtree_lookup_dir (GtkDTree *dtree, GtkCTreeNode *parent, char *dirname) +{ + GtkCTreeNode *node; + + g_assert (dtree); + g_assert (parent); + g_assert (dirname); + + node = GTK_CTREE_ROW (parent)->children; + + while (node && GTK_CTREE_ROW (node)->parent == parent){ + char *text; + + gtk_ctree_node_get_pixtext ( + GTK_CTREE (dtree), node, 0, &text, + NULL, NULL, NULL); + + if (strcmp (dirname, text) == 0) + return node; + + node = GTK_CTREE_NODE_NEXT (node); + } + + return NULL; +} + +/** + * gtk_dtree_select_dir: + * @dtree: the tree + * @path: The path we want loaded into the tree + * + * Attemps to open all of the tree notes until + * path is reached. It takes a fully qualified + * pathname. + * + * Returns: TRUE if it succeeded, otherwise, FALSE + */ +gboolean +gtk_dtree_select_dir (GtkDTree *dtree, char *path) +{ + GtkCTreeNode *current_node; + char *s, *current, *npath; + + g_return_if_fail (dtree != NULL); + g_return_if_fail (GTK_IS_DTREE (dtree)); + g_return_if_fail (path != NULL); + g_return_if_fail (*path == '/'); + + s = alloca (strlen (path)+1); + strcpy (s, path); + current_node = dtree->root_node; + + s++; + npath = g_strdup ("/"); + while ((current = strtok (s, "/")) != NULL){ + char *comp, *full_path; + GtkCTreeNode *node; + + full_path = g_concat_dir_and_file (npath, current); + g_free (npath); + npath = full_path; + + node = gtk_dtree_lookup_dir (dtree, current_node, current); + if (!node){ + printf ("Cargando: [%s]\n", current); + gtk_dtree_load_path (dtree, full_path, current_node, 2); + + node = gtk_dtree_lookup_dir (dtree, current_node, current); + } + g_free (full_path); + + if (node) + current_node = node; + else + break; + + s = NULL; + } + g_free (npath); +} + static void gtk_dtree_expand (GtkCTree *ctree, GtkCTreeNode *node) { diff --git a/gnome/gtree.h b/gnome/gtree.h index 6c9e8129d..d5a507fd5 100644 --- a/gnome/gtree.h +++ b/gnome/gtree.h @@ -36,8 +36,8 @@ GtkWidget *gtk_dtree_new (); void gtk_dtree_select_parent (GtkDTree *dtree, char *directory); void gtk_dtree_select_child (GtkDTree *dtree); -gboolean gtk_dtree_add_dir_by_name (GtkDTree *dtree, - char *directory); void gtk_dtree_remove_dir_by_name (GtkDTree *dtree, - gchar *directory); + char *directory); +gboolean gtk_dtree_select_dir (GtkDTree *dtree, + char *directory); #endif