aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/ChangeLog5
-rw-r--r--widgets/misc/e-filter-bar.c362
2 files changed, 179 insertions, 188 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog
index 9d5b0ff4ab..0af8f2bb42 100644
--- a/widgets/misc/ChangeLog
+++ b/widgets/misc/ChangeLog
@@ -1,3 +1,8 @@
+2001-07-18 Jeffrey Stedfast <fejj@ximian.com>
+
+ * e-filter-bar.c (rule_editor_destroyed): When the dialog gets
+ closed, always make sure the entry widget becomes sensitive again.
+
2001-07-16 Federico Mena Quintero <federico@ximian.com>
Fixes bug #2901.
diff --git a/widgets/misc/e-filter-bar.c b/widgets/misc/e-filter-bar.c
index 6150e8cc2f..b9115590f7 100644
--- a/widgets/misc/e-filter-bar.c
+++ b/widgets/misc/e-filter-bar.c
@@ -57,36 +57,40 @@ enum {
/* Callbacks. */
/* rule editor thingy */
-static void rule_editor_destroyed(GtkWidget *w, EFilterBar *efb)
+static void
+rule_editor_destroyed (GtkWidget *w, EFilterBar *efb)
{
efb->save_dialogue = NULL;
- e_search_bar_set_menu_sensitive((ESearchBar *)efb, E_FILTERBAR_SAVE_ID, TRUE);
+ e_search_bar_set_menu_sensitive (E_SEARCH_BAR (efb), E_FILTERBAR_SAVE_ID, TRUE);
+ gtk_widget_set_sensitive (E_SEARCH_BAR (efb)->entry, TRUE);
}
/* FIXME: need to update the popup menu to match any edited rules, sigh */
-static void full_rule_editor_clicked(GtkWidget *w, int button, void *data)
+static void
+full_rule_editor_clicked (GtkWidget *dialog, int button, void *data)
{
EFilterBar *efb = data;
-
+
switch (button) {
case 0:
- rule_context_save(efb->context, efb->userrules);
+ rule_context_save (efb->context, efb->userrules);
case 1:
default:
- gnome_dialog_close((GnomeDialog *)w);
+ gnome_dialog_close (GNOME_DIALOG (dialog));
case -1:
}
}
-static void rule_editor_clicked(GtkWidget *w, int button, void *data)
+static void
+rule_editor_clicked (GtkWidget *dialog, int button, void *data)
{
EFilterBar *efb = data;
ESearchBarItem item;
FilterRule *rule;
-
- switch(button) {
+
+ switch (button) {
case 0:
- rule = gtk_object_get_data((GtkObject *)w, "rule");
+ rule = gtk_object_get_data (GTK_OBJECT (dialog), "rule");
if (rule) {
if (!filter_rule_validate (rule))
return;
@@ -94,38 +98,39 @@ static void rule_editor_clicked(GtkWidget *w, int button, void *data)
item.text = rule->name;
item.id = efb->menu_base + efb->menu_rules->len;
- g_ptr_array_add(efb->menu_rules, rule);
-
- rule_context_add_rule(efb->context, rule);
+ g_ptr_array_add (efb->menu_rules, rule);
+
+ rule_context_add_rule (efb->context, rule);
/* FIXME: check return */
- rule_context_save(efb->context, efb->userrules);
- e_search_bar_add_menu((ESearchBar *)efb, &item);
+ rule_context_save (efb->context, efb->userrules);
+ e_search_bar_add_menu ((ESearchBar *)efb, &item);
}
case 1:
- gnome_dialog_close((GnomeDialog *)w);
+ gnome_dialog_close (GNOME_DIALOG (dialog));
break;
case -1:
}
}
-static void rule_advanced_clicked(GtkWidget *w, int button, void *data)
+static void
+rule_advanced_clicked (GtkWidget *dialog, int button, void *data)
{
EFilterBar *efb = data;
FilterRule *rule;
- switch(button) {
+ switch (button) {
case 0: /* 'ok' */
case 1:
- rule = gtk_object_get_data((GtkObject *)w, "rule");
+ rule = gtk_object_get_data (GTK_OBJECT (dialog), "rule");
if (rule) {
efb->current_query = rule;
- gtk_object_ref((GtkObject *)rule);
- gtk_signal_emit_by_name((GtkObject *)efb, "query_changed");
+ gtk_object_ref (GTK_OBJECT (rule));
+ gtk_signal_emit_by_name (GTK_OBJECT (efb), "query_changed");
}
if (button == 1)
- rule_editor_clicked(w, 0, data);
+ rule_editor_clicked (dialog, 0, data);
case 2:
- gnome_dialog_close((GnomeDialog *)w);
+ gnome_dialog_close (GNOME_DIALOG (dialog));
break;
case -1:
}
@@ -135,79 +140,77 @@ static void
menubar_activated (ESearchBar *esb, int id, void *data)
{
EFilterBar *efb = (EFilterBar *)esb;
-
- switch(id) {
+
+ switch (id) {
case E_FILTERBAR_RESET_ID:
d(printf("Reset menu\n"));
efb->current_query = NULL;
- gtk_object_set((GtkObject *)esb, "option_choice", efb->option_base, NULL);
- gtk_object_set((GtkObject *)esb, "text", NULL, NULL);
- gtk_widget_set_sensitive(esb->entry, TRUE);
+ gtk_object_set (GTK_OBJECT (esb), "option_choice", efb->option_base, NULL);
+ gtk_object_set (GTK_OBJECT (esb), "text", NULL, NULL);
+ gtk_widget_set_sensitive (esb->entry, TRUE);
break;
case E_FILTERBAR_EDIT_ID:
if (!efb->save_dialogue) {
GnomeDialog *gd;
-
- gd = (GnomeDialog *)rule_editor_new(efb->context, FILTER_SOURCE_INCOMING);
- gtk_signal_connect((GtkObject *)gd, "clicked", full_rule_editor_clicked, efb);
- gtk_signal_connect((GtkObject *)gd, "destroy", rule_editor_destroyed, efb);
- gtk_widget_show((GtkWidget *)gd);
+
+ gd = (GnomeDialog *) rule_editor_new (efb->context, FILTER_SOURCE_INCOMING);
+ gtk_signal_connect (GTK_OBJECT (gd), "clicked", full_rule_editor_clicked, efb);
+ gtk_signal_connect (GTK_OBJECT (gd), "destroy", rule_editor_destroyed, efb);
+ gtk_widget_show (GTK_WIDGET (gd));
}
break;
case E_FILTERBAR_SAVE_ID:
if (efb->current_query && !efb->save_dialogue) {
GtkWidget *w;
- GnomeDialog *gd;
+ GtkWidget *gd;
FilterRule *rule;
-
- rule = filter_rule_clone(efb->current_query, efb->context);
-
- w = filter_rule_get_widget(rule, efb->context);
- filter_rule_set_source(rule, FILTER_SOURCE_INCOMING);
- gd = (GnomeDialog *)gnome_dialog_new(_("Save Search"),
- GNOME_STOCK_BUTTON_OK,
- GNOME_STOCK_BUTTON_CANCEL,
- NULL);
- efb->save_dialogue = (GtkWidget *)gd;
- gnome_dialog_set_default (gd, 0);
-
- gtk_window_set_policy(GTK_WINDOW(gd), FALSE, TRUE, FALSE);
-
- gtk_box_pack_start((GtkBox *)gd->vbox, w, TRUE, TRUE, 0);
- gtk_widget_show((GtkWidget *)gd);
- gtk_object_ref((GtkObject *)rule);
- gtk_object_set_data_full((GtkObject *)gd, "rule", rule, (GtkDestroyNotify)gtk_object_unref);
- gtk_signal_connect((GtkObject *)gd, "clicked", rule_editor_clicked, efb);
- gtk_signal_connect((GtkObject *)gd, "destroy", rule_editor_destroyed, efb);
-
- e_search_bar_set_menu_sensitive(esb, E_FILTERBAR_SAVE_ID, FALSE);
- gtk_widget_set_sensitive(esb->entry, FALSE);
-
- gtk_widget_show((GtkWidget *)gd);
+
+ rule = filter_rule_clone (efb->current_query, efb->context);
+
+ w = filter_rule_get_widget (rule, efb->context);
+ filter_rule_set_source (rule, FILTER_SOURCE_INCOMING);
+ gd = gnome_dialog_new (_("Save Search"), GNOME_STOCK_BUTTON_OK,
+ GNOME_STOCK_BUTTON_CANCEL, NULL);
+ efb->save_dialogue = gd;
+ gnome_dialog_set_default (GNOME_DIALOG (gd), 0);
+
+ gtk_window_set_policy (GTK_WINDOW (gd), FALSE, TRUE, FALSE);
+
+ gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (gd)->vbox), w, TRUE, TRUE, 0);
+ gtk_widget_show (gd);
+ gtk_object_ref (GTK_OBJECT (rule));
+ gtk_object_set_data_full (GTK_OBJECT (gd), "rule", rule, (GtkDestroyNotify)gtk_object_unref);
+ gtk_signal_connect (GTK_OBJECT (gd), "clicked", rule_editor_clicked, efb);
+ gtk_signal_connect (GTK_OBJECT (gd), "destroy", rule_editor_destroyed, efb);
+
+ e_search_bar_set_menu_sensitive (esb, E_FILTERBAR_SAVE_ID, FALSE);
+ gtk_widget_set_sensitive (esb->entry, FALSE);
+
+ gtk_widget_show (gd);
}
d(printf("Save menu\n"));
break;
default:
if (id >= efb->menu_base && id < efb->menu_base + efb->menu_rules->len) {
- GString *out = g_string_new("");
+ GString *out = g_string_new ("");
d(printf("Selected rule: %s\n", ((FilterRule *)efb->menu_rules->pdata[id - efb->menu_base])->name));
- filter_rule_build_code(efb->menu_rules->pdata[id - efb->menu_base], out);
+ filter_rule_build_code (efb->menu_rules->pdata[id - efb->menu_base], out);
d(printf("query: '%s'\n", out->str));
- g_string_free(out, 1);
-
+ g_string_free (out, TRUE);
+
efb->current_query = (FilterRule *)efb->menu_rules->pdata[id - efb->menu_base];
efb->setquery = TRUE;
- gtk_object_set((GtkObject *)esb, "option_choice", E_FILTERBAR_ADVANCED_ID, NULL);
-
- gtk_widget_set_sensitive(esb->entry, FALSE);
+ gtk_object_set (GTK_OBJECT (esb), "option_choice", E_FILTERBAR_ADVANCED_ID, NULL);
+
+ gtk_widget_set_sensitive (esb->entry, FALSE);
} else {
- gtk_widget_set_sensitive(esb->entry, TRUE);
+ gtk_widget_set_sensitive (esb->entry, TRUE);
return;
}
}
- gtk_signal_emit_stop_by_name((GtkObject *)esb, "menu_activated");
+ gtk_signal_emit_stop_by_name (GTK_OBJECT (esb), "menu_activated");
}
static void
@@ -216,126 +219,126 @@ option_changed (ESearchBar *esb, void *data)
EFilterBar *efb = (EFilterBar *)esb;
int id = esb->option_choice;
char *query;
-
+
d(printf("option changed, id = %d\n", id));
-
- switch(id) {
+
+ switch (id) {
case E_FILTERBAR_ADVANCED_ID: {
d(printf("Advanced search!\n"));
-
+
if (!efb->save_dialogue && !efb->setquery) {
- GtkWidget *w;
- GnomeDialog *gd;
+ GtkWidget *w, *gd;
FilterRule *rule;
-
+
if (efb->current_query)
- rule = filter_rule_clone(efb->current_query, efb->context);
+ rule = filter_rule_clone (efb->current_query, efb->context);
else
- rule = filter_rule_new();
-
- w = filter_rule_get_widget(rule, efb->context);
- filter_rule_set_source(rule, FILTER_SOURCE_INCOMING);
- gd = (GnomeDialog *)gnome_dialog_new(_("Advanced Search"),
- GNOME_STOCK_BUTTON_OK,
- _("Save"),
- GNOME_STOCK_BUTTON_CANCEL,
- NULL);
- efb->save_dialogue = (GtkWidget *)gd;
- gnome_dialog_set_default (gd, 0);
-
- gtk_window_set_policy(GTK_WINDOW(gd), FALSE, TRUE, FALSE);
+ rule = filter_rule_new ();
+
+ w = filter_rule_get_widget (rule, efb->context);
+ filter_rule_set_source (rule, FILTER_SOURCE_INCOMING);
+ gd = gnome_dialog_new (_("Advanced Search"),
+ GNOME_STOCK_BUTTON_OK,
+ _("Save"),
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
+ efb->save_dialogue = gd;
+ gnome_dialog_set_default (GNOME_DIALOG (gd), 0);
+
+ gtk_window_set_policy (GTK_WINDOW (gd), FALSE, TRUE, FALSE);
gtk_window_set_default_size (GTK_WINDOW (gd), 600, 300);
- gtk_box_pack_start((GtkBox *)gd->vbox, w, TRUE, TRUE, 0);
- gtk_widget_show((GtkWidget *)gd);
- gtk_object_ref((GtkObject *)rule);
- gtk_object_set_data_full((GtkObject *)gd, "rule", rule, (GtkDestroyNotify)gtk_object_unref);
- gtk_signal_connect((GtkObject *)gd, "clicked", rule_advanced_clicked, efb);
- gtk_signal_connect((GtkObject *)gd, "destroy", rule_editor_destroyed, efb);
-
- e_search_bar_set_menu_sensitive(esb, E_FILTERBAR_SAVE_ID, FALSE);
- gtk_widget_set_sensitive(esb->entry, FALSE);
-
- gtk_widget_show((GtkWidget *)gd);
+ gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (gd)->vbox), w, TRUE, TRUE, 0);
+ gtk_widget_show (gd);
+ gtk_object_ref (GTK_OBJECT (rule));
+ gtk_object_set_data_full (GTK_OBJECT (gd), "rule", rule, (GtkDestroyNotify)gtk_object_unref);
+ gtk_signal_connect (GTK_OBJECT (gd), "clicked", rule_advanced_clicked, efb);
+ gtk_signal_connect (GTK_OBJECT (gd), "destroy", rule_editor_destroyed, efb);
+
+ e_search_bar_set_menu_sensitive (esb, E_FILTERBAR_SAVE_ID, FALSE);
+ gtk_widget_set_sensitive (esb->entry, FALSE);
+
+ gtk_widget_show (gd);
}
} break;
default:
if (id >= efb->option_base && id < efb->option_base + efb->option_rules->len) {
efb->current_query = (FilterRule *)efb->option_rules->pdata[id - efb->option_base];
if (efb->config) {
- gtk_object_get((GtkObject *)esb, "text", &query, NULL);
- efb->config(efb, efb->current_query, id, query, efb->config_data);
- g_free(query);
+ gtk_object_get (GTK_OBJECT (esb), "text", &query, NULL);
+ efb->config (efb, efb->current_query, id, query, efb->config_data);
+ g_free (query);
}
- gtk_widget_set_sensitive(esb->entry, TRUE);
+ gtk_widget_set_sensitive (esb->entry, TRUE);
} else {
- gtk_widget_set_sensitive(esb->entry, FALSE);
+ gtk_widget_set_sensitive (esb->entry, FALSE);
efb->current_query = NULL;
}
}
efb->setquery = FALSE;
}
-static GArray *build_items(ESearchBar *esb, ESearchBarItem *items, int type, int *start, GPtrArray *rules)
+static GArray *
+build_items (ESearchBar *esb, ESearchBarItem *items, int type, int *start, GPtrArray *rules)
{
FilterRule *rule = NULL;
EFilterBar *efb = (EFilterBar *)esb;
int id = 0, i;
- GArray *menu = g_array_new(FALSE, FALSE, sizeof(ESearchBarItem));
+ GArray *menu = g_array_new (FALSE, FALSE, sizeof (ESearchBarItem));
ESearchBarItem item;
char *source;
-
+
/* find a unique starting point for the id's of our items */
- for (i=0;items[i].id != -1;i++) {
+ for (i = 0; items[i].id != -1; i++) {
if (items[i].id >= id)
- id = items[i].id+1;
+ id = items[i].id + 1;
}
-
+
/* add the user menus */
- g_array_append_vals(menu, items, i);
-
+ g_array_append_vals (menu, items, i);
+
*start = id;
-
+
if (type == 0) {
/* and add ours */
item.id = 0;
item.text = NULL;
- g_array_append_vals(menu, &item, 1);
+ g_array_append_vals (menu, &item, 1);
source = FILTER_SOURCE_INCOMING;
} else {
source = FILTER_SOURCE_DEMAND;
}
-
- while ( (rule = rule_context_next_rule(efb->context, rule, source)) ) {
+
+ while ((rule = rule_context_next_rule (efb->context, rule, source))) {
item.id = id++;
item.text = rule->name;
- g_array_append_vals(menu, &item, 1);
- g_ptr_array_add(rules, rule);
+ g_array_append_vals (menu, &item, 1);
+ g_ptr_array_add (rules, rule);
}
-
+
/* always add on the advanced menu */
if (type == 1) {
ESearchBarItem advanced_item = E_FILTERBAR_ADVANCED;
- g_array_append_vals(menu, &advanced_item, 1);
+ g_array_append_vals (menu, &advanced_item, 1);
}
-
+
item.id = -1;
item.text = NULL;
- g_array_append_vals(menu, &item, 1);
-
+ g_array_append_vals (menu, &item, 1);
+
return menu;
}
/* Virtual methods */
static void
-set_menu(ESearchBar *esb, ESearchBarItem *items)
+set_menu (ESearchBar *esb, ESearchBarItem *items)
{
GArray *menu;
EFilterBar *efb = (EFilterBar *)esb;
-
- g_ptr_array_set_size(efb->menu_rules, 0);
- menu = build_items(esb, items, 0, &efb->menu_base, efb->menu_rules);
- ((ESearchBarClass *)parent_class)->set_menu(esb, (ESearchBarItem *)menu->data);
- g_array_free(menu, TRUE);
+
+ g_ptr_array_set_size (efb->menu_rules, 0);
+ menu = build_items (esb, items, 0, &efb->menu_base, efb->menu_rules);
+ ((ESearchBarClass *)parent_class)->set_menu (esb, (ESearchBarItem *)menu->data);
+ g_array_free (menu, TRUE);
}
static void
@@ -343,11 +346,11 @@ set_option(ESearchBar *esb, ESearchBarItem *items)
{
GArray *menu;
EFilterBar *efb = (EFilterBar *)esb;
-
- g_ptr_array_set_size(efb->option_rules, 0);
- menu = build_items(esb, items, 1, &efb->option_base, efb->option_rules);
- ((ESearchBarClass *)parent_class)->set_option(esb, (ESearchBarItem *)menu->data);
- g_array_free(menu, TRUE);
+
+ g_ptr_array_set_size (efb->option_rules, 0);
+ menu = build_items (esb, items, 1, &efb->option_base, efb->option_rules);
+ ((ESearchBarClass *)parent_class)->set_option (esb, (ESearchBarItem *)menu->data);
+ g_array_free (menu, TRUE);
}
@@ -357,17 +360,17 @@ static void
impl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
EFilterBar *efb = E_FILTER_BAR(object);
-
+
switch (arg_id) {
case ARG_QUERY:
if (efb->current_query) {
- GString *out = g_string_new("");
-
- filter_rule_build_code(efb->current_query, out);
- GTK_VALUE_STRING(*arg) = out->str;
- g_string_free(out, FALSE);
+ GString *out = g_string_new ("");
+
+ filter_rule_build_code (efb->current_query, out);
+ GTK_VALUE_STRING (*arg) = out->str;
+ g_string_free (out, FALSE);
} else {
- GTK_VALUE_STRING(*arg) = NULL;
+ GTK_VALUE_STRING (*arg) = NULL;
}
break;
}
@@ -379,18 +382,18 @@ class_init (EFilterBarClass *klass)
{
GtkObjectClass *object_class;
ESearchBarClass *esb_class = (ESearchBarClass *)klass;
-
+
object_class = GTK_OBJECT_CLASS(klass);
-
+
parent_class = gtk_type_class(e_search_bar_get_type());
-
+
object_class->get_arg = impl_get_arg;
-
+
esb_class->set_menu = set_menu;
esb_class->set_option = set_option;
-
+
gtk_object_add_arg_type ("EFilterBar::query", GTK_TYPE_STRING, GTK_ARG_READABLE, ARG_QUERY);
-
+
#if 0
esb_signals [QUERY_CHANGED] =
gtk_signal_new ("query_changed",
@@ -399,7 +402,7 @@ class_init (EFilterBarClass *klass)
GTK_SIGNAL_OFFSET (EFilterBarClass, query_changed),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
-
+
esb_signals [MENU_ACTIVATED] =
gtk_signal_new ("menu_activated",
GTK_RUN_LAST,
@@ -407,7 +410,7 @@ class_init (EFilterBarClass *klass)
GTK_SIGNAL_OFFSET (EFilterBarClass, menu_activated),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
-
+
gtk_object_class_add_signals (object_class, esb_signals, LAST_SIGNAL);
#endif
}
@@ -415,34 +418,36 @@ class_init (EFilterBarClass *klass)
static void
init (EFilterBar *efb)
{
- gtk_signal_connect((GtkObject *)efb, "menu_activated", menubar_activated, NULL);
- gtk_signal_connect((GtkObject *)efb, "query_changed", option_changed, NULL);
-
- efb->menu_rules = g_ptr_array_new();
- efb->option_rules = g_ptr_array_new();
+ gtk_signal_connect (GTK_OBJECT (efb), "menu_activated", menubar_activated, NULL);
+ gtk_signal_connect (GTK_OBJECT (efb), "query_changed", option_changed, NULL);
+
+ efb->menu_rules = g_ptr_array_new ();
+ efb->option_rules = g_ptr_array_new ();
}
/* Object construction. */
-EFilterBar *e_filter_bar_new (RuleContext *context, const char *systemrules, const char *userrules, EFilterBarConfigRule config, void *data)
+EFilterBar *
+e_filter_bar_new (RuleContext *context, const char *systemrules, const char *userrules,
+ EFilterBarConfigRule config, void *data)
{
EFilterBar *bar;
ESearchBarItem item = { NULL, -1 };
-
- bar = gtk_type_new(e_filter_bar_get_type());
-
+
+ bar = gtk_type_new (e_filter_bar_get_type ());
+
bar->context = context;
- gtk_object_ref((GtkObject *)context);
- bar->systemrules = g_strdup(systemrules);
- bar->userrules = g_strdup(userrules);
- rule_context_load(context, systemrules, userrules);
-
+ gtk_object_ref (GTK_OBJECT (context));
+ bar->systemrules = g_strdup (systemrules);
+ bar->userrules = g_strdup (userrules);
+ rule_context_load (context, systemrules, userrules);
+
bar->config = config;
bar->config_data = data;
-
- e_search_bar_construct((ESearchBar *)bar, &item, &item);
-
+
+ e_search_bar_construct ((ESearchBar *)bar, &item, &item);
+
return bar;
}
@@ -450,7 +455,7 @@ GtkType
e_filter_bar_get_type (void)
{
static GtkType type = 0;
-
+
if (!type) {
static const GtkTypeInfo info = {
"EFilterBar",
@@ -465,25 +470,6 @@ e_filter_bar_get_type (void)
type = gtk_type_unique (e_search_bar_get_type (), &info);
}
-
+
return type;
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-