Commit 05184743 authored by Andreas J. Guelzow 's avatar Andreas J. Guelzow

Make autofilter condition changes undoable. [#625143]

2010-07-30  Andreas J. Guelzow <aguelzow@pyrshep.ca>

	* src/commands.c (cmd_autofilter_set_condition): new
	* src/commands.h (cmd_autofilter_set_condition): new
	* src/sheet-filter.c (gnm_filter_condition_dup): publish
	(gnm_filter_condition_free): publish
	* src/sheet-filter.h (gnm_filter_condition_dup): new
	(gnm_filter_condition_free): new
	* src/undo.c (GNM_UNDO_FILTER_SET_CONDITION): new object
	* src/undo.h (GNM_UNDO_FILTER_SET_CONDITION): new object

2010-07-30  Andreas J. Guelzow <aguelzow@pyrshep.ca>

	* gnm-filter-combo-view.c (cb_fcombo_count): deleted
	(fcombo_activate): use cmd_autofilter_set_condition

2010-07-30  Andreas J. Guelzow <aguelzow@pyrshep.ca>

	* dialog-autofilter.c (cb_autofilter_ok): use
	cmd_autofilter_set_condition
parent 6ff908a8
2010-07-30 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* src/commands.c (cmd_autofilter_set_condition): new
* src/commands.h (cmd_autofilter_set_condition): new
* src/sheet-filter.c (gnm_filter_condition_dup): publish
(gnm_filter_condition_free): publish
* src/sheet-filter.h (gnm_filter_condition_dup): new
(gnm_filter_condition_free): new
* src/undo.c (GNM_UNDO_FILTER_SET_CONDITION): new object
* src/undo.h (GNM_UNDO_FILTER_SET_CONDITION): new object
2010-07-29 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* src/wbc-gtk.c (cb_accept_input_array): new
......
......@@ -58,6 +58,7 @@ Andreas:
* Fix row height dialog. [#625543]
* Add menu to specify whether to enter as array, into multiple cells,
etc. Part of [#53733]
* Make autofilter condition changes undoable. [#625143]
Jean:
* Fix strong/weak cursor display. [#623241]
......
......@@ -7740,4 +7740,41 @@ cmd_autofilter_add_remove (WorkbookControl *wbc)
}
/******************************************************************/
gboolean cmd_autofilter_set_condition (WorkbookControl *wbc,
GnmFilter *filter, unsigned i,
GnmFilterCondition *cond)
{
char *descr = NULL, *name = NULL;
GOUndo *undo = NULL;
GOUndo *redo = NULL;
gboolean result;
undo = gnm_undo_filter_set_condition_new (filter, i,
NULL, TRUE);
g_return_val_if_fail (undo != NULL, TRUE);
redo = gnm_undo_filter_set_condition_new (filter, i,
cond, FALSE);
g_return_val_if_fail (redo != NULL, TRUE);
name = undo_range_name (filter->sheet, &(filter->r));
descr = g_strdup_printf (_("Change filter condition for %s"),
name);
result = cmd_generic (wbc, descr, undo, redo);
g_free (name);
g_free (descr);
return result;
}
/******************************************************************/
......@@ -163,6 +163,9 @@ gboolean cmd_tabulate (WorkbookControl *wbc, gpointer data);
gboolean cmd_toggle_rtl (WorkbookControl *wbc, Sheet *sheet);
gboolean cmd_autofilter_add_remove (WorkbookControl *wbc);
gboolean cmd_autofilter_set_condition (WorkbookControl *wbc,
GnmFilter *filter, unsigned i,
GnmFilterCondition *cond);
/************************** Sheet Objects **************************************/
......
2010-07-30 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* dialog-autofilter.c (cb_autofilter_ok): use
cmd_autofilter_set_condition
2010-07-29 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* dialog-row-height.c (dialog_row_height): make sure the spin
......
......@@ -34,6 +34,7 @@
#include <value.h>
#include <sheet-filter.h>
#include <number-match.h>
#include <undo.h>
#include <glade/glade.h>
#include <gtk/gtk.h>
......@@ -152,11 +153,10 @@ cb_autofilter_ok (G_GNUC_UNUSED GtkWidget *button,
cond = gnm_filter_condition_new_bucket (
!bottom, !percentage, count);
}
if (cond != NULL) {
gnm_filter_set_condition (state->filter, state->field,
cond, TRUE);
sheet_update (state->filter->sheet);
}
if (cond != NULL)
cmd_autofilter_set_condition (WORKBOOK_CONTROL (state->wbcg),
state->filter, state->field,
cond);
gtk_widget_destroy (state->dialog);
}
......
......@@ -93,7 +93,7 @@ gnm_filter_condition_new_bucket (gboolean top, gboolean absolute, double n)
return res;
}
static GnmFilterCondition *
GnmFilterCondition *
gnm_filter_condition_dup (GnmFilterCondition const *src)
{
GnmFilterCondition *dst;
......@@ -111,7 +111,7 @@ gnm_filter_condition_dup (GnmFilterCondition const *src)
return dst;
}
static void
void
gnm_filter_condition_free (GnmFilterCondition *cond)
{
if (cond == NULL)
......
......@@ -61,6 +61,8 @@ struct _GnmFilter {
gboolean is_active;
};
GnmFilterCondition *gnm_filter_condition_dup (GnmFilterCondition const *src);
void gnm_filter_condition_free (GnmFilterCondition *cond);
GnmFilterCondition *gnm_filter_condition_new_single (GnmFilterOp op, GnmValue *v);
GnmFilterCondition *gnm_filter_condition_new_double (GnmFilterOp op1, GnmValue *v1,
gboolean join_with_and,
......
......@@ -22,8 +22,18 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gnumeric-config.h>
#include "undo.h"
#include "sheet.h"
#include "sheet-view.h"
#include "sheet-control-gui.h"
#include "wbc-gtk.h"
#include "wbc-gtk-impl.h"
#include "colrow.h"
#include <gsf/gsf-impl-utils.h>
#include <glib/gi18n-lib.h>
/* ------------------------------------------------------------------------- */
......@@ -169,3 +179,110 @@ gnm_undo_colrow_set_sizes_new (Sheet *sheet, gboolean is_cols,
}
/* ------------------------------------------------------------------------- */
static GObjectClass *gnm_undo_filter_set_condition_parent_class;
static void
gnm_undo_filter_set_condition_finalize (GObject *o)
{
GNMUndoFilterSetCondition *ua = (GNMUndoFilterSetCondition *)o;
gnm_filter_condition_free (ua->cond);
ua->cond = NULL;
}
static gboolean
cb_filter_set_condition_undo (GnmColRowIter const *iter, gint *count)
{
if (iter->cri->visible)
(*count)++;
return FALSE;
}
static void
cb_filter_set_condition_undo_set_pb (SheetControl *control, char *text)
{
SheetControlGUI *scg = (SheetControlGUI *) control;
WBCGtk *wbcg = scg_wbcg (scg);
if (wbcg != NULL)
gtk_progress_bar_set_text
(GTK_PROGRESS_BAR (wbcg->progress_bar), text);
}
static void
gnm_undo_filter_set_condition_undo (GOUndo *u, gpointer data)
{
GNMUndoFilterSetCondition *ua = (GNMUndoFilterSetCondition *)u;
gint count = 0;
char const *format;
char *text;
gnm_filter_set_condition (ua->filter, ua->i,
gnm_filter_condition_dup (ua->cond), TRUE);
sheet_update (ua->filter->sheet);
colrow_foreach (&ua->filter->sheet->rows,
ua->filter->r.start.row + 1,
ua->filter->r.end.row,
(ColRowHandler) cb_filter_set_condition_undo,
&count);
format = ngettext ("%d row of %d match",
"%d rows of %d match",
count);
text = g_strdup_printf (format, count,
ua->filter->r.end.row -
ua->filter->r.start.row);
SHEET_FOREACH_CONTROL (ua->filter->sheet, view, control, cb_filter_set_condition_undo_set_pb (control, text););
g_free (text);
}
static void
gnm_undo_filter_set_condition_class_init (GObjectClass *gobject_class)
{
GOUndoClass *uclass = (GOUndoClass *)gobject_class;
gnm_undo_filter_set_condition_parent_class = g_type_class_peek_parent
(gobject_class);
gobject_class->finalize = gnm_undo_filter_set_condition_finalize;
uclass->undo = gnm_undo_filter_set_condition_undo;
}
GSF_CLASS (GNMUndoFilterSetCondition, gnm_undo_filter_set_condition,
gnm_undo_filter_set_condition_class_init, NULL, GO_TYPE_UNDO)
/**
* gnm_undo_filter_set_condition_new:
*
* if (retrieve_from_filter), cond is ignored
*
* Returns: a new undo object.
**/
GOUndo *
gnm_undo_filter_set_condition_new (GnmFilter *filter, unsigned i,
GnmFilterCondition *cond,
gboolean retrieve_from_filter)
{
GNMUndoFilterSetCondition *ua;
g_return_val_if_fail (filter != NULL, NULL);
g_return_val_if_fail (i < filter->fields->len , NULL);
ua = g_object_new (GNM_TYPE_UNDO_FILTER_SET_CONDITION, NULL);
ua->filter = filter;
ua->i = i;
if (retrieve_from_filter)
ua->cond = gnm_filter_condition_dup
(gnm_filter_get_condition (filter, i));
else
ua->cond = cond;
return (GOUndo *)ua;
}
/* ------------------------------------------------------------------------- */
......@@ -5,6 +5,7 @@
#include "gnumeric.h"
#include "sheet.h"
#include "colrow.h"
#include "sheet-filter.h"
#include <goffice/goffice.h>
#include <glib-object.h>
......@@ -66,6 +67,32 @@ GOUndo *gnm_undo_colrow_set_sizes_new (Sheet *sheet, gboolean is_cols,
/* ------------------------------------------------------------------------- */
#define GNM_TYPE_UNDO_FILTER_SET_CONDITION (gnm_undo_filter_set_condition_get_type ())
#define GNM_UNDO_FILTER_SET_CONDITION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNM_TYPE_UNDO_FILTER_SET_CONDITION, GNMUndoFilterSetCondition))
#define GNM_IS_UNDO_FILTER_SET_CONDITION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_TYPE_UNDO_FILTER_SET_CONDITION))
GType gnm_undo_filter_set_condition_get_type (void);
typedef struct _GNMUndoFilterSetCondition GNMUndoFilterSetCondition;
typedef struct _GNMUndoFilterSetConditionClass GNMUndoFilterSetConditionClass;
struct _GNMUndoFilterSetCondition {
GOUndo base;
GnmFilter *filter;
unsigned i;
GnmFilterCondition *cond;
};
struct _GNMUndoFilterSetConditionClass {
GOUndoClass base;
};
GOUndo *gnm_undo_filter_set_condition_new (GnmFilter *filter, unsigned i,
GnmFilterCondition *cond,
gboolean retrieve_from_filter);
/* ------------------------------------------------------------------------- */
G_END_DECLS
......
2010-07-30 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* gnm-filter-combo-view.c (cb_fcombo_count): deleted
(fcombo_activate): use cmd_autofilter_set_condition
2010-07-30 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* gnumeric-expr-entry.c (gee_finalize): fix warning on NULL expr_top
......
......@@ -30,6 +30,7 @@
#include "gnm-format.h"
#include "value.h"
#include "cell.h"
#include "commands.h"
#include "sheet.h"
#include "sheet-object-impl.h"
#include "wbc-gtk.h"
......@@ -38,6 +39,7 @@
#include "sheet-control-gui.h"
#include "../dialogs/dialogs.h"
#include "wbc-gtk-impl.h"
#include <undo.h>
#include <goffice/goffice.h>
#include <gsf/gsf-impl-utils.h>
......@@ -45,14 +47,6 @@
#include <glib/gi18n-lib.h>
#include <string.h>
static gboolean
cb_fcombo_count (GnmColRowIter const *iter, gint *count)
{
if (iter->cri->visible)
(*count)++;
return FALSE;
}
static gboolean
fcombo_activate (SheetObject *so, GtkTreeView *list, WBCGtk *wbcg,
G_GNUC_UNUSED gboolean button)
......@@ -102,28 +96,10 @@ fcombo_activate (SheetObject *so, GtkTreeView *list, WBCGtk *wbcg,
g_warning ("Unknown type %d", type);
}
if (set_condition) {
gint count = 0;
char const *format;
char *text;
gnm_filter_set_condition (fcombo->filter, field_num,
cond, TRUE);
sheet_update (fcombo->filter->sheet);
colrow_foreach (&fcombo->filter->sheet->rows,
fcombo->filter->r.start.row + 1,
fcombo->filter->r.end.row,
(ColRowHandler) cb_fcombo_count,
&count);
format = ngettext ("%d row of %d match",
"%d rows of %d match",
count);
text = g_strdup_printf (format, count,
fcombo->filter->r.end.row -
fcombo->filter->r.start.row);
gtk_progress_bar_set_text
(GTK_PROGRESS_BAR (wbcg->progress_bar), text);
g_free (text);
}
if (set_condition)
cmd_autofilter_set_condition
(WORKBOOK_CONTROL (wbcg),
fcombo->filter, field_num, cond);
}
return TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment