dialog-define-names.c 16.2 KB
Newer Older
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
Jody Goldberg's avatar
Jody Goldberg committed
2 3 4
/* vim: set sw=8: */
/*
 * dialog-define-name.c: Edit named regions.
Miguel de Icaza's avatar
Miguel de Icaza committed
5 6
 *
 * Author:
7
 * 	Jody Goldberg <jgoldberg@home.com>
Jody Goldberg's avatar
Jody Goldberg committed
8
 *	Michael Meeks <michael@imaginator.com>
9
 *	Chema Celorio <chema@celorio.com>
Jody Goldberg's avatar
Jody Goldberg committed
10
 */
Miguel de Icaza's avatar
Miguel de Icaza committed
11 12
#include <config.h>
#include <gnome.h>
Michael Meeks's avatar
Michael Meeks committed
13
#include <glade/glade.h>
Miguel de Icaza's avatar
Miguel de Icaza committed
14
#include "dialogs.h"
15
#include "expr.h"
16
#include "str.h"
17
#include "expr-name.h"
Jody Goldberg's avatar
Jody Goldberg committed
18
#include "sheet.h"
19
#include "workbook.h"
20
#include "workbook-control.h"
21
#include "workbook-edit.h"
22
#include "gnumeric-util.h"
Jody Goldberg's avatar
Jody Goldberg committed
23
#include "parse-util.h"
24
#include "widgets/gnumeric-expr-entry.h"
Miguel de Icaza's avatar
Miguel de Icaza committed
25

26 27
#define LIST_KEY "name_list_data"

28 29 30 31 32
typedef enum {
	NAME_GURU_SCOPE_SHEET,
	NAME_GURU_SCOPE_WORKBOOK,
} NameGuruScope;

Michael Meeks's avatar
Michael Meeks committed
33 34
typedef struct {
	GladeXML  *gui;
35
	GtkWidget *dialog;
36 37
	GtkList   *list;
	GtkEntry  *name;
38
	GnumericExprEntry *expr_text;
39
	GtkCombo  *scope;
Michael Meeks's avatar
Michael Meeks committed
40
	GList     *expr_names;
41
	NamedExpression *cur_name;
Jody Goldberg's avatar
Jody Goldberg committed
42

43 44 45 46
	GtkWidget *ok_button;
	GtkWidget *add_button;
	GtkWidget *close_button;
	GtkWidget *delete_button;
47
	GtkWidget *update_button;
48

49
	Sheet	  *sheet;
50 51
	Workbook  *wb;
	WorkbookControlGUI  *wbcg;
52 53

	gboolean updating;
54
} NameGuruState;
Michael Meeks's avatar
Michael Meeks committed
55

56 57
/**
 * name_guru_warned_if_used:
58 59
 * @state:
 *
60 61
 * If the expresion that is about to be deleted is beeing used,
 * warn the user about it. Ask if we should procede or not
62
 *
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
 * Return Value: TRUE if users confirms deletion, FALSE otherwise
 **/
static gboolean
name_guru_warn (NameGuruState *state)
{
	static gboolean warned = FALSE;
	if (!warned)
		g_warning ("Implement me !. name_guru_warned_if_used\n");
	warned = TRUE;

	return TRUE;
}

/**
 * name_guru_scope_change:
78 79 80 81
 * @state:
 * @scope:
 *
 * Change the scope of state->cur_name. Ask the user if we want to procede with the
82 83 84 85 86 87 88 89 90 91 92 93 94
 * change if we are going to invalidate expressions in the sheet.
 *
 * Return Value: FALSE, if the user cancels the scope change
 **/
static gboolean
name_guru_scope_change (NameGuruState *state, NameGuruScope scope)
{
	NamedExpression *expression;

	g_return_val_if_fail (state != NULL, FALSE);
	expression = state->cur_name;
	if (expression == NULL)
		return TRUE;
95

96 97 98 99 100 101 102 103
	/* get the current values for the expression */
	if (scope == NAME_GURU_SCOPE_WORKBOOK) {
		expr_name_sheet2wb (expression);
	}

	if (scope == NAME_GURU_SCOPE_SHEET) {
		if (!name_guru_warn (state))
			return FALSE;
104

105 106
		expr_name_wb2sheet (expression, state->sheet);
	}
107

108 109
	return TRUE;
}
110

111 112 113
static void
cb_scope_changed (GtkEntry *entry, NameGuruState *state)
{
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
	NamedExpression *expression;

	if (state->updating)
		return;

	expression = state->cur_name;
	if (expression == NULL)
		return;

	if (!name_guru_scope_change (state,
				     (expression->sheet == NULL) ?
				     NAME_GURU_SCOPE_SHEET :
				     NAME_GURU_SCOPE_WORKBOOK))
		g_print ("Here we toggle the scope back to what it was\n"
			 "The user cancelled the scope change.\n");
129

130 131 132 133 134
}

static void
name_guru_init_scope (NameGuruState *state)
{
135
	NamedExpression *expression;
136 137
	GList *list = NULL;

138 139 140
	expression  = state->cur_name;
	if (expression != NULL && expression->wb) {
		list = g_list_prepend (list, state->sheet->name_unquoted);
141 142 143
		list = g_list_prepend (list, _("Workbook"));
	} else {
		list = g_list_prepend (list, _("Workbook"));
144
		list = g_list_prepend (list, state->sheet->name_unquoted);
145 146 147
	}

	state->cur_name = NULL;
148
	state->updating = TRUE;
149 150
	gtk_combo_set_popdown_strings (state->scope, list);
	g_list_free (list);
151 152
	state->updating = FALSE;
	state->cur_name = expression;
153 154
}

155 156 157 158 159

static void cb_name_guru_select_name (GtkWidget *list, NameGuruState *state);

/**
 * name_guru_set_expr:
160
 * @state:
161
 * @expr_name: Expression to set in the entries, NULL to clear entries
162
 *
163 164 165 166 167 168 169
 * Set the entries in the dialog from an NamedExpression
 **/
static void
name_guru_set_expr (NameGuruState *state, NamedExpression *expr_name)
{
	g_return_if_fail (state != NULL);

170
	/* Don't recur.  */
171
	state->updating = TRUE;
172

173
	if (expr_name) {
174 175
		gchar *txt;

176 177 178
		/* Display the name */
		gtk_entry_set_text (state->name, expr_name->name->str);

Jody Goldberg's avatar
Jody Goldberg committed
179
		/* Display the expr_text */
180
		txt = expr_name_value (expr_name);
181
		gtk_entry_set_text (GTK_ENTRY (state->expr_text), txt);
182 183 184
		g_free (txt);
	} else {
		gtk_entry_set_text (state->name, "");
185
		gtk_entry_set_text (GTK_ENTRY (state->expr_text), "");
186 187 188 189 190 191 192 193 194 195 196 197
	}

	/* unblock them */
	state->updating = FALSE;

	/* Init the scope combo box */
	name_guru_init_scope (state);

}

/**
 * name_guru_clear_selection:
198 199
 * @state:
 *
200 201 202 203 204 205 206 207 208 209 210 211 212 213
 * Clear the selection of the gtklist
 **/
static void
name_guru_clear_selection (NameGuruState *state)
{
	g_return_if_fail (state != NULL);

	state->updating = TRUE;
	gtk_list_unselect_all (state->list);
	state->updating = FALSE;
}

/**
 * name_guru_in_list:
214
 * @name:
215
 * @state:
216
 *
217
 * Given a name, it searches for it inside the list of Names
218
 *
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
 * Return Value: TRUE if name is already defined, FALSE otherwise
 **/
static gboolean
name_guru_in_list (const gchar *name, NameGuruState *state)
{
	NamedExpression *expression;
	GList *list;

	g_return_val_if_fail (name != NULL, FALSE);
	g_return_val_if_fail (state != NULL, FALSE);

	for (list = state->expr_names; list; list = list->next) {
		expression = (NamedExpression *) list->data;
		g_return_val_if_fail (expression != NULL, FALSE);
		g_return_val_if_fail (expression->name != NULL, FALSE);
		g_return_val_if_fail (expression->name->str != NULL, FALSE);
		if (strcasecmp (name, expression->name->str) == 0) {
			return TRUE;
		}
	}

	return FALSE;
}



/**
 * name_guru_update_sensitivity:
247 248 249
 * @state:
 * @update_entries:
 *
250 251 252 253 254 255 256 257 258
 * Update the dialog widgets sensitivity
 **/
static void
name_guru_update_sensitivity (NameGuruState *state, gboolean update_entries)
{
	gboolean selection;
	gboolean update;
	gboolean add;
	gboolean in_list = FALSE;
Jody Goldberg's avatar
Jody Goldberg committed
259 260
	char const *expr_text;
	char const *name;
261 262 263 264 265

	g_return_if_fail (state->list != NULL);

	if (state->updating)
		return;
266

267
	name  = gtk_entry_get_text (state->name);
268
	expr_text = gtk_entry_get_text (GTK_ENTRY (state->expr_text));
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295

	/** Add is active if :
	 *  - We have a name in the entry to add
	 *  - Either we don't have a current Name or if we have a current
	 *     name, the name is different than what we are going to add
	 **/
	add = (name != NULL &&
	       name[0] != '\0' &&
	       !(in_list = name_guru_in_list (name, state)));
	selection = (g_list_length (state->list->selection) > 0);
	update = (name && *name && !add);

	gtk_widget_set_sensitive (state->delete_button, selection && in_list);
	gtk_widget_set_sensitive (state->add_button,    add);
	gtk_widget_set_sensitive (state->update_button, update);

	if (!selection && update_entries)
		name_guru_set_expr (state, NULL);

	if (selection && !in_list)
		name_guru_clear_selection (state);
}



/**
 * name_guru_update_sensitivity_cb:
296 297 298
 * @dummy:
 * @state:
 *
299 300 301 302 303 304 305 306 307
 **/
static void
name_guru_update_sensitivity_cb (GtkWidget *dummy, NameGuruState *state)
{
	name_guru_update_sensitivity (state, FALSE);
}

/**
 * cb_name_guru_select_name:
308 309 310
 * @list:
 * @state:
 *
311 312
 * Set the expression from the selected row in the gtklist
 **/
313
static void
Jody Goldberg's avatar
Jody Goldberg committed
314
cb_name_guru_select_name (GtkWidget *list, NameGuruState *state)
315
{
Jody Goldberg's avatar
Jody Goldberg committed
316 317
	NamedExpression *expr_name;
	GList *sel = GTK_LIST(list)->selection;
318

319
	if (sel == NULL || state->updating)
320 321 322 323
		return;

	g_return_if_fail (sel->data != NULL);

Jody Goldberg's avatar
Jody Goldberg committed
324
	expr_name = gtk_object_get_data (GTK_OBJECT (sel->data), LIST_KEY);
325

326
	g_return_if_fail (expr_name != NULL);
Jody Goldberg's avatar
Jody Goldberg committed
327 328 329
	g_return_if_fail (expr_name->name != NULL);
	g_return_if_fail (expr_name->name->str != NULL);

330 331
	state->cur_name = expr_name;

332 333
	name_guru_set_expr (state, expr_name);
	name_guru_update_sensitivity (state, FALSE);
Jody Goldberg's avatar
Jody Goldberg committed
334

Michael Meeks's avatar
Michael Meeks committed
335 336
}

337

Michael Meeks's avatar
Michael Meeks committed
338
static void
Jody Goldberg's avatar
Jody Goldberg committed
339
name_guru_populate_list (NameGuruState *state)
Michael Meeks's avatar
Michael Meeks committed
340 341
{
	GList *names;
Jody Goldberg's avatar
Jody Goldberg committed
342
	GtkContainer *list;
Michael Meeks's avatar
Michael Meeks committed
343

344 345
	g_return_if_fail (state != NULL);
	g_return_if_fail (state->list != NULL);
Michael Meeks's avatar
Michael Meeks committed
346

347
	state->cur_name = NULL;
Michael Meeks's avatar
Michael Meeks committed
348

Morten Welinder's avatar
Morten Welinder committed
349
	g_list_free (state->expr_names);
350
	state->expr_names = expr_name_list (state->wb, state->sheet, FALSE);
351

352
	list = GTK_CONTAINER (state->list);
353
	for (names = state->expr_names ; names != NULL ; names = g_list_next (names)) {
354
		NamedExpression *expr_name = names->data;
355 356 357 358 359 360 361 362 363
		GtkWidget *li;
		if (expr_name->sheet != NULL) {
			char *name = g_strdup_printf ("%s!%s",
						      expr_name->sheet->name_unquoted,
						      expr_name->name->str);
			li = gtk_list_item_new_with_label (name);
			g_free (name);
		} else
			li = gtk_list_item_new_with_label (expr_name->name->str);
364
		gtk_object_set_data (GTK_OBJECT (li), LIST_KEY, expr_name);
Jody Goldberg's avatar
Jody Goldberg committed
365
		gtk_container_add (list, li);
Michael Meeks's avatar
Michael Meeks committed
366
	}
Jody Goldberg's avatar
Jody Goldberg committed
367
	gtk_widget_show_all (GTK_WIDGET (state->list));
368
	name_guru_update_sensitivity (state, TRUE);
369 370
}

371 372
/**
 * name_guru_scope_get:
373 374
 * @state:
 *
375
 * Get the selected Scope from the combo box
376 377
 *
 * Return Value:
378 379 380 381 382 383 384 385 386
 **/
static NameGuruScope
name_guru_scope_get (NameGuruState *state)
{
	gchar *text;

	text = gtk_entry_get_text (GTK_ENTRY (state->scope->entry));

	g_return_val_if_fail (text != NULL, NAME_GURU_SCOPE_WORKBOOK);
387

388 389 390 391 392 393 394 395 396
	if (strcmp (text, _("Workbook"))==0)
	    return NAME_GURU_SCOPE_WORKBOOK;
	else
	    return NAME_GURU_SCOPE_SHEET;
}


/**
 * cb_name_guru_remove:
397 398 399
 * @ignored:
 * @state:
 *
400 401
 * Remove the state->cur_name
 **/
402
static void
403
cb_name_guru_remove (GtkWidget *ignored, NameGuruState *state)
Michael Meeks's avatar
Michael Meeks committed
404
{
405 406
	g_return_if_fail (state != NULL);

407
	if (state->cur_name != NULL) {
408 409 410 411 412
		if (!name_guru_warn (state))
			return;
		state->expr_names = g_list_remove (state->expr_names, state->cur_name);
		expr_name_remove (state->cur_name);
		state->cur_name = NULL;
413

414 415 416 417
		gtk_list_clear_items (state->list, 0, -1);
		name_guru_populate_list (state);
	} else {
		g_warning ("Why is the delete button sensitive ? ...\n");
Jody Goldberg's avatar
Jody Goldberg committed
418
	}
419

420 421
}

422 423 424

/**
 * cb_name_guru_add:
425 426
 * @state:
 *
427
 * Update or add a NamedExpression from the values in the gtkentries.
428
 *
429 430
 * Return Value: FALSE if the expression was invalid, TRUE otherwise
 **/
431
static gboolean
432
cb_name_guru_add (NameGuruState *state)
433
{
434
	NamedExpression *expr_name;
Jody Goldberg's avatar
Jody Goldberg committed
435
	ParsePos      pos, *pp;
436
	ExprTree *expr;
Jody Goldberg's avatar
Jody Goldberg committed
437
	char const *name, *expr_text, *tmp;
438
	gchar *error;
439 440 441

	g_return_val_if_fail (state != NULL, FALSE);

442
	expr_text = gtk_entry_get_text (GTK_ENTRY (state->expr_text));
443 444 445 446
	name  = gtk_entry_get_text (state->name);

	if (!name || (name[0] == '\0'))
		return TRUE;
447

448 449 450 451
	pp = parse_pos_init (&pos, state->wb, state->sheet, 0, 0);
	/*
	 * expr name uses 0,0 for now.  Figure out what to do with this
	 * eventually.
452 453
			     state->sheet->edit_pos.col,
			     state->sheet->edit_pos.row);
Jody Goldberg's avatar
Jody Goldberg committed
454
         */
Jody Goldberg's avatar
Jody Goldberg committed
455 456 457

	expr_name = expr_name_lookup (pp, name);

Jody Goldberg's avatar
Jody Goldberg committed
458 459 460
	if (NULL != (tmp = gnumeric_char_start_expr_p (expr_text)))
		expr_text = tmp;
	expr = expr_parse_string (expr_text, pp, NULL, &error);
Jody Goldberg's avatar
Jody Goldberg committed
461

Jody Goldberg's avatar
Jody Goldberg committed
462 463
	/* If the expression is invalid */
	if (expr == NULL) {
464
		gnumeric_notice (state->wbcg, GNOME_MESSAGE_BOX_ERROR, error);
Jody Goldberg's avatar
Jody Goldberg committed
465
		gtk_widget_grab_focus (GTK_WIDGET (state->expr_text));
Jody Goldberg's avatar
Jody Goldberg committed
466 467
		return FALSE;
	} else if (expr_name) {
Jody Goldberg's avatar
Jody Goldberg committed
468
		if (!expr_name->builtin) {
469 470
			/* This means that the expresion was updated updated.
			 * FIXME: if the scope has been changed too, call scope
471
			 * chaned first.
472
			 */
Jody Goldberg's avatar
Jody Goldberg committed
473 474
			expr_tree_unref (expr_name->t.expr_tree);
			expr_name->t.expr_tree = expr;
475
		} else
476
			gnumeric_notice (state->wbcg, GNOME_MESSAGE_BOX_ERROR,
Morten Welinder's avatar
Morten Welinder committed
477
					 _("You cannot redefine a builtin name."));
478 479 480 481 482 483
	} else {
		if (name_guru_scope_get (state) == NAME_GURU_SCOPE_WORKBOOK)
			expr_name = expr_name_add (state->wb, NULL, name, expr, &error);
		else
			expr_name = expr_name_add (NULL, state->sheet, name, expr, &error);
	}
484

Jody Goldberg's avatar
Jody Goldberg committed
485
	g_return_val_if_fail (expr_name != NULL, FALSE);
486

487
	gtk_list_clear_items (state->list, 0, -1);
Jody Goldberg's avatar
Jody Goldberg committed
488
	name_guru_populate_list (state);
489
	gtk_widget_grab_focus (GTK_WIDGET (state->name));
490 491 492 493 494

	return TRUE;
}

static void
495
cb_name_guru_clicked (GtkWidget *button, NameGuruState *state)
496
{
497 498 499
	if (state->dialog == NULL)
		return;

500
	workbook_set_entry (state->wbcg, NULL);
501

502
	if (button == state->delete_button) {
503
		cb_name_guru_remove (NULL, state);
504 505 506
		return;
	}

507 508 509 510 511
	if (button == state->add_button ||
	    button == state->update_button ||
	    button == state->ok_button) {
		/* If adding the name failed, do not exit */
		if (!cb_name_guru_add (state)) {
Jody Goldberg's avatar
Jody Goldberg committed
512
			return;
513 514
		}
	}
515

516
	if (button == state->close_button || button == state->ok_button) {
517
		gtk_widget_destroy (state->dialog);
518 519
		return;
	}
520

521 522
}

523 524
static GtkWidget *
name_guru_init_button (NameGuruState *state, char const *name)
525
{
526
	GtkWidget *tmp = glade_xml_get_widget (state->gui, name);
527 528

	g_return_val_if_fail (tmp != NULL, NULL);
529

530 531 532 533
	gtk_signal_connect (GTK_OBJECT (tmp), "clicked",
			    GTK_SIGNAL_FUNC (cb_name_guru_clicked),
			    state);
	return tmp;
534 535
}

536 537
static gboolean
cb_name_guru_destroy (GtkObject *w, NameGuruState *state)
538
{
539 540 541
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (state != NULL, FALSE);

542
	workbook_edit_detach_guru (state->wbcg);
543 544 545 546 547 548

	if (state->gui != NULL) {
		gtk_object_unref (GTK_OBJECT (state->gui));
		state->gui = NULL;
	}

549
	workbook_finish_editing (state->wbcg, FALSE);
550 551 552

	state->dialog = NULL;

Morten Welinder's avatar
Morten Welinder committed
553 554 555
	g_list_free (state->expr_names);
	state->expr_names = NULL;

556
	g_free (state);
557

558
	return FALSE;
559 560
}

561 562 563 564 565 566 567 568 569 570 571 572
static void
cb_name_guru_set_focus (GtkWidget *window, GtkWidget *focus_widget,
		 NameGuruState *state)
{
	if (GNUMERIC_IS_EXPR_ENTRY (focus_widget)) {
		workbook_set_entry (state->wbcg,
				    GNUMERIC_EXPR_ENTRY (focus_widget));
		gnumeric_expr_entry_set_absolute (state->expr_text);
	} else
		workbook_set_entry (state->wbcg, NULL);
}

573
static gboolean
574
name_guru_init (NameGuruState *state, WorkbookControlGUI *wbcg)
575
{
576
	Workbook *wb = wb_control_workbook (WORKBOOK_CONTROL (wbcg));
577
	GtkTable *table2;
578 579 580 581 582

	state->wbcg  = wbcg;
	state->wb   = wb;
	state->sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (wbcg));
	state->gui = gnumeric_glade_xml_new (state->wbcg, "names.glade");
583 584 585
        if (state->gui == NULL)
                return TRUE;

586
	state->dialog = glade_xml_get_widget (state->gui, "NameGuru");
587
	table2 = GTK_TABLE (glade_xml_get_widget (state->gui, "table2"));
588
	state->name  = GTK_ENTRY (glade_xml_get_widget (state->gui, "name"));
589 590 591 592 593 594
	state->expr_text = GNUMERIC_EXPR_ENTRY (gnumeric_expr_entry_new ());
	gtk_table_attach (table2, GTK_WIDGET (state->expr_text),
			  1, 2, 1, 2,
			  GTK_EXPAND | GTK_FILL, 0,
			  0, 0);
	gtk_widget_show (GTK_WIDGET (state->expr_text));
595
	state->scope = GTK_COMBO (glade_xml_get_widget (state->gui, "scope_combo"));
596 597
	state->list  = GTK_LIST  (glade_xml_get_widget (state->gui, "name_list"));
	state->expr_names = NULL;
598
	state->cur_name   = NULL;
599
	state->updating   = FALSE;
600 601 602 603 604

	/* Init the scope combo box */
	name_guru_init_scope (state);
	gtk_signal_connect (GTK_OBJECT (state->scope->entry), "changed",
			    GTK_SIGNAL_FUNC (cb_scope_changed), state);
605

606 607 608
	state->ok_button     = name_guru_init_button (state, "ok_button");
	state->close_button  = name_guru_init_button (state, "close_button");
	state->add_button    = name_guru_init_button (state, "add_button");
609
	state->delete_button = name_guru_init_button (state, "delete_button");
610
	state->update_button = name_guru_init_button (state, "update_button");
611 612

	gtk_signal_connect (GTK_OBJECT (state->list), "selection_changed",
613
			    GTK_SIGNAL_FUNC (cb_name_guru_select_name), state);
614 615
	gtk_signal_connect (GTK_OBJECT (state->dialog), "set-focus",
			    GTK_SIGNAL_FUNC (cb_name_guru_set_focus), state);
616
	gtk_signal_connect (GTK_OBJECT (state->dialog), "destroy",
Jody Goldberg's avatar
Jody Goldberg committed
617
			    GTK_SIGNAL_FUNC (cb_name_guru_destroy), state);
618 619
	gtk_signal_connect (GTK_OBJECT (state->name), "changed",
			    GTK_SIGNAL_FUNC (name_guru_update_sensitivity_cb), state);
620 621 622
	/* We need to connect after because this is an expresion, and it will
	 * be changed by the mouse selecting a range, update after the entry
	 * is updated with the new text.
623
	 */
Jody Goldberg's avatar
Jody Goldberg committed
624
	gtk_signal_connect_after (GTK_OBJECT (state->expr_text), "changed",
625
				  GTK_SIGNAL_FUNC (name_guru_update_sensitivity_cb), state);
626

Jody Goldberg's avatar
Jody Goldberg committed
627 628 629
 	gnumeric_editable_enters (GTK_WINDOW (state->dialog),
				  GTK_EDITABLE(state->name));
 	gnumeric_editable_enters (GTK_WINDOW (state->dialog),
Jody Goldberg's avatar
Jody Goldberg committed
630
				  GTK_EDITABLE (state->expr_text));
631 632
	gnumeric_combo_enters (GTK_WINDOW (state->dialog),
			       state->scope);
633
	gnumeric_non_modal_dialog (state->wbcg, GTK_WINDOW (state->dialog));
634

635 636
	gnumeric_expr_entry_set_scg (state->expr_text,
				     wb_control_gui_cur_sheet (wbcg));
637
	workbook_edit_attach_guru (state->wbcg, state->dialog);
638 639

	return FALSE;
Michael Meeks's avatar
Michael Meeks committed
640 641
}

642 643
/**
 * dialog_define_names:
644 645
 * @wbcg:
 *
646 647
 * Create and show the define names dialog.
 **/
Miguel de Icaza's avatar
Miguel de Icaza committed
648
void
649
dialog_define_names (WorkbookControlGUI *wbcg)
Miguel de Icaza's avatar
Miguel de Icaza committed
650
{
651
	NameGuruState *state;
Michael Meeks's avatar
Michael Meeks committed
652

653
	g_return_if_fail (wbcg != NULL);
Michael Meeks's avatar
Michael Meeks committed
654

655
	state = g_new (NameGuruState, 1);
656
	if (name_guru_init (state, wbcg)) {
657 658
		gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR,
				 _("Could not create the Name Guru."));
659
		g_free (state);
Michael Meeks's avatar
Michael Meeks committed
660 661 662
		return;
	}

Jody Goldberg's avatar
Jody Goldberg committed
663
	name_guru_populate_list (state);
664
	gtk_widget_show (state->dialog);
Miguel de Icaza's avatar
Miguel de Icaza committed
665
}