diff options
author | Johannes Schmid <jhs@gnome.org> | 2011-01-07 12:56:06 +0100 |
---|---|---|
committer | Johannes Schmid <jhs@gnome.org> | 2011-01-07 12:56:06 +0100 |
commit | 097de9b14d0de293620049ab1863b62be0b2bdff (patch) | |
tree | a58fb61413637a1da9900749cdf1f4500e085232 /gladeui/glade-signal-model.c | |
parent | a654ad9307819137e29f6629673e9728f138b398 (diff) | |
download | glade-097de9b14d0de293620049ab1863b62be0b2bdff.tar.gz |
glade-signal-editor: Adapt to tristan's UI wishes
Diffstat (limited to 'gladeui/glade-signal-model.c')
-rw-r--r-- | gladeui/glade-signal-model.c | 779 |
1 files changed, 395 insertions, 384 deletions
diff --git a/gladeui/glade-signal-model.c b/gladeui/glade-signal-model.c index f3b1f9c7..de699397 100644 --- a/gladeui/glade-signal-model.c +++ b/gladeui/glade-signal-model.c @@ -1,12 +1,12 @@ /* * glade3 * Copyright (C) Johannes Schmid 2010 <jhs@gnome.org> - * + * * glade3 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. - * + * * glade3 is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -55,14 +55,26 @@ static void on_glade_signal_model_removed (GladeWidget* widget, const GladeSignal* signal, GladeSignalModel* model); static void -on_glade_signal_model_changed (GladeWidget* widget, const GladeSignal* old_signal, - const GladeSignal* new_signal, GladeSignalModel* model); +on_glade_signal_model_changed (GladeWidget* widget, const GladeSignal* signal, + GladeSignalModel* model); G_DEFINE_TYPE_WITH_CODE (GladeSignalModel, glade_signal_model, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, - gtk_tree_model_iface_init); + gtk_tree_model_iface_init); G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE, - gtk_tree_drag_source_iface_init)) + gtk_tree_drag_source_iface_init)) + +static gint +g_ptr_array_find (GPtrArray* array, gpointer data) +{ + gint i; + for (i = 0; i < array->len; i++) + { + if (array->pdata[i] == data) + return i; + } + return -1; +} static void glade_signal_model_init (GladeSignalModel *object) @@ -80,12 +92,12 @@ glade_signal_model_create_widget_list (GladeSignalModel* sig_model) GladeWidget *widget = sig_model->priv->widget; GladeWidgetAdaptor *adaptor = glade_widget_get_adaptor (widget); - for (list = glade_widget_adaptor_get_signals (adaptor); + for (list = glade_widget_adaptor_get_signals (adaptor); list != NULL; list = g_list_next (list)) { GladeSignalClass *signal = (GladeSignalClass *) list->data; - if (!g_list_find_custom (sig_model->priv->widgets, (gpointer) glade_signal_class_get_type (signal), (GCompareFunc) strcmp)) + if (!g_list_find_custom (sig_model->priv->widgets, (gpointer) glade_signal_class_get_type (signal), (GCompareFunc) strcmp)) { sig_model->priv->widgets = g_list_prepend (sig_model->priv->widgets, (gpointer) glade_signal_class_get_type (signal)); } @@ -98,7 +110,7 @@ glade_signal_model_finalize (GObject *object) { GladeSignalModel* sig_model = GLADE_SIGNAL_MODEL (object); - g_list_free (sig_model->priv->widgets); + g_list_free (sig_model->priv->widgets); g_hash_table_destroy (sig_model->priv->dummy_signals); G_OBJECT_CLASS (glade_signal_model_parent_class)->finalize (object); } @@ -108,31 +120,31 @@ glade_signal_model_set_property (GObject *object, guint prop_id, const GValue *v { GladeSignalModel* sig_model; - g_return_if_fail (GLADE_IS_SIGNAL_MODEL (object)); + g_return_if_fail (GLADE_IS_SIGNAL_MODEL (object)); - sig_model = GLADE_SIGNAL_MODEL (object); + sig_model = GLADE_SIGNAL_MODEL (object); switch (prop_id) { - case PROP_WIDGET: - sig_model->priv->widget = g_value_get_object (value); - glade_signal_model_create_widget_list (sig_model); - g_signal_connect (sig_model->priv->widget, - "add-signal-handler", - G_CALLBACK (on_glade_signal_model_added), sig_model); - g_signal_connect (sig_model->priv->widget, - "remove-signal-handler", - G_CALLBACK (on_glade_signal_model_removed), sig_model); - g_signal_connect (sig_model->priv->widget, - "change-signal-handler", - G_CALLBACK (on_glade_signal_model_changed), sig_model); - break; - case PROP_SIGNALS: - sig_model->priv->signals = g_value_get_pointer (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + case PROP_WIDGET: + sig_model->priv->widget = g_value_get_object (value); + glade_signal_model_create_widget_list (sig_model); + g_signal_connect (sig_model->priv->widget, + "add-signal-handler", + G_CALLBACK (on_glade_signal_model_added), sig_model); + g_signal_connect (sig_model->priv->widget, + "remove-signal-handler", + G_CALLBACK (on_glade_signal_model_removed), sig_model); + g_signal_connect (sig_model->priv->widget, + "change-signal-handler", + G_CALLBACK (on_glade_signal_model_changed), sig_model); + break; + case PROP_SIGNALS: + sig_model->priv->signals = g_value_get_pointer (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -141,21 +153,21 @@ glade_signal_model_get_property (GObject *object, guint prop_id, GValue *value, { GladeSignalModel* sig_model; - g_return_if_fail (GLADE_IS_SIGNAL_MODEL (object)); + g_return_if_fail (GLADE_IS_SIGNAL_MODEL (object)); - sig_model = GLADE_SIGNAL_MODEL (object); + sig_model = GLADE_SIGNAL_MODEL (object); switch (prop_id) { - case PROP_WIDGET: - g_value_set_object (value, sig_model->priv->widget); - break; - case PROP_SIGNALS: - g_value_set_pointer (value, sig_model->priv->signals); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + case PROP_WIDGET: + g_value_set_object (value, sig_model->priv->widget); + break; + case PROP_SIGNALS: + g_value_set_pointer (value, sig_model->priv->signals); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -165,7 +177,7 @@ glade_signal_model_class_init (GladeSignalModelClass *klass) GObjectClass* object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (GladeSignalModelPrivate)); - + object_class->finalize = glade_signal_model_finalize; object_class->set_property = glade_signal_model_set_property; object_class->get_property = glade_signal_model_get_property; @@ -180,9 +192,9 @@ glade_signal_model_class_init (GladeSignalModelClass *klass) g_object_class_install_property (object_class, PROP_SIGNALS, g_param_spec_pointer ("signals", - "A GHashTable containing the widget signals", - "Use to query signals", - G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE)); + "A GHashTable containing the widget signals", + "Use to query signals", + G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE)); } /* @@ -224,6 +236,8 @@ glade_signal_model_get_column_type (GtkTreeModel* model, { case GLADE_SIGNAL_COLUMN_NAME: return G_TYPE_STRING; + case GLADE_SIGNAL_COLUMN_SHOW_NAME: + return G_TYPE_BOOLEAN; case GLADE_SIGNAL_COLUMN_HANDLER: return G_TYPE_STRING; case GLADE_SIGNAL_COLUMN_OBJECT: @@ -236,8 +250,6 @@ glade_signal_model_get_column_type (GtkTreeModel* model, return G_TYPE_BOOLEAN; case GLADE_SIGNAL_COLUMN_NOT_DUMMY: return G_TYPE_BOOLEAN; - case GLADE_SIGNAL_COLUMN_HAS_HANDLERS: - return G_TYPE_BOOLEAN; case GLADE_SIGNAL_COLUMN_VERSION_WARNING: return G_TYPE_BOOLEAN; case GLADE_SIGNAL_COLUMN_TOOLTIP: @@ -254,7 +266,6 @@ enum { ITER_WIDGET = 0, ITER_SIGNAL = 1, - ITER_HANDLER = 2 }; static GladeSignal* @@ -289,7 +300,7 @@ glade_signal_model_not_dummy_handler (GladeSignalModel* model, if (widget && sig_class && handler) return handler != glade_signal_model_get_dummy_handler (model, - sig_class); + sig_class); return FALSE; } @@ -305,27 +316,17 @@ glade_signal_model_create_widget_iter (GladeSignalModel* sig_model, } static void -glade_signal_model_create_handler_iter (GladeSignalModel* sig_model, - const gchar* widget, - GladeSignalClass* signal_class, - GladeSignal* signal, - GtkTreeIter* iter) -{ - glade_signal_model_create_widget_iter (sig_model, widget, iter); - iter->user_data2 = signal_class; - iter->user_data3 = signal; - /* Check the version warning here */ - glade_project_verify_signal (sig_model->priv->widget, signal); -} - -static void glade_signal_model_create_signal_iter (GladeSignalModel* sig_model, const gchar* widget, - GladeSignalClass* signal_class, + const GladeSignalClass* signal_class, + const GladeSignal* signal, GtkTreeIter* iter) { glade_signal_model_create_widget_iter (sig_model, widget, iter); - iter->user_data2 = signal_class; + iter->user_data2 = (GladeSignalClass*) signal_class; + iter->user_data3 = (GladeSignal*) signal; + /* Check the version warning here */ + glade_project_verify_signal (sig_model->priv->widget, (GladeSignal*) signal); } static GList* glade_signal_model_create_signal_list (GladeSignalModel* sig_model, @@ -336,7 +337,7 @@ static GList* glade_signal_model_create_signal_list (GladeSignalModel* sig_model GladeWidget *widget = sig_model->priv->widget; GladeWidgetAdaptor *adaptor = glade_widget_get_adaptor (widget); - for (signals = glade_widget_adaptor_get_signals (adaptor); + for (signals = glade_widget_adaptor_get_signals (adaptor); signals != NULL; signals = g_list_next (signals)) { @@ -349,109 +350,100 @@ static GList* glade_signal_model_create_signal_list (GladeSignalModel* sig_model return widget_signals; } -static gboolean -glade_signal_model_has_handlers (GladeSignalModel* model, GtkTreeIter* iter) +/* Be sure to update the parent columns when signals are added/removed + * as that might affect the appearance */ +static void +glade_signal_model_update_class (GladeSignalModel* model, + GtkTreeIter* iter) { const gchar* widget = iter->user_data; - GladeSignalClass* sig_class = iter->user_data2; - GladeSignal* signal = iter->user_data3; + GladeSignalClass* class = iter->user_data2; + GtkTreeIter class_dummy; - if (signal) - return FALSE; + glade_signal_model_create_signal_iter (model, + widget, + class, + glade_signal_model_get_dummy_handler (model, + class), + &class_dummy); - if (sig_class) + do { - GPtrArray* handlers = g_hash_table_lookup (model->priv->signals, - glade_signal_class_get_name (sig_class)); - if (handlers && handlers->len > 0) - return TRUE; - } - else if (widget) - { - GList* signals = glade_signal_model_create_signal_list (model, widget); - GList* class_iter; + GtkTreePath* path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), + &class_dummy); - for (class_iter = signals; class_iter != NULL; class_iter = g_list_next (class_iter)) - { - GPtrArray* handlers; - - sig_class = class_iter->data; - handlers = g_hash_table_lookup (model->priv->signals, - glade_signal_class_get_name (sig_class)); - if (handlers && handlers->len > 0) - { - g_list_free (signals); - return TRUE; - } - } - g_list_free (signals); + gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &class_dummy); + gtk_tree_path_free (path); } - return FALSE; + while (gtk_tree_model_iter_previous (GTK_TREE_MODEL (model), &class_dummy) && + class == class_dummy.user_data2); } -static gboolean -glade_signal_model_iter_for_signal (GladeSignalModel* model, const GladeSignal* signal, GtkTreeIter* iter) +static GladeSignalClass* +glade_signal_model_find_signal_class (GladeSignalModel* model, + const GladeSignal* handler) { - const GList* list; - GladeWidget *widget = model->priv->widget; - GladeWidgetAdaptor *adaptor = glade_widget_get_adaptor (widget); - - for (list = glade_widget_adaptor_get_signals (adaptor); - list != NULL; list = g_list_next (list)) + GladeSignalClass* class = NULL; + GList* widgets = model->priv->widgets; + GList* widget; + for (widget = widgets; widget != NULL; widget = g_list_next (widget)) { - GladeSignalClass *sig_class = (GladeSignalClass *) list->data; - if (g_str_equal (glade_signal_get_name (signal), - glade_signal_class_get_name (sig_class))) + GList* signals = glade_signal_model_create_signal_list (model, + widget->data); + GList* signal; + for (signal = signals; signal != NULL; signal = g_list_next (signal)) { - glade_signal_model_create_handler_iter (model, - glade_signal_class_get_type (sig_class), - sig_class, - (GladeSignal*) signal, - iter); - return TRUE; - } + GPtrArray* handlers = + g_hash_table_lookup (model->priv->signals, + glade_signal_class_get_name (GLADE_SIGNAL_CLASS(signal->data))); + if (handlers && g_ptr_array_find (handlers, (gpointer) handler) != -1) + { + class = signal->data; + break; + } + } + g_list_free (signals); + if (class) + break; } - return FALSE; + return class; } -/* Be sure to update the parent columns when signals are added/removed - * as that might affect the appearance */ static void -glade_signal_model_update_parents (GladeSignalModel* model, - GtkTreeIter* iter) +glade_signal_model_iter_for_signal (GladeSignalModel* model, + const GladeSignalClass* sig_class, + const GladeSignal* handler, + GtkTreeIter* iter) { - GtkTreeIter sig_class_iter; - GtkTreeIter widget_iter; - GtkTreePath* sig_class_path; - GtkTreePath* widget_path; - - gtk_tree_model_iter_parent (GTK_TREE_MODEL (model), &sig_class_iter, iter); - gtk_tree_model_iter_parent (GTK_TREE_MODEL (model), &widget_iter, &sig_class_iter); - - sig_class_path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &sig_class_iter); - widget_path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &widget_iter); - - gtk_tree_model_row_changed (GTK_TREE_MODEL (model), sig_class_path, &sig_class_iter); - gtk_tree_model_row_changed (GTK_TREE_MODEL (model), widget_path, &widget_iter); - - gtk_tree_path_free (sig_class_path); - gtk_tree_path_free (widget_path); + glade_signal_model_create_signal_iter (model, + glade_signal_class_get_type (sig_class), + sig_class, + handler, + iter); } static void on_glade_signal_model_added (GladeWidget* widget, const GladeSignal* signal, GladeSignalModel* model) { - GtkTreeIter iter; - - if (glade_signal_model_iter_for_signal (model, signal, &iter)) + GtkTreeIter iter; + GladeSignalClass* sig_class = + glade_signal_model_find_signal_class (model, + signal); + if (sig_class) { - GtkTreePath* path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), + GtkTreePath* path; + glade_signal_model_iter_for_signal (model, + sig_class, + signal, + &iter); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); + gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter); - glade_signal_model_update_parents (model, &iter); + glade_signal_model_update_class (model, &iter); gtk_tree_path_free (path); model->priv->stamp++; } @@ -462,34 +454,49 @@ on_glade_signal_model_removed (GladeWidget* widget, const GladeSignal* signal, GladeSignalModel* model) { GtkTreeIter iter; + GladeSignalClass* sig_class = + glade_signal_model_find_signal_class (model, + signal); - if (glade_signal_model_iter_for_signal (model, signal, &iter)) + if (sig_class) { - GtkTreePath* path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), + GtkTreePath* path; + glade_signal_model_iter_for_signal (model, + sig_class, + signal, + &iter); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), - gtk_tree_model_get_path (GTK_TREE_MODEL (model), - &iter)); - glade_signal_model_update_parents (model, &iter); + path); + glade_signal_model_update_class (model, &iter); gtk_tree_path_free (path); model->priv->stamp++; } } static void -on_glade_signal_model_changed (GladeWidget* widget, const GladeSignal* old_signal, - const GladeSignal* new_signal, GladeSignalModel* model) +on_glade_signal_model_changed (GladeWidget* widget, const GladeSignal* signal, + GladeSignalModel* model) { GtkTreeIter iter; + GladeSignalClass* sig_class = + glade_signal_model_find_signal_class (model, + signal); - if (glade_signal_model_iter_for_signal (model, new_signal, &iter)) + if (sig_class) { - GtkTreePath* path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), + GtkTreePath* path; + glade_signal_model_iter_for_signal (model, + sig_class, + signal, + &iter); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); gtk_tree_model_row_changed (GTK_TREE_MODEL (model), - gtk_tree_model_get_path (GTK_TREE_MODEL (model), - &iter), - &iter); + path, + &iter); + glade_signal_model_update_class (model, &iter); gtk_tree_path_free (path); model->priv->stamp++; } @@ -503,11 +510,11 @@ glade_signal_model_get_iter (GtkTreeModel* model, gint* indices; gint depth; GladeSignalModel* sig_model; - + g_return_val_if_fail (path != NULL, FALSE); g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (GLADE_IS_SIGNAL_MODEL(model), FALSE); - + indices = gtk_tree_path_get_indices(path); depth = gtk_tree_path_get_depth (path); sig_model = GLADE_SIGNAL_MODEL (model); @@ -515,7 +522,7 @@ glade_signal_model_get_iter (GtkTreeModel* model, switch (depth) { case 1: - /* Widget */ + /* Widget */ { glade_signal_model_create_widget_iter (sig_model, g_list_nth_data (sig_model->priv->widgets, @@ -524,72 +531,25 @@ glade_signal_model_get_iter (GtkTreeModel* model, return TRUE; } case 2: - /* Signal */ - { - const gchar* widget = g_list_nth_data (sig_model->priv->widgets, - indices[ITER_WIDGET]); - GList* signals = glade_signal_model_create_signal_list (sig_model, - widget); - if (signals) - { - glade_signal_model_create_signal_iter (sig_model, widget, - g_list_nth_data (signals, indices[ITER_SIGNAL]), - iter); - g_list_free (signals); - return TRUE; - } - return FALSE; - } - case 3: - /* Handler */ + /* Signal */ { - GPtrArray* handlers; - const gchar* widget = g_list_nth_data (sig_model->priv->widgets, - indices[ITER_WIDGET]); - GList* signals = glade_signal_model_create_signal_list (sig_model, - widget); - if (signals) - { - GladeSignalClass* signal = g_list_nth_data (signals, indices[ITER_SIGNAL]); - handlers = g_hash_table_lookup (sig_model->priv->signals, - glade_signal_class_get_name (signal)); - if (handlers && indices[ITER_HANDLER] < handlers->len) - { - GladeSignal* handler = - (GladeSignal*) g_ptr_array_index (handlers, indices[ITER_HANDLER]); - glade_signal_model_create_handler_iter (sig_model, widget, - signal, - handler, iter); - return TRUE; - } - else if ((!handlers && indices[ITER_HANDLER] == 0) || indices[ITER_HANDLER] == handlers->len) - { - GladeSignal *handler = - glade_signal_model_get_dummy_handler (sig_model, signal); - glade_signal_model_create_handler_iter (sig_model, widget, - signal, - handler, iter); - return TRUE; - } - } - return FALSE; + gboolean retval; + GtkTreePath* path = + gtk_tree_path_new_from_indices (indices[ITER_WIDGET], -1); + GtkTreeIter widget_iter; + + gtk_tree_model_get_iter (model, &widget_iter, path); + retval = gtk_tree_model_iter_nth_child (model, + iter, + &widget_iter, + indices[ITER_SIGNAL]); + gtk_tree_path_free (path); + return retval; } } return FALSE; } -static gint -g_ptr_array_find (GPtrArray* array, gpointer data) -{ - gint i; - for (i = 0; i < array->len; i++) - { - if (array->pdata[i] == data) - return i; - } - return -1; -} - static GtkTreePath* glade_signal_model_get_path (GtkTreeModel* model, GtkTreeIter* iter) @@ -600,55 +560,52 @@ glade_signal_model_get_path (GtkTreeModel* model, GladeSignalModel* sig_model; - g_return_val_if_fail (iter != NULL, NULL); + g_return_val_if_fail (iter != NULL, NULL); g_return_val_if_fail (GLADE_IS_SIGNAL_MODEL(model), NULL); - widget = iter->user_data; - sig_class = iter->user_data2; - handler = iter->user_data3; - sig_model = GLADE_SIGNAL_MODEL (model); - - if (handler) + widget = iter->user_data; + sig_class = iter->user_data2; + handler = iter->user_data3; + sig_model = GLADE_SIGNAL_MODEL (model); + + if (handler && sig_class) { - /* Handler */ - GPtrArray* handlers; - gint index0, index1, index2; + /* Signal */ + gint index0, index1 = 0; + GList* signal; GList* signals = glade_signal_model_create_signal_list (sig_model, widget); index0 = g_list_index (sig_model->priv->widgets, widget); - index1 = g_list_index (signals, sig_class); + + for (signal = signals; signal != NULL; signal = g_list_next (signal)) + { - handlers = g_hash_table_lookup (sig_model->priv->signals, - glade_signal_class_get_name (sig_class)); + GPtrArray* handlers = g_hash_table_lookup (sig_model->priv->signals, + glade_signal_class_get_name (signal->data)); - if (handler == glade_signal_model_get_dummy_handler (sig_model, - sig_class)) - { - if (handlers) - index2 = handlers->len; + if (signal->data != sig_class) + { + if (handlers) + index1 += handlers->len; + index1++; /* dummy_handler */ + } else - index2 = 0; + { + if (handlers) + { + gint handler_index = g_ptr_array_find (handlers, handler); + if (handler_index == -1) /* dummy handler */ + { + index1 += handlers->len; + } + else + index1 += handler_index; + } + break; + } } - else if (handlers) - index2 = g_ptr_array_find (handlers, handler); - else - g_assert_not_reached(); - - g_list_free (signals); - return gtk_tree_path_new_from_indices (index0, index1, index2, -1); - } - else if (sig_class) - { - /* Signal */ - GList* signals = glade_signal_model_create_signal_list (sig_model, - widget); - gint index0 = g_list_index (sig_model->priv->widgets, - widget); - gint index1 = g_list_index (signals, sig_class); - g_list_free (signals); - return gtk_tree_path_new_from_indices (index0, index1, -1); } else if (widget) @@ -672,30 +629,46 @@ glade_signal_model_get_value (GtkTreeModel* model, GladeSignalModel* sig_model; - g_return_if_fail (iter != NULL); + g_return_if_fail (iter != NULL); g_return_if_fail (GLADE_IS_SIGNAL_MODEL(model)); - widget = iter->user_data; - sig_class = iter->user_data2; - handler = iter->user_data3; - sig_model = GLADE_SIGNAL_MODEL (model); - + widget = iter->user_data; + sig_class = iter->user_data2; + handler = iter->user_data3; + sig_model = GLADE_SIGNAL_MODEL (model); + value = g_value_init (value, glade_signal_model_get_column_type (model, column)); - + switch (column) { case GLADE_SIGNAL_COLUMN_NAME: if (widget && sig_class && handler) - g_value_set_static_string (value, - ""); - else if (widget && sig_class) + { g_value_set_static_string (value, glade_signal_class_get_name (sig_class)); + + } else if (widget) g_value_set_static_string (value, widget); break; + case GLADE_SIGNAL_COLUMN_SHOW_NAME: + if (widget && sig_class && handler) + { + GPtrArray* handlers = g_hash_table_lookup (sig_model->priv->signals, + glade_signal_class_get_name (sig_class)); + if (!handlers || !handlers->len || g_ptr_array_find (handlers, handler) == 0) + g_value_set_boolean (value, + TRUE); + else + g_value_set_boolean (value, + FALSE); + } + else if (widget) + g_value_set_boolean (value, + TRUE); + break; case GLADE_SIGNAL_COLUMN_HANDLER: if (widget && sig_class && handler) g_value_set_static_string (value, @@ -706,15 +679,15 @@ glade_signal_model_get_value (GtkTreeModel* model, break; case GLADE_SIGNAL_COLUMN_OBJECT: if (widget && sig_class && handler) - { - const gchar* userdata = glade_signal_get_userdata (handler); - if (userdata && strlen (userdata)) - g_value_set_static_string (value, - userdata); - else - g_value_set_static_string (value, - USERDATA_DEFAULT); - } + { + const gchar* userdata = glade_signal_get_userdata (handler); + if (userdata && strlen (userdata)) + g_value_set_static_string (value, + userdata); + else + g_value_set_static_string (value, + USERDATA_DEFAULT); + } else g_value_set_static_string (value, ""); @@ -741,31 +714,26 @@ glade_signal_model_get_value (GtkTreeModel* model, break; case GLADE_SIGNAL_COLUMN_NOT_DUMMY: g_value_set_boolean (value, - glade_signal_model_not_dummy_handler (sig_model, - iter)); - break; - case GLADE_SIGNAL_COLUMN_HAS_HANDLERS: - g_value_set_boolean (value, - glade_signal_model_has_handlers (sig_model, - iter)); + glade_signal_model_not_dummy_handler (sig_model, + iter)); break; case GLADE_SIGNAL_COLUMN_VERSION_WARNING: - { - gboolean warn = FALSE; - if (handler) - { - const gchar* warning = glade_signal_get_support_warning (handler); - warn = warning && strlen (warning); - } - g_value_set_boolean (value, warn); - } + { + gboolean warn = FALSE; + if (handler) + { + const gchar* warning = glade_signal_get_support_warning (handler); + warn = warning && strlen (warning); + } + g_value_set_boolean (value, warn); + } break; case GLADE_SIGNAL_COLUMN_TOOLTIP: if (handler) g_value_set_string (value, - glade_signal_get_support_warning (handler)); - else - g_value_set_static_string (value, NULL); + glade_signal_get_support_warning (handler)); + else + g_value_set_static_string (value, NULL); break; case GLADE_SIGNAL_COLUMN_SIGNAL: g_value_set_pointer (value, handler); @@ -776,70 +744,116 @@ glade_signal_model_get_value (GtkTreeModel* model, } static gboolean +glade_signal_model_iter_next_signal (GladeSignalModel* sig_model, + const gchar* widget, + GtkTreeIter* iter, + GList* signal) +{ + if (signal->next) + { + signal = signal->next; + GladeSignal* next_handler; + GPtrArray* next_handlers = + g_hash_table_lookup (sig_model->priv->signals, + glade_signal_class_get_name (signal->data)); + if (next_handlers && next_handlers->len) + { + next_handler = g_ptr_array_index (next_handlers, 0); + } + else + { + next_handler = + glade_signal_model_get_dummy_handler (sig_model, + signal->data); + } + glade_signal_model_create_signal_iter (sig_model, widget, + signal->data, next_handler, + iter); + g_list_free (signal); + return TRUE; + } + else + { + g_list_free (signal); + return FALSE; + } +} + + +static gboolean glade_signal_model_iter_next (GtkTreeModel* model, GtkTreeIter* iter) { const gchar* widget; GladeSignalClass* sig_class; GladeSignal* handler; - GtkTreeIter parent; + GtkTreeIter parent; GladeSignalModel* sig_model; - g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (GLADE_IS_SIGNAL_MODEL(model), FALSE); - widget = iter->user_data; - sig_class = iter->user_data2; - handler = iter->user_data3; + widget = iter->user_data; + sig_class = iter->user_data2; + handler = iter->user_data3; - sig_model = GLADE_SIGNAL_MODEL (model); + sig_model = GLADE_SIGNAL_MODEL (model); gtk_tree_model_iter_parent (model, &parent, iter); - if (handler) + if (handler && sig_class) { + GList* signals = glade_signal_model_create_signal_list (sig_model, + widget); + GList* signal = g_list_find (signals, sig_class); GPtrArray* handlers = g_hash_table_lookup (sig_model->priv->signals, glade_signal_class_get_name (sig_class)); GladeSignal* dummy = glade_signal_model_get_dummy_handler (sig_model, sig_class); if (handler == dummy) { - return FALSE; + return glade_signal_model_iter_next_signal (sig_model, widget, iter, signal); } else if (handlers) { gint new_index = g_ptr_array_find (handlers, handler) + 1; - if (new_index > 0) + if (new_index < handlers->len) + { + glade_signal_model_create_signal_iter (sig_model, widget, + sig_class, + g_ptr_array_index (handlers, new_index), + iter); + g_list_free (signals); + return TRUE; + } + else if (new_index == handlers->len) { - gtk_tree_model_iter_nth_child (model, iter, &parent, new_index); + glade_signal_model_create_signal_iter (sig_model, widget, + sig_class, + glade_signal_model_get_dummy_handler (sig_model, + sig_class), + iter); + g_list_free (signals); return TRUE; } + else + { + return glade_signal_model_iter_next_signal (sig_model, widget, iter, signal); + } } else { - glade_signal_model_create_handler_iter (sig_model, - widget, - sig_class, - dummy, - iter); - return TRUE; + g_list_free (signals); + return FALSE; } } - else if (sig_class) - { - GList* signals = glade_signal_model_create_signal_list (sig_model, - widget); - - gint new_index = g_list_index (signals, sig_class) + 1; - return gtk_tree_model_iter_nth_child (model, iter, &parent, new_index); - } else if (widget) { gint new_index = g_list_index (sig_model->priv->widgets, widget) + 1; - + return gtk_tree_model_iter_nth_child (model, iter, NULL, new_index); } iter->user_data = NULL; @@ -861,31 +875,32 @@ glade_signal_model_iter_n_children (GtkTreeModel* model, g_return_val_if_fail (iter != NULL, 0); g_return_val_if_fail (GLADE_IS_SIGNAL_MODEL(model), 0); - handler = iter->user_data3; - sig_model = GLADE_SIGNAL_MODEL (model); - sig_class = iter->user_data2; - widget = iter->user_data; - - if (handler) + handler = iter->user_data3; + sig_model = GLADE_SIGNAL_MODEL (model); + sig_class = iter->user_data2; + widget = iter->user_data; + + if (handler && sig_class) { return 0; } - else if (sig_class) - { - gint children = 0; - GPtrArray* handlers = g_hash_table_lookup (sig_model->priv->signals, - glade_signal_class_get_name (sig_class)); - if (handlers) - children = handlers->len; - return children + 1; - } else if (widget) { GList* signals = glade_signal_model_create_signal_list (sig_model, widget); - gint retval = g_list_length (signals); - + GList* signal; + gint retval = 0; + + for (signal = signals; signal != NULL; signal = g_list_next (signal)) + { + GPtrArray* handlers = g_hash_table_lookup (sig_model->priv->signals, + glade_signal_class_get_name (signal->data)); + if (handlers) + retval += handlers->len; + retval++; + } g_list_free (signals); + return retval; } g_assert_not_reached (); @@ -897,7 +912,7 @@ glade_signal_model_iter_has_child (GtkTreeModel* model, { g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (GLADE_IS_SIGNAL_MODEL(model), FALSE); - + return (glade_signal_model_iter_n_children (model, iter) != 0); } @@ -915,55 +930,56 @@ glade_signal_model_iter_nth_child (GtkTreeModel* model, g_return_val_if_fail (iter != NULL, 0); g_return_val_if_fail (GLADE_IS_SIGNAL_MODEL(model), 0); - handler = parent ? parent->user_data3 : NULL; - sig_model = GLADE_SIGNAL_MODEL (model); - sig_class = parent ? parent->user_data2 : NULL; - widget =parent ? parent->user_data : NULL; - + handler = parent ? parent->user_data3 : NULL; + sig_model = GLADE_SIGNAL_MODEL (model); + sig_class = parent ? parent->user_data2 : NULL; + widget = parent ? parent->user_data : NULL; + if (handler) { return FALSE; } - else if (sig_class) + else if (widget) { - GPtrArray* handlers = g_hash_table_lookup (sig_model->priv->signals, - glade_signal_class_get_name (sig_class)); - - if (handlers) + GList* signals = glade_signal_model_create_signal_list (sig_model, + widget); + GList* signal; + for (signal = signals; signal != NULL; signal = g_list_next (signal)) { - if (n < handlers->len) + GPtrArray* handlers = g_hash_table_lookup (sig_model->priv->signals, + glade_signal_class_get_name (signal->data)); + if (handlers) { - glade_signal_model_create_handler_iter (sig_model, widget, sig_class, - g_ptr_array_index (handlers, n), - iter); + if (n >= handlers->len) + n -= handlers->len; + else + { + glade_signal_model_create_signal_iter (sig_model, + widget, + signal->data, + g_ptr_array_index (handlers, n), + iter); + g_list_free (signals); + return TRUE; + } + } + if (n == 0) + { + GladeSignal* handler = + glade_signal_model_get_dummy_handler (sig_model, + signal->data); + glade_signal_model_create_signal_iter (sig_model, + widget, + signal->data, + handler, + iter); + g_list_free (signals); return TRUE; } - } - if (!handlers || handlers->len == n) - { - glade_signal_model_create_handler_iter (sig_model, widget, sig_class, - glade_signal_model_get_dummy_handler (sig_model, - sig_class), - iter); - return TRUE; + n--; } return FALSE; } - else if (widget) - { - GList* signals = glade_signal_model_create_signal_list (sig_model, - widget); - gboolean retval = FALSE; - if (g_list_length (signals) > n) - { - glade_signal_model_create_signal_iter (sig_model, widget, - g_list_nth_data (signals, n), - iter); - retval = TRUE; - } - g_list_free (signals); - return retval; - } else { if (g_list_length (sig_model->priv->widgets) > n) @@ -995,21 +1011,16 @@ glade_signal_model_iter_parent (GtkTreeModel* model, GladeSignalClass* sig_class; const gchar* widget; - g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (child != NULL, FALSE); g_return_val_if_fail (GLADE_IS_SIGNAL_MODEL(model), FALSE); - sig_model = GLADE_SIGNAL_MODEL (model); - handler = child->user_data3; - sig_class = child->user_data2; - widget = child->user_data; - - if (handler) - { - glade_signal_model_create_signal_iter (sig_model, widget, sig_class, iter); - return TRUE; - } - else if (sig_class) + sig_model = GLADE_SIGNAL_MODEL (model); + handler = child->user_data3; + sig_class = child->user_data2; + widget = child->user_data; + + if (handler && sig_class) { glade_signal_model_create_widget_iter (sig_model, widget, iter); return TRUE; @@ -1047,7 +1058,7 @@ glade_signal_model_row_draggable (GtkTreeDragSource* model, GLADE_SIGNAL_COLUMN_IS_HANDLER, &is_handler, GLADE_SIGNAL_COLUMN_NOT_DUMMY, ¬_dummy, -1); - + return (is_handler && not_dummy); } |