diff options
Diffstat (limited to 'filter/filter-filter.c')
-rw-r--r-- | filter/filter-filter.c | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/filter/filter-filter.c b/filter/filter-filter.c index c939fa9b2c..9625b5cd59 100644 --- a/filter/filter-filter.c +++ b/filter/filter-filter.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 2000 Helix Code Inc. + * Copyright (C) 2000-2001 Ximian Inc. * - * Authors: Not Zed <notzed@lostzed.mmc.com.au> - * Jeffrey Stedfast <fejj@helixcode.com> + * Authors: Not Zed <notzed@ximian.com> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -298,6 +298,8 @@ option_activate (GtkMenuItem *item, struct _part_data *data) data->partwidget = filter_part_get_widget (newpart); if (data->partwidget) gtk_box_pack_start (GTK_BOX (data->container), data->partwidget, FALSE, FALSE, 0); + + gtk_object_set_data (GTK_OBJECT (data->container), "part", newpart); } static GtkWidget * @@ -361,49 +363,64 @@ struct _rule_data { static void less_parts (GtkWidget *button, struct _rule_data *data) { - GList *l; FilterPart *part; - GtkWidget *w; + GtkWidget *rule; + GList *l; l = ((FilterFilter *)data->fr)->actions; if (g_list_length (l) < 2) return; - /* remove the last one from the list */ - l = g_list_last (l); - part = l->data; + rule = gtk_object_get_data (GTK_OBJECT (button), "rule"); + part = gtk_object_get_data (GTK_OBJECT (rule), "part"); + + /* remove the part from the list */ filter_filter_remove_action ((FilterFilter *)data->fr, part); gtk_object_unref (GTK_OBJECT (part)); /* and from the display */ - l = g_list_last (GTK_BOX (data->parts)->children); - w = ((GtkBoxChild *) l->data)->widget; - gtk_container_remove (GTK_CONTAINER (data->parts), w); + gtk_container_remove (GTK_CONTAINER (data->parts), rule); + gtk_container_remove (GTK_CONTAINER (data->parts), button); +} + +static void +attach_rule (GtkWidget *rule, struct _rule_data *data, FilterPart *part, int row) +{ + GtkWidget *remove; + GtkWidget *pixmap; - /* if there's only 1 action, we can't remove anymore so set insensitive */ - if (g_list_length (((FilterFilter *)data->fr)->actions) <= 1) - gtk_widget_set_sensitive (button, FALSE); + gtk_table_attach (GTK_TABLE (data->parts), rule, 0, 1, row, row + 1, + GTK_EXPAND | GTK_FILL, 0, 0, 0); + + pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_REMOVE); + remove = gnome_pixmap_button (pixmap, _("Remove")); + gtk_object_set_data (GTK_OBJECT (remove), "rule", rule); + gtk_object_set_data (GTK_OBJECT (rule), "part", part); + /*gtk_button_set_relief (GTK_BUTTON (remove), GTK_RELIEF_NONE);*/ + gtk_signal_connect (GTK_OBJECT (remove), "clicked", less_parts, data); + gtk_table_attach (GTK_TABLE (data->parts), remove, 1, 2, row, row + 1, + 0, 0, 0, 0); + gtk_widget_show (remove); } static void more_parts (GtkWidget *button, struct _rule_data *data) { FilterPart *new; - GtkWidget *w; /* create a new rule entry, use the first type of rule */ new = filter_context_next_action ((FilterContext *)data->f, NULL); if (new) { + GtkWidget *w; + guint16 rows; + new = filter_part_clone (new); filter_filter_add_action ((FilterFilter *)data->fr, new); w = get_rule_part_widget (data->f, new, data->fr); - gtk_box_pack_start (GTK_BOX (data->parts), w, FALSE, FALSE, 0); - } - - /* set the "Remove action" button sensitive */ - if (g_list_length (((FilterFilter *)data->fr)->actions) > 1) { - w = gtk_object_get_data (GTK_OBJECT (button), "remove"); - gtk_widget_set_sensitive (w, TRUE); + + rows = GTK_TABLE (data->parts)->nrows; + gtk_table_resize (GTK_TABLE (data->parts), rows + 1, 2); + attach_rule (w, data, new, rows); } } @@ -413,7 +430,7 @@ get_widget (FilterRule *fr, struct _RuleContext *f) GtkWidget *widget; GtkWidget *parts, *inframe; GtkWidget *hbox; - GtkWidget *add, *remove, *pixmap; + GtkWidget *add, *pixmap; GtkWidget *w; GtkWidget *frame; GtkWidget *scrolledwindow; @@ -422,6 +439,7 @@ get_widget (FilterRule *fr, struct _RuleContext *f) FilterPart *part; struct _rule_data *data; FilterFilter *ff = (FilterFilter *)fr; + gint rows, i = 0; widget = ((FilterRuleClass *)(parent_class))->get_widget (fr, f); @@ -430,7 +448,8 @@ get_widget (FilterRule *fr, struct _RuleContext *f) inframe = gtk_vbox_new (FALSE, 3); gtk_container_add (GTK_CONTAINER (frame), inframe); - parts = gtk_vbox_new (FALSE, 3); + rows = g_list_length (ff->actions); + parts = gtk_table_new (rows, 2, FALSE); data = g_malloc0 (sizeof (*data)); data->f = (FilterContext *)f; data->fr = fr; @@ -444,17 +463,6 @@ get_widget (FilterRule *fr, struct _RuleContext *f) gtk_signal_connect (GTK_OBJECT (add), "clicked", more_parts, data); gtk_box_pack_start (GTK_BOX (hbox), add, FALSE, FALSE, 3); - pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_REMOVE); - remove = gnome_pixmap_button (pixmap, _("Remove action")); - gtk_object_set_data (GTK_OBJECT (add), "remove", remove); - gtk_button_set_relief (GTK_BUTTON (remove), GTK_RELIEF_NONE); - gtk_signal_connect (GTK_OBJECT (remove), "clicked", less_parts, data); - gtk_box_pack_start (GTK_BOX (hbox), remove, FALSE, FALSE, 3); - - /* if we only have 1 action, then we can't remove any more so disable this */ - if (g_list_length (ff->actions) <= 1) - gtk_widget_set_sensitive (remove, FALSE); - gtk_box_pack_start (GTK_BOX (inframe), hbox, FALSE, FALSE, 3); l = ff->actions; @@ -462,7 +470,7 @@ get_widget (FilterRule *fr, struct _RuleContext *f) part = l->data; d(printf ("adding action %s\n", part->title)); w = get_rule_part_widget ((FilterContext *)f, part, fr); - gtk_box_pack_start (GTK_BOX (parts), w, FALSE, FALSE, 3); + attach_rule (w, data, part, i++); l = g_list_next (l); } |