SF.net SVN: geany-plugins:[489] trunk/geanylatex

frlan at users.sourceforge.net frlan at xxxxx
Wed Feb 18 00:21:13 UTC 2009


Revision: 489
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=489&view=rev
Author:   frlan
Date:     2009-02-18 00:21:13 +0000 (Wed, 18 Feb 2009)

Log Message:
-----------
GeanyLaTeX: Format selected text if any

Modified Paths:
--------------
    trunk/geanylatex/ChangeLog
    trunk/geanylatex/src/formatutils.c

Modified: trunk/geanylatex/ChangeLog
===================================================================
--- trunk/geanylatex/ChangeLog	2009-02-18 00:20:44 UTC (rev 488)
+++ trunk/geanylatex/ChangeLog	2009-02-18 00:21:13 UTC (rev 489)
@@ -1,3 +1,8 @@
+2009-02-18  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>
+
+ * Formating of selected text
+
+
 2009-02-15  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>
 
  * Added a menu entry for easy formating of text

Modified: trunk/geanylatex/src/formatutils.c
===================================================================
--- trunk/geanylatex/src/formatutils.c	2009-02-18 00:20:44 UTC (rev 488)
+++ trunk/geanylatex/src/formatutils.c	2009-02-18 00:21:13 UTC (rev 489)
@@ -25,8 +25,32 @@
                          G_GNUC_UNUSED gpointer gdata)
 {
     gint format = GPOINTER_TO_INT(gdata);
+    GeanyDocument *doc = NULL;
+	doc = document_get_current();
 
-    glatex_insert_string(glatex_format_pattern[format], TRUE);
-    glatex_insert_string("{", TRUE);
-    glatex_insert_string("}", FALSE);
+	if (doc != NULL)
+	{
+        if (sci_has_selection(doc->editor->sci))
+        {
+            gint selection_len = sci_get_selected_text_length(doc->editor->sci);
+            gchar *selection = g_malloc(selection_len + 1);
+            const gchar *replacement = NULL;
+
+            sci_get_selected_text(doc->editor->sci, selection);
+
+            replacement = g_strconcat(glatex_format_pattern[format],"{",
+                selection, "}", NULL);
+
+            sci_replace_sel(doc->editor->sci, replacement);
+            g_free(selection);
+        }
+        else
+        {
+            glatex_insert_string(glatex_format_pattern[format], TRUE);
+            glatex_insert_string("{", TRUE);
+            glatex_insert_string("}", FALSE);
+        }
+    }
 }
+
+


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