[gnumeric] Read edit position and active sheet from LibreOffice generated ODF files.



commit a7ace6b5492acd6c59cdc8e4619245402b841ef5
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Mon Aug 29 15:07:40 2011 -0600

    Read edit position and active sheet from LibreOffice generated ODF files.
    
    2011-08-29  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (odf_config_item_end): handle G_TYPE_STRING
    	(odf_config_item): handle string type
    	(odf_apply_ooo_table_config): set edit position
    	(odf_apply_ooo_config): set active sheet

 NEWS                                 |    1 +
 plugins/openoffice/ChangeLog         |    7 +++++
 plugins/openoffice/openoffice-read.c |   49 +++++++++++++++++++++++++++++----
 3 files changed, 51 insertions(+), 6 deletions(-)
---
diff --git a/NEWS b/NEWS
index cb88358..982a032 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Andreas:
 	* Fix saving of newlines to xls. [#356711]
 	* Enable markup selection in scientific format selector.
 	* Be compatible wihthe changed LibreOffice ODF documents with tab colours.
+	* Read edit position and active sheet from LibreOffice generated ODF files.
 
 Jean:
 	* Make things build against gtk+-3.0.
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index d1cb94a..dbb9883 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,10 @@
+2011-08-29  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (odf_config_item_end): handle G_TYPE_STRING
+	(odf_config_item): handle string type
+	(odf_apply_ooo_table_config): set edit position
+	(odf_apply_ooo_config): set active sheet
+
 2011-08-28  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-read.c (oo_style_prop_table): read LibreOffice
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 275539d..edfc8c6 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -30,8 +30,10 @@
 #include <workbook-view.h>
 #include <workbook.h>
 #include <sheet.h>
+#include <sheet-view.h>
 #include <sheet-merge.h>
 #include <sheet-filter.h>
+#include <selection.h>
 #include <ranges.h>
 #include <cell.h>
 #include <value.h>
@@ -8397,6 +8399,10 @@ odf_config_item_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 			}
 			break;
 		}
+		case G_TYPE_STRING:
+			val = g_value_init (g_new0 (GValue, 1), G_TYPE_STRING);
+			g_value_set_string (val, (xin->content->str));
+			break;
 		default:
 			break;
 		}
@@ -8422,7 +8428,7 @@ odf_config_item (GsfXMLIn *xin, xmlChar const **attrs)
 		{"int", G_TYPE_INT},
 		{"long", G_TYPE_LONG},
 		{"short", G_TYPE_INVALID},
-		{"string", G_TYPE_INVALID},
+		{"string", G_TYPE_STRING},
 		{ NULL,	0},
 	};
 	OOParseState *state = (OOParseState *)xin->user_state;
@@ -8539,12 +8545,32 @@ odf_apply_ooo_table_config (char const *key, GValue *val, OOParseState *state)
 		GHashTable *hash = g_value_get_boxed (val);
 		Sheet *sheet = workbook_sheet_by_name (state->pos.wb, key);
 		if (hash != NULL && sheet != NULL) {
-			GValue *tab = g_hash_table_lookup (hash, "TabColor");
-			if (tab != NULL && G_VALUE_HOLDS(tab, G_TYPE_INT)) {
-				GOColor color = g_value_get_int (tab);
+			GValue *item = g_hash_table_lookup (hash, "TabColor");
+			if (item != NULL && G_VALUE_HOLDS(item, G_TYPE_INT)) {
+				GOColor color = g_value_get_int (item);
 				color = color << 8;
 				sheet->tab_color = style_color_new_go (color);
 			}
+			item = g_hash_table_lookup (hash, "CursorPositionX");
+			if (item != NULL && G_VALUE_HOLDS(item, G_TYPE_INT)) {
+				GValue *itemy = g_hash_table_lookup (hash, "CursorPositionY");
+				if (itemy != NULL && G_VALUE_HOLDS(itemy, G_TYPE_INT)) {
+					GnmCellPos pos;
+					SheetView *sv 
+						= sheet_get_view (sheet, state->wb_view);
+					GnmRange r;
+					pos.col = g_value_get_int (item);
+					pos.row = g_value_get_int (itemy);
+					r.start = pos;
+					r.end = pos;
+
+					sv_selection_reset (sv);
+					sv_selection_add_range (sv, &r);
+					sv_set_edit_pos 
+						(sheet_get_view (sheet, state->wb_view), 
+						 &pos);
+				}
+			}
 		}
 	}
 }
@@ -8574,8 +8600,19 @@ odf_apply_ooo_config (OOParseState *state)
 		return;
 	hash =  g_value_get_boxed (val);
 
-	if ((hash == NULL) ||
-	    NULL == (val = g_hash_table_lookup (hash, "Tables")) ||
+	if (hash == NULL)
+		return;
+
+	val = g_hash_table_lookup (hash, "ActiveTable");
+
+	if (NULL != val && G_VALUE_HOLDS(val,G_TYPE_STRING)) {
+		const gchar *name = g_value_get_string (val);
+		Sheet *sheet = workbook_sheet_by_name (state->pos.wb, name);
+		if (sheet != NULL)
+			wb_view_sheet_focus (state->wb_view, sheet);
+ 	}
+
+	if (NULL == (val = g_hash_table_lookup (hash, "Tables")) ||
 	    !G_VALUE_HOLDS(val,G_TYPE_HASH_TABLE))
 		return;
 	hash =  g_value_get_boxed (val);



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