gnumeric r17028 - in trunk: . src



Author: mortenw
Date: Mon Dec 22 14:10:31 2008
New Revision: 17028
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17028&view=rev

Log:
2008-12-19  Morten Welinder  <terra gnome org>

	* src/search.c (gnm_search_replace_query_fail,
	gnm_search_replace_query_cell, gnm_search_replace_query_comment):
	New functions to hide the details of how to query.

	* src/commands.c (cmd_search_replace_do_cell): Simplify using
	gnm_search_replace_query_fail, gnm_search_replace_query_cell, and
	gnm_search_replace_query_comment.



Modified:
   trunk/ChangeLog
   trunk/src/commands.c
   trunk/src/search.c
   trunk/src/search.h

Modified: trunk/src/commands.c
==============================================================================
--- trunk/src/commands.c	(original)
+++ trunk/src/commands.c	Mon Dec 22 14:10:31 2008
@@ -4027,12 +4027,7 @@
 
 		if (err) {
 			if (test_run) {
-				if (sr->query_func)
-					sr->query_func (GNM_SRQ_FAIL,
-							sr,
-							cell_res.cell,
-							cell_res.old_text,
-							cell_res.new_text);
+				gnm_search_replace_query_fail (sr, &cell_res);
 				g_free (cell_res.old_text);
 				g_free (cell_res.new_text);
 				return TRUE;
@@ -4074,19 +4069,14 @@
 		}
 
 		if (!err && !test_run) {
-			gboolean doit = TRUE;
-			if (sr->query && sr->query_func) {
-				int res = sr->query_func (GNM_SRQ_QUERY,
-							  sr,
-							  cell_res.cell,
-							  cell_res.old_text,
-							  cell_res.new_text);
-				if (res == GTK_RESPONSE_CANCEL) {
-					g_free (cell_res.old_text);
-					g_free (cell_res.new_text);
-					return TRUE;
-				}
-				doit = (res == GTK_RESPONSE_YES);
+			int res = gnm_search_replace_query_cell
+				(sr, &cell_res);
+			gboolean doit = (res == GTK_RESPONSE_YES);
+
+			if (res == GTK_RESPONSE_CANCEL) {
+				g_free (cell_res.old_text);
+				g_free (cell_res.new_text);
+				return TRUE;
 			}
 
 			if (doit) {
@@ -4108,22 +4098,11 @@
 		g_free (cell_res.old_text);
 	}
 
-	if (!test_run && gnm_search_replace_comment (sr, ep, TRUE, &comment_res)) {
-		gboolean doit = TRUE;
-
-		if (sr->query && sr->query_func) {
-			int res = sr->query_func (GNM_SRQ_QUERY_COMMENT,
-						  sr,
-						  ep->sheet,
-						  &ep->eval,
-						  comment_res.old_text,
-						  comment_res.new_text);
-			if (res == GTK_RESPONSE_CANCEL) {
-				g_free (comment_res.new_text);
-				return TRUE;
-			}
-			doit = (res == GTK_RESPONSE_YES);
-		}
+	if (!test_run &&
+	    gnm_search_replace_comment (sr, ep, TRUE, &comment_res)) {
+		int res = gnm_search_replace_query_comment
+			(sr, ep, &comment_res);
+		gboolean doit = (res == GTK_RESPONSE_YES);
 
 		if (doit) {
 			SearchReplaceItem *sri = g_new (SearchReplaceItem, 1);
@@ -4134,8 +4113,11 @@
 			me->cells = g_list_prepend (me->cells, sri);
 
 			cell_comment_text_set (comment_res.comment, comment_res.new_text);
-		} else
+		} else {
 			g_free (comment_res.new_text);
+			if (res == GTK_RESPONSE_CANCEL)
+				return TRUE;
+		}
 	}
 
 	return FALSE;

Modified: trunk/src/search.c
==============================================================================
--- trunk/src/search.c	(original)
+++ trunk/src/search.c	Mon Dec 22 14:10:31 2008
@@ -381,6 +381,44 @@
 
 /* ------------------------------------------------------------------------- */
 
+void
+gnm_search_replace_query_fail (GnmSearchReplace *sr,
+			       const GnmSearchReplaceCellResult *res)
+{
+	if (!sr->query_func)
+		return;
+
+	sr->query_func (GNM_SRQ_FAIL, sr,
+			res->cell, res->old_text, res->new_text);
+}
+
+int
+gnm_search_replace_query_cell (GnmSearchReplace *sr,
+			       const GnmSearchReplaceCellResult *res)
+{
+	if (!sr->query || !sr->query_func)
+		return GTK_RESPONSE_YES;
+
+	return sr->query_func (GNM_SRQ_QUERY, sr,
+			       res->cell, res->old_text, res->new_text);
+}
+
+
+int
+gnm_search_replace_query_comment (GnmSearchReplace *sr,
+				  const GnmEvalPos *ep,
+				  const GnmSearchReplaceCommentResult *res)
+{
+	if (!sr->query || !sr->query_func)
+		return GTK_RESPONSE_YES;
+
+	return sr->query_func (GNM_SRQ_QUERY_COMMENT, sr,
+			       ep->sheet, &ep->eval,
+			       res->old_text, res->new_text);
+}
+
+/* ------------------------------------------------------------------------- */
+
 GType
 gnm_search_replace_scope_get_type (void)
 {

Modified: trunk/src/search.h
==============================================================================
--- trunk/src/search.h	(original)
+++ trunk/src/search.h	Mon Dec 22 14:10:31 2008
@@ -132,6 +132,16 @@
 				   GnmEvalPos const *ep,
 				   GnmSearchReplaceValueResult *res);
 
+void gnm_search_replace_query_fail (GnmSearchReplace *sr,
+				    const GnmSearchReplaceCellResult *res);
+
+int gnm_search_replace_query_cell (GnmSearchReplace *sr,
+				   const GnmSearchReplaceCellResult *res);
+
+int gnm_search_replace_query_comment (GnmSearchReplace *sr,
+				      const GnmEvalPos *ep,
+				      const GnmSearchReplaceCommentResult *res);
+
 G_END_DECLS
 
 #endif /* _GNM_SEARCH_H_ */



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