[gnumeric] Avoid creating interacting auto filters. [#607086]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Avoid creating interacting auto filters. [#607086]
- Date: Mon, 5 Jul 2010 18:03:19 +0000 (UTC)
commit 3586d4c673630bc081b37693c3939ca60f0f25bc
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Mon Jul 5 12:03:22 2010 -0600
Avoid creating interacting auto filters. [#607086]
2010-07-05 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/sheet-filter.h (gnm_sheet_filter_intersect_rows): new
* src/sheet-filter.c (gnm_sheet_filter_intersect_rows): new
* src/sheet-view.h (sv_selection_intersects_filter_rows): new
* src/sheet-view.c (sv_selection_intersects_filter_rows): new
* src/wbc-gtk.c (wbcg_menu_state_update): check for prohibited
autofilter positions
ChangeLog | 11 ++++++++++-
NEWS | 1 +
src/sheet-filter.c | 25 +++++++++++++++++++++++++
src/sheet-filter.h | 1 +
src/sheet-view.c | 20 ++++++++++++++++++++
src/sheet-view.h | 1 +
src/wbc-gtk.c | 31 ++++++++++++++++++++++++-------
7 files changed, 82 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a62b63e..d1d6acb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2010-07-05 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * src/sheet-filter.h (gnm_sheet_filter_intersect_rows): new
+ * src/sheet-filter.c (gnm_sheet_filter_intersect_rows): new
+ * src/sheet-view.h (sv_selection_intersects_filter_rows): new
+ * src/sheet-view.c (sv_selection_intersects_filter_rows): new
+ * src/wbc-gtk.c (wbcg_menu_state_update): check for prohibited
+ autofilter positions
+
+2010-07-05 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* src/sheet-control-gui.c (scg_drag_receive_same_process): one need to
first duplicate the sheet before committing that change
@@ -27,7 +36,7 @@
* src/sheet-control-gui.c (scg_objects_drag_commit): simplify slightly
(scg_drag_receive_same_process): pass the correct argument to
scg_objects_drag_commit
- * src/sheet-object.c (sheet_object_set_sheet): don't complain if the oject
+ * src/sheet-object.c (sheet_object_set_sheet): don't complain if the object
is already set to this sheet.
* src/commands.c (CMD_OBJECTS_MOVE): delete
(cmd_objects_move_*): delete
diff --git a/NEWS b/NEWS
index 2a02936..697f6dd 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Andreas:
* Fix undo text for sheet object duplication. [#623557]
* Fix additional undo entry for sheet object duplication. [#623559]
* Fix undo of object creation followed by duplication. [#623566]
+ * Avoid creating interacting auto filters. [#607086]
Morten:
* Ask user to locate solver binaries when plain search fails.
diff --git a/src/sheet-filter.c b/src/sheet-filter.c
index 9b3e9ae..83a9a27 100644
--- a/src/sheet-filter.c
+++ b/src/sheet-filter.c
@@ -863,6 +863,31 @@ gnm_sheet_filter_at_pos (Sheet const *sheet, GnmCellPos const *pos)
return NULL;
}
+/**
+ * gnm_sheet_filter_intersect_rows :
+ *
+ * Returns: the filter (if any) that intersect the rows from to to
+ **/
+GnmFilter *
+gnm_sheet_filter_intersect_rows (Sheet const *sheet, int from, int to)
+{
+ GSList *ptr;
+ GnmRange r;
+
+ g_return_val_if_fail (IS_SHEET (sheet), NULL);
+
+ range_init_rows (&r, sheet, from, to);
+ for (ptr = sheet->filters; ptr != NULL ; ptr = ptr->next)
+ if (gnm_filter_overlaps_range (ptr->data, &r))
+ return ptr->data;
+
+ return NULL;
+}
+
+
+
+/*************************************************************************/
+
struct cb_remove_col_undo {
unsigned col;
GnmFilterCondition *cond;
diff --git a/src/sheet-filter.h b/src/sheet-filter.h
index a0ac9b4..79071cf 100644
--- a/src/sheet-filter.h
+++ b/src/sheet-filter.h
@@ -84,6 +84,7 @@ gboolean gnm_filter_overlaps_range (GnmFilter const *filter, GnmRange const *
void gnm_filter_reapply (GnmFilter *filter);
GnmFilter *gnm_sheet_filter_at_pos (Sheet const *sheet, GnmCellPos const *pos);
+GnmFilter *gnm_sheet_filter_intersect_rows (Sheet const *sheet, int from, int to);
void gnm_sheet_filter_insdel_colrow (Sheet *sheet,
gboolean is_cols, gboolean is_insert,
int start, int count,
diff --git a/src/sheet-view.c b/src/sheet-view.c
index 7fc108a..06a7153 100644
--- a/src/sheet-view.c
+++ b/src/sheet-view.c
@@ -684,6 +684,26 @@ sv_editpos_in_filter (SheetView const *sv)
}
/**
+ * sv_selection_intersects_filter_rows :
+ * @sv : #SheetView
+ *
+ * Returns: %NULL or GnmFilter whose rows intersect the rows
+ * of the current selection.
+ **/
+GnmFilter *
+sv_selection_intersects_filter_rows (SheetView const *sv)
+{
+ GnmRange *r;
+ g_return_val_if_fail (IS_SHEET_VIEW (sv), NULL);
+ r = selection_first_range (sv, NULL, NULL);
+
+ return gnm_sheet_filter_intersect_rows
+ (sv->sheet, r->start.row, r->end.row);
+}
+
+
+
+/**
* sv_editpos_in_slicer :
* @sv : #SheetView
*
diff --git a/src/sheet-view.h b/src/sheet-view.h
index 2ebba90..011709a 100644
--- a/src/sheet-view.h
+++ b/src/sheet-view.h
@@ -86,6 +86,7 @@ gboolean sv_is_region_empty_or_selected (SheetView const *sv,
GnmRange const *r);
GnmFilter *sv_editpos_in_filter (SheetView const *sv);
+GnmFilter *sv_selection_intersects_filter_rows (SheetView const *sv);
GnmSheetSlicer *sv_editpos_in_slicer (SheetView const *sv);
/* Manipulation */
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index c6409c9..fe04708 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -1573,13 +1573,30 @@ wbcg_menu_state_update (WorkbookControl *wbc, int flags)
if (MS_ADD_VS_REMOVE_FILTER & flags) {
gboolean const has_filter = (NULL != sv_editpos_in_filter (sv));
- char const* label = has_filter
- ? _("Remove _Auto Filter")
- : _("Add _Auto Filter");
- char const *new_tip = has_filter
- ? _("Remove a filter")
- : _("Add a filter");
- wbc_gtk_set_action_label (wbcg, "DataAutoFilter", NULL, label, new_tip);
+ GnmFilter *f = sv_selection_intersects_filter_rows (sv);
+ char const* label;
+ char const *new_tip;
+ gboolean active = TRUE;
+
+ if ((!has_filter) && (NULL != f)) {
+ gchar *nlabel;
+ active = FALSE;
+ nlabel = g_strdup_printf (_("_Auto Filter blocked by %s"),
+ range_as_string (&f->r));
+ new_tip = _("The selection intersects an existing auto filter.");
+ wbc_gtk_set_action_label (wbcg, "DataAutoFilter", NULL, nlabel, new_tip);
+ g_free (nlabel);
+ } else {
+ label = has_filter
+ ? _("Remove _Auto Filter")
+ : _("Add _Auto Filter");
+ new_tip = has_filter
+ ? _("Remove a filter")
+ : _("Add a filter");
+ wbc_gtk_set_action_label (wbcg, "DataAutoFilter", NULL, label, new_tip);
+ }
+
+ wbc_gtk_set_action_sensitivity (wbcg, "DataAutoFilter", active);
}
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]