[gnumeric] gnm_app_workbook_get_by_index: make index zero-based.



commit d0670fc79002dff39072435fe8609a4246ac3188
Author: Morten Welinder <terra gnome org>
Date:   Wed Apr 29 10:21:57 2009 -0400

    gnm_app_workbook_get_by_index: make index zero-based.
---
 ChangeLog         |    3 +++
 src/application.c |   25 ++-----------------------
 2 files changed, 5 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 65d0984..8b9a178 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2009-04-29  Morten Welinder  <terra gnome org>
 
+	* src/application.c (gnm_app_workbook_get_by_index): Simplify and
+	make zero-based.
+
 	* src/position.c (gnm_cellpos_init_cellref_ss): Make public.
 
 	* src/parse-util.c (cellref_as_string, rangeref_parse): Handle
diff --git a/src/application.c b/src/application.c
index 308f4e1..6d14e53 100644
--- a/src/application.c
+++ b/src/application.c
@@ -435,32 +435,11 @@ gnm_app_workbook_foreach (GnmWbIterFunc cback, gpointer data)
 	return TRUE;
 }
 
-struct wb_index_closure
-{
-	Workbook *wb;
-	int index;	/* 1 based */
-};
-
-static gboolean
-cb_workbook_index (Workbook *wb, gpointer closure)
-{
-	struct wb_index_closure *dat = closure;
-	if (--(dat->index) == 0) {
-		dat->wb = wb;
-		return FALSE;
-	}
-	return TRUE;
-}
-
+/* Get nth workbook.  Index is zero-based.  */
 Workbook *
 gnm_app_workbook_get_by_index (int i)
 {
-	struct wb_index_closure closure;
-	closure.wb = NULL;
-	closure.index = i;
-	gnm_app_workbook_foreach (&cb_workbook_index, &closure);
-
-	return closure.wb;
+	return g_list_nth_data (app->workbook_list, i);
 }
 
 double



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