aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2001-05-22 12:04:23 +0800
committerChris Toshok <toshok@src.gnome.org>2001-05-22 12:04:23 +0800
commit07a5f9979fa997db9d2584cbaeb4673d7a16e230 (patch)
tree42c0fb468a5fc2447554c711c38ad35b0dba2fc9 /widgets
parent1564ba5ed23a9c3cc07a20598828960a781d6e0d (diff)
downloadgsoc2013-evolution-07a5f9979fa997db9d2584cbaeb4673d7a16e230.tar
gsoc2013-evolution-07a5f9979fa997db9d2584cbaeb4673d7a16e230.tar.gz
gsoc2013-evolution-07a5f9979fa997db9d2584cbaeb4673d7a16e230.tar.bz2
gsoc2013-evolution-07a5f9979fa997db9d2584cbaeb4673d7a16e230.tar.lz
gsoc2013-evolution-07a5f9979fa997db9d2584cbaeb4673d7a16e230.tar.xz
gsoc2013-evolution-07a5f9979fa997db9d2584cbaeb4673d7a16e230.tar.zst
gsoc2013-evolution-07a5f9979fa997db9d2584cbaeb4673d7a16e230.zip
make the view menuitems radio items of the same group, and allocate the
2001-05-21 Chris Toshok <toshok@ximian.com> * menus/gal-view-menus.c (build_menus): make the view menuitems radio items of the same group, and allocate the closure here. (free_verbs): only need to free the one DefineViews verb here. (closure_free): new function - EListFreeFunc for our listenerClosure list. (remove_listeners): new function, free our listener list. (gvm_destroy): call remove_listeners. (gvm_init): init listenerClosures list. (toggled_cb): callback for radio items. (build_verbs): strip out almost all the code since there's only 1 verb now. (build_stuff): call remove_listeners. svn path=/trunk/; revision=9916
Diffstat (limited to 'widgets')
-rw-r--r--widgets/ChangeLog15
-rw-r--r--widgets/menus/gal-view-menus.c122
2 files changed, 85 insertions, 52 deletions
diff --git a/widgets/ChangeLog b/widgets/ChangeLog
index f80719b0cc..b9ada966b1 100644
--- a/widgets/ChangeLog
+++ b/widgets/ChangeLog
@@ -1,3 +1,18 @@
+2001-05-21 Chris Toshok <toshok@ximian.com>
+
+ * menus/gal-view-menus.c (build_menus): make the view menuitems
+ radio items of the same group, and allocate the closure here.
+ (free_verbs): only need to free the one DefineViews verb here.
+ (closure_free): new function - EListFreeFunc for our
+ listenerClosure list.
+ (remove_listeners): new function, free our listener list.
+ (gvm_destroy): call remove_listeners.
+ (gvm_init): init listenerClosures list.
+ (toggled_cb): callback for radio items.
+ (build_verbs): strip out almost all the code since there's only 1
+ verb now.
+ (build_stuff): call remove_listeners.
+
2001-05-08 Gediminas Paulauskas <menesis@delfi.lt>
* misc/e-search-bar.c (add_dropdown), (set_option): first try to
diff --git a/widgets/menus/gal-view-menus.c b/widgets/menus/gal-view-menus.c
index ac99ae1793..89eb38022a 100644
--- a/widgets/menus/gal-view-menus.c
+++ b/widgets/menus/gal-view-menus.c
@@ -21,14 +21,22 @@
#include <gal/util/e-xml-utils.h>
#include <gal/menus/gal-define-views-dialog.h>
#include <gal/widgets/e-unicode.h>
+#include <e-util/e-list.h>
struct _GalViewMenusPrivate {
GalViewCollection *collection;
int collection_changed_id;
BonoboUIVerb *verbs;
BonoboUIComponent *component;
+ EList *listenerClosures;
};
+typedef struct {
+ GalViewCollection *collection;
+ GalView *view;
+ const char *id;
+} ListenerClosure;
+
#define PARENT_TYPE (gtk_object_get_type())
static GtkObjectClass *gvm_parent_class;
@@ -37,32 +45,37 @@ static void collection_changed (GalViewCollection *collection,
#define d(x)
-typedef struct {
- GalViewCollection *collection;
- GalView *view;
-} CollectionAndView;
-
static void
free_verbs (GalViewMenus *gvm)
{
- BonoboUIVerb *verbs;
if (gvm->priv->verbs) {
- for (verbs = gvm->priv->verbs + 1; verbs->cname; verbs++) {
- CollectionAndView *cnv;
+ g_free(gvm->priv->verbs->cname);
+ g_free(gvm->priv->verbs);
+ }
+ gvm->priv->verbs = NULL;
+}
+
+static void
+closure_free (void *data, void *user_data)
+{
+ ListenerClosure *closure = data;
+ GalViewMenus *gvm = user_data;
- if (gvm->priv->component)
- bonobo_ui_component_remove_verb(gvm->priv->component, verbs->cname);
+ gtk_object_ref(GTK_OBJECT(closure->view));
+ gtk_object_ref(GTK_OBJECT(closure->collection));
- cnv = verbs->user_data;
- g_free(verbs->cname);
+ bonobo_ui_component_remove_listener (gvm->priv->component, closure->id);
- gtk_object_unref(GTK_OBJECT(cnv->collection));
- gtk_object_unref(GTK_OBJECT(cnv->view));
- g_free(cnv);
- }
- g_free(gvm->priv->verbs);
+ g_free (closure);
+}
+
+static void
+remove_listeners (GalViewMenus *gvm)
+{
+ if (gvm->priv->listenerClosures) {
+ gtk_object_unref (GTK_OBJECT(gvm->priv->listenerClosures));
}
- gvm->priv->verbs = NULL;
+ gvm->priv->listenerClosures = NULL;
}
static void
@@ -83,6 +96,7 @@ gvm_destroy (GtkObject *object)
gtk_object_unref(GTK_OBJECT(gvm->priv->collection));
free_verbs(gvm);
remove_xml(gvm);
+ remove_listeners(gvm);
g_free(gvm->priv);
gvm->priv = NULL;
@@ -105,6 +119,7 @@ gvm_init (GalViewMenus *gvm)
gvm->priv->collection_changed_id = 0;
gvm->priv->verbs = NULL;
gvm->priv->component = NULL;
+ gvm->priv->listenerClosures = NULL;
}
E_MAKE_TYPE(gal_view_menus, "GalViewMenus", GalViewMenus, gvm_class_init, gvm_init, PARENT_TYPE);
@@ -152,6 +167,22 @@ define_views(BonoboUIComponent *component,
gtk_widget_show(dialog);
}
+static void
+toggled_cb (BonoboUIComponent *component,
+ const char *path,
+ Bonobo_UIComponent_EventType type,
+ const char *state,
+ gpointer user_data)
+{
+ ListenerClosure *closure = user_data;
+
+ /* do nothing on state change to untoggled */
+ if (!strcmp (state, "0"))
+ return;
+
+ gal_view_collection_display_view(closure->collection, closure->view);
+}
+
static char *
build_menus(GalViewMenus *menus)
{
@@ -176,12 +207,19 @@ build_menus(GalViewMenus *menus)
bonobo_ui_node_set_attr(submenu, "_label", N_("_Current View"));
length = gal_view_collection_get_count(collection);
+
+ menus->priv->listenerClosures = e_list_new (NULL, closure_free, menus);
+
for (i = 0; i < length; i++) {
- char *verb;
char *label;
GalViewCollectionItem *item = gal_view_collection_get_view_item(collection, i);
+ ListenerClosure *closure;
+
menuitem = bonobo_ui_node_new_child(submenu, "menuitem");
bonobo_ui_node_set_attr(menuitem, "name", item->id);
+ bonobo_ui_node_set_attr(menuitem, "id", item->id);
+ bonobo_ui_node_set_attr(menuitem, "group", "GalViewMenus");
+ bonobo_ui_node_set_attr(menuitem, "type", "radio");
/* bonobo displays this string so it must be in locale */
label = e_utf8_to_locale_string(item->title);
@@ -190,9 +228,17 @@ build_menus(GalViewMenus *menus)
bonobo_ui_node_set_attr(menuitem, "_label", label);
g_free(label);
- verb = g_strdup_printf("DefineViews:%s", item->id);
- bonobo_ui_node_set_attr(menuitem, "verb", verb);
- g_free(verb);
+ closure = g_new (ListenerClosure, 1);
+ closure->collection = collection;
+ closure->view = item->view;
+ closure->id = item->id;
+
+ gtk_object_ref(GTK_OBJECT(closure->view));
+ gtk_object_ref(GTK_OBJECT(closure->collection));
+
+ bonobo_ui_component_add_listener (menus->priv->component, item->id, toggled_cb, closure);
+
+ e_list_append (menus->priv->listenerClosures, closure);
}
menuitem = bonobo_ui_node_new_child(submenu, "separator");
@@ -213,23 +259,11 @@ build_menus(GalViewMenus *menus)
return xml;
}
-static void
-show_view(BonoboUIComponent *component,
- gpointer user_data,
- const char *cname)
-{
- CollectionAndView *cnv = user_data;
- gal_view_collection_display_view(cnv->collection, cnv->view);
-}
-
static BonoboUIVerb *
build_verbs (GalViewMenus *menus)
{
- GalViewCollection *collection = menus->priv->collection;
- int count = gal_view_collection_get_count(collection);
- BonoboUIVerb *verbs = g_new(BonoboUIVerb, count + 2);
+ BonoboUIVerb *verbs = g_new(BonoboUIVerb, 2);
BonoboUIVerb *verb;
- int i;
verb = verbs;
verb->cname = g_strdup("DefineViews");
@@ -237,23 +271,6 @@ build_verbs (GalViewMenus *menus)
verb->user_data = menus;
verb->dummy = NULL;
verb ++;
- for (i = 0; i < count; i++) {
- CollectionAndView *cnv;
- GalViewCollectionItem *item = gal_view_collection_get_view_item(collection, i);
-
- cnv = g_new(CollectionAndView, 1);
- cnv->view = item->view;
- cnv->collection = collection;
-
- gtk_object_ref(GTK_OBJECT(cnv->view));
- gtk_object_ref(GTK_OBJECT(cnv->collection));
-
- verb->cname = g_strdup_printf("DefineViews:%s", item->id);
- verb->cb = show_view;
- verb->user_data = cnv;
- verb->dummy = NULL;
- verb++;
- }
verb->cname = NULL;
verb->cb = NULL;
@@ -271,6 +288,7 @@ build_stuff (GalViewMenus *gvm,
char *xml;
remove_xml(gvm);
+ remove_listeners(gvm);
xml = build_menus(gvm);
bonobo_ui_component_set_translate(gvm->priv->component, "/", xml, ev);
g_free(xml);