(cleaning) using assert() instead of if (...) {} else {}
This commit is contained in:
parent
2f1112085a
commit
8d3039d6c2
18
display.c
18
display.c
|
@ -251,29 +251,13 @@ GtkBox *get_rules_comparator_new(){
|
||||||
return comparator;
|
return comparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkBox *get_experimental_box_new(){
|
|
||||||
GtkBox *experimental_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
|
|
||||||
gtk_widget_set_size_request (GTK_WIDGET (experimental_box), 0, 400);
|
|
||||||
gtk_box_append (experimental_box, GTK_WIDGET(gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
|
|
||||||
gtk_box_append (experimental_box, GTK_WIDGET(gtk_label_new ("\n\n")));
|
|
||||||
create_experimental_tree(experimental_box);
|
|
||||||
gtk_box_append (experimental_box, GTK_WIDGET(gtk_label_new ("\n\n")));
|
|
||||||
return experimental_box;
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkBox *get_rules_user_tree_new(){
|
|
||||||
GtkBox *tree_sketch_box = GTK_BOX(gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
|
|
||||||
gtk_box_append (tree_sketch_box, GTK_WIDGET (get_experimental_box_new()));
|
|
||||||
return tree_sketch_box;
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkWidget *get_rules_tree_hpaned_new(){
|
GtkWidget *get_rules_tree_hpaned_new(){
|
||||||
GtkPaned *H_tree_vs_comparison = GTK_PANED (gtk_paned_new (GTK_ORIENTATION_HORIZONTAL));
|
GtkPaned *H_tree_vs_comparison = GTK_PANED (gtk_paned_new (GTK_ORIENTATION_HORIZONTAL));
|
||||||
|
|
||||||
// GtkWidget *arbre_des_règles = gtk_frame_new ("Arbre");
|
// GtkWidget *arbre_des_règles = gtk_frame_new ("Arbre");
|
||||||
// GtkWidget *comparaison_des_règles_sélectionnées = gtk_frame_new ("Sélection");
|
// GtkWidget *comparaison_des_règles_sélectionnées = gtk_frame_new ("Sélection");
|
||||||
|
|
||||||
gtk_paned_set_start_child (H_tree_vs_comparison, GTK_WIDGET (get_rules_user_tree_new()));
|
gtk_paned_set_start_child (H_tree_vs_comparison, GTK_WIDGET (get_user_rules_tree()));
|
||||||
gtk_paned_set_end_child (H_tree_vs_comparison, GTK_WIDGET (get_rules_comparator_new()));
|
gtk_paned_set_end_child (H_tree_vs_comparison, GTK_WIDGET (get_rules_comparator_new()));
|
||||||
gtk_paned_set_position (H_tree_vs_comparison, 300);
|
gtk_paned_set_position (H_tree_vs_comparison, 300);
|
||||||
gtk_paned_set_wide_handle (H_tree_vs_comparison, TRUE);
|
gtk_paned_set_wide_handle (H_tree_vs_comparison, TRUE);
|
||||||
|
|
62
hot.c
62
hot.c
|
@ -15,10 +15,10 @@
|
||||||
|
|
||||||
static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
|
static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
|
||||||
|
|
||||||
static struct TreeNode_t *create_tree_node (const gchar* text){
|
static struct TreeNode_t *create_user_tree_node (const gchar* text){
|
||||||
struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t));
|
struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t));
|
||||||
node->text = g_strdup(text);
|
node->text = g_strdup(text);
|
||||||
node->child = NULL; // if (0) printf("create_tree_node %s\n", text);
|
node->child = NULL; // if (0) printf("create_user_tree_node %s\n", text);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child)
|
||||||
} else parent->child = child;
|
} else parent->child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_experimental_tree_expander_toggled(GtkExpander *expander, gpointer user_data)
|
void on_experimental_user_tree_expander_toggled(GtkExpander *expander, gpointer user_data)
|
||||||
{
|
{
|
||||||
// This is a conceptual callback for when an expander is toggled
|
// This is a conceptual callback for when an expander is toggled
|
||||||
GtkTreeListRow *row = GTK_TREE_LIST_ROW(user_data);
|
GtkTreeListRow *row = GTK_TREE_LIST_ROW(user_data);
|
||||||
|
@ -38,32 +38,33 @@ void on_experimental_tree_expander_toggled(GtkExpander *expander, gpointer user_
|
||||||
gtk_tree_list_row_set_expanded(row, !is_expanded);
|
gtk_tree_list_row_set_expanded(row, !is_expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){
|
static void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){
|
||||||
GtkListItem *list_item = GTK_LIST_ITEM (object);
|
GtkListItem *list_item = GTK_LIST_ITEM (object); assert (list_item);
|
||||||
GtkTreeListRow *row = gtk_list_item_get_item (list_item);
|
GtkTreeListRow *row = gtk_list_item_get_item (list_item); assert (row);
|
||||||
if (row != NULL) {
|
// if (row != NULL) {
|
||||||
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
|
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
|
||||||
GtkWidget *expander = gtk_list_item_get_child (list_item);
|
GtkWidget *expander = gtk_list_item_get_child (list_item);
|
||||||
gtk_expander_set_label (GTK_EXPANDER (expander), text);
|
gtk_expander_set_label (GTK_EXPANDER (expander), text);
|
||||||
g_signal_handlers_disconnect_by_func(expander, G_CALLBACK(on_experimental_tree_expander_toggled), row);
|
g_signal_handlers_disconnect_by_func(expander, G_CALLBACK(on_experimental_user_tree_expander_toggled), row);
|
||||||
g_signal_connect(expander, "activate", G_CALLBACK(on_experimental_tree_expander_toggled), row);
|
g_signal_connect(expander, "activate", G_CALLBACK(on_experimental_user_tree_expander_toggled), row);
|
||||||
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20);
|
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20);
|
||||||
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
|
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
|
||||||
if (0) printf("[on_experimental_tree_bind_factory] row content is [%s] and expander is [%d]\n", text, is_expanded);
|
if (0) printf("[on_bind_user_tree_factory] row content is [%s] and expander is [%d]\n", text, is_expanded);
|
||||||
} else if (0) printf("[on_experimental_tree_bind_factory] row == NULL\n");
|
// } else if (0) printf("[on_bind_user_tree_factory] row == NULL\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_experimental_tree_setup_factory (GtkSignalListItemFactory *factory,
|
void on_setup_user_tree_factory (GtkSignalListItemFactory *factory,
|
||||||
GObject* object, gpointer user_data){
|
GObject* object, gpointer user_data){
|
||||||
GtkWidget* expander = gtk_expander_new (NULL);
|
GtkWidget* expander = gtk_expander_new (NULL);
|
||||||
gtk_list_item_set_child (GTK_LIST_ITEM(object), expander);
|
gtk_list_item_set_child (GTK_LIST_ITEM (object), expander);
|
||||||
if (0) printf("[on_experimental_tree_setup_factory] here is an expander\n");
|
if (0) printf("[on_setup_user_tree_factory] here is an expander\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static GListModel* get_experimental_tree_model_child (struct TreeNode_t *parent){
|
static GListModel* get_experimental_user_tree_model_child (struct TreeNode_t *parent){
|
||||||
GtkStringList *list = NULL;
|
GtkStringList *list = NULL;
|
||||||
if (parent) {
|
assert (parent);
|
||||||
if (0) printf("[get_experimental_tree_model_child] here is %s content : ", parent->text);
|
// if (parent) {
|
||||||
|
if (0) printf("[get_experimental_user_tree_model_child] here is %s content : ", parent->text);
|
||||||
struct TreeNode_t *child = parent->child;
|
struct TreeNode_t *child = parent->child;
|
||||||
if (child) {list = gtk_string_list_new(NULL);}
|
if (child) {list = gtk_string_list_new(NULL);}
|
||||||
while(child) {
|
while(child) {
|
||||||
|
@ -71,12 +72,12 @@ static GListModel* get_experimental_tree_model_child (struct TreeNode_t *parent)
|
||||||
if (0) printf("%s ", child->text);
|
if (0) printf("%s ", child->text);
|
||||||
child = child->next;
|
child = child->next;
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
if (0) printf("\n");
|
if (0) printf("\n");
|
||||||
return G_LIST_MODEL(list);
|
return G_LIST_MODEL(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
GListModel* create_experimental_tree_model (GObject *item, gpointer root){
|
GListModel* get_user_tree_model (GObject *item, gpointer root){
|
||||||
struct TreeNode_t *cur = (struct TreeNode_t *)root;
|
struct TreeNode_t *cur = (struct TreeNode_t *)root;
|
||||||
struct TreeNode_t *parent = root;
|
struct TreeNode_t *parent = root;
|
||||||
const gchar *string = gtk_string_object_get_string (GTK_STRING_OBJECT(item));
|
const gchar *string = gtk_string_object_get_string (GTK_STRING_OBJECT(item));
|
||||||
|
@ -85,28 +86,28 @@ GListModel* create_experimental_tree_model (GObject *item, gpointer root){
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
if (cur == NULL) {cur = parent->child; parent = cur;}
|
if (cur == NULL) {cur = parent->child; parent = cur;}
|
||||||
}
|
}
|
||||||
if (0) printf("[create_experimental_tree_model] looked for %s in %s item\n", cur->text, string);
|
if (0) printf("[get_user_user_tree_model] looked for %s in %s item\n", cur->text, string);
|
||||||
return get_experimental_tree_model_child (cur);
|
return get_experimental_user_tree_model_child (cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_experimental_tree (GtkBox *experimental_box){
|
GtkScrolledWindow *get_user_rules_tree (){
|
||||||
struct TreeNode_t *tree_root = create_tree_node("hello");
|
struct TreeNode_t *tree_root = create_user_tree_node("hello");
|
||||||
struct TreeNode_t *it_s_me = create_tree_node("it's me"); add_child_node(tree_root, it_s_me);
|
struct TreeNode_t *it_s_me = create_user_tree_node("it's me"); add_child_node(tree_root, it_s_me);
|
||||||
struct TreeNode_t *remember = create_tree_node("do you remember ?"); add_child_node(it_s_me, remember);
|
struct TreeNode_t *remember = create_user_tree_node("do you remember ?"); add_child_node(it_s_me, remember);
|
||||||
|
|
||||||
GtkStringList *model = gtk_string_list_new(NULL);
|
GtkStringList *model = gtk_string_list_new(NULL);
|
||||||
gtk_string_list_append (model, tree_root->text);
|
gtk_string_list_append (model, tree_root->text);
|
||||||
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new());
|
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new());
|
||||||
g_signal_connect (factory, "setup", G_CALLBACK(on_experimental_tree_setup_factory), NULL);
|
g_signal_connect (factory, "setup", G_CALLBACK(on_setup_user_tree_factory), NULL);
|
||||||
g_signal_connect (factory, "bind", G_CALLBACK(on_experimental_tree_bind_factory), NULL);
|
g_signal_connect (factory, "bind", G_CALLBACK(on_bind_user_tree_factory), NULL);
|
||||||
|
|
||||||
GtkTreeListModel *tree_model = gtk_tree_list_model_new(
|
GtkTreeListModel *tree_model = gtk_tree_list_model_new(
|
||||||
G_LIST_MODEL (model),
|
G_LIST_MODEL (model),
|
||||||
FALSE, // Passthrough - False in actual usage with dynamic children retrieval
|
FALSE, // Passthrough - False in actual usage with dynamic children retrieval
|
||||||
FALSE, // autoexpand
|
FALSE, // autoexpand
|
||||||
(GtkTreeListModelCreateModelFunc) &create_experimental_tree_model,
|
(GtkTreeListModelCreateModelFunc) &get_user_tree_model,
|
||||||
tree_root,
|
tree_root,
|
||||||
NULL // (GDestroyNotify) free_tree_node
|
NULL // (GDestroyNotify) free_user_tree_node
|
||||||
);
|
);
|
||||||
|
|
||||||
GtkSingleSelection *selection_model = gtk_single_selection_new (G_LIST_MODEL (tree_model));
|
GtkSingleSelection *selection_model = gtk_single_selection_new (G_LIST_MODEL (tree_model));
|
||||||
|
@ -117,8 +118,7 @@ void create_experimental_tree (GtkBox *experimental_box){
|
||||||
gtk_scrolled_window_set_child(experimental_scrolled_window, list_view);
|
gtk_scrolled_window_set_child(experimental_scrolled_window, list_view);
|
||||||
gtk_scrolled_window_set_policy (experimental_scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
gtk_scrolled_window_set_policy (experimental_scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||||
gtk_widget_set_vexpand(GTK_WIDGET(experimental_scrolled_window), TRUE);
|
gtk_widget_set_vexpand(GTK_WIDGET(experimental_scrolled_window), TRUE);
|
||||||
assert(experimental_box);
|
|
||||||
gtk_box_append(GTK_BOX(experimental_box), GTK_WIDGET(experimental_scrolled_window));
|
|
||||||
gtk_widget_set_visible(GTK_WIDGET(experimental_scrolled_window), TRUE);
|
gtk_widget_set_visible(GTK_WIDGET(experimental_scrolled_window), TRUE);
|
||||||
gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE);
|
gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE);
|
||||||
|
return experimental_scrolled_window;
|
||||||
}
|
}
|
||||||
|
|
5
hot.h
5
hot.h
|
@ -12,7 +12,4 @@
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "contain.h"
|
#include "contain.h"
|
||||||
|
|
||||||
void on_experimental_tree_setup_factory (GtkSignalListItemFactory *factory,
|
GtkScrolledWindow *get_user_rules_tree ();
|
||||||
GObject* object,
|
|
||||||
gpointer user_data);
|
|
||||||
void create_experimental_tree (GtkBox *experimental_box);
|
|
||||||
|
|
Loading…
Reference in New Issue