Branch
Hash :
94046104
Author :
Thomas de Grivel
Date :
2020-02-24T15:19:27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/*
pw13_gtk - A Patchwork13! GTK User Interface
Copyright (C) 2005 Thomas de Grivel <billitch@yahoo.fr>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
FUCKABILITY, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more freakish details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
tb_tree.c - Toolbox treeview. Contains patch classes
*/
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <pw13/pw13.h>
#include "tb_tree.h"
static void mk_tree_item (tb_tree_item item,
tb_tree_item parent,
const char *name)
{
int name_len = strlen (name);
item->parent = parent;
item->name = (char*) malloc (name_len + 1);
strcpy (item->name, name);
if (parent) {
item->path = (char*) malloc (strlen (parent->path) + name_len + 2);
sprintf (item->path, "%s/%s", parent->path, name);
}
else {
item->path = (char*) malloc (strlen (name) + 1);
strcpy (item->path, name);
}
}
static void tb_tree_add_folder (tb_tree t, tb_tree_item item)
{
GtkTreeIter *pi;
if (item->parent)
pi = &item->parent->iter;
else
pi = NULL;
gtk_tree_store_append (t->tree_store,
&item->iter,
pi);
gtk_tree_store_set (t->tree_store,
&item->iter,
TB_TREE_NAME_COLUMN, item->name,
-1);
}
static void tb_tree_add_file (tb_tree t, tb_tree_item item)
{
GtkTreeIter *pi;
if (item->parent)
pi = &(item->parent->iter);
else
pi = NULL;
gtk_tree_store_append (t->tree_store,
&(item->iter),
pi);
gtk_tree_store_set (t->tree_store,
&(item->iter),
TB_TREE_NAME_COLUMN, item->name,
-1);
}
static int tb_tree_is_duplicate (GtkTreeModel *model, tb_tree_item item)
{
GtkTreeIter iter, *pi;
if (!item->parent)
pi = NULL;
else
pi = &item->parent->iter;
if (gtk_tree_model_iter_children (model, &iter, pi) == FALSE)
return 0;
do {
char *name;
gtk_tree_model_get (model, &iter, TB_TREE_NAME_COLUMN,
&name, -1);
if (!strcmp (name, item->name))
return 1;
} while (gtk_tree_model_iter_next (model, &iter) == TRUE);
return 0;
}
static void tb_tree_parse_dir_r (tb_tree t, tb_tree_item item)
{
if (g_file_test (item->path, G_FILE_TEST_IS_DIR)) {
const char * n;
GDir * d = g_dir_open(item->path, 0,NULL);
tb_tree_add_folder(t, item);
while ((n = (const char*) g_dir_read_name(d))) {
tb_tree_item_s ni;
mk_tree_item (&ni, item, n);
tb_tree_parse_dir_r (t, &ni);
}
g_dir_close (d);
}
else if (pw13_dl_is_patch_class (item->path)) {
if (!pw13_classpath_of_filepath (item->path) &&
!pw13_classpath_of_filepath (item->name) &&
!tb_tree_is_duplicate (GTK_TREE_MODEL (t->tree_store), item)) {
tb_tree_add_file (t, item);
}
}
}
void tb_tree_parse_dir (tb_tree t, const char *path)
{
tb_tree_item_s item;
mk_tree_item (&item, NULL, path);
tb_tree_parse_dir_r (t, &item);
/*
gtk_tree_view_expand_all (GTK_TREE_VIEW (t->tree_view));
*/
}
void tb_tree_build_widget (tb_tree t)
{
GtkCellRenderer *cell;
GtkTreeViewColumn *column;
t->scrolled_window = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL,
NULL));
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (t->scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
t->tree_store = gtk_tree_store_new (TB_TREE_NB_COLUMNS,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
t->tree_view = gtk_tree_view_new ();
gtk_scrolled_window_add_with_viewport (t->scrolled_window,
t->tree_view);
gtk_tree_view_set_model (GTK_TREE_VIEW(t->tree_view),
GTK_TREE_MODEL(t->tree_store));
cell = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("NOM",
cell,
"text",0,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (t->tree_view),
GTK_TREE_VIEW_COLUMN (column));
g_object_unref (G_OBJECT(t->tree_store));
gtk_widget_show (t->tree_view);
}