[PATCH] : filters
- From: Emmanuel <e allaud wanadoo fr>
- To: balsa-list gnome org
- Subject: [PATCH] : filters
- Date: Wed, 21 Nov 2001 14:12:02 +0100
Hi all,
this patch replaces the previous one (balsa-cvs-1.patch). It tries to grey
buttons when they are useless (ie it greys out a "delete" button when
there is no more filters or conditions...). So this is mostly UI tweaks.
[Q] : what is the exact differences between BROWSE and SINGLE selection
mode for clists ?
Bye
Manu
--- /home/manu/prog/balsa-cvs/balsa/src/filter-edit-callbacks.c Sun Nov 18 19:20:28 2001
+++ /home/manu/prog/test/balsa-cvs/balsa/src/filter-edit-callbacks.c Wed Nov 21 13:58:10 2001
@@ -100,6 +100,14 @@
extern GtkWidget *fe_action_option_menu;
extern GtkWidget *fe_action_entry;
+/* Different buttons that need to be greyed or ungreyed */
+extern GtkWidget * fe_delete_button;
+extern GtkWidget * fe_apply_button;
+extern GtkWidget * fe_revert_button;
+extern GtkWidget * fe_condition_delete_button;
+extern GtkWidget * fe_condition_edit_button;
+GtkWidget * fe_regex_remove_button;
+
#define ELEMENTS(x) (sizeof (x) / sizeof (x[0]))
/* condition_has_changed allows us to be smart enough not to make the whole process
@@ -182,8 +190,11 @@
{
gchar *str;
- gtk_clist_get_text(fe_type_regex_list,row,0,&str);
- gtk_entry_set_text(GTK_ENTRY(fe_type_regex_entry),str);
+ if (row<fe_type_regex_list->rows) {
+ gtk_clist_get_text(fe_type_regex_list,row,0,&str);
+ gtk_entry_set_text(GTK_ENTRY(fe_type_regex_entry),str);
+ }
+ else gtk_entry_set_text(GTK_ENTRY(fe_type_regex_entry),"");
}
/*
@@ -537,6 +548,7 @@
case CONDITION_REGEX:
for (regex=cnd->match.regexs;regex;regex=g_slist_next(regex))
gtk_clist_append(fe_type_regex_list,&(((LibBalsaConditionRegex *)regex->data)->string));
+ gtk_widget_set_sensitive(fe_regex_remove_button,cnd->match.regexs!=NULL);
fe_update_type_regex_label();
break;
case CONDITION_DATE:
@@ -579,27 +591,32 @@
if (condition_has_changed) {
new_cnd = libbalsa_condition_new();
if (!condition_validate(new_cnd))
- return;
+ return;
/* No error occured, condition is valid, so change/add it based on is_new_condition
* and only if something has changed of course
*/
if (condition_has_changed) {
- if (!is_new_condition) {
- /* We free the old condition*/
- row=GPOINTER_TO_INT(fe_conditions_list->selection->data);
- libbalsa_condition_free((LibBalsaCondition*)
- gtk_clist_get_row_data(fe_conditions_list,row));
- }
- else {
- gchar * str[]={""};
- /* It was a new condition, so add it to the list */
- row=gtk_clist_append(fe_conditions_list,str);
- gtk_clist_select_row(fe_conditions_list,row,-1);
- }
- /* Associate the new condition to the row in the clist*/
- gtk_clist_set_row_data(fe_conditions_list,row,new_cnd);
- /* And refresh the conditions list */
- update_condition_list_label();
+ if (!is_new_condition) {
+ /* We free the old condition*/
+ row=GPOINTER_TO_INT(fe_conditions_list->selection->data);
+ libbalsa_condition_free((LibBalsaCondition*)
+ gtk_clist_get_row_data(fe_conditions_list,row));
+ }
+ else {
+ gchar * str[]={""};
+ /* It was a new condition, so add it to the list */
+ row=gtk_clist_append(fe_conditions_list,str);
+ gtk_clist_select_row(fe_conditions_list,row,-1);
+ /* We make the buttons sensitive if they were unsensitive */
+ if (fe_conditions_list->rows==1) {
+ gtk_widget_set_sensitive(fe_condition_delete_button,TRUE);
+ gtk_widget_set_sensitive(fe_condition_edit_button,TRUE);
+ }
+ }
+ /* Associate the new condition to the row in the clist*/
+ gtk_clist_set_row_data(fe_conditions_list,row,new_cnd);
+ /* And refresh the conditions list */
+ update_condition_list_label();
}
}
case 1: /* Cancel button */
@@ -677,7 +694,7 @@
fe_type_regex_list = GTK_CLIST(gtk_clist_new(1));
- gtk_clist_set_selection_mode(fe_type_regex_list, GTK_SELECTION_SINGLE);
+ gtk_clist_set_selection_mode(fe_type_regex_list, GTK_SELECTION_BROWSE);
gtk_clist_set_row_height(fe_type_regex_list, 0);
gtk_clist_set_reorderable(fe_type_regex_list, FALSE);
gtk_clist_set_use_drag_icons(fe_type_regex_list, FALSE);
@@ -696,9 +713,9 @@
gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT(button),
"clicked", GTK_SIGNAL_FUNC(fe_add_pressed), NULL);
- button = gtk_button_new_with_label(_("Remove"));
- gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
- gtk_signal_connect(GTK_OBJECT(button),
+ fe_regex_remove_button = gtk_button_new_with_label(_("Remove"));
+ gtk_box_pack_start(GTK_BOX(box), fe_regex_remove_button, TRUE, TRUE, 0);
+ gtk_signal_connect(GTK_OBJECT(fe_regex_remove_button),
"clicked",
GTK_SIGNAL_FUNC(fe_remove_pressed), NULL);
button = gtk_button_new_with_label(_("One matches/None matches"));
@@ -938,7 +955,6 @@
build_condition_dialog();
/* For now this box is modal */
gtk_window_set_modal(GTK_WINDOW(condition_dialog),TRUE);
-
}
title = g_strconcat(_("Edit condition for filter: "),
((LibBalsaFilter*)
@@ -958,7 +974,7 @@
fe_conditions_select_row(GtkWidget * widget, gint row, gint column,
GdkEventButton * bevent, gpointer data)
{
- if (bevent == NULL)
+ if (bevent == NULL || row<0)
return;
if (bevent->type == GDK_2BUTTON_PRESS)
@@ -974,11 +990,16 @@
selected = fe_conditions_list->selection;
if (!selected)
- return;
+ return;
row=GPOINTER_TO_INT(selected->data);
libbalsa_condition_free((LibBalsaCondition*)
gtk_clist_get_row_data(fe_conditions_list,row));
gtk_clist_remove(fe_conditions_list,row);
+
+ if (!fe_conditions_list->rows) {
+ gtk_widget_set_sensitive(fe_condition_delete_button,FALSE);
+ gtk_widget_set_sensitive(fe_condition_edit_button,FALSE);
+ }
}
/**************** Filters ****************************/
@@ -1186,6 +1207,7 @@
gtk_clist_append(fe_type_regex_list, &text);
condition_has_changed=TRUE;
+ gtk_widget_set_sensitive(fe_regex_remove_button,TRUE);
} /* end fe_add_pressed() */
/*
@@ -1205,6 +1227,8 @@
gtk_clist_remove(fe_type_regex_list, GPOINTER_TO_INT(selected->data));
condition_has_changed=TRUE;
+ if (!fe_type_regex_list->rows)
+ gtk_widget_set_sensitive(fe_regex_remove_button,FALSE);
} /* end fe_remove_pressed() */
/************************************************************/
@@ -1352,6 +1376,23 @@
libbalsa_filter_free(fil, NULL);
gtk_clist_remove(fe_filters_list, row);
+ if (row>=fe_filters_list->rows) row=fe_filters_list->rows-1;
+ if (row<0) {
+ /* We make the filters delete,revert,apply buttons unsensitive */
+ gtk_widget_set_sensitive(fe_delete_button,FALSE);
+ gtk_widget_set_sensitive(fe_apply_button,FALSE);
+ gtk_widget_set_sensitive(fe_revert_button,FALSE);
+ /* We clear all widgets */
+ gtk_entry_set_text(GTK_ENTRY(fe_name_entry),"");
+ gtk_entry_set_text(GTK_ENTRY(fe_popup_entry),"");
+ gtk_entry_set_text(GTK_ENTRY(fe_action_entry),"");
+ gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(fe_sound_entry))),"");
+ gtk_clist_clear(fe_conditions_list);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fe_sound_button),FALSE);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fe_popup_button),FALSE);
+ }
+ else
+ gtk_clist_select_row(fe_filters_list,row,-1);
} /* end fe_delete_pressed() */
/*
@@ -1533,8 +1574,11 @@
fil=(LibBalsaFilter*)gtk_clist_get_row_data(fe_filters_list,row);
- /* FIXME : Should be impossible */
- g_assert(fil!=NULL);
+ /* FIXME : this seems necessary : this callback is called
+ really early, so early that the clist has not been populated
+ in between! (this is related to the selection mode
+ I have chosen : GTK_CLIST_SELECTION_BROWSE)*/
+ if (!fil) return;
/* Populate all fields with filter data */
gtk_entry_set_text(GTK_ENTRY(fe_name_entry),fil->name);
@@ -1544,9 +1588,9 @@
FILTER_CHKFLAG(fil,FILTER_POPUP) ? fil->popup_text : "");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fe_sound_button),
FILTER_CHKFLAG(fil,FILTER_SOUND));
- /* gtk_entry_set_text(GTK_ENTRY(fe_sound_entry),
- FILTER_CHKFLAG(fil,FILTER_SOUND) ? fil->sound : "");*/
-
+ gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(fe_sound_entry))),
+ FILTER_CHKFLAG(fil,FILTER_SOUND) ? fil->sound : "");
+
gtk_option_menu_set_history(GTK_OPTION_MENU(fe_action_option_menu), fil->action-1);
gtk_option_menu_set_history(GTK_OPTION_MENU(fe_op_codes_option_menu), fil->conditions_op-1);
@@ -1573,6 +1617,18 @@
if (filter_errno!=FILTER_NOERR)
gnome_dialog_close(fe_window);
- if (fe_conditions_list->rows)
+ if (fe_conditions_list->rows) {
gtk_clist_select_row(fe_conditions_list,0,-1);
+ gtk_widget_set_sensitive(fe_condition_delete_button,TRUE);
+ gtk_widget_set_sensitive(fe_condition_edit_button,TRUE);
+ }
+ else {
+ gtk_widget_set_sensitive(fe_condition_delete_button,FALSE);
+ gtk_widget_set_sensitive(fe_condition_edit_button,FALSE);
+ }
+
+ /* We make the filters delete,revert,apply buttons sensitive */
+ gtk_widget_set_sensitive(fe_delete_button,TRUE);
+ gtk_widget_set_sensitive(fe_apply_button,TRUE);
+ gtk_widget_set_sensitive(fe_revert_button,TRUE);
} /* end fe_clist_select_row */
--- /home/manu/prog/balsa-cvs/balsa/src/filter-edit-dialog.c Sun Nov 18 19:20:28 2001
+++ /home/manu/prog/test/balsa-cvs/balsa/src/filter-edit-dialog.c Wed Nov 21 14:02:27 2001
@@ -69,6 +69,10 @@
GtkWidget *fe_action_option_menu;
GtkWidget *fe_action_entry;
+/* Different buttons that need to be greyed or ungreyed */
+GtkWidget * fe_delete_button,* fe_apply_button,* fe_revert_button;
+GtkWidget * fe_condition_delete_button,* fe_condition_edit_button;
+
/* ******************************** */
option_list fe_search_type[] = {
@@ -217,18 +221,17 @@
gtk_widget_pop_colormap();
gtk_widget_pop_visual();
- gtk_clist_set_selection_mode(fe_filters_list, GTK_SELECTION_SINGLE);
+ gtk_clist_set_selection_mode(fe_filters_list, GTK_SELECTION_BROWSE);
gtk_clist_set_row_height(fe_filters_list, 0);
gtk_clist_column_titles_passive(fe_filters_list);
gtk_clist_set_sort_column(fe_filters_list,0);
gtk_clist_set_sort_type(fe_filters_list,GTK_SORT_ASCENDING);
gtk_clist_set_auto_sort(fe_filters_list,TRUE);
-
-
- gtk_container_add(GTK_CONTAINER(sw), GTK_WIDGET(fe_filters_list));
gtk_signal_connect(GTK_OBJECT(fe_filters_list), "select_row",
GTK_SIGNAL_FUNC(fe_clist_select_row), NULL);
+ gtk_container_add(GTK_CONTAINER(sw), GTK_WIDGET(fe_filters_list));
+
gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 2);
/* new and delete buttons */
@@ -249,10 +252,11 @@
gtk_container_add(GTK_CONTAINER(bbox), button);
/* delete button */
pixmap = gnome_stock_new_with_icon(GNOME_STOCK_MENU_TRASH);
- button = gnome_pixmap_button(pixmap, _("Delete"));
- gtk_signal_connect(GTK_OBJECT(button), "clicked",
+ fe_delete_button = gnome_pixmap_button(pixmap, _("Delete"));
+ gtk_signal_connect(GTK_OBJECT(fe_delete_button), "clicked",
GTK_SIGNAL_FUNC(fe_delete_pressed), NULL);
- gtk_container_add(GTK_CONTAINER(bbox), button);
+ gtk_container_add(GTK_CONTAINER(bbox), fe_delete_button);
+ gtk_widget_set_sensitive(fe_delete_button,FALSE);
return vbox;
} /* end build_left_side() */
@@ -318,7 +322,7 @@
GTK_FILL | GTK_SHRINK | GTK_EXPAND, 2, 2);
fe_conditions_list = GTK_CLIST(gtk_clist_new(1));
- gtk_clist_set_selection_mode(fe_conditions_list,GTK_SELECTION_SINGLE);
+ gtk_clist_set_selection_mode(fe_conditions_list,GTK_SELECTION_BROWSE);
gtk_clist_set_row_height(fe_conditions_list, 0);
gtk_clist_set_reorderable(fe_conditions_list, FALSE);
gtk_clist_set_use_drag_icons(fe_conditions_list, FALSE);
@@ -334,17 +338,17 @@
box,
0, 5, 8, 9,
GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
- button = gtk_button_new_with_label(_("Edit"));
- gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
- gtk_signal_connect(GTK_OBJECT(button),
+ fe_condition_edit_button = gtk_button_new_with_label(_("Edit"));
+ gtk_box_pack_start(GTK_BOX(box), fe_condition_edit_button, TRUE, TRUE, 0);
+ gtk_signal_connect(GTK_OBJECT(fe_condition_edit_button),
"clicked", GTK_SIGNAL_FUNC(fe_edit_condition), GINT_TO_POINTER(0));
button = gtk_button_new_with_label(_("New"));
gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT(button),
"clicked", GTK_SIGNAL_FUNC(fe_edit_condition), GINT_TO_POINTER(1));
- button = gtk_button_new_with_label(_("Remove"));
- gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
- gtk_signal_connect(GTK_OBJECT(button),
+ fe_condition_delete_button = gtk_button_new_with_label(_("Remove"));
+ gtk_box_pack_start(GTK_BOX(box), fe_condition_delete_button, TRUE, TRUE, 0);
+ gtk_signal_connect(GTK_OBJECT(fe_condition_delete_button),
"clicked",
GTK_SIGNAL_FUNC(fe_condition_remove_pressed), NULL);
@@ -431,7 +435,7 @@
{
GtkWidget *rightside;
GtkWidget *notebook, *page;
- GtkWidget *bbox, *pixmap, *button;
+ GtkWidget *bbox, *pixmap;
rightside = gtk_vbox_new(FALSE, 0);
@@ -451,18 +455,20 @@
bbox = gtk_hbutton_box_new();
gtk_box_pack_start(GTK_BOX(rightside), bbox, FALSE, FALSE, 0);
- button = gnome_stock_button(GNOME_STOCK_BUTTON_APPLY);
- gtk_signal_connect(GTK_OBJECT(button),
+ fe_apply_button = gnome_stock_button(GNOME_STOCK_BUTTON_APPLY);
+ gtk_signal_connect(GTK_OBJECT(fe_apply_button),
"clicked",
GTK_SIGNAL_FUNC(fe_apply_pressed), NULL);
- gtk_container_add(GTK_CONTAINER(bbox), button);
+ gtk_container_add(GTK_CONTAINER(bbox), fe_apply_button);
pixmap = gnome_stock_new_with_icon(GNOME_STOCK_MENU_UNDO);
- button = gnome_pixmap_button(pixmap, _("Revert"));
- gtk_signal_connect(GTK_OBJECT(button),
+ fe_revert_button = gnome_pixmap_button(pixmap, _("Revert"));
+ gtk_signal_connect(GTK_OBJECT(fe_revert_button),
"clicked",
GTK_SIGNAL_FUNC(fe_revert_pressed), NULL);
- gtk_container_add(GTK_CONTAINER(bbox), button);
+ gtk_container_add(GTK_CONTAINER(bbox), fe_revert_button);
+ gtk_widget_set_sensitive(fe_apply_button,FALSE);
+ gtk_widget_set_sensitive(fe_revert_button,FALSE);
return rightside;
} /* end build_right_side() */
@@ -566,4 +572,6 @@
}
gtk_widget_show_all(GTK_WIDGET(fe_window));
+ if (fe_filters_list->rows)
+ gtk_clist_select_row(fe_filters_list,0,-1);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]