[gnumeric] Redesign define-named-expressions dialog. [#465840]



commit bdabf981bffd94125677af5785f83ddc6654213a
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Jun 3 00:14:46 2010 -0600

    Redesign define-named-expressions dialog. [#465840]
    
    2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* define-name.glade: simplify
    	* dialog-define-names.c: rewrite in its entirety

 NEWS                              |    3 +-
 src/dialogs/ChangeLog             |    5 +
 src/dialogs/define-name.glade     |  653 ++++-------------------
 src/dialogs/dialog-define-names.c | 1055 +++++++++++++++++++++++--------------
 4 files changed, 764 insertions(+), 952 deletions(-)
---
diff --git a/NEWS b/NEWS
index 3f0e387..5db5068 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,8 @@ Gnumeric 1.10.6
 
 Andreas:
 	* Add Wilcoxon Signed Rank Test tools for one and two populations.
-	* Fix spin button handling in various tool dialogs. [#619971] 
+	* Fix spin button handling in various tool dialogs. [#619971]
+	* Redesign define-named-expressions dialog. [#465840] 
 
 Jean:
 	* Do not ungrab a not grabbed item. [#620369]
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 6367698..e6069df 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,8 @@
+2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* define-name.glade: simplify
+	* dialog-define-names.c: rewrite in its entirety
+
 2010-06-02  Morten Welinder  <terra gnome org>
 
 	* dialog-solver.c (cb_timer_tick): Use gnm_solver_elapsed.
diff --git a/src/dialogs/define-name.glade b/src/dialogs/define-name.glade
index 5481423..90b3857 100644
--- a/src/dialogs/define-name.glade
+++ b/src/dialogs/define-name.glade
@@ -1,550 +1,107 @@
-<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
-<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd";>
-
+<?xml version="1.0"?>
 <glade-interface>
-
-<widget class="GtkDialog" id="NameGuru">
-  <property name="border_width">5</property>
-  <property name="title" translatable="yes">Define Names</property>
-  <property name="type">GTK_WINDOW_TOPLEVEL</property>
-  <property name="window_position">GTK_WIN_POS_NONE</property>
-  <property name="modal">False</property>
-  <property name="default_width">475</property>
-  <property name="default_height">300</property>
-  <property name="resizable">True</property>
-  <property name="destroy_with_parent">False</property>
-  <property name="decorated">True</property>
-  <property name="skip_taskbar_hint">False</property>
-  <property name="skip_pager_hint">False</property>
-  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
-  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
-  <property name="focus_on_map">True</property>
-  <property name="has_separator">False</property>
-
-  <child internal-child="vbox">
-    <widget class="GtkVBox" id="vbox1">
-      <property name="visible">True</property>
-      <property name="homogeneous">False</property>
-      <property name="spacing">2</property>
-
-      <child internal-child="action_area">
-	<widget class="GtkHButtonBox" id="hbuttonbox1">
-	  <property name="visible">True</property>
-	  <property name="layout_style">GTK_BUTTONBOX_END</property>
-
-	  <child>
-	    <widget class="GtkButton" id="close_button">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-close</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <property name="response_id">0</property>
-	    </widget>
-	  </child>
-
-	  <child>
-	    <widget class="GtkButton" id="help_button">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-help</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <property name="response_id">-11</property>
-	    </widget>
-	  </child>
-
-	  <child>
-	    <widget class="GtkButton" id="ok_button">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-ok</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <property name="response_id">-5</property>
-	    </widget>
-	  </child>
-	</widget>
-	<packing>
-	  <property name="padding">0</property>
-	  <property name="expand">False</property>
-	  <property name="fill">False</property>
-	  <property name="pack_type">GTK_PACK_END</property>
-	</packing>
-      </child>
-
-      <child>
-	<widget class="GtkVBox" id="vbox2">
-	  <property name="border_width">5</property>
-	  <property name="visible">True</property>
-	  <property name="homogeneous">False</property>
-	  <property name="spacing">18</property>
-
-	  <child>
-	    <widget class="GtkTable" id="table1">
-	      <property name="visible">True</property>
-	      <property name="n_rows">2</property>
-	      <property name="n_columns">2</property>
-	      <property name="homogeneous">False</property>
-	      <property name="row_spacing">6</property>
-	      <property name="column_spacing">0</property>
-
-	      <child>
-		<widget class="GtkLabel" id="label1">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">&lt;b&gt;Available Names&lt;/b&gt;</property>
-		  <property name="use_underline">False</property>
-		  <property name="use_markup">True</property>
-		  <property name="justify">GTK_JUSTIFY_LEFT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">0</property>
-		  <property name="ypad">0</property>
-		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		  <property name="width_chars">-1</property>
-		  <property name="single_line_mode">False</property>
-		  <property name="angle">0</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">2</property>
-		  <property name="top_attach">0</property>
-		  <property name="bottom_attach">1</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkLabel" id="label2">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">    </property>
-		  <property name="use_underline">False</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_LEFT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">0</property>
-		  <property name="ypad">0</property>
-		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		  <property name="width_chars">-1</property>
-		  <property name="single_line_mode">False</property>
-		  <property name="angle">0</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options">fill</property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkHBox" id="hbox1">
-		  <property name="visible">True</property>
-		  <property name="homogeneous">False</property>
-		  <property name="spacing">6</property>
-
-		  <child>
-		    <widget class="GtkScrolledWindow" id="scrolledwindow1">
-		      <property name="height_request">120</property>
-		      <property name="visible">True</property>
-		      <property name="can_focus">True</property>
-		      <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
-		      <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
-		      <property name="shadow_type">GTK_SHADOW_IN</property>
-		      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
-
-		      <child>
-			<widget class="GtkTreeView" id="name_list">
-			  <property name="visible">True</property>
-			  <property name="can_focus">True</property>
-			  <property name="headers_visible">False</property>
-			  <property name="rules_hint">False</property>
-			  <property name="reorderable">True</property>
-			  <property name="enable_search">True</property>
-			  <property name="fixed_height_mode">False</property>
-			  <property name="hover_selection">False</property>
-			  <property name="hover_expand">False</property>
-			</widget>
-		      </child>
-		    </widget>
-		    <packing>
-		      <property name="padding">0</property>
-		      <property name="expand">True</property>
-		      <property name="fill">True</property>
-		    </packing>
-		  </child>
-
-		  <child>
-		    <widget class="GtkAlignment" id="alignment1">
-		      <property name="visible">True</property>
-		      <property name="xalign">0.5</property>
-		      <property name="yalign">0.5</property>
-		      <property name="xscale">0</property>
-		      <property name="yscale">1</property>
-		      <property name="top_padding">0</property>
-		      <property name="bottom_padding">0</property>
-		      <property name="left_padding">0</property>
-		      <property name="right_padding">0</property>
-
-		      <child>
-			<widget class="GtkVBox" id="vbox3">
-			  <property name="visible">True</property>
-			  <property name="homogeneous">False</property>
-			  <property name="spacing">6</property>
-
-			  <child>
-			    <widget class="GtkButton" id="add_button">
-			      <property name="visible">True</property>
-			      <property name="can_focus">True</property>
-			      <property name="label">gtk-add</property>
-			      <property name="use_stock">True</property>
-			      <property name="relief">GTK_RELIEF_NORMAL</property>
-			      <property name="focus_on_click">True</property>
-			    </widget>
-			    <packing>
-			      <property name="padding">0</property>
-			      <property name="expand">False</property>
-			      <property name="fill">False</property>
-			    </packing>
-			  </child>
-
-			  <child>
-			    <widget class="GtkButton" id="delete_button">
-			      <property name="visible">True</property>
-			      <property name="can_focus">True</property>
-			      <property name="label">gtk-remove</property>
-			      <property name="use_stock">True</property>
-			      <property name="relief">GTK_RELIEF_NORMAL</property>
-			      <property name="focus_on_click">True</property>
-			    </widget>
-			    <packing>
-			      <property name="padding">0</property>
-			      <property name="expand">False</property>
-			      <property name="fill">False</property>
-			    </packing>
-			  </child>
-
-			  <child>
-			    <widget class="GtkButton" id="update_button">
-			      <property name="visible">True</property>
-			      <property name="can_focus">True</property>
-			      <property name="label" translatable="yes">_Update</property>
-			      <property name="use_underline">True</property>
-			      <property name="relief">GTK_RELIEF_NORMAL</property>
-			      <property name="focus_on_click">True</property>
-			    </widget>
-			    <packing>
-			      <property name="padding">0</property>
-			      <property name="expand">False</property>
-			      <property name="fill">False</property>
-			    </packing>
-			  </child>
-
-			  <child>
-                              <widget class="GtkButton" id="switchscope_button">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="label" translatable="yes">Switch _Scope</property>
-                                <property name="use_underline">True</property>
-                                <property name="relief">GTK_RELIEF_NORMAL</property>
-                                <property name="focus_on_click">True</property>
-                              </widget>
-                              <packing>
-                                <property name="padding">0</property>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                              </packing>
-                          </child>
-			</widget>
-		      </child>
-		    </widget>
-		    <packing>
-		      <property name="padding">0</property>
-		      <property name="expand">False</property>
-		      <property name="fill">False</property>
-		    </packing>
-		  </child>
-		</widget>
-		<packing>
-		  <property name="left_attach">1</property>
-		  <property name="right_attach">2</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		</packing>
-	      </child>
-	    </widget>
-	    <packing>
-	      <property name="padding">0</property>
-	      <property name="expand">True</property>
-	      <property name="fill">True</property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="GtkTable" id="table2">
-	      <property name="visible">True</property>
-	      <property name="n_rows">2</property>
-	      <property name="n_columns">2</property>
-	      <property name="homogeneous">False</property>
-	      <property name="row_spacing">6</property>
-	      <property name="column_spacing">0</property>
-
-	      <child>
-		<widget class="GtkLabel" id="label5">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">&lt;b&gt;Definition&lt;/b&gt;</property>
-		  <property name="use_underline">False</property>
-		  <property name="use_markup">True</property>
-		  <property name="justify">GTK_JUSTIFY_LEFT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">0</property>
-		  <property name="ypad">0</property>
-		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		  <property name="width_chars">-1</property>
-		  <property name="single_line_mode">False</property>
-		  <property name="angle">0</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">2</property>
-		  <property name="top_attach">0</property>
-		  <property name="bottom_attach">1</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkLabel" id="label6">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">    </property>
-		  <property name="use_underline">False</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_LEFT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">0</property>
-		  <property name="ypad">0</property>
-		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		  <property name="width_chars">-1</property>
-		  <property name="single_line_mode">False</property>
-		  <property name="angle">0</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkTable" id="definition_table">
-		  <property name="visible">True</property>
-		  <property name="n_rows">4</property>
-		  <property name="n_columns">2</property>
-		  <property name="homogeneous">False</property>
-		  <property name="row_spacing">6</property>
-		  <property name="column_spacing">12</property>
-
-		  <child>
-		    <widget class="GtkLabel" id="label7">
-		      <property name="visible">True</property>
-		      <property name="label" translatable="yes">_Name: </property>
-		      <property name="use_underline">True</property>
-		      <property name="use_markup">False</property>
-		      <property name="justify">GTK_JUSTIFY_CENTER</property>
-		      <property name="wrap">False</property>
-		      <property name="selectable">False</property>
-		      <property name="xalign">0</property>
-		      <property name="yalign">0.5</property>
-		      <property name="xpad">0</property>
-		      <property name="ypad">0</property>
-		      <property name="mnemonic_widget">name</property>
-		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		      <property name="width_chars">-1</property>
-		      <property name="single_line_mode">False</property>
-		      <property name="angle">0</property>
-		    </widget>
-		    <packing>
-		      <property name="left_attach">0</property>
-		      <property name="right_attach">1</property>
-		      <property name="top_attach">0</property>
-		      <property name="bottom_attach">1</property>
-		      <property name="x_options">fill</property>
-		      <property name="y_options"></property>
-		    </packing>
-		  </child>
-
-		  <child>
-		    <widget class="GtkEntry" id="name">
-		      <property name="visible">True</property>
-		      <property name="can_focus">True</property>
-		      <property name="has_focus">True</property>
-		      <property name="editable">True</property>
-		      <property name="visibility">True</property>
-		      <property name="max_length">0</property>
-		      <property name="text" translatable="yes"></property>
-		      <property name="has_frame">True</property>
-		      <property name="invisible_char">*</property>
-		      <property name="activates_default">False</property>
-		    </widget>
-		    <packing>
-		      <property name="left_attach">1</property>
-		      <property name="right_attach">2</property>
-		      <property name="top_attach">0</property>
-		      <property name="bottom_attach">1</property>
-		      <property name="y_options"></property>
-		    </packing>
-		  </child>
-
-		  <child>
-		    <widget class="GtkLabel" id="label8">
-		      <property name="visible">True</property>
-		      <property name="label" translatable="yes">_Expression: </property>
-		      <property name="use_underline">True</property>
-		      <property name="use_markup">False</property>
-		      <property name="justify">GTK_JUSTIFY_CENTER</property>
-		      <property name="wrap">False</property>
-		      <property name="selectable">False</property>
-		      <property name="xalign">0</property>
-		      <property name="yalign">0.5</property>
-		      <property name="xpad">0</property>
-		      <property name="ypad">0</property>
-		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		      <property name="width_chars">-1</property>
-		      <property name="single_line_mode">False</property>
-		      <property name="angle">0</property>
-		    </widget>
-		    <packing>
-		      <property name="left_attach">0</property>
-		      <property name="right_attach">1</property>
-		      <property name="top_attach">1</property>
-		      <property name="bottom_attach">2</property>
-		      <property name="x_options">fill</property>
-		      <property name="y_options"></property>
-		    </packing>
-		  </child>
-
-		  <child>
-		    <widget class="GtkLabel" id="label9">
-		      <property name="visible">True</property>
-		      <property name="label" translatable="yes">_Scope:</property>
-		      <property name="use_underline">True</property>
-		      <property name="use_markup">False</property>
-		      <property name="justify">GTK_JUSTIFY_CENTER</property>
-		      <property name="wrap">False</property>
-		      <property name="selectable">False</property>
-		      <property name="xalign">0</property>
-		      <property name="yalign">0.5</property>
-		      <property name="xpad">0</property>
-		      <property name="ypad">0</property>
-		      <property name="mnemonic_widget">workbook_scope</property>
-		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		      <property name="width_chars">-1</property>
-		      <property name="single_line_mode">False</property>
-		      <property name="angle">0</property>
-		    </widget>
-		    <packing>
-		      <property name="left_attach">0</property>
-		      <property name="right_attach">1</property>
-		      <property name="top_attach">2</property>
-		      <property name="bottom_attach">3</property>
-		      <property name="x_options">fill</property>
-		      <property name="y_options"></property>
-		    </packing>
-		  </child>
-
-		  <child>
-		    <widget class="GtkRadioButton" id="workbook_scope">
-		      <property name="visible">True</property>
-		      <property name="can_focus">True</property>
-		      <property name="label" translatable="yes">Workbook</property>
-		      <property name="use_underline">True</property>
-		      <property name="relief">GTK_RELIEF_NORMAL</property>
-		      <property name="focus_on_click">True</property>
-		      <property name="active">False</property>
-		      <property name="inconsistent">False</property>
-		      <property name="draw_indicator">True</property>
-		    </widget>
-		    <packing>
-		      <property name="left_attach">1</property>
-		      <property name="right_attach">2</property>
-		      <property name="top_attach">2</property>
-		      <property name="bottom_attach">3</property>
-		      <property name="x_options">fill</property>
-		      <property name="y_options"></property>
-		    </packing>
-		  </child>
-
-		  <child>
-		    <widget class="GtkRadioButton" id="sheet_scope">
-		      <property name="visible">True</property>
-		      <property name="can_focus">True</property>
-		      <property name="label" translatable="yes"></property>
-		      <property name="use_underline">True</property>
-		      <property name="relief">GTK_RELIEF_NORMAL</property>
-		      <property name="focus_on_click">True</property>
-		      <property name="active">False</property>
-		      <property name="inconsistent">False</property>
-		      <property name="draw_indicator">True</property>
-		      <property name="group">workbook_scope</property>
-		    </widget>
-		    <packing>
-		      <property name="left_attach">1</property>
-		      <property name="right_attach">2</property>
-		      <property name="top_attach">3</property>
-		      <property name="bottom_attach">4</property>
-		      <property name="x_options">fill</property>
-		      <property name="y_options"></property>
-		    </packing>
-		  </child>
-		</widget>
-		<packing>
-		  <property name="left_attach">1</property>
-		  <property name="right_attach">2</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="y_options">fill</property>
-		</packing>
-	      </child>
-	    </widget>
-	    <packing>
-	      <property name="padding">0</property>
-	      <property name="expand">False</property>
-	      <property name="fill">True</property>
-	    </packing>
-	  </child>
-	</widget>
-	<packing>
-	  <property name="padding">0</property>
-	  <property name="expand">True</property>
-	  <property name="fill">True</property>
-	</packing>
-      </child>
-    </widget>
-  </child>
-</widget>
-
+  <!-- interface-requires gtk+ 2.6 -->
+  <!-- interface-naming-policy toplevel-contextual -->
+  <widget class="GtkDialog" id="NameGuru">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Define Names</property>
+    <property name="default_width">475</property>
+    <property name="default_height">300</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="vbox1">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkScrolledWindow" id="scrolledwindow1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">automatic</property>
+            <property name="vscrollbar_policy">automatic</property>
+            <property name="shadow_type">in</property>
+            <child>
+              <widget class="GtkTreeView" id="name_list">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="headers_visible">False</property>
+                <property name="reorderable">True</property>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="padding">5</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkHSeparator" id="hseparator1">
+            <property name="visible">True</property>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="hbuttonbox1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <widget class="GtkButton" id="help_button">
+                <property name="label">gtk-help</property>
+                <property name="response_id">-11</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="close_button">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="paste_button">
+                <property name="label">gtk-paste</property>
+                <property name="response_id">-5</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
 </glade-interface>
diff --git a/src/dialogs/dialog-define-names.c b/src/dialogs/dialog-define-names.c
index b4e1149..36b9bf1 100644
--- a/src/dialogs/dialog-define-names.c
+++ b/src/dialogs/dialog-define-names.c
@@ -7,6 +7,7 @@
  *	Jody Goldberg <jody gnome org>
  *	Michael Meeks <michael ximian com>
  *	Chema Celorio <chema celorio com>
+ *      Andreas J. Guelzow <aguelzow pyrshep ca>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -41,6 +42,8 @@
 #include <parse-util.h>
 #include <commands.h>
 #include <widgets/gnumeric-expr-entry.h>
+#include <widgets/gnumeric-cell-renderer-expr-entry.h>
+#include <widgets/gnumeric-cell-renderer-toggle.h>
 
 #include <glade/glade.h>
 #include <gtk/gtk.h>
@@ -52,34 +55,70 @@ typedef struct {
 	GladeXML		*gui;
 	GtkWidget		*dialog;
 	GtkWidget		*treeview;
-	GtkListStore		*model;
-	GtkTreeSelection	*selection;
-	GtkEntry		*name;
-	GnmExprEntry		*expr_entry;
-	GtkToggleButton		*sheet_scope, *wb_scope;
-
-	GtkWidget *ok_button;
-	GtkWidget *add_button;
+	GtkTreeStore		*model;
+
 	GtkWidget *close_button;
-	GtkWidget *delete_button;
-	GtkWidget *update_button;
-	GtkWidget *switchscope_button;
+	GtkWidget *paste_button;
 
 	Sheet			*sheet;
 	SheetView		*sv;
 	Workbook		*wb;
-	WBCGtk	*wbcg;
-	GList			*expr_names;
-	GnmNamedExpr		*cur_name;
+	WBCGtk	                *wbcg;
 	GnmParsePos		 pp;
-	gboolean		 updating;
-	gboolean                 action_possible;
+
+	GdkPixbuf               *image_add;
+	GdkPixbuf               *image_delete;
+	GdkPixbuf               *image_lock;
+	GdkPixbuf               *image_up;
+	GdkPixbuf               *image_down;
+
 } NameGuruState;
 
-static gboolean
-name_guru_scope_is_sheet (NameGuruState *state)
+enum {
+	ITEM_NAME,
+	ITEM_NAME_POINTER,
+	ITEM_CONTENT,
+	ITEM_TYPE,
+	ITEM_CONTENT_IS_EDITABLE,
+	ITEM_NAME_IS_EDITABLE,
+	ITEM_UPDOWN_IMAGE,
+	ITEM_ADDDELETE_IMAGE,
+	ITEM_UPDOWN_ACTIVE,
+	ITEM_ADDDELETE_ACTIVE,
+	NUM_COLMNS
+};
+
+typedef enum {
+	item_type_workbook = 0,
+	item_type_main_sheet,
+	item_type_other_sheet,
+	item_type_locked_name,
+	item_type_available_wb_name,
+	item_type_available_sheet_name,
+	item_type_foreign_name,
+	item_type_new_unsaved_wb_name,
+	item_type_new_unsaved_sheet_name,
+} item_type_t;
+
+/**
+ * name_guru_expand_at_iter:
+ * @state:
+ * @iter:
+ *
+ * expand the treeview at the given iter. 
+ *
+ **/
+static void
+name_guru_expand_at_iter (NameGuruState *state, GtkTreeIter *iter)
 {
-	return gtk_toggle_button_get_active (state->sheet_scope);
+	GtkTreePath *path;
+
+	path = gtk_tree_model_get_path 
+		(GTK_TREE_MODEL (state->model), iter);
+	gtk_tree_view_expand_to_path 
+		(GTK_TREE_VIEW (state->treeview), path);
+	gtk_tree_path_free (path);	
+
 }
 
 /**
@@ -91,452 +130,630 @@ name_guru_scope_is_sheet (NameGuruState *state)
  *
  * Return Value: TRUE if users confirms deletion, FALSE otherwise
  **/
+
 static gboolean
 name_guru_warn (G_GNUC_UNUSED NameGuruState *state)
 {
+#warning Implement me!
 	return TRUE;
 }
 
 static void
-name_guru_display_scope (NameGuruState *state)
+cb_get_names (G_GNUC_UNUSED gpointer key, GnmNamedExpr *nexpr,
+	      GList **accum)
 {
-	GnmNamedExpr const *nexpr = state->cur_name;
-
-	state->updating = TRUE;
-	if (nexpr == NULL || nexpr->pos.sheet == NULL)
-		gtk_toggle_button_set_active (state->wb_scope, TRUE);
-	else
-		gtk_toggle_button_set_active (state->sheet_scope, TRUE);
-	state->updating = FALSE;
+	if (!nexpr->is_hidden)
+		*accum = g_list_prepend (*accum, nexpr);
 }
 
-/*
- * use_sheet_scope: look only at sheet scope names
- * not use_sheet_scope: look only at workbook scope names
- *
- */
-
-static GnmNamedExpr *
-name_guru_in_list (NameGuruState *state, char const *name,
-		   gboolean ignore_placeholders,
-		   gboolean use_sheet_scope)
+static GList *
+name_guru_get_available_sheet_names (Sheet const *sheet)
 {
-	GnmNamedExpr *nexpr;
-	GList *list;
-
-	for (list = state->expr_names; list; list = list->next) {
-		nexpr = (GnmNamedExpr *) list->data;
+	GList *res = NULL;
 
-		g_return_val_if_fail (nexpr != NULL, NULL);
-		g_return_val_if_fail (nexpr->name != NULL, NULL);
-		g_return_val_if_fail (expr_name_name (nexpr) != NULL, NULL);
-
-		if (ignore_placeholders && expr_name_is_placeholder (nexpr))
-			continue;
-		if ((nexpr->pos.sheet == NULL) == use_sheet_scope)
-			continue;
+	gnm_sheet_foreach_name (sheet, (GHFunc) cb_get_names, 
+				&res);
+	return g_list_sort (res, (GCompareFunc)expr_name_cmp_by_name);
+}
 
-		/* no need for UTF-8 or collation magic, just equality */
-		if (strcmp (name, expr_name_name (nexpr)) == 0)
-			return nexpr;
-	}
+static GList *
+name_guru_get_available_wb_names (Workbook const *wb)
+{
+	GList *res = NULL;
 
-	return NULL;
+	workbook_foreach_name (wb, TRUE,
+			       (GHFunc) cb_get_names, 
+			       &res);
+	return g_list_sort (res, (GCompareFunc)expr_name_cmp_by_name);
 }
 
 static void
-name_guru_set_expr (NameGuruState *state, GnmNamedExpr *nexpr)
+name_guru_set_images (NameGuruState *state, GtkTreeIter	*name_iter,
+		      item_type_t type)
 {
-	state->updating = TRUE;
-	if (nexpr) {
-		char *txt = expr_name_as_string (nexpr, &state->pp,
-				 gnm_conventions_default);
-		gnm_expr_entry_load_from_text  (state->expr_entry, txt);
-		g_free (txt);
-		gtk_entry_set_text (state->name, expr_name_name (nexpr));
-	} else {
-		gnm_expr_entry_load_from_text (state->expr_entry, "");
-		gtk_entry_set_text (state->name, "");
+	GdkPixbuf *button1 = NULL, *button2 = NULL;
+
+	switch (type) {
+	case item_type_workbook:
+	case item_type_main_sheet:
+		button2 = state->image_add;
+		break;
+	case item_type_locked_name:
+		button2 = state->image_lock;
+		break;
+	case item_type_available_wb_name:
+	case item_type_new_unsaved_wb_name:
+		button1 = state->image_down;
+		button2 = state->image_delete;
+		break;
+	case item_type_available_sheet_name:
+	case item_type_new_unsaved_sheet_name:
+		button1 = state->image_up;
+		button2 = state->image_delete;
+		break;
+	case item_type_other_sheet:
+	case item_type_foreign_name:
+	default:
+		break;
 	}
-	state->updating = FALSE;
 
-	name_guru_display_scope (state);
+	gtk_tree_store_set (state->model, name_iter, 
+			    ITEM_UPDOWN_IMAGE, button1,
+			    ITEM_ADDDELETE_IMAGE, button2,
+			    ITEM_UPDOWN_ACTIVE, button1 != NULL,
+			    ITEM_ADDDELETE_ACTIVE, button2 != NULL,
+			    -1);	
 }
 
 static void
-name_guru_update_sensitivity (NameGuruState *state, gboolean update_entries)
+name_guru_store_names (GList            *list,
+		       GtkTreeIter	*iter,
+		       NameGuruState    *state,
+		       item_type_t       type)
 {
-	gboolean selection;
-	gboolean update = FALSE;
-	gboolean add = FALSE;
-	gboolean delete;
-	gboolean switchscope;
-	gboolean clear_selection;
-	char const *name;
-
-	if (state->updating)
-		return;
-
-	name  = gtk_entry_get_text (state->name);
-	selection = gtk_tree_selection_get_selected (state->selection, NULL, NULL);
-	delete = clear_selection = switchscope = (selection != 0);
-
-	if (name != NULL && name[0] != '\0') {
-		GnmNamedExpr *in_list = NULL;
-		gboolean sheet_scope;
-
-		/** 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
-		 *  - If we have a current name which is equal to the name to be added but
-		 *     the scope differs.
-		 **/
-
-		sheet_scope = name_guru_scope_is_sheet (state);
-
-		in_list = name_guru_in_list (state, name, TRUE, sheet_scope);
-
-		if (in_list != NULL) {
-			delete = delete && !in_list->is_permanent;
-			clear_selection = FALSE;
-		} else
-			add = TRUE;
-
-		update = !add && in_list->is_editable;
-	}
-
-	if (switchscope) {
-		GnmNamedExpr const *nexpr = state->cur_name;
-
-		if (nexpr != NULL )
-			switchscope = !nexpr->is_permanent &&
-				(NULL == name_guru_in_list (state, expr_name_name (nexpr),
-						TRUE, (nexpr->pos.sheet == NULL)));
-	}
-
-	gtk_widget_set_sensitive (state->delete_button, delete);
-	gtk_widget_set_sensitive (state->add_button,    add);
-	gtk_widget_set_sensitive (state->update_button, update);
-	gtk_widget_set_sensitive (state->switchscope_button, switchscope);
-
-	state->action_possible = update || add;
+	GtkTreeIter	 name_iter;
+	char            *content;
+	item_type_t      adj_type = type;
+	GList           *l;
 
-	gtk_widget_set_sensitive (state->ok_button, state->action_possible);
+	for (l = list; l != NULL; l = l->next) {
+		GnmNamedExpr    *nexpr = l->data;
 
+		if (nexpr->is_hidden || expr_name_is_placeholder (nexpr))
+			continue;
 
-	if (!selection && update_entries)
-		name_guru_set_expr (state, NULL);
-
-	if (clear_selection) {
-		state->updating = TRUE;
-		gtk_tree_selection_unselect_all (state->selection);
-		state->updating = FALSE;
+		if (nexpr->is_permanent)
+			adj_type =  item_type_locked_name;
+
+		content = expr_name_as_string (nexpr, &state->pp,
+					       gnm_conventions_default);
+
+
+		gtk_tree_store_append (state->model, &name_iter, 
+				       iter);
+		gtk_tree_store_set (state->model, &name_iter, 
+				    ITEM_NAME, expr_name_name (nexpr), 
+				    ITEM_NAME_POINTER, nexpr, 
+				    ITEM_CONTENT, content, 
+				    ITEM_TYPE, adj_type, 
+				    ITEM_CONTENT_IS_EDITABLE, 
+				    adj_type == item_type_available_wb_name 
+				    || adj_type == item_type_available_sheet_name,
+				    ITEM_NAME_IS_EDITABLE, FALSE,
+				    -1);
+		g_free (content);
+		
+		name_guru_set_images (state, &name_iter, adj_type);
 	}
+	g_list_free (list);
 }
 
 static void
 name_guru_populate_list (NameGuruState *state)
 {
-	GnmNamedExpr	*nexpr;
-	GList		*ptr;
 	GtkTreeIter	 iter;
+	GSList          *sheets;
 
 	g_return_if_fail (state != NULL);
 	g_return_if_fail (state->treeview != NULL);
 
-	state->cur_name = NULL;
+	gtk_tree_store_clear (state->model);
+
+	gtk_tree_store_append (state->model, &iter, NULL);
+	gtk_tree_store_set (state->model, &iter, 
+			    ITEM_NAME, _("Workbook"), 
+			    ITEM_NAME_POINTER, NULL, 
+			    ITEM_TYPE, item_type_workbook, 
+			    ITEM_CONTENT_IS_EDITABLE, FALSE,
+			    ITEM_NAME_IS_EDITABLE, FALSE,
+			    -1);
+	name_guru_set_images (state, &iter, item_type_workbook);
+	name_guru_store_names (name_guru_get_available_wb_names (state->wb),
+		       &iter,
+		       state,
+		       item_type_available_wb_name);
+	name_guru_expand_at_iter (state, &iter);
+
+	gtk_tree_store_append (state->model, &iter, NULL);
+	gtk_tree_store_set (state->model, &iter, 
+			    ITEM_NAME,  state->sheet->name_unquoted, 
+			    ITEM_NAME_POINTER,  state->sheet, 
+			    ITEM_TYPE, item_type_main_sheet, 
+			    ITEM_CONTENT_IS_EDITABLE, FALSE, 
+			    ITEM_NAME_IS_EDITABLE, FALSE,
+			    -1);
+	name_guru_set_images (state, &iter, item_type_main_sheet);
+
+	name_guru_store_names (name_guru_get_available_sheet_names 
+			       (state->sheet),
+		       &iter,
+		       state,
+		       item_type_available_sheet_name);
+	name_guru_expand_at_iter (state, &iter);
+
+	for (sheets = workbook_sheets (state->wb); 
+	     sheets != NULL; 
+	     sheets = sheets->next) {
+		Sheet *sheet = sheets->data;
+
+		if (sheet == state->sheet)
+			continue;
 
-	gtk_list_store_clear (state->model);
+		gtk_tree_store_append (state->model, &iter, NULL);
+		gtk_tree_store_set (state->model, &iter, 
+				    ITEM_NAME, sheet->name_unquoted, 
+				    ITEM_NAME_POINTER, sheet, 
+				    ITEM_TYPE, item_type_other_sheet, 
+				    ITEM_CONTENT_IS_EDITABLE, FALSE, 
+				    ITEM_NAME_IS_EDITABLE, FALSE,
+				    -1);
+
+		name_guru_store_names 
+			(name_guru_get_available_sheet_names (sheet),
+			 &iter, state, item_type_foreign_name);
+	}
+}
 
-	g_list_free (state->expr_names);
-	state->expr_names =
-		g_list_sort (sheet_names_get_available (state->sheet),
-			     (GCompareFunc)expr_name_cmp_by_name);
 
-	for (ptr = state->expr_names ; ptr != NULL ; ptr = ptr->next) {
-		nexpr = ptr->data;
+static void
+cb_name_guru_clicked (GtkWidget *button, NameGuruState *state)
+{
+	if (state->dialog == NULL)
+		return;
 
-		/* ignore placeholders for unknown names */
-		if (expr_name_is_placeholder (nexpr))
-			continue;
+	wbcg_set_entry (state->wbcg, NULL);
 
-		gtk_list_store_append (state->model, &iter);
-		if (nexpr->pos.sheet != NULL) {
-			char *name = g_strdup_printf ("%s!%s",
-						      nexpr->pos.sheet->name_unquoted,
-						      expr_name_name (nexpr));
-			gtk_list_store_set (state->model,
-					    &iter, 0, name, 1, nexpr, -1);
-			g_free (name);
-		} else
-			gtk_list_store_set (state->model,
-					    &iter,
-					    0, expr_name_name (nexpr),
-					    1, nexpr,
-					    -1);
+	if (button == state->close_button) {
+		gtk_widget_destroy (state->dialog);
+		return;
 	}
-	name_guru_update_sensitivity (state, TRUE);
 }
 
-static void
-cb_scope_changed (G_GNUC_UNUSED GtkToggleButton *button, NameGuruState *state)
+static GtkWidget *
+name_guru_init_button (NameGuruState *state, char const *name)
 {
-	name_guru_update_sensitivity (state, FALSE);
-}
+	GtkWidget *tmp = glade_xml_get_widget (state->gui, name);
 
+	g_return_val_if_fail (tmp != NULL, NULL);
 
-/**
- * cb_name_guru_update_sensitivity:
- * @dummy:
- * @state:
- *
- **/
-static void
-cb_name_guru_update_sensitivity (G_GNUC_UNUSED GtkWidget *dummy,
-				 NameGuruState *state)
-{
-	name_guru_update_sensitivity (state, FALSE);
+	g_signal_connect (G_OBJECT (tmp),
+		"clicked",
+		G_CALLBACK (cb_name_guru_clicked), state);
+	return tmp;
 }
 
 static void
-cb_name_guru_select_name (G_GNUC_UNUSED GtkTreeSelection *ignored,
-			  NameGuruState *state)
+cb_name_guru_destroy (NameGuruState *state)
 {
-	GnmNamedExpr *nexpr;
-	GtkTreeIter  iter;
+	WorkbookControl *wbc = WORKBOOK_CONTROL (state->wbcg);
 
-	if (state->updating ||
-	    !gtk_tree_selection_get_selected (state->selection, NULL, &iter))
-		return;
+	wb_view_selection_desc (wb_control_view (wbc), TRUE, wbc);
+	if (state->gui != NULL) {
+		g_object_unref (G_OBJECT (state->gui));
+		state->gui = NULL;
+	}
 
-	gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter, 1, &nexpr, -1);
+	wbcg_edit_finish (state->wbcg, WBC_EDIT_REJECT, NULL);
 
-	g_return_if_fail (nexpr != NULL);
-	g_return_if_fail (nexpr->name != NULL);
-	g_return_if_fail (expr_name_name (nexpr) != NULL);
+	state->dialog = NULL;
 
-	state->cur_name = nexpr;
+	g_object_unref (G_OBJECT (state->image_add));
+	g_object_unref (G_OBJECT (state->image_delete));
+	g_object_unref (G_OBJECT (state->image_lock));
+	g_object_unref (G_OBJECT (state->image_up));
+	g_object_unref (G_OBJECT (state->image_down));
 
-	name_guru_set_expr (state, nexpr);
-	name_guru_update_sensitivity (state, FALSE);
+	g_free (state);
 }
 
-/**
- * name_guru_remove:
- * @ignored:
- * @state:
- *
- * Remove the state->cur_name
- **/
 static void
-name_guru_remove (G_GNUC_UNUSED GtkWidget *ignored,
-		  NameGuruState *state)
+name_guru_add (NameGuruState *state, GtkTreeIter *iter, gchar const *path_string)
 {
-	g_return_if_fail (state != NULL);
-	g_return_if_fail (state->cur_name != NULL);
+	GtkTreeIter	 name_iter;
+	char            *content;
+	GtkTreePath     *path;
+	item_type_t      type;
+
+	path = gtk_tree_path_new_from_string (path_string);
+
+	type = ((gtk_tree_path_get_indices (path))[0] == 0) ?
+		item_type_new_unsaved_wb_name :
+		item_type_new_unsaved_sheet_name;
+	content =  selection_to_string (state->sv, FALSE);
+
+	gtk_tree_store_insert (state->model, &name_iter, 
+			       iter, 0);
+	gtk_tree_store_set (state->model, &name_iter, 
+			    ITEM_NAME, _("<new name>"), 
+			    ITEM_NAME_POINTER, NULL, 
+			    ITEM_CONTENT, 
+			    ((content == NULL) ? "#REF!" : content),
+			    ITEM_TYPE, type, 
+			    ITEM_CONTENT_IS_EDITABLE, TRUE,
+			    ITEM_NAME_IS_EDITABLE, TRUE,
+			    -1);
+	name_guru_set_images (state, &name_iter, type);
+	name_guru_expand_at_iter (state, iter);
+	g_free (content);
+}
 
+static void
+name_guru_delete (NameGuruState *state, GtkTreeIter *iter, item_type_t type)
+{
+	GnmNamedExpr *nexpr;
+	
 	if (!name_guru_warn (state))
 		return;
 
-	cmd_remove_name (WORKBOOK_CONTROL (state->wbcg), state->cur_name);
-	state->cur_name = NULL;
-	name_guru_populate_list (state);
-	gtk_widget_grab_focus (GTK_WIDGET (state->name));
+	if (type != item_type_new_unsaved_wb_name &&
+	    type != item_type_new_unsaved_sheet_name) {
+		gtk_tree_model_get (GTK_TREE_MODEL (state->model), 
+				    iter,
+				    ITEM_NAME_POINTER, &nexpr,
+				    -1);
+		
+		cmd_remove_name (WORKBOOK_CONTROL (state->wbcg), nexpr);
+	}
+	gtk_tree_store_remove (state->model, iter);
 }
 
-/*
- * name_guru_switchscope:
- * @state:
- *
- * switch the scope of the currently selected name
- */
+
 static void
-name_guru_switchscope (NameGuruState *state)
+cb_name_guru_add_delete (G_GNUC_UNUSED GtkCellRendererToggle *cell,
+			 gchar                 *path_string,
+			 gpointer               data)
 {
-	GnmNamedExpr const *nexpr = state->cur_name;
+	NameGuruState *state = data;
+	GtkTreeIter iter;
+
+	if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (state->model), 
+						 &iter,
+						 path_string)) {
+		item_type_t type;
+
+		gtk_tree_model_get (GTK_TREE_MODEL (state->model), 
+				    &iter,
+				    ITEM_TYPE, &type,
+				    -1);
+
+		switch (type) {
+		case item_type_workbook:
+		case item_type_main_sheet:
+			name_guru_add (state, &iter, path_string);
+			break;
+		case item_type_available_wb_name:
+		case item_type_available_sheet_name:
+		case item_type_new_unsaved_wb_name:
+		case item_type_new_unsaved_sheet_name:
+			name_guru_delete (state, &iter, type);
+			break;
+		case item_type_other_sheet:
+		case item_type_locked_name:
+		case item_type_foreign_name:
+		default:
+			break;
+		}
+	}
+}
 
-	g_return_if_fail (nexpr != NULL);
-	g_return_if_fail (!nexpr->is_permanent);
+static void
+name_guru_move_record (NameGuruState *state, GtkTreeIter *from_iter, 
+		       gchar const *to_path, item_type_t new_type)
+{
+	GtkTreeIter new_parent_iter;
+	GnmNamedExpr *nexpr;
+	gchar *name, *content;
+	gboolean ceditable, neditable;
+
+	gtk_tree_model_get (GTK_TREE_MODEL (state->model), 
+			    from_iter,
+			    ITEM_NAME, &name,
+			    ITEM_NAME_POINTER, &nexpr,
+			    ITEM_CONTENT, &content,
+			    ITEM_CONTENT_IS_EDITABLE, &ceditable,
+			    ITEM_NAME_IS_EDITABLE, &neditable,
+			    -1);
+
+	gtk_tree_store_remove (state->model, from_iter);
+
+	if (gtk_tree_model_get_iter_from_string 
+	    (GTK_TREE_MODEL (state->model), 
+	     &new_parent_iter,
+	     to_path)) {
+		GtkTreeIter new_iter;
+		
+#warning We should be inserting the new record where it belongs in the ordering!
+		gtk_tree_store_prepend (state->model, &new_iter,
+					&new_parent_iter);
+		gtk_tree_store_set (state->model, &new_iter, 
+				    ITEM_NAME, name, 
+				    ITEM_NAME_POINTER, nexpr, 
+				    ITEM_CONTENT, content, 
+				    ITEM_TYPE, new_type, 
+				    ITEM_CONTENT_IS_EDITABLE, ceditable,
+				    ITEM_NAME_IS_EDITABLE, neditable,
+				    -1);
+		name_guru_set_images (state, &new_iter, new_type);
+		name_guru_expand_at_iter (state, &new_iter);
+		g_free (name);
+		g_free (content);
+	}
+}
 
-	expr_name_set_scope (state->cur_name,
-			     (nexpr->pos.sheet == NULL) ?
-			     state->sheet : NULL);
-	name_guru_populate_list (state);
+static void
+cb_name_guru_switch_scope (G_GNUC_UNUSED GtkCellRendererToggle *cell,
+			   gchar                 *path_string,
+			   gpointer               data)
+{
+	NameGuruState *state = data;
+	GtkTreeIter iter;
+
+	if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (state->model), 
+						 &iter,
+						 path_string)) {
+
+		item_type_t type, new_type;
+		gchar const *new_path;
+		GnmNamedExpr *nexpr;
+
+		gtk_tree_model_get (GTK_TREE_MODEL (state->model), 
+				    &iter,
+				    ITEM_TYPE, &type,
+				    ITEM_NAME_POINTER, &nexpr,
+				    -1);
+
+		switch (type) {
+		case item_type_available_wb_name:
+#warning make undoable		       
+			expr_name_set_scope (nexpr, state->sheet);
+			new_path  = "1"; 
+			new_type  = item_type_available_sheet_name;
+			break;
+		case item_type_new_unsaved_wb_name:
+			new_path  = "1"; 
+			new_type  = item_type_new_unsaved_sheet_name;
+			break;
+		case item_type_available_sheet_name:
+#warning make undoable		       
+			expr_name_set_scope (nexpr, NULL);
+			new_path  = "0"; 
+			new_type  = item_type_available_wb_name;
+			break;
+		case item_type_new_unsaved_sheet_name:
+			new_path  = "0"; 
+			new_type  = item_type_new_unsaved_wb_name;
+			break;
+		case item_type_workbook:
+		case item_type_main_sheet:
+		case item_type_other_sheet:
+		case item_type_locked_name:
+		case item_type_foreign_name:
+		default:
+			return;
+		}
+		
+		name_guru_move_record (state, &iter, new_path, new_type);
+	}
 }
 
+/*
+ * Return the expression if it is acceptable.
+ * The parse position will be initialized then.
+ */
 
-/**
- * name_guru_add:
- * @state:
- *
- * Update or add a GnmNamedExpr from the values in the gtkentries.
- *
- * Return Value: FALSE if the expression was invalid, TRUE otherwise
- **/
-static gboolean
-name_guru_add (NameGuruState *state)
+static  GnmExprTop const*
+name_guru_check_expression (NameGuruState *state, gchar *text, 
+			    GnmParsePos *pp, item_type_t type)
 {
 	GnmExprTop const *texpr;
-	GnmParsePos	pp;
-	GnmParseError	perr;
-	char const *name;
-	gboolean	res;
-
-	g_return_val_if_fail (state != NULL, FALSE);
-
-	if (!state->action_possible)
-		return TRUE;
-
-	name = gtk_entry_get_text (state->name);
-	if (name[0] == 0) {
-		/* Empty name -- probably ok/close after add.  */
-		return TRUE;
+	GnmParseError	  perr;
+
+	switch (type) {
+	case item_type_available_wb_name:
+	case item_type_new_unsaved_wb_name:
+		parse_pos_init (pp, state->wb, NULL,
+				state->pp.eval.col, state->pp.eval.row);
+		break;
+	case item_type_available_sheet_name:
+	case item_type_new_unsaved_sheet_name:
+		parse_pos_init (pp, state->wb, state->sheet,
+				state->pp.eval.col, state->pp.eval.row);
+		break;
+	case item_type_workbook:
+	case item_type_main_sheet:
+	case item_type_other_sheet:
+	case item_type_locked_name:
+	case item_type_foreign_name:
+	default:
+		return NULL; /* We should have never gotten here. */
 	}
 
-	if (!expr_name_validate (name, state->sheet)) {
-		go_gtk_notice_dialog (GTK_WINDOW (state->dialog),
+	if (text == NULL || text[0] == '\0') {
+		go_gtk_notice_dialog (GTK_WINDOW (state->dialog), 
 				      GTK_MESSAGE_ERROR,
-				      _("Invalid name"));
-		gtk_widget_grab_focus (GTK_WIDGET (state->expr_entry));
-		return FALSE;
+				      _("Why would you want to define a "
+					"name for the empty string?"));
+		return NULL;
 	}
 
-	parse_pos_init (&pp, state->wb,
-			name_guru_scope_is_sheet (state) ? state->sheet : NULL,
-			state->pp.eval.col, state->pp.eval.row);
-
-	texpr = gnm_expr_entry_parse (state->expr_entry, &pp,
-				      parse_error_init (&perr),
-				      FALSE,
-				      GNM_EXPR_PARSE_DEFAULT | GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_INVALID);
+	texpr = gnm_expr_parse_str (text, pp,
+				    GNM_EXPR_PARSE_DEFAULT | 
+				    GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_INVALID |
+				    GNM_EXPR_PARSE_PERMIT_MULTIPLE_EXPRESSIONS,
+				    NULL, 
+				    parse_error_init (&perr));
 	if (texpr == NULL) {
 		if (perr.err == NULL)
-			return TRUE;
+			return NULL;
 
 		go_gtk_notice_dialog (GTK_WINDOW (state->dialog),
 				      GTK_MESSAGE_ERROR,
 				      "%s", perr.err->message);
-		gtk_widget_grab_focus (GTK_WIDGET (state->expr_entry));
 		parse_error_free (&perr);
-		return FALSE;
+		return NULL;
 	}
-
-	/* don't allow user to define a nexpr that looks like a placeholder
-	 * because it will be would disappear from the lists.
-	 */
+	/* don't allow user to define a nexpr that looks like a placeholder *
+	 * because it will be would disappear from the lists.               */
 	if (gnm_expr_top_is_err (texpr, GNM_ERROR_NAME)) {
 		go_gtk_notice_dialog (GTK_WINDOW (state->dialog), GTK_MESSAGE_ERROR,
 			_("Why would you want to define a name to be #NAME?"));
-		gtk_widget_grab_focus (GTK_WIDGET (state->expr_entry));
 		parse_error_free (&perr);
 		gnm_expr_top_unref (texpr);
-		return FALSE;
-	}
-
-	res = !cmd_define_name (WORKBOOK_CONTROL (state->wbcg), name, &pp,
-				texpr, NULL);
-
-	if (res) {
-		name_guru_populate_list (state);
-		gtk_widget_grab_focus (GTK_WIDGET (state->name));
+		return NULL;
 	}
 
-	return res;
+	return texpr;
 }
 
+
 static void
-cb_name_guru_clicked (GtkWidget *button, NameGuruState *state)
+cb_name_guru_content_edited (GnumericCellRendererExprEntry *cell,
+			     gchar               *path_string,
+			     gchar               *new_text,
+			     NameGuruState       *state)
 {
-	if (state->dialog == NULL)
+	GtkTreeIter       iter;
+	gboolean          have_iter = FALSE;
+	item_type_t       type;
+	GnmParsePos       pp;
+	GnmExprTop const *texpr;
+	GnmNamedExpr     *nexpr;
+
+	have_iter = gtk_tree_model_get_iter_from_string 
+		(GTK_TREE_MODEL (state->model),
+					     &iter, path_string);
+	if (!have_iter)
 		return;
 
-	wbcg_set_entry (state->wbcg, NULL);
+	gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter,
+			    ITEM_TYPE, &type, 
+			    ITEM_NAME_POINTER, &nexpr,
+			    -1);
 
-	if (button == state->delete_button) {
-		name_guru_remove (NULL, state);
-		return;
-	}
-	 if (button == state->switchscope_button) {
-                 name_guru_switchscope (state);
-                 return;
-        }
-
-	if (button == state->add_button ||
-	    button == state->update_button ||
-	    button == state->ok_button) {
-		/* If adding the name failed, do not exit */
-		if (!name_guru_add (state))
-			return;
-	}
+	/* check whether the content is valid */
 
-	if (button == state->close_button || button == state->ok_button) {
-		gtk_widget_destroy (state->dialog);
+
+	texpr = name_guru_check_expression (state, new_text, &pp , type);
+	if (texpr == NULL)
 		return;
-	}
-}
 
-static GtkWidget *
-name_guru_init_button (NameGuruState *state, char const *name)
-{
-	GtkWidget *tmp = glade_xml_get_widget (state->gui, name);
+	/* content is valid */
 
-	g_return_val_if_fail (tmp != NULL, NULL);
+	if (type != item_type_new_unsaved_wb_name 
+	    && type != item_type_new_unsaved_sheet_name) {
+		/* save the changes (if the name is already saved) */
+		cmd_define_name (WORKBOOK_CONTROL (state->wbcg), 
+				 expr_name_name (nexpr), 
+				 &pp, texpr, NULL);
+	}
 
-	g_signal_connect (G_OBJECT (tmp),
-		"clicked",
-		G_CALLBACK (cb_name_guru_clicked), state);
-	return tmp;
+	/* set the model */
+	gtk_tree_store_set (state->model, &iter, ITEM_CONTENT, new_text, -1);
 }
 
 static void
-cb_name_guru_destroy (NameGuruState *state)
+cb_name_guru_name_edited (G_GNUC_UNUSED GtkCellRendererText *cell,
+			     gchar               *path_string,
+			     gchar               *new_text,
+			     NameGuruState       *state)
 {
-	WorkbookControl *wbc = WORKBOOK_CONTROL (state->wbcg);
+	GtkTreeIter       iter;
+	gboolean          have_iter = FALSE;
+	item_type_t       type;
+	GnmParsePos       pp;
+	GnmExprTop const *texpr;
+	gchar            *content;
 
-	wb_view_selection_desc (wb_control_view (wbc), TRUE, wbc);
-	if (state->gui != NULL) {
-		g_object_unref (G_OBJECT (state->gui));
-		state->gui = NULL;
-	}
+	have_iter = gtk_tree_model_get_iter_from_string 
+		(GTK_TREE_MODEL (state->model),
+					     &iter, path_string);
 
-	wbcg_edit_finish (state->wbcg, WBC_EDIT_REJECT, NULL);
+	if (!have_iter)
+		return;
 
-	state->dialog = NULL;
+	gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter,
+			    ITEM_TYPE, &type,
+			    ITEM_CONTENT, &content,
+			    -1);
 
-	g_list_free (state->expr_names);
-	state->expr_names = NULL;
+	if (type != item_type_new_unsaved_wb_name && 
+	    type != item_type_new_unsaved_sheet_name)
+		return;
 
-	g_free (state);
-}
+	if (new_text == NULL || new_text[0] == '\0') {
+		go_gtk_notice_dialog (GTK_WINDOW (state->dialog), 
+				      GTK_MESSAGE_ERROR,
+				      _("The empty string is not a valid "
+					"name for a named expression!"));
+		return;
+	}
 
-static void
-cb_entry_activate (G_GNUC_UNUSED GtkWidget *item,
-		   NameGuruState *state)
-{
-	if (!state->action_possible ||
-	    gnm_expr_entry_is_blank (state->expr_entry))
-		gtk_widget_destroy (state->dialog);
-	name_guru_add (state);
-}
+	if (!expr_name_validate (new_text, state->sheet)) {
+		go_gtk_notice_dialog (GTK_WINDOW (state->dialog),
+				      GTK_MESSAGE_ERROR,
+				      _("Invalid name"));
+		return;
+	}
 
-static void
-load_selection (NameGuruState *state)
-{
-	GnmRange const *first = selection_first_range (state->sv, NULL, NULL);
+	texpr = name_guru_check_expression (state, content, &pp , type);
+	if (texpr == NULL)
+		return;
+	
+	if (type == item_type_new_unsaved_wb_name) {
+		gtk_tree_store_set 
+			(state->model, &iter, 
+			 ITEM_NAME, new_text,
+			 ITEM_TYPE, item_type_available_wb_name,
+			 -1);
+		name_guru_set_images (state, &iter, 
+				      item_type_available_wb_name);
+		cmd_define_name (WORKBOOK_CONTROL (state->wbcg), 
+				 new_text, &pp,
+				 texpr, NULL);
+	} else {
 
-	if (first != NULL)
-		gnm_expr_entry_load_from_range (state->expr_entry,
-						state->sheet, first);
+		gtk_tree_store_set 
+			(state->model, &iter, 
+			 ITEM_NAME, new_text,
+			 ITEM_TYPE, item_type_new_unsaved_sheet_name,
+			 -1);
+		name_guru_set_images (state, &iter, 
+				      item_type_available_sheet_name);
+		cmd_define_name (WORKBOOK_CONTROL (state->wbcg), 
+				 new_text, &pp,
+				 texpr, NULL);
+	}
 }
 
 
 static gboolean
-name_guru_init (NameGuruState *state, WBCGtk *wbcg)
+name_guru_init (NameGuruState *state, WBCGtk *wbcg, gboolean is_paste_dialog)
 {
-	Workbook *wb = wb_control_get_workbook (WORKBOOK_CONTROL (wbcg));
-	GtkTable *definition_table;
+	Workbook          *wb = wb_control_get_workbook 
+		(WORKBOOK_CONTROL (wbcg));
 	GtkTreeViewColumn *column;
+	GtkCellRenderer   *renderer;
+	GtkTreeSelection  *selection;
 
 	state->gui = gnm_glade_xml_new (GO_CMD_CONTEXT (wbcg),
 		"define-name.glade", NULL, NULL);
@@ -550,80 +767,109 @@ name_guru_init (NameGuruState *state, WBCGtk *wbcg)
 	parse_pos_init_editpos (&state->pp, state->sv);
 
 	state->dialog = glade_xml_get_widget (state->gui, "NameGuru");
-	definition_table = GTK_TABLE (glade_xml_get_widget (state->gui, "definition_table"));
-	state->name  = GTK_ENTRY (glade_xml_get_widget (state->gui, "name"));
-	state->expr_entry = g_object_new (GNM_EXPR_ENTRY_TYPE,
-			     "flags",	  GNM_EE_SHEET_OPTIONAL | GNM_EE_DEFAULT_ABS_REF,
-			     "with-icon", TRUE,
-			     "scg",	  wbcg_cur_scg (wbcg),
-			     NULL);
-	gtk_table_attach (definition_table, GTK_WIDGET (state->expr_entry),
-			  1, 2, 1, 2,
-			  GTK_EXPAND | GTK_FILL, 0,
-			  0, 0);
-	gtk_widget_show (GTK_WIDGET (state->expr_entry));
-	state->sheet_scope = GTK_TOGGLE_BUTTON (glade_xml_get_widget (state->gui, "sheet_scope"));
-
-	state->wb_scope = GTK_TOGGLE_BUTTON (glade_xml_get_widget (state->gui, "workbook_scope"));
-	state->expr_names = NULL;
-	state->cur_name   = NULL;
-	state->updating   = FALSE;
-	state->action_possible = FALSE;
-
-	state->model	 = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
+
+	state->model	 = gtk_tree_store_new 
+		(NUM_COLMNS, 
+		 G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING, 
+		 G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
+		 GDK_TYPE_PIXBUF, GDK_TYPE_PIXBUF,
+		 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
 	state->treeview  = glade_xml_get_widget (state->gui, "name_list");
 	gtk_tree_view_set_model (GTK_TREE_VIEW (state->treeview),
 				 GTK_TREE_MODEL (state->model));
-	column = gtk_tree_view_column_new_with_attributes (_("Name"),
-			gtk_cell_renderer_text_new (),
-			"text", 0,
-			NULL);
+	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (state->treeview), 
+					   FALSE);
+	gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (state->treeview), 
+				      GTK_TREE_VIEW_GRID_LINES_NONE);
+	gtk_tree_view_set_reorderable (GTK_TREE_VIEW (state->treeview),
+				       FALSE);
+
+	renderer = gtk_cell_renderer_text_new ();
+	g_signal_connect (G_OBJECT (renderer), "edited",
+			  G_CALLBACK (cb_name_guru_name_edited), state);
+	column = gtk_tree_view_column_new_with_attributes 
+		("name",
+		 renderer,
+		 "text", ITEM_NAME,
+		 "editable", ITEM_NAME_IS_EDITABLE,
+		 NULL);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (state->treeview), column);
 
-	state->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (state->treeview));
-	gtk_tree_selection_set_mode (state->selection, GTK_SELECTION_BROWSE);
+	renderer = gnumeric_cell_renderer_toggle_new ();
+	g_signal_connect (G_OBJECT (renderer),
+			  "toggled",
+			  G_CALLBACK (cb_name_guru_add_delete), state);
+	column = gtk_tree_view_column_new_with_attributes
+		("Lock",
+		 renderer,
+		 "active", ITEM_ADDDELETE_ACTIVE,
+		 "pixbuf", ITEM_ADDDELETE_IMAGE,
+		 NULL);
+	gtk_tree_view_append_column (GTK_TREE_VIEW (state->treeview), column);
 
-	gtk_label_set_text (GTK_LABEL (GTK_BIN (state->sheet_scope)->child),
-		state->sheet->name_unquoted);
-	name_guru_display_scope (state);
-	g_signal_connect (G_OBJECT (state->sheet_scope),
+	renderer = gnumeric_cell_renderer_toggle_new ();
+	g_signal_connect (G_OBJECT (renderer),
 		"toggled",
-		G_CALLBACK (cb_scope_changed), state);
+		G_CALLBACK (cb_name_guru_switch_scope), state);
+	column = gtk_tree_view_column_new_with_attributes
+		("Lock",
+		 renderer,
+		 "active", ITEM_UPDOWN_ACTIVE,
+		 "pixbuf", ITEM_UPDOWN_IMAGE,
+		 NULL);
+	gtk_tree_view_append_column (GTK_TREE_VIEW (state->treeview), column);
+	
+	renderer = gnumeric_cell_renderer_expr_entry_new (state->wbcg);
+	g_signal_connect (G_OBJECT (renderer), "edited",
+			  G_CALLBACK (cb_name_guru_content_edited), state);
+	column = gtk_tree_view_column_new_with_attributes 
+		(_("content"),
+		 renderer,
+		 "text", ITEM_CONTENT,
+		 "editable", ITEM_CONTENT_IS_EDITABLE,
+		 NULL);
+	gtk_tree_view_append_column (GTK_TREE_VIEW (state->treeview), column);
+
+
+	selection = gtk_tree_view_get_selection 
+		(GTK_TREE_VIEW (state->treeview));
+	gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
 
-	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");
-	gtk_button_set_alignment (GTK_BUTTON (state->add_button), 0., .5);
-	state->delete_button = name_guru_init_button (state, "delete_button");
-	gtk_button_set_alignment (GTK_BUTTON (state->delete_button), 0., .5);
-	state->update_button = name_guru_init_button (state, "update_button");
-	gtk_button_set_alignment (GTK_BUTTON (state->update_button), 0., .5);
-	state->switchscope_button = name_guru_init_button (state, "switchscope_button");
-	gtk_button_set_alignment (GTK_BUTTON (state->switchscope_button), 0., .5);
-
-	g_signal_connect (G_OBJECT (state->selection),
-		"changed",
-		G_CALLBACK (cb_name_guru_select_name), state);
-	g_signal_connect (G_OBJECT (state->name),
-		"changed",
-		G_CALLBACK (cb_name_guru_update_sensitivity), state);
-	g_signal_connect (G_OBJECT (state->name),
-		"activate",
-		G_CALLBACK (cb_entry_activate), state);
-
-	/* 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.
-	 */
-	g_signal_connect_after (G_OBJECT (state->expr_entry),
-		"changed",
-		G_CALLBACK (cb_name_guru_update_sensitivity), state);
-	g_signal_connect (G_OBJECT (gnm_expr_entry_get_entry (state->expr_entry)),
-		"activate",
-		G_CALLBACK (cb_entry_activate), state);
+
+	if (is_paste_dialog)
+		g_signal_connect (G_OBJECT (selection),
+				  "changed",
+				  NULL, state);
+
+	state->image_add =  gtk_widget_render_icon 
+		(state->dialog,
+		 GTK_STOCK_ADD,
+		 GTK_ICON_SIZE_SMALL_TOOLBAR,
+		 "Gnumeric-Define-Names-Dialog");
+	state->image_delete =  gtk_widget_render_icon 
+		(state->dialog,
+		 GTK_STOCK_REMOVE,
+		 GTK_ICON_SIZE_SMALL_TOOLBAR,
+		 "Gnumeric-Define-Names-Dialog");
+	state->image_lock =  gtk_widget_render_icon 
+		(state->dialog,
+		 "Gnumeric_Protection_Yes",
+		 GTK_ICON_SIZE_SMALL_TOOLBAR,
+		 "Gnumeric-Define-Names-Dialog");
+	state->image_up =  gtk_widget_render_icon 
+		(state->dialog,
+		 GTK_STOCK_GO_UP,
+		 GTK_ICON_SIZE_SMALL_TOOLBAR,
+		 "Gnumeric-Define-Names-Dialog");
+	state->image_down =  gtk_widget_render_icon 
+		(state->dialog,
+		 GTK_STOCK_GO_DOWN,
+		 GTK_ICON_SIZE_SMALL_TOOLBAR,
+		 "Gnumeric-Define-Names-Dialog");
+
 
 	name_guru_populate_list (state);
-	load_selection (state);
 
 	gnumeric_init_help_button (
 		glade_xml_get_widget (state->gui, "help_button"),
@@ -639,7 +885,10 @@ name_guru_init (NameGuruState *state, WBCGtk *wbcg)
 	g_object_set_data_full (G_OBJECT (state->dialog),
 		"state", state, (GDestroyNotify)cb_name_guru_destroy);
 
-	gtk_widget_show_all (GTK_WIDGET (state->dialog));
+	if (is_paste_dialog)
+		gtk_widget_show_all (GTK_WIDGET (state->dialog));
+	else
+		gtk_widget_show (GTK_WIDGET (state->dialog));
 
 	return FALSE;
 }
@@ -666,7 +915,7 @@ dialog_define_names (WBCGtk *wbcg)
 		return;
 
 	state = g_new0 (NameGuruState, 1);
-	if (name_guru_init (state, wbcg)) {
+	if (name_guru_init (state, wbcg, FALSE)) {
 		go_gtk_notice_dialog (wbcg_toplevel (wbcg), GTK_MESSAGE_ERROR,
 				 _("Could not create the Name Guru."));
 		g_free (state);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]