diff options
-rw-r--r-- | libindicator/indicator-object.c | 67 | ||||
-rw-r--r-- | tools/indicator-loader.c | 59 |
2 files changed, 39 insertions, 87 deletions
diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index ca821af..1119657 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -113,9 +113,7 @@ static void get_property (GObject*, guint prop_id, GValue*, GParamSpec* ); /* entries' visibility */ static GList * get_entries_default (IndicatorObject*); static GList * get_all_entries (IndicatorObject*); -static void entry_being_removed_default (IndicatorObject*, IndicatorObjectEntry*); static void indicator_object_entry_being_removed (IndicatorObject*, IndicatorObjectEntry*); -static void entry_was_added_default (IndicatorObject*, IndicatorObjectEntry*); static void indicator_object_entry_was_added (IndicatorObject*, IndicatorObjectEntry*); static IndicatorObjectEntryPrivate * entry_get_private (IndicatorObject*, IndicatorObjectEntry*); @@ -141,8 +139,8 @@ indicator_object_class_init (IndicatorObjectClass *klass) klass->get_accessible_desc = NULL; klass->get_entries = get_entries_default; klass->get_location = NULL; - klass->entry_being_removed = entry_being_removed_default; - klass->entry_was_added = entry_was_added_default; + klass->entry_being_removed = NULL; + klass->entry_was_added = NULL; klass->entry_activate = NULL; klass->entry_activate_window = NULL; @@ -935,63 +933,4 @@ set_property (GObject * object, G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } -} - -/*** -**** -***/ - -/* Cloaked entries are ones which are hidden but may be re-added later. - They are reffed + unparented so that they'll survive even if the - rest of the widgetry is destroyed */ -#define CLOAKED_KEY "entry-is-cloaked" - -static void -decloak_widget (gpointer w) -{ - if (w != NULL) { - GObject * o = G_OBJECT(w); - if (g_object_steal_data (o, CLOAKED_KEY) != NULL) { - g_object_unref (o); - } - } -} - -static void -entry_was_added_default (IndicatorObject * io, IndicatorObjectEntry * entry) -{ - decloak_widget (entry->image); - decloak_widget (entry->label); - decloak_widget (entry->menu); -} - -static void -cloak_widget (gpointer w) -{ - if (w != NULL) { - GtkWidget * parent; - - /* tag this object as cloaked */ - GObject * o = G_OBJECT(w); - g_object_ref (o); - g_object_set_data (o, CLOAKED_KEY, GINT_TO_POINTER(1)); - - /* remove it from its surrounding widgetry */ - if(GTK_IS_MENU(w)) { - if (gtk_menu_get_attach_widget (GTK_MENU(w)) != NULL) { - gtk_menu_detach (GTK_MENU(w)); - } - } - else if((parent = gtk_widget_get_parent(w))) { - gtk_container_remove(GTK_CONTAINER(parent), w); - } - } -} - -static void -entry_being_removed_default (IndicatorObject * io, IndicatorObjectEntry * entry) -{ - cloak_widget (entry->image); - cloak_widget (entry->label); - cloak_widget (entry->menu); -} +}
\ No newline at end of file diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index 10952dc..560fc45 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -25,6 +25,8 @@ License along with this library. If not, see #include <gtk/gtk.h> #include <libindicator/indicator-object.h> +static GHashTable * entry_to_menuitem = NULL; + #define ENTRY_DATA_NAME "indicator-custom-entry-data" static void @@ -40,20 +42,18 @@ activate_entry (GtkWidget * widget, gpointer user_data) return; } -static void -entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) +static GtkWidget* +create_menu_item (IndicatorObjectEntry * entry) { - g_debug("Signal: Entry Added"); + GtkWidget * hbox; + GtkWidget * menuitem; - if (entry->parent_object == NULL) { - g_warning("Entry '%p' does not have a parent object", entry); - } + menuitem = gtk_menu_item_new(); - GtkWidget * menuitem = gtk_menu_item_new(); #if GTK_CHECK_VERSION(3,0,0) - GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3); + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3); #else - GtkWidget * hbox = gtk_hbox_new(FALSE, 3); + hbox = gtk_hbox_new(FALSE, 3); #endif if (entry->image != NULL) { @@ -69,26 +69,34 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu)); } - g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(activate_entry), io); - - gtk_menu_shell_append(GTK_MENU_SHELL(user_data), menuitem); - gtk_widget_show(menuitem); - - g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry); - - return; + return menuitem; } static void -entry_removed_cb (GtkWidget * widget, gpointer userdata) +entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) { - gpointer data = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME); + GtkWidget * menuitem; + + g_debug("Signal: Entry Added"); - if (data != userdata) { - return; + if (entry->parent_object == NULL) { + g_warning("Entry '%p' does not have a parent object", entry); } - gtk_widget_destroy(widget); + menuitem = g_hash_table_lookup (entry_to_menuitem, entry); + if (menuitem == NULL) { + g_debug ("This is the first time this entry's been added -- creating a new menuitem for it"); + menuitem = create_menu_item (entry); + g_hash_table_insert (entry_to_menuitem, entry, menuitem); + + g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry); + g_signal_connect (G_OBJECT(menuitem), "activate", G_CALLBACK(activate_entry), io); + + gtk_menu_shell_append (GTK_MENU_SHELL(user_data), menuitem); + + } + gtk_widget_show (menuitem); + return; } @@ -97,7 +105,9 @@ entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user { g_debug("Signal: Entry Removed"); - gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry); + GtkWidget * menuitem = g_hash_table_lookup (entry_to_menuitem, entry); + if (menuitem != NULL) + gtk_widget_hide (menuitem); return; } @@ -162,6 +172,8 @@ main (int argc, char ** argv) gtk_init(&argc, &argv); + entry_to_menuitem = g_hash_table_new (g_direct_hash, g_direct_equal); + if (argc != 2) { g_error("Need filename"); return 1; @@ -183,5 +195,6 @@ main (int argc, char ** argv) gtk_main(); + g_hash_table_destroy (entry_to_menuitem); return 0; } |