Commit 4d2dd844 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

don't freak out with emoty names.

2003-06-03  Jody Goldberg <jody@gnome.org>

	* dialog-define-names.c (name_guru_add) : don't freak out with emoty
	  names.

2003-06-03  Jody Goldberg <jody@gnome.org>

	* dialog-define-names.c (name_guru_add) : cmd_define_name is smarter
	  now we don't need to do any heavy lifting here.

2003-06-02  Jody Goldberg <jody@gnome.org>

	* dialog-define-names.c (cb_scope_changed) : handle failure to change
	  scope and update the name list on success.

2003-06-03  Jody Goldberg <jody@gnome.org>

	* src/sheet-object.c (sheet_objects_relocate) : kludgy tweak so that
	  ins/del col/row moves things and cut-n-paste does not.

2003-06-03  Jody Goldberg <jody@gnome.org>

	* src/sheet-filter.c (gnm_filter_overlaps_range) : new.
	(gnm_filter_contains_row) : delete.
	* src/sheet-view.c (sv_first_selection_in_filter) : new.
	(sv_edit_pos_in_filter) : delete.
	* src/workbook-control-gui.c (wbcg_menu_state_update) : use here.
	(cb_auto_filter) : and here.

2003-06-03  Jody Goldberg <jody@gnome.org>

	* src/expr-name.c (gnm_named_expr_collection_insert) : ease
	  requirements and allow active names to be inserted.  This is the
	  majority case for all the places we up/dowgrade placeholders and
	  change scope.
	(expr_name_check_for_loop) : rename from name_refer_circular and make
	  public.
	(expr_name_downgrade_to_placeholder) : new.
	(expr_name_set_scope) : no need to diddle ::active now that
	  collection_insert is less anal.
	(expr_name_cmp_by_name) : renamed from expr_name_by_name.

	* src/commands.c (cmd_define_name*) : add more checking at the start.
	  Don't bother keeping a ref to the nexpr.
	  handle undo for defining an existing placeholder.
parent 143cc161
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/sheet-object.c (sheet_objects_relocate) : kludgy tweak so that
ins/del col/row moves things and cut-n-paste does not.
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/sheet-filter.c (gnm_filter_overlaps_range) : new.
(gnm_filter_contains_row) : delete.
* src/sheet-view.c (sv_first_selection_in_filter) : new.
(sv_edit_pos_in_filter) : delete.
* src/workbook-control-gui.c (wbcg_menu_state_update) : use here.
(cb_auto_filter) : and here.
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/expr-name.c (gnm_named_expr_collection_insert) : ease
requirements and allow active names to be inserted. This is the
majority case for all the places we up/dowgrade placeholders and
change scope.
(expr_name_check_for_loop) : rename from name_refer_circular and make
public.
(expr_name_downgrade_to_placeholder) : new.
(expr_name_set_scope) : no need to diddle ::active now that
collection_insert is less anal.
(expr_name_cmp_by_name) : renamed from expr_name_by_name.
* src/commands.c (cmd_define_name*) : add more checking at the start.
Don't bother keeping a ref to the nexpr.
handle undo for defining an existing placeholder.
2003-06-03 Morten Welinder <terra@gnome.org>
* src/stf-parse.c (stf_parse_lines): New function.
......
......@@ -9,9 +9,6 @@ Andreas:
Ben Liblit:
* Move the various compile time paths into a generated header.
Chema:
* Grandma rides again!
Jean Br?fort:
* Initial version of gradient editor for chart style page.
......@@ -37,7 +34,8 @@ Jody:
* Fix undo bug for moving merged regions (yummy).
* Support Move with cells flag for sheet object.
* Text in charts.
* Fix lots of chema's bug reports.
* Fix lots of bugs in the run up to a beta.
* Fix undo of defining an existing named expression placeholded
Morten:
* New function COLUMNNUMBER.
......
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/sheet-object.c (sheet_objects_relocate) : kludgy tweak so that
ins/del col/row moves things and cut-n-paste does not.
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/sheet-filter.c (gnm_filter_overlaps_range) : new.
(gnm_filter_contains_row) : delete.
* src/sheet-view.c (sv_first_selection_in_filter) : new.
(sv_edit_pos_in_filter) : delete.
* src/workbook-control-gui.c (wbcg_menu_state_update) : use here.
(cb_auto_filter) : and here.
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/expr-name.c (gnm_named_expr_collection_insert) : ease
requirements and allow active names to be inserted. This is the
majority case for all the places we up/dowgrade placeholders and
change scope.
(expr_name_check_for_loop) : rename from name_refer_circular and make
public.
(expr_name_downgrade_to_placeholder) : new.
(expr_name_set_scope) : no need to diddle ::active now that
collection_insert is less anal.
(expr_name_cmp_by_name) : renamed from expr_name_by_name.
* src/commands.c (cmd_define_name*) : add more checking at the start.
Don't bother keeping a ref to the nexpr.
handle undo for defining an existing placeholder.
2003-06-03 Morten Welinder <terra@gnome.org>
* src/stf-parse.c (stf_parse_lines): New function.
......
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/sheet-object.c (sheet_objects_relocate) : kludgy tweak so that
ins/del col/row moves things and cut-n-paste does not.
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/sheet-filter.c (gnm_filter_overlaps_range) : new.
(gnm_filter_contains_row) : delete.
* src/sheet-view.c (sv_first_selection_in_filter) : new.
(sv_edit_pos_in_filter) : delete.
* src/workbook-control-gui.c (wbcg_menu_state_update) : use here.
(cb_auto_filter) : and here.
2003-06-03 Jody Goldberg <jody@gnome.org>
* src/expr-name.c (gnm_named_expr_collection_insert) : ease
requirements and allow active names to be inserted. This is the
majority case for all the places we up/dowgrade placeholders and
change scope.
(expr_name_check_for_loop) : rename from name_refer_circular and make
public.
(expr_name_downgrade_to_placeholder) : new.
(expr_name_set_scope) : no need to diddle ::active now that
collection_insert is less anal.
(expr_name_cmp_by_name) : renamed from expr_name_by_name.
* src/commands.c (cmd_define_name*) : add more checking at the start.
Don't bother keeping a ref to the nexpr.
handle undo for defining an existing placeholder.
2003-06-03 Morten Welinder <terra@gnome.org>
* src/stf-parse.c (stf_parse_lines): New function.
......
......@@ -5402,8 +5402,8 @@ typedef struct
ParsePos pp;
char *name;
GnmExpr const *expr;
GnmNamedExpr *nexpr;
gboolean create_name;
gboolean new_name;
gboolean placeholder;
} CmdDefineName;
GNUMERIC_MAKE_COMMAND (CmdDefineName, cmd_define_name);
......@@ -5413,17 +5413,16 @@ cmd_define_name_undo (GnumericCommand *cmd,
G_GNUC_UNUSED WorkbookControl *wbc)
{
CmdDefineName *me = CMD_DEFINE_NAME (cmd);
GnmExpr const *expr;
GnmNamedExpr *nexpr = expr_name_lookup (&(me->pp), me->name);
GnmExpr const *expr = nexpr->expr;
expr = me->nexpr->expr;
gnm_expr_ref (expr);
if (me->create_name) {
expr_name_remove (me->nexpr);
expr_name_unref (me->nexpr);
me->nexpr = NULL;
} else
expr_name_set_expr (me->nexpr, me->expr);
if (me->new_name)
expr_name_remove (nexpr);
else if (me->placeholder)
expr_name_downgrade_to_placeholder (nexpr);
else
expr_name_set_expr (nexpr, me->expr); /* restore old def */
me->expr = expr;
return FALSE;
......@@ -5433,23 +5432,26 @@ static gboolean
cmd_define_name_redo (GnumericCommand *cmd, WorkbookControl *wbc)
{
CmdDefineName *me = CMD_DEFINE_NAME (cmd);
GnmNamedExpr *nexpr = expr_name_lookup (&(me->pp), me->name);
me->new_name = (nexpr == NULL);
me->placeholder = (nexpr != NULL)
&& expr_name_is_placeholder (nexpr);
if (me->nexpr == NULL) { /* create a new name */
if (me->new_name || me->placeholder) {
char *err = NULL;
me->nexpr = expr_name_add (&me->pp, me->name, me->expr, &err, TRUE);
if (me->nexpr == NULL) {
nexpr = expr_name_add (&me->pp, me->name, me->expr, &err, TRUE);
if (nexpr == NULL) {
gnumeric_error_invalid (COMMAND_CONTEXT (wbc), _("Name"), err);
g_free (err);
return TRUE;
}
expr_name_ref (me->nexpr);
me->expr = NULL;
} else {/* assigning a value to a placeholder */
GnmExpr const *tmp = me->nexpr->expr;
} else { /* changing the definition */
GnmExpr const *tmp = nexpr->expr;
gnm_expr_ref (tmp);
expr_name_set_expr (me->nexpr, me->expr);
me->expr = tmp;
expr_name_set_expr (nexpr, me->expr);
me->expr = tmp; /* store the old definition */
}
return FALSE;
......@@ -5466,10 +5468,6 @@ cmd_define_name_finalize (GObject *cmd)
gnm_expr_unref (me->expr);
me->expr = NULL;
}
if (me->nexpr != NULL) {
expr_name_unref (me->nexpr);
me->nexpr = NULL;
}
gnumeric_command_finalize (cmd);
}
......@@ -5480,35 +5478,49 @@ cmd_define_name_finalize (GObject *cmd)
* @name :
* @pp :
* @expr : absorbs a ref to the expr.
* @nexpr : an optional named expression to assign the expr to.
* absorb a ref to this too.
*
* If the @name has never been defined in context @pp create a new name
* If its a placeholder assign @expr to it and make it real
* If it already exists as a real name just assign @expr.
*
* Returns TRUE on error
**/
gboolean
cmd_define_name (WorkbookControl *wbc, char const *name, ParsePos const *pp,
GnmExpr const *expr, GnmNamedExpr *nexpr)
cmd_define_name (WorkbookControl *wbc,
char const *name, ParsePos const *pp, GnmExpr const *expr)
{
GObject *obj;
CmdDefineName *me;
GnmNamedExpr *nexpr;
g_return_val_if_fail (name != NULL, TRUE);
g_return_val_if_fail (pp != NULL, TRUE);
g_return_val_if_fail (expr != NULL, TRUE);
if (expr_name_check_for_loop (name, expr)) {
gnumeric_error_invalid (COMMAND_CONTEXT (wbc), name,
_("has a circular reference"));
gnm_expr_unref (expr);
return TRUE;
}
nexpr = expr_name_lookup (pp, name);
if (nexpr != NULL && !expr_name_is_placeholder (nexpr) &&
gnm_expr_equal (expr, nexpr->expr)) {
gnm_expr_unref (expr);
return FALSE; /* expr is not changing, do nothing */
}
obj = g_object_new (CMD_DEFINE_NAME_TYPE, NULL);
me = CMD_DEFINE_NAME (obj);
me->name = g_strdup (name);
me->pp = *pp;
me->expr = expr;
me->nexpr = nexpr;
me->create_name = nexpr == NULL;
if (nexpr != NULL)
expr_name_ref (me->nexpr);
me->cmd.sheet = wb_control_cur_sheet (wbc);
me->cmd.size = 1;
if (me->create_name)
nexpr = expr_name_lookup (pp, name);
if (nexpr == NULL || expr_name_is_placeholder (nexpr))
me->cmd.cmd_descriptor =
g_strdup_printf (_("Define Name %s"), name);
else
......
......@@ -108,8 +108,8 @@ gboolean cmd_merge_data (WorkbookControl *wbc, Sheet *sheet,
gboolean cmd_change_summary (WorkbookControl *wbc, GSList *sin_changes);
gboolean cmd_print_setup (WorkbookControl *wbc, Sheet *sheet, PrintInformation const *pi);
gboolean cmd_define_name (WorkbookControl *wbc, char const *name, ParsePos const *pp,
GnmExpr const *expr, GnmNamedExpr *nexpr);
gboolean cmd_define_name (WorkbookControl *wbc, char const *name,
ParsePos const *pp, GnmExpr const *expr);
typedef enum {
cmd_object_raise_up ,
......
2003-06-03 Jody Goldberg <jody@gnome.org>
* dialog-define-names.c (name_guru_add) : don't freak out with emoty
names.
2003-06-03 Jody Goldberg <jody@gnome.org>
* dialog-define-names.c (name_guru_add) : cmd_define_name is smarter
now we don't need to do any heavy lifting here.
2003-06-02 Jody Goldberg <jody@gnome.org>
* dialog-define-names.c (cb_scope_changed) : handle failure to change
......
......@@ -205,7 +205,7 @@ name_guru_populate_list (NameGuruState *state)
g_list_free (state->expr_names);
state->expr_names =
g_list_sort (sheet_names_get_available (state->sheet),
(GCompareFunc)expr_name_by_name);
(GCompareFunc)expr_name_cmp_by_name);
for (ptr = state->expr_names ; ptr != NULL ; ptr = ptr->next) {
nexpr = ptr->data;
......@@ -317,10 +317,11 @@ name_guru_remove (G_GNUC_UNUSED GtkWidget *ignored,
static gboolean
name_guru_add (NameGuruState *state)
{
GnmNamedExpr *nexpr;
GnmExpr const *expr;
ParseError perr;
ParsePos pp;
ParseError perr;
char const *name;
gboolean res;
g_return_val_if_fail (state != NULL, FALSE);
......@@ -332,6 +333,9 @@ name_guru_add (NameGuruState *state)
expr = gnm_expr_entry_parse (state->expr_entry,
&state->pp, parse_error_init (&perr), FALSE, GNM_EXPR_PARSE_DEFAULT);
if (expr == NULL) {
if (perr.err == NULL)
return TRUE;
gnumeric_notice (state->wbcg, GTK_MESSAGE_ERROR, perr.err->message);
gtk_widget_grab_focus (GTK_WIDGET (state->expr_entry));
parse_error_free (&perr);
......@@ -349,28 +353,18 @@ name_guru_add (NameGuruState *state)
return FALSE;
}
nexpr = expr_name_lookup (&state->pp, name);
if (nexpr) {
/* This means that the expresion was updated.
* FIXME: if the scope has been changed too, call scope
* changed first.
*/
cmd_define_name (WORKBOOK_CONTROL (state->wbcg), name,
&state->pp, expr, nexpr);
} else {
ParsePos pp;
parse_pos_init (&pp, NULL, state->sheet,
state->pp.eval.col, state->pp.eval.row);
if (!name_guru_scope_is_sheet (state))
pp.sheet = NULL;
cmd_define_name (WORKBOOK_CONTROL (state->wbcg), name,
&pp, expr, NULL);
}
parse_pos_init (&pp, NULL, state->sheet,
state->pp.eval.col, state->pp.eval.row);
if (!name_guru_scope_is_sheet (state))
pp.sheet = NULL;
res = !cmd_define_name (WORKBOOK_CONTROL (state->wbcg), name, &pp, expr);
name_guru_populate_list (state);
gtk_widget_grab_focus (GTK_WIDGET (state->name));
if (res) {
name_guru_populate_list (state);
gtk_widget_grab_focus (GTK_WIDGET (state->name));
}
return TRUE;
return res;
}
static void
......
......@@ -88,8 +88,8 @@ static void
gnm_named_expr_collection_insert (GnmNamedExprCollection const *scope,
GnmNamedExpr *nexpr)
{
g_return_if_fail (!nexpr->active);
/* name can be active at this point, eg we are converting a
* placeholder, or changing a scope */
nexpr->active = TRUE;
g_hash_table_replace (nexpr->is_placeholder
? scope->placeholders : scope->names, nexpr->name->str, nexpr);
......@@ -274,8 +274,8 @@ expr_name_new (char const *name, gboolean is_placeholder)
* NB. if we already have a circular reference in addition
* to this one we are checking we will come to serious grief.
*/
static gboolean
name_refer_circular (char const *name, GnmExpr const *expr)
gboolean
expr_name_check_for_loop (char const *name, GnmExpr const *expr)
{
g_return_val_if_fail (expr != NULL, TRUE);
......@@ -283,22 +283,22 @@ name_refer_circular (char const *name, GnmExpr const *expr)
case GNM_EXPR_OP_RANGE_CTOR:
case GNM_EXPR_OP_INTERSECT:
case GNM_EXPR_OP_ANY_BINARY:
return (name_refer_circular (name, expr->binary.value_a) ||
name_refer_circular (name, expr->binary.value_b));
return (expr_name_check_for_loop (name, expr->binary.value_a) ||
expr_name_check_for_loop (name, expr->binary.value_b));
case GNM_EXPR_OP_ANY_UNARY:
return name_refer_circular (name, expr->unary.value);
return expr_name_check_for_loop (name, expr->unary.value);
case GNM_EXPR_OP_NAME: {
GnmNamedExpr const *nexpr = expr->name.name;
if (!strcmp (nexpr->name->str, name))
return TRUE;
/* And look inside this name tree too */
return name_refer_circular (name, nexpr->expr);
return expr_name_check_for_loop (name, nexpr->expr);
}
case GNM_EXPR_OP_FUNCALL: {
GnmExprList *l = expr->func.arg_list;
for (; l ; l = l->next)
if (name_refer_circular (name, l->data))
if (expr_name_check_for_loop (name, l->data))
return TRUE;
break;
}
......@@ -309,7 +309,7 @@ name_refer_circular (char const *name, GnmExpr const *expr)
case GNM_EXPR_OP_SET: {
GnmExprList *l = expr->set.set;
for (; l ; l = l->next)
if (name_refer_circular (name, l->data))
if (expr_name_check_for_loop (name, l->data))
return TRUE;
break;
}
......@@ -348,7 +348,7 @@ expr_name_add (ParsePos const *pp, char const *name,
g_return_val_if_fail (pp->sheet != NULL || pp->wb != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
if (expr != NULL && name_refer_circular (name, expr)) {
if (expr != NULL && expr_name_check_for_loop (name, expr)) {
gnm_expr_unref (expr);
if (error_msg)
*error_msg = g_strdup_printf (_("'%s' has a circular reference"), name);
......@@ -367,7 +367,7 @@ expr_name_add (ParsePos const *pp, char const *name,
}
/* convert the placeholder into a real name */
g_hash_table_remove (scope->placeholders, nexpr->name);
g_hash_table_steal (scope->placeholders, name);
nexpr->is_placeholder = FALSE;
} else {
nexpr = g_hash_table_lookup (scope->names, name);
......@@ -494,6 +494,36 @@ expr_name_eval (GnmNamedExpr const *nexpr, EvalPos const *pos,
return gnm_expr_eval (nexpr->expr, pos, flags);
}
/**
* expr_name_downgrade_to_placeholder:
* @nexpr:
*
* Takes a real non-placeholder name and converts it to being a placeholder.
* unrefing its expression
**/
void
expr_name_downgrade_to_placeholder (GnmNamedExpr *nexpr)
{
GnmNamedExprCollection *scope;
g_return_if_fail (nexpr != NULL);
g_return_if_fail (nexpr->pos.sheet != NULL || nexpr->pos.wb != NULL);
g_return_if_fail (nexpr->active);
g_return_if_fail (!nexpr->is_placeholder);
scope = (nexpr->pos.sheet != NULL)
? nexpr->pos.sheet->names : nexpr->pos.wb->names;
g_return_if_fail (scope != NULL);
g_hash_table_steal (scope->names, nexpr->name->str);
nexpr->is_placeholder = TRUE;
expr_name_set_expr (nexpr,
gnm_expr_new_constant (value_new_error_NAME (NULL)));
gnm_named_expr_collection_insert (scope, nexpr);
}
/*******************************************************************
* Manage things that depend on named expressions.
*/
......@@ -534,7 +564,6 @@ expr_name_set_scope (GnmNamedExpr *nexpr, Sheet *sheet)
nexpr->name->str);
nexpr->pos.sheet = sheet;
nexpr->active = FALSE; /* to placate collection_insert */
gnm_named_expr_collection_insert (*new_scope, nexpr);
return NULL;
}
......@@ -600,7 +629,7 @@ expr_name_is_placeholder (GnmNamedExpr const *nexpr)
}
int
expr_name_by_name (GnmNamedExpr const *a, GnmNamedExpr const *b)
expr_name_cmp_by_name (GnmNamedExpr const *a, GnmNamedExpr const *b)
{
Sheet const *sheeta = a->pos.sheet;
Sheet const *sheetb = b->pos.sheet;
......
......@@ -34,8 +34,10 @@ void expr_name_set_expr (GnmNamedExpr *ne, GnmExpr const *new_expr);
void expr_name_add_dep (GnmNamedExpr *ne, Dependent *dep);
void expr_name_remove_dep (GnmNamedExpr *ne, Dependent *dep);
gboolean expr_name_is_placeholder (GnmNamedExpr const *ne);
void expr_name_downgrade_to_placeholder (GnmNamedExpr *nexpr);
int expr_name_by_name (const GnmNamedExpr *a, const GnmNamedExpr *b);
int expr_name_cmp_by_name (GnmNamedExpr const *a, GnmNamedExpr const *b);
gboolean expr_name_check_for_loop (char const *name, GnmExpr const *expr);
GList *sheet_names_get_available (Sheet const *sheet);
char const *sheet_names_check (Sheet const *sheet, Range const *r);
......
......@@ -322,7 +322,7 @@ sv_menu_enable_insert (SheetView *sv, gboolean col, gboolean row)
/**
* selection_first_range
* @sheet : The sheet whose selection we are testing.
* @sv : The #SheetView whose selection we are testing.
* @wbc : The calling context to report errors to (GUI or corba)
* @command_name : A string naming the operation requiring a single range.
*
......
......@@ -1091,19 +1091,18 @@ gnm_filter_set_condition (GnmFilter *filter, unsigned i,
}
/**
* gnm_filter_contains_row :
* @filter :
* @col :
* gnm_filter_overlaps_range :
* @filter : #GnmFilter
* @r : #Range
*
* We can not use the is_filtered flags because they are only applied when one
* of the fields is active.
* Does the range filter by @filter overlap with Range @r
**/
gboolean
gnm_filter_contains_row (GnmFilter const *filter, int row)
gnm_filter_overlaps_range (GnmFilter const *filter, Range const *r)
{
g_return_val_if_fail (filter != NULL, FALSE);
return (filter->r.start.row <= row && row <= filter->r.end.row);
return range_overlap (&filter->r, r);
}
/**
......
......@@ -54,7 +54,7 @@ GnmFilterCondition const *gnm_filter_get_condition (GnmFilter const *filter, un
void gnm_filter_set_condition (GnmFilter *filter, unsigned i,
GnmFilterCondition *cond,
gboolean apply);
gboolean gnm_filter_contains_row (GnmFilter const *filter, int row);
gboolean gnm_filter_overlaps_range (GnmFilter const *filter, Range const *r);
void sheet_filter_insdel_colrow (Sheet *sheet, gboolean is_cols, gboolean is_insert,
int start, int count);
......
......@@ -762,6 +762,7 @@ sheet_object_position_pts_get (SheetObject const *so, double *coords)
*
* @rinfo : details on what should be moved.
* @update : Should we do the bound_update now, or leave it for later.
* if FALSE honour the move_with_cells flag.
*
* Uses the relocation info and the anchors to decide whether or not, and how
* to relocate objects when the grid moves (eg ins/del col/row).
......@@ -799,7 +800,7 @@ sheet_objects_relocate (GnmExprRelocateInfo const *rinfo, gboolean update)
Range *r = &so->anchor.cell_bound;
next = ptr->next;
if (!so->move_with_cells)
if (!update || !so->move_with_cells)
continue;
if (range_contains (&rinfo->origin,
r->start.col, r->start.row)) {
......
......@@ -580,22 +580,23 @@ fail_if_not_selected (Sheet *sheet, int col, int row, Cell *cell, void *sv)
}
/**
* sv_edit_pos_in_filter :
* sv_first_selection_in_filter :
* @sv :
*
* Is the row in the edit_pos part of an auto filter ?
**/
GnmFilter *
sv_edit_pos_in_filter (SheetView const *sv)
sv_first_selection_in_filter (SheetView const *sv)
{
GSList *ptr;
int row;
Range const *r;
g_return_val_if_fail (IS_SHEET_VIEW (sv), NULL);
g_return_val_if_fail (sv->selections != NULL, NULL);
row = sv->edit_pos.row;
r = sv->selections->data;
for (ptr = sv->sheet->filters; ptr != NULL ; ptr = ptr->next)
if (gnm_filter_contains_row (ptr->data, row))
if (gnm_filter_overlaps_range (ptr->data, r))
return ptr->data;
return NULL;
}
......
......@@ -71,7 +71,7 @@ void sv_update (SheetView *sv);
Sheet *sv_sheet (SheetView const *sv);
WorkbookView *sv_wbv (SheetView const *sv);
gboolean sv_is_frozen (SheetView const *sv);
GnmFilter *sv_edit_pos_in_filter (SheetView const *sv);
GnmFilter *sv_first_selection_in_filter (SheetView const *sv);
gboolean sv_is_region_empty_or_selected (SheetView const *sv,
Range const *r);
......
......@@ -1354,7 +1354,7 @@ wbcg_menu_state_update (WorkbookControl *wbc, int flags)
}
if (MS_ADD_VS_REMOVE_FILTER & flags) {
gboolean const has_filter = (sv_edit_pos_in_filter (sv) != NULL);
gboolean const has_filter = (sv_first_selection_in_filter (sv) != NULL);
char const* label = has_filter
? _("Remove _Auto Filter")
: _("Add _Auto Filter");
......@@ -2803,18 +2803,19 @@ cb_data_shuffle (GtkWidget *widget, WorkbookControlGUI *wbcg)
dialog_shuffle (wbcg);
}
#if 0
static void
cb_data_import_text (GtkWidget *widget, WorkbookControlGUI *wbcg)
{
#warning TODO
}
#endif
static void
cb_auto_filter (GtkWidget *widget, WorkbookControlGUI *wbcg)
{
WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
SheetView *sv = wb_control_cur_sheet_view (wbc);
GnmFilter *filter = sv_edit_pos_in_filter (sv);
GnmFilter *filter = sv_first_selection_in_filter (sv);
if (filter == NULL) {
Range const *src = selection_first_range (sv,
......@@ -2825,7 +2826,7 @@ cb_auto_filter (GtkWidget *widget, WorkbookControlGUI *wbcg)
return;
}
#warning Add undo/redo
gnm_filter_new (sv->sheet, src);
gnm_filter_new (sv->sheet, src);
sheet_update (sv->sheet);
} else {
/* keep distinct to simplify undo/redo later */
......
......@@ -221,7 +221,7 @@ wb_control_parse_and_jump (WorkbookControl *wbc, char const *text)
GnmNamedExpr *nexpr = expr_name_lookup (
parse_pos_init_sheet (&pp, sheet), text);
/* Not a name or a placeholder for a name, create one */
/* If no name, or just a placeholder exists create a name */
if (nexpr == NULL || expr_name_is_placeholder (nexpr)) {
Range const *r = selection_first_range (
wb_control_cur_sheet_view (wbc),
......@@ -240,8 +240,7 @@ wb_control_parse_and_jump (WorkbookControl *wbc, char const *text)
pp.sheet = NULL; /* make it a global name */
target_range = gnm_expr_new_constant (
value_new_cellrange_unsafe (&a, &b));
cmd_define_name (wbc, text, &pp,
target_range, nexpr);
cmd_define_name (wbc, text, &pp, target_range);
}
return FALSE;
} else {
......
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