[gnumeric] Add search tool to paste- and define-names dialogs. [#465840]



commit c2f11873661aa9a4288295df083dadea9264ee08
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Fri Jun 4 03:18:28 2010 -0600

    Add search tool to paste- and define-names dialogs. [#465840]
    
    2010-06-04 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* configure.in: check for gtk_entry_set_icon_from_stock
    
    2010-06-04 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* dialog-define-names.c: convert GtkTreeModelFilter iters to
    	  GtkTreeStore iters throughout
    	(cb_name_guru_show_all): new
    	(name_guru_erase_search_entry): new
    	(cb_name_guru_search): new
    	(name_guru_search): new
    	(name_guru_init): setup search entry
    	* define-name.glade: add icon and search entry

 ChangeLog                         |    4 +
 NEWS                              |    1 +
 configure.in                      |    2 +-
 src/dialogs/ChangeLog             |   13 ++++-
 src/dialogs/define-name.glade     |   37 +++++++++++-
 src/dialogs/dialog-define-names.c |  113 ++++++++++++++++++++++++++++++++++++-
 6 files changed, 163 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d1742f8..b4bf5a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-06-04 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* configure.in: check for gtk_entry_set_icon_from_stock
+
 2010-06-03 Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/commands.h (cmd_rescope_name): new
diff --git a/NEWS b/NEWS
index 9349ab9..a12ae30 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Andreas:
 	* Redesign define-named-expressions dialog. [#465840] 
 	* Add paste-names dialog. [#613325]
 	* Make changing the scope of a named expression undoable.
+	* Add search tool to paste- and define-names dialogs. [#465840]
 
 Jean:
 	* Do not ungrab a not grabbed item. [#620369]
diff --git a/configure.in b/configure.in
index ffb0bb2..7ae23ff 100644
--- a/configure.in
+++ b/configure.in
@@ -689,7 +689,7 @@ LIBS="$GNUMERIC_LIBS $LIBS"
 
 AC_CHECK_FUNCS(g_date_set_time_t g_slice_alloc g_option_context_set_delocalize)
 AC_CHECK_FUNCS(pango_font_map_create_context)
-AC_CHECK_FUNCS(gtk_orientable_set_orientation gtk_adjustment_configure gtk_widget_get_state gtk_widget_is_toplevel gtk_widget_get_window gsf_open_pkg_foreach_rel gtk_dialog_get_content_area gtk_entry_get_buffer gtk_widget_get_can_focus gtk_entry_get_text_length)
+AC_CHECK_FUNCS(gtk_orientable_set_orientation gtk_adjustment_configure gtk_widget_get_state gtk_widget_is_toplevel gtk_widget_get_window gsf_open_pkg_foreach_rel gtk_dialog_get_content_area gtk_entry_get_buffer gtk_widget_get_can_focus gtk_entry_get_text_length gtk_entry_set_icon_from_stock)
 AC_CHECK_FUNCS(gsf_infile_msvba_steal_modules)
 
 AC_MSG_CHECKING([for PANGO_WEIGHT_THIN etc.])
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index aafa302..6ecbda2 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,6 +1,17 @@
 2010-06-04 Andreas J. Guelzow <aguelzow pyrshep ca>
 
-	* dialog-define-names.c: insert GtkTreModelFilter between
+	* dialog-define-names.c: convert GtkTreeModelFilter iters to
+	  GtkTreeStore iters throughout
+	(cb_name_guru_show_all): new
+	(name_guru_erase_search_entry): new
+	(cb_name_guru_search): new
+	(name_guru_search): new
+	(name_guru_init): setup search entry
+	* define-name.glade: add icon and search entry
+
+2010-06-04 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dialog-define-names.c: insert GtkTreeModelFilter between
 	 GtkTreeStore and GtkTreeView and adjust code throughout.
 	(name_guru_store_names): new type adjustment for every name
 	(cb_name_guru_content_edited): don't leak GnmExprTop
diff --git a/src/dialogs/define-name.glade b/src/dialogs/define-name.glade
index 90b3857..bc6b373 100644
--- a/src/dialogs/define-name.glade
+++ b/src/dialogs/define-name.glade
@@ -35,14 +35,46 @@
           </packing>
         </child>
         <child>
-          <widget class="GtkHSeparator" id="hseparator1">
+          <widget class="GtkHBox" id="hbox1">
             <property name="visible">True</property>
+            <child>
+              <widget class="GtkImage" id="image1">
+                <property name="visible">True</property>
+                <property name="xpad">2</property>
+                <property name="ypad">2</property>
+                <property name="stock">gtk-find</property>
+                <property name="icon-size">2</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkEntry" id="search_entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">&#x25CF;</property>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
           </widget>
           <packing>
             <property name="expand">False</property>
             <property name="position">2</property>
           </packing>
         </child>
+        <child>
+          <widget class="GtkHSeparator" id="hseparator1">
+            <property name="visible">True</property>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
         <child internal-child="action_area">
           <widget class="GtkHButtonBox" id="hbuttonbox1">
             <property name="visible">True</property>
@@ -84,7 +116,8 @@
                 <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="has_default">True</property>
+                <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
               </widget>
               <packing>
diff --git a/src/dialogs/dialog-define-names.c b/src/dialogs/dialog-define-names.c
index f5b9bc2..2bae6ba 100644
--- a/src/dialogs/dialog-define-names.c
+++ b/src/dialogs/dialog-define-names.c
@@ -67,6 +67,7 @@ typedef struct {
 
 	GtkWidget *close_button;
 	GtkWidget *paste_button;
+	GtkWidget *search_entry;
 
 	Sheet			*sheet;
 	SheetView		*sv;
@@ -180,6 +181,80 @@ name_guru_warn (G_GNUC_UNUSED NameGuruState *state)
 	return TRUE;
 }
 
+static gboolean
+cb_name_guru_show_all (GtkTreeModel *model, GtkTreePath *path,
+		       GtkTreeIter *iter, gpointer data)
+{
+	NameGuruState *state = data;
+	gtk_tree_store_set (state->model, iter, 
+			    ITEM_VISIBLE, TRUE,
+			    -1);
+	return FALSE;
+}
+
+static void
+name_guru_erase_search_entry (GtkEntry *entry,
+#ifdef HAVE_GTK_ENTRY_SET_ICON_FROM_STOCK
+			      G_GNUC_UNUSED GtkEntryIconPosition icon_pos,
+			      G_GNUC_UNUSED GdkEvent *event,
+#endif
+			      gpointer data)
+{
+	NameGuruState *state = data;
+	gtk_entry_set_text (entry, "");
+	gtk_tree_model_foreach (GTK_TREE_MODEL (state->model),
+				cb_name_guru_show_all, state);
+}
+
+static gboolean
+cb_name_guru_search (GtkTreeModel *model, GtkTreePath *path,
+		       GtkTreeIter *iter, gpointer data)
+{
+	char const *text = data;
+	gchar *name;
+	gboolean visible = TRUE, was_visible;
+	item_type_t type;
+
+	gtk_tree_model_get (model, iter,
+			    ITEM_TYPE, &type,
+			    ITEM_NAME, &name,
+			    ITEM_VISIBLE, &was_visible,
+			    -1);
+
+	if (type != item_type_workbook &&
+	    type != item_type_main_sheet &&
+	    type != item_type_other_sheet)
+		visible = (NULL != g_strstr_len (name, -1, text));
+	
+	if (visible != was_visible)
+		gtk_tree_store_set (GTK_TREE_STORE (model), iter, 
+				    ITEM_VISIBLE, visible,
+				    -1);
+
+	g_free (name);
+	return FALSE;
+}
+
+static void
+name_guru_search (GtkEntry *entry, gpointer data)
+{
+	gchar const *text;
+	NameGuruState *state = data;
+
+	if (0 == gtk_entry_get_text_length (entry)){
+		name_guru_erase_search_entry 
+			(entry,
+#ifdef HAVE_GTK_ENTRY_SET_ICON_FROM_STOCK
+			 GTK_ENTRY_ICON_SECONDARY, NULL,
+#endif
+			 data);
+		return;
+	}
+	text = gtk_entry_get_text (entry);	
+	gtk_tree_model_foreach (GTK_TREE_MODEL (state->model),
+				cb_name_guru_search, (gpointer) text);
+}
+
 static void
 cb_get_names (G_GNUC_UNUSED gpointer key, GnmNamedExpr *nexpr,
 	      GList **accum)
@@ -433,12 +508,17 @@ cb_name_guru_clicked (GtkWidget *button, NameGuruState *state)
 		return;
 	}
 	if (button == state->paste_button) {
+		GtkTreeIter iter_f;
 		GtkTreeIter iter;
 		if (gtk_tree_selection_get_selected 
 		    (gtk_tree_view_get_selection 
-		     (GTK_TREE_VIEW (state->treeview)), NULL, &iter) &&
-		    name_guru_paste (state, &iter))
-			gtk_widget_destroy (state->dialog);
+		     (GTK_TREE_VIEW (state->treeview)), NULL, &iter_f)) {
+			gtk_tree_model_filter_convert_iter_to_child_iter
+				(GTK_TREE_MODEL_FILTER (state->model_f), 
+				 &iter, &iter_f);
+			if (name_guru_paste (state, &iter))
+				gtk_widget_destroy (state->dialog);
+		}
 		return;
 	}
 }
@@ -1086,6 +1166,33 @@ name_guru_init (NameGuruState *state, WBCGtk *wbcg, gboolean is_paste_dialog)
 			 "Gnumeric-Define-Names-Dialog");
 	}
 
+	state->search_entry = glade_xml_get_widget (state->gui, 
+						    "search_entry");
+#ifdef HAVE_GTK_ENTRY_SET_ICON_FROM_STOCK
+
+	gtk_entry_set_icon_from_stock 
+		(GTK_ENTRY (state->search_entry),
+		 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
+	gtk_entry_set_icon_tooltip_text 
+		(GTK_ENTRY (state->search_entry),
+		 GTK_ENTRY_ICON_SECONDARY,
+		 _("Erase the search entry."));
+	gtk_entry_set_icon_sensitive
+		(GTK_ENTRY (state->search_entry),
+		 GTK_ENTRY_ICON_SECONDARY, TRUE);
+	gtk_entry_set_icon_activatable
+		(GTK_ENTRY (state->search_entry),
+		 GTK_ENTRY_ICON_SECONDARY, TRUE);
+
+	g_signal_connect (G_OBJECT (state->search_entry),
+			  "icon-press",
+			  G_CALLBACK (name_guru_erase_search_entry),
+			  state);
+#endif
+	g_signal_connect (G_OBJECT (state->search_entry),
+			  "activate",
+			  G_CALLBACK (name_guru_search),
+			  state);
 
 	name_guru_populate_list (state);
 	name_guru_update_sensitivity (selection, state);



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