SF.net SVN: geany-plugins:[1891] trunk/geany-plugins/tableconvert

frlan at users.sourceforge.net frlan at xxxxx
Sat Jan 29 16:41:05 UTC 2011


Revision: 1891
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1891&view=rev
Author:   frlan
Date:     2011-01-29 16:41:04 +0000 (Sat, 29 Jan 2011)

Log Message:
-----------
Tableconvert: Add logic to convert also to LaTeX tabular

This has been taken from GeanyLaTeX plugin and will be removed there as it fits better to this plugin.

Modified Paths:
--------------
    trunk/geany-plugins/tableconvert/ChangeLog
    trunk/geany-plugins/tableconvert/src/tableconvert.c

Modified: trunk/geany-plugins/tableconvert/ChangeLog
===================================================================
--- trunk/geany-plugins/tableconvert/ChangeLog	2011-01-29 16:40:40 UTC (rev 1890)
+++ trunk/geany-plugins/tableconvert/ChangeLog	2011-01-29 16:41:04 UTC (rev 1891)
@@ -1,6 +1,7 @@
 2011-01-29  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>
 
  * Rename plugin to Tableconvert.
+ * Include logic to transform also lists to LaTeX tabular.
 
 
 2011-01-27  Frank Lanitz  <frlan at frank.uvena.de>

Modified: trunk/geany-plugins/tableconvert/src/tableconvert.c
===================================================================
--- trunk/geany-plugins/tableconvert/src/tableconvert.c	2011-01-29 16:40:40 UTC (rev 1890)
+++ trunk/geany-plugins/tableconvert/src/tableconvert.c	2011-01-29 16:41:04 UTC (rev 1891)
@@ -125,17 +125,55 @@
 				g_free(rows);
 				g_free(replacement);
 			}
+			else if (doc->file_type->id == GEANY_FILETYPES_LATEX)
+			{
+				guint i;
+				guint j;
+
+				/* Adding header to replacement */
+				replacement_str = g_string_new("\\begin{tabular}{}\n");
+
+				/* Iteration onto rows and building up lines of table for
+				* replacement */
+				for (i = 0; rows[i] != NULL ; i++)
+				{
+					gchar **columns = NULL;
+					columns = g_strsplit_set(rows[i], "\t", -1);
+
+					for (j = 0; columns[j] != NULL; j++)
+					{
+						if (j > 0)
+						{
+							g_string_append(replacement_str, "  &  ");
+						}
+						g_string_append(replacement_str, columns[j]);
+					}
+
+					g_string_append(replacement_str, "\\\\\n");
+
+					g_free(columns);
+				}
+				/* Adding the footer of table */
+
+				g_string_append(replacement_str, "\\end{tabular}\n");
+
+				/* Replacing selection with new table */
+				replacement = g_string_free(replacement_str, FALSE);
+				sci_replace_sel(doc->editor->sci, replacement);
+				g_free(rows);
+				g_free(replacement);
+			}
 		}
+		else
+		{
+			/* OK. Something went not as expected.
+			* We did have a selection but cannot parse it into rows.
+			* Aborting */
+			g_warning(_("Something went went wrong on parsing selection. Aborting"));
+			return;
+		}
 	}
-	else
-	{
-		/* OK. Something went not as expected.
-		 * We did have a selection but cannot parse it into rows.
-		 * Aborting */
-		g_warning(_("Something went went wrong on parsing selection. Aborting"));
-		return;
-	} /* Selection was given -- end
-	   * in case of there was no selection we are just doing nothing */
+	   /* in case of there was no selection we are just doing nothing */
 	return;
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Plugins-Commits mailing list