ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #01655
[Merge] lp:~ted/indicator-appmenu/glist-love into lp:indicator-appmenu
Ted Gould has proposed merging lp:~ted/indicator-appmenu/glist-love into lp:indicator-appmenu.
Requested reviews:
Indicator Applet Developers (indicator-applet-developers)
Reshuffle the switch function to be flatter.
--
https://code.launchpad.net/~ted/indicator-appmenu/glist-love/+merge/27955
Your team ayatana-commits is subscribed to branch lp:indicator-appmenu.
=== modified file 'src/indicator-appmenu.c'
--- src/indicator-appmenu.c 2010-06-17 04:49:02 +0000
+++ src/indicator-appmenu.c 2010-06-18 18:48:31 +0000
@@ -507,6 +507,8 @@
static void
switch_default_app (IndicatorAppmenu * iapp, WindowMenus * newdef, BamfWindow * active_window)
{
+ GList * entry_head, * entries;
+
if (iapp->default_app == newdef && iapp->default_app != NULL) {
/* We've got an app with menus and it hasn't changed. */
@@ -521,72 +523,38 @@
return;
}
- GList * entries;
-
- /* No matter what, we want to remove the old application menu */
- if (iapp->default_app != NULL) {
- for (entries = window_menus_get_entries(iapp->default_app); entries != NULL; entries = g_list_next(entries)) {
- IndicatorObjectEntry * entry = (IndicatorObjectEntry *)entries->data;
-
- if (entry->label != NULL) {
- gtk_widget_hide(GTK_WIDGET(entry->label));
- }
-
- if (entry->menu != NULL) {
- gtk_menu_detach(entry->menu);
- }
-
- g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, entries->data, TRUE);
- }
+ entry_head = indicator_object_get_entries(INDICATOR_OBJECT(iapp));
+
+ for (entries = entry_head; entries != NULL; entries = g_list_next(entries)) {
+ IndicatorObjectEntry * entry = (IndicatorObjectEntry *)entries->data;
+
+ if (entry->label != NULL) {
+ gtk_widget_hide(GTK_WIDGET(entry->label));
+ }
+
+ if (entry->menu != NULL) {
+ gtk_menu_detach(entry->menu);
+ }
+
+ g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, entries->data, TRUE);
+ }
+
+ g_list_free(entry_head);
- /* Disconnect signals */
- if (iapp->sig_entry_added != 0) {
- g_signal_handler_disconnect(G_OBJECT(iapp->default_app), iapp->sig_entry_added);
- iapp->sig_entry_added = 0;
- }
- if (iapp->sig_entry_removed != 0) {
- g_signal_handler_disconnect(G_OBJECT(iapp->default_app), iapp->sig_entry_removed);
- iapp->sig_entry_removed = 0;
- }
-
- iapp->default_app = NULL;
- } else {
- /* If the default app was previously NULL, then we probably had other
- menus up. Let's remove those. */
-
- if (iapp->active_window == NULL) {
- /* No active window means that the desktop menu items were
- the ones being shown. */
- int i;
- for (i = 0; i < iapp->desktop_menus->len; i++) {
- if (g_array_index(iapp->desktop_menus, IndicatorObjectEntry, i).label != NULL) {
- gtk_widget_hide(GTK_WIDGET(g_array_index(iapp->desktop_menus, IndicatorObjectEntry, i).label));
- }
- if (g_array_index(iapp->desktop_menus, IndicatorObjectEntry, i).menu != NULL) {
- gtk_menu_detach(g_array_index(iapp->desktop_menus, IndicatorObjectEntry, i).menu);
- }
- g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, &g_array_index(iapp->desktop_menus, IndicatorObjectEntry, i), TRUE);
- }
- } else {
- /* We had an active window so we must have had the window
- specific menu items shown. */
- int i;
- for (i = 0; i < iapp->window_menus->len; i++) {
- if (g_array_index(iapp->window_menus, IndicatorObjectEntry, i).label != NULL) {
- gtk_widget_hide(GTK_WIDGET(g_array_index(iapp->window_menus, IndicatorObjectEntry, i).label));
- }
- if (g_array_index(iapp->window_menus, IndicatorObjectEntry, i).menu != NULL) {
- gtk_menu_detach(g_array_index(iapp->window_menus, IndicatorObjectEntry, i).menu);
- }
- g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, &g_array_index(iapp->window_menus, IndicatorObjectEntry, i), TRUE);
- }
- }
- }
-
- /* Through either the if or the setting, we know at this point that iapp->default_app
- is NULL and all the menus from it have been removed. */
-
- /* Update the active window pointer */
+ /* Disconnect signals */
+ if (iapp->sig_entry_added != 0) {
+ g_signal_handler_disconnect(G_OBJECT(iapp->default_app), iapp->sig_entry_added);
+ iapp->sig_entry_added = 0;
+ }
+ if (iapp->sig_entry_removed != 0) {
+ g_signal_handler_disconnect(G_OBJECT(iapp->default_app), iapp->sig_entry_removed);
+ iapp->sig_entry_removed = 0;
+ }
+
+ /* Default App is NULL, let's see if it needs replacement */
+ iapp->default_app = NULL;
+
+ /* Update the active window pointer -- may be NULL */
iapp->active_window = active_window;
/* If we're putting up a new window, let's do that now. */
@@ -603,41 +571,24 @@
WINDOW_MENUS_SIGNAL_ENTRY_REMOVED,
G_CALLBACK(window_entry_removed),
iapp);
-
- /* Add new */
- for (entries = window_menus_get_entries(iapp->default_app); entries != NULL; entries = g_list_next(entries)) {
- IndicatorObjectEntry * entry = (IndicatorObjectEntry *)entries->data;
-
- if (entry->label != NULL) {
- gtk_widget_show(GTK_WIDGET(entry->label));
- }
-
- g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, entries->data, TRUE);
- }
- } else {
- /* No new application here we need to put up something. No blankness. */
- if (iapp->active_window == NULL) {
- /* No active window means that the desktop menu items were
- the ones being shown. */
- int i;
- for (i = 0; i < iapp->desktop_menus->len; i++) {
- if (g_array_index(iapp->desktop_menus, IndicatorObjectEntry, i).label != NULL) {
- gtk_widget_show(GTK_WIDGET(g_array_index(iapp->desktop_menus, IndicatorObjectEntry, i).label));
- }
- g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, &g_array_index(iapp->desktop_menus, IndicatorObjectEntry, i), TRUE);
- }
- } else {
- /* We had an active window so we must have had the window
- specific menu items shown. */
- int i;
- for (i = 0; i < iapp->window_menus->len; i++) {
- if (g_array_index(iapp->window_menus, IndicatorObjectEntry, i).label != NULL) {
- gtk_widget_show(GTK_WIDGET(g_array_index(iapp->window_menus, IndicatorObjectEntry, i).label));
- }
- g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, &g_array_index(iapp->window_menus, IndicatorObjectEntry, i), TRUE);
- }
- }
- }
+ }
+
+ /* Get our new list of entries. Now we can go ahead and signal
+ that each of them has been added */
+
+ entry_head = indicator_object_get_entries(INDICATOR_OBJECT(iapp));
+
+ for (entries = entry_head; entries != NULL; entries = g_list_next(entries)) {
+ IndicatorObjectEntry * entry = (IndicatorObjectEntry *)entries->data;
+
+ if (entry->label != NULL) {
+ gtk_widget_show(GTK_WIDGET(entry->label));
+ }
+
+ g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, entries->data, TRUE);
+ }
+
+ g_list_free(entry_head);
return;
}
Follow ups