SF.net SVN: geany-plugins:[807] trunk/geanylatex
frlan at users.sourceforge.net
frlan at xxxxx
Thu Jul 9 21:39:12 UTC 2009
Revision: 807
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=807&view=rev
Author: frlan
Date: 2009-07-09 21:39:12 +0000 (Thu, 09 Jul 2009)
Log Message:
-----------
GeanyLaTeX: Added a function to level up and level down structure element.
Modified Paths:
--------------
trunk/geanylatex/ChangeLog
trunk/geanylatex/src/Makefile.am
trunk/geanylatex/src/geanylatex.c
trunk/geanylatex/src/geanylatex.h
trunk/geanylatex/src/latexkeybindings.c
trunk/geanylatex/src/latexkeybindings.h
Added Paths:
-----------
trunk/geanylatex/src/latexstructure.c
trunk/geanylatex/src/latexstructure.h
Modified: trunk/geanylatex/ChangeLog
===================================================================
--- trunk/geanylatex/ChangeLog 2009-07-09 21:38:35 UTC (rev 806)
+++ trunk/geanylatex/ChangeLog 2009-07-09 21:39:12 UTC (rev 807)
@@ -1,3 +1,8 @@
+2009-07-09 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
+
+ * Added a function to level up and level down structure element.
+
+
2009-07-08 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
* Migrated bibTeX inserting entry framework to make usage of a GPtrArray.
Modified: trunk/geanylatex/src/Makefile.am
===================================================================
--- trunk/geanylatex/src/Makefile.am 2009-07-09 21:38:35 UTC (rev 806)
+++ trunk/geanylatex/src/Makefile.am 2009-07-09 21:39:12 UTC (rev 807)
@@ -1,5 +1,5 @@
lib_LTLIBRARIES = geanylatex.la
-geanylatex_la_SOURCES = geanylatex.c geanylatex.h datatypes.h latexencodings.c latexencodings.h letters.c letters.h bibtex.h bibtex.c bibtexlabels.c reftex.c reftex.h latexutils.c latexutils.h formatutils.c formatutils.h formatpatterns.c latexenvironments.h latexenvironments.c latexkeybindings.h latexkeybindings.c
+geanylatex_la_SOURCES = geanylatex.c geanylatex.h datatypes.h latexencodings.c latexencodings.h letters.c letters.h bibtex.h bibtex.c bibtexlabels.c reftex.c reftex.h latexutils.c latexutils.h formatutils.c formatutils.h formatpatterns.c latexenvironments.h latexenvironments.c latexkeybindings.h latexkeybindings.c latexstructure.h latexstructure.c
geanylatex_la_LDFLAGS = -module -avoid-version
geanylatex_la_LIBADD = @GEANY_LIBS@ $(INTLLIBS)
Modified: trunk/geanylatex/src/geanylatex.c
===================================================================
--- trunk/geanylatex/src/geanylatex.c 2009-07-09 21:38:35 UTC (rev 806)
+++ trunk/geanylatex/src/geanylatex.c 2009-07-09 21:39:12 UTC (rev 807)
@@ -88,6 +88,8 @@
KB_LATEX_ENVIRONMENT_INSERT_DESCRIPTION,
KB_LATEX_ENVIRONMENT_INSERT_ITEMIZE,
KB_LATEX_ENVIRONMENT_INSERT_ENUMERATE,
+ KB_LATEX_STRUCTURE_LVLUP,
+ KB_LATEX_STRUCTURE_LVLDOWN,
COUNT_KB
};
@@ -1148,6 +1150,12 @@
keybindings_set_item(plugin_key_group, KB_LATEX_ENVIRONMENT_INSERT_ENUMERATE,
glatex_kb_insert_enumerate_list, 0, 0, "insert_enumerate_list",
_("Insert enumerate list"), NULL);
+ keybindings_set_item(plugin_key_group, KB_LATEX_STRUCTURE_LVLUP,
+ glatex_kb_structure_lvlup, 0, 0, "structure_lvl_up",
+ _("Set selection one level up"), NULL);
+ keybindings_set_item(plugin_key_group, KB_LATEX_STRUCTURE_LVLDOWN,
+ glatex_kb_structure_lvldown, 0, 0, "structure_lvl_down",
+ _("Set selection one level down"), NULL);
}
void plugin_help()
Modified: trunk/geanylatex/src/geanylatex.h
===================================================================
--- trunk/geanylatex/src/geanylatex.h 2009-07-09 21:38:35 UTC (rev 806)
+++ trunk/geanylatex/src/geanylatex.h 2009-07-09 21:39:12 UTC (rev 807)
@@ -45,6 +45,7 @@
#include "reftex.h"
#include "latexenvironments.h"
#include "formatutils.h"
+#include "latexstructure.h"
#include "latexkeybindings.h"
#include "Scintilla.h"
#include "plugindata.h"
Modified: trunk/geanylatex/src/latexkeybindings.c
===================================================================
--- trunk/geanylatex/src/latexkeybindings.c 2009-07-09 21:38:35 UTC (rev 806)
+++ trunk/geanylatex/src/latexkeybindings.c 2009-07-09 21:39:12 UTC (rev 807)
@@ -131,3 +131,17 @@
return;
glatex_insert_list_environment(GLATEX_LIST_ENUMERATE);
}
+
+void glatex_kb_structure_lvlup(G_GNUC_UNUSED guint key_id)
+{
+ if (NULL == document_get_current())
+ return;
+ glatex_structure_lvlup();
+}
+
+void glatex_kb_structure_lvldown(G_GNUC_UNUSED guint key_id)
+{
+ if (NULL == document_get_current())
+ return;
+ glatex_structure_lvldown();
+}
Modified: trunk/geanylatex/src/latexkeybindings.h
===================================================================
--- trunk/geanylatex/src/latexkeybindings.h 2009-07-09 21:38:35 UTC (rev 806)
+++ trunk/geanylatex/src/latexkeybindings.h 2009-07-09 21:39:12 UTC (rev 807)
@@ -40,5 +40,7 @@
void glatex_kb_insert_description_list(G_GNUC_UNUSED guint key_id);
void glatex_kb_insert_itemize_list(G_GNUC_UNUSED guint key_id);
void glatex_kb_insert_enumerate_list(G_GNUC_UNUSED guint key_id);
+void glatex_kb_structure_lvlup(G_GNUC_UNUSED guint key_id);
+void glatex_kb_structure_lvldown(G_GNUC_UNUSED guint key_id);
#endif
Added: trunk/geanylatex/src/latexstructure.c
===================================================================
--- trunk/geanylatex/src/latexstructure.c (rev 0)
+++ trunk/geanylatex/src/latexstructure.c 2009-07-09 21:39:12 UTC (rev 807)
@@ -0,0 +1,122 @@
+/*
+ * latexstructure.c
+ *
+ * Copyright 2009 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include "latexstructure.h"
+
+const gchar *glatex_structure_values[] = {
+ ("\\part"),
+ ("\\chapter"),
+ ("\\section"),
+ ("\\subsection"),
+ ("\\subsubsection"),
+ ("\\paragraph"),
+ ("\\subparagraph"),
+ ("\\subsubparagraph"),
+ ( NULL )
+};
+
+/* Takes over a direktion into which the structur element should
+ * be changed.
+ * TRUE -> rotate down (\section -> \subsection)
+ * FALSE -> rotate up (\section -> \chapter)
+ * Also it takes over the start structure level as a gint enum */
+gint glatex_structure_rotate(gboolean direction, gint start)
+{
+ gint new_value;
+
+ if (direction == TRUE)
+ {
+ if (start == GLATEX_STRUCTURE_SUBSUBPARAGRAPH)
+ new_value = GLATEX_STRUCTURE_PART;
+ else
+ new_value = start + 1;
+ }
+ else
+ {
+ if (start == GLATEX_STRUCTURE_PART)
+ new_value = GLATEX_STRUCTURE_SUBSUBPARAGRAPH;
+ else
+ new_value = start - 1;
+ }
+ return new_value;
+}
+
+
+void glatex_structure_lvlup()
+{
+ gint i;
+ GeanyDocument *doc = NULL;
+ doc = document_get_current();
+ gchar *tmp = NULL;
+ GString *haystack = NULL;
+
+ sci_start_undo_action(doc->editor->sci);
+ tmp = sci_get_selection_contents(doc->editor->sci);
+ haystack = g_string_new(tmp);
+
+ g_free(tmp);
+ tmp = NULL;
+
+ for (i = 0; i < GLATEX_STRUCTURE_N_LEVEL; i++)
+ {
+ if (utils_string_replace_all
+ (haystack,
+ glatex_structure_values[i],
+ glatex_structure_values[glatex_structure_rotate(FALSE, i)]
+ ) > 0)
+ {
+ tmp = g_string_free(haystack, FALSE);
+ sci_replace_sel(doc->editor->sci, tmp);
+ g_free(tmp);
+ sci_end_undo_action(doc->editor->sci);
+ break;
+ }
+ }
+}
+
+void glatex_structure_lvldown()
+{
+ gint i;
+ GeanyDocument *doc = NULL;
+ doc = document_get_current();
+ gchar *tmp = NULL;
+ GString *haystack = NULL;
+
+ tmp = sci_get_selection_contents(doc->editor->sci);
+ haystack = g_string_new(tmp);
+
+ g_free(tmp);
+ tmp = NULL;
+
+ for (i = 0; i < GLATEX_STRUCTURE_N_LEVEL; i++)
+ {
+ if (utils_string_replace_all(haystack,
+ glatex_structure_values[i],
+ glatex_structure_values[glatex_structure_rotate(TRUE, i)])
+ > 0)
+ {
+ tmp = g_string_free(haystack, FALSE);
+ sci_replace_sel(doc->editor->sci, tmp);
+ g_free(tmp);
+ break;
+ }
+ }
+}
Added: trunk/geanylatex/src/latexstructure.h
===================================================================
--- trunk/geanylatex/src/latexstructure.h (rev 0)
+++ trunk/geanylatex/src/latexstructure.h 2009-07-09 21:39:12 UTC (rev 807)
@@ -0,0 +1,44 @@
+/*
+ * latexstructure.h
+ *
+ * Copyright 2009 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef LATEXSTRUCTURE_H
+#define LATEXSTRUCTURE_H
+
+#include "geanylatex.h"
+
+enum {
+ GLATEX_STRUCTURE_PART = 0,
+ GLATEX_STRUCTURE_CHAPTER,
+ GLATEX_STRUCTURE_SECTION,
+ GLATEX_STRUCTURE_SUBSECTION,
+ GLATEX_STRUCTURE_SUBSUBSECTION,
+ GLATEX_STRUCTURE_PARAGRAPH,
+ GLATEX_STRUCTURE_SUBPARAGRAPH,
+ GLATEX_STRUCTURE_SUBSUBPARAGRAPH,
+ GLATEX_STRUCTURE_N_LEVEL};
+
+extern const gchar *glatex_structure_values[];
+
+void glatex_structure_lvlup();
+
+void glatex_structure_lvldown();
+
+#endif
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