[gnumeric] Trigger configurable text importer on paste of tabs. [#395631]



commit 14e93c0169010438f0d979703d600ea4ff7cfef9
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Tue Feb 22 10:56:15 2011 -0700

    Trigger configurable text importer on paste of tabs. [#395631]
    
    2011-02-22  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/gui-clipboard.c (text_is_single_cell): new
    	(text_to_cell_region): use text_is_single_cell

 ChangeLog           |    5 +++++
 NEWS                |    1 +
 src/gui-clipboard.c |   33 +++++++++++++++++++--------------
 3 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6f7d648..d07e67a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-02-22  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/gui-clipboard.c (text_is_single_cell): new
+	(text_to_cell_region): use text_is_single_cell
+
 2011-02-21  Morten Welinder  <terra gnome org>
 
 	* src/stf-parse.c (trim_spaces_inplace): Don't use strcpy for
diff --git a/NEWS b/NEWS
index 661d5b9..293fb54 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Andreas:
 	  [#642850]
 	* Fix crash on resaving LibreOffice created xlsx files with unauthored 
 	  comments. [#642850]
+	* Trigger configurable text importer on paste of tabs. [#395631]
 
 Jean:
 	* Fix cursor position inside a cell edited in a zoomed sheet. [#641709]
diff --git a/src/gui-clipboard.c b/src/gui-clipboard.c
index 2fdb1b9..49f8b50 100644
--- a/src/gui-clipboard.c
+++ b/src/gui-clipboard.c
@@ -100,6 +100,20 @@ typedef struct {
 #define CTEXT_ATOM_NAME "COMPOUND_TEXT"
 #define STRING_ATOM_NAME "STRING"
 
+	/* See if this is a "single line + line end", a "multiline" or a "tab separated"
+	 * string. If this is _not_ the case we won't invoke the STF, it is
+	 * unlikely that the user will actually need it in this case. */
+static gboolean
+text_is_single_cell (gchar const *data, int data_len)
+{
+	int i;
+
+	for (i = 0; i < data_len; i++)
+		if (data[i] == '\n' || data[i] == '\t')
+			return FALSE;
+	return TRUE;
+}
+
 
 static GnmCellRegion *
 text_to_cell_region (WBCGtk *wbcg,
@@ -112,19 +126,8 @@ text_to_cell_region (WBCGtk *wbcg,
 	GnmCellRegion *cr = NULL;
 	gboolean oneline;
 	char *data_converted = NULL;
-	int i;
 
-	/* See if this is a "single line + line end" or a "multiline"
-	 * string. If this is _not_ the case we won't invoke the STF, it is
-	 * unlikely that the user will actually need it in this case.
-	 * NOTE: This is making an assumption on what the user 'wants', this
-	 * is not really a good thing. We should put this in a config dialog. */
-	oneline = TRUE;
-	for (i = 0; i < data_len; i++)
-		if (data[i] == '\n') {
-			oneline = FALSE;
-			break;
-		}
+	oneline = text_is_single_cell (data, data_len);
 
 	if (oneline && (opt_encoding == NULL || strcmp (opt_encoding, "UTF-8") != 0)) {
 		size_t bytes_written;
@@ -208,7 +211,8 @@ text_content_received (GtkClipboard *clipboard,  GtkSelectionData *sel,
 	if (gtk_selection_data_get_length (sel) < 0) {
 		;
 	} else if (target == gdk_atom_intern (UTF8_ATOM_NAME, FALSE)) {
-		content = text_to_cell_region (wbcg, (const char *)gtk_selection_data_get_data (sel), gtk_selection_data_get_length (sel), "UTF-8", TRUE);
+		content = text_to_cell_region (wbcg, (const char *)gtk_selection_data_get_data (sel), 
+					       gtk_selection_data_get_length (sel), "UTF-8", TRUE);
 	} else if (target == gdk_atom_intern (CTEXT_ATOM_NAME, FALSE)) {
 		/* COMPOUND_TEXT is icky.  Just let GTK+ do the work.  */
 		char *data_utf8 = (char *)gtk_selection_data_get_text (sel);
@@ -218,7 +222,8 @@ text_content_received (GtkClipboard *clipboard,  GtkSelectionData *sel,
 		char const *locale_encoding;
 		g_get_charset (&locale_encoding);
 
-		content = text_to_cell_region (wbcg, (const char *)gtk_selection_data_get_data (sel), gtk_selection_data_get_length (sel), locale_encoding, FALSE);
+		content = text_to_cell_region (wbcg, (const char *)gtk_selection_data_get_data (sel), 
+					       gtk_selection_data_get_length (sel), locale_encoding, FALSE);
 	}
 	if (content) {
 		/*



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