SF.net SVN: geany-plugins:[515] trunk
frlan at users.sourceforge.net
frlan at xxxxx
Sat Feb 28 12:04:19 UTC 2009
Revision: 515
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=515&view=rev
Author: frlan
Date: 2009-02-28 12:04:19 +0000 (Sat, 28 Feb 2009)
Log Message:
-----------
GeanyLaTeX: Added a feature for easy inserting environments to document
Modified Paths:
--------------
trunk/geanylatex/ChangeLog
trunk/geanylatex/src/Makefile.am
trunk/geanylatex/src/geanylatex.c
trunk/geanylatex/src/geanylatex.h
trunk/geanylatex/src/letters.h
trunk/wscript
Added Paths:
-----------
trunk/geanylatex/src/latexenvironments.c
trunk/geanylatex/src/latexenvironments.h
Modified: trunk/geanylatex/ChangeLog
===================================================================
--- trunk/geanylatex/ChangeLog 2009-02-28 01:35:41 UTC (rev 514)
+++ trunk/geanylatex/ChangeLog 2009-02-28 12:04:19 UTC (rev 515)
@@ -1,6 +1,7 @@
2009-02-28 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
* Don't react on some keybindings in case of no document is open.
+ * Added a feature for easy inserting environments to document.
2009-02-18 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
Modified: trunk/geanylatex/src/Makefile.am
===================================================================
--- trunk/geanylatex/src/Makefile.am 2009-02-28 01:35:41 UTC (rev 514)
+++ trunk/geanylatex/src/Makefile.am 2009-02-28 12:04:19 UTC (rev 515)
@@ -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
+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
geanylatex_la_LDFLAGS = -module -avoid-version
geanylatex_la_LIBADD = @GEANY_LIBS@ $(INTLLIBS)
Modified: trunk/geanylatex/src/geanylatex.c
===================================================================
--- trunk/geanylatex/src/geanylatex.c 2009-02-28 01:35:41 UTC (rev 514)
+++ trunk/geanylatex/src/geanylatex.c 2009-02-28 12:04:19 UTC (rev 515)
@@ -45,6 +45,7 @@
GtkWidget *menu_latex_bibtex_submenu = NULL;
GtkWidget *menu_latex_format_insert = NULL;
GtkWidget *menu_latex_format_insert_submenu = NULL;
+GtkWidget *menu_latex_insert_environment = NULL;
/* doing some global stuff */
static GtkWidget *menu_latex_replace_toggle = NULL;
@@ -63,6 +64,7 @@
LATEX_INSERT_REF_KB,
LATEX_INSERT_NEWLINE,
LATEX_TOGGLE_ACTIVE,
+ LATEX_ENVIRONMENT_INSERT,
COUNT_KB
};
@@ -298,6 +300,77 @@
}
+static void
+glatex_environment_insert_activated (G_GNUC_UNUSED GtkMenuItem * menuitem,
+ G_GNUC_UNUSED gpointer gdata)
+{
+ gint env = GPOINTER_TO_INT(gdata);
+ glatex_insert_environment(glatex_environment_array[env].latex);
+}
+
+
+static void
+glatex_insert_environment_dialog(G_GNUC_UNUSED GtkMenuItem * menuitem,
+ G_GNUC_UNUSED gpointer gdata)
+{
+ GtkWidget *dialog = NULL;
+ GtkWidget *vbox = NULL;
+ GtkWidget *label_env = NULL;
+ GtkWidget *textbox_env = NULL;
+ GtkWidget *table = NULL;
+ gint i, max;
+
+ dialog = gtk_dialog_new_with_buttons(_("Insert Environment"),
+ GTK_WINDOW(geany->main_widgets->window),
+ GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
+ gtk_widget_set_name(dialog, "GeanyDialog");
+ gtk_box_set_spacing(GTK_BOX(vbox), 10);
+
+ table = gtk_table_new(1, 2, FALSE);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 6);
+ gtk_table_set_row_spacings(GTK_TABLE(table), 6);
+
+ label_env = gtk_label_new(_("Environment:"));
+ textbox_env = gtk_combo_box_entry_new_text();
+
+ max = glatex_count_menu_entries(glatex_environment_array,
+ ENVIRONMENT_CAT_DUMMY);
+ for (i = 0; i < max; i++)
+ {
+ gtk_combo_box_append_text(GTK_COMBO_BOX(textbox_env),
+ glatex_environment_array[i].label);
+ }
+
+ gtk_misc_set_alignment(GTK_MISC(label_env), 0, 0.5);
+
+ gtk_table_attach_defaults(GTK_TABLE(table), label_env, 0, 1, 0, 1);
+ gtk_table_attach_defaults(GTK_TABLE(table), textbox_env, 1, 2, 0, 1);
+ gtk_container_add(GTK_CONTAINER(vbox), table);
+
+ gtk_widget_show_all(vbox);
+
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+ gchar *env_string = NULL;
+
+ env_string = g_strdup(gtk_combo_box_get_active_text(
+ GTK_COMBO_BOX(textbox_env)));
+
+ if (env_string != NULL)
+ {
+ glatex_insert_environment(env_string);
+ g_free(env_string);
+ }
+ }
+
+ gtk_widget_destroy(dialog);
+}
+
+
static void character_create_menu_item(GtkWidget *menu, const gchar *label,
gint letter, SubMenuCallback callback)
{
@@ -315,8 +388,8 @@
* returns 0, if categorie is empty
* if gint categorie is -1, function will count every element.
* Useful, if there is no need for a categorie check.*/
-static gint
-count_menu_entries(SubMenuTemplate *tmp, gint categorie)
+gint
+glatex_count_menu_entries(SubMenuTemplate *tmp, gint categorie)
{
/* TODO: Reset max value to stop before it's too late */
gint i;
@@ -344,7 +417,7 @@
}
}
}
- return count;
+ return count + 1;
}
static gint
@@ -371,7 +444,7 @@
/* Creates sub menus based on information from letter.h */
for (i = 0; i < categories; i++)
{
- if (count_menu_entries(menu_template, i) > 0)
+ if (glatex_count_menu_entries(menu_template, i) > 0)
{
create_sub_menu(base_menu, sub_menu_cat[i][0],
sub_menu_cat[i][1], category_name[i].label);
@@ -386,7 +459,7 @@
gboolean sorted = category_name[i].sorted;
/* To check whether we need to build up a new sub sub menu. */
gint local_count = 0;
- gint item_count = count_menu_entries(menu_template, i);
+ gint item_count = glatex_count_menu_entries(menu_template, i);
if (item_count < 1)
continue;
@@ -920,6 +993,14 @@
insert_ref_activated(NULL, NULL);
}
+
+static void kbref_insert_environment(G_GNUC_UNUSED guint key_id)
+{
+ if (NULL == document_get_current())
+ return;
+ glatex_insert_environment_dialog(NULL, NULL);
+}
+
static void kbwizard(G_GNUC_UNUSED guint key_id)
{
wizard_activated(NULL, NULL);
@@ -951,7 +1032,11 @@
keybindings_set_item(plugin_key_group, LATEX_TOGGLE_ACTIVE, kblatex_toggle,
0, 0, "latex_toggle_status", _("Turn input replacement on/off"),
menu_latex_replace_toggle);
+ keybindings_set_item(plugin_key_group, LATEX_ENVIRONMENT_INSERT,
+ kbref_insert_environment, 0, 0, "latex_insert_environment",
+ _("Run insert environment dialog"), menu_latex_insert_environment);
+
}
void plugin_help()
@@ -1012,11 +1097,19 @@
menu_latex_label = gtk_menu_item_new_with_mnemonic(_("Insert _Label"));
gtk_tooltips_set_tip(tooltips, menu_latex_label,
- _("Helps at inserting labels to a document"), NULL);
+ _("Helps at inserting labels to a document"), NULL);
gtk_container_add(GTK_CONTAINER(menu_latex_menu), menu_latex_label);
g_signal_connect((gpointer) menu_latex_label, "activate",
G_CALLBACK(insert_label_activated), NULL);
+ menu_latex_insert_environment = gtk_menu_item_new_with_mnemonic(
+ _("Insert _Environment"));
+ gtk_tooltips_set_tip(tooltips, menu_latex_insert_environment,
+ _("Helps at inserting an environment a document"), NULL);
+ gtk_container_add(GTK_CONTAINER(menu_latex_menu), menu_latex_insert_environment);
+ g_signal_connect((gpointer) menu_latex_insert_environment, "activate",
+ G_CALLBACK(glatex_insert_environment_dialog), NULL);
+
menu_latex_bibtex = gtk_menu_item_new_with_mnemonic(_("BibTeX"));
gtk_container_add(GTK_CONTAINER(menu_latex_menu), menu_latex_bibtex);
Modified: trunk/geanylatex/src/geanylatex.h
===================================================================
--- trunk/geanylatex/src/geanylatex.h 2009-02-28 01:35:41 UTC (rev 514)
+++ trunk/geanylatex/src/geanylatex.h 2009-02-28 12:04:19 UTC (rev 515)
@@ -28,7 +28,6 @@
#include "geany.h"
#include "support.h"
-
#include "document.h"
#include "editor.h"
#include "filetypes.h"
@@ -44,6 +43,7 @@
#include "bibtex.h"
#include "latexutils.h"
#include "reftex.h"
+#include "latexenvironments.h"
#include "formatutils.h"
#include "Scintilla.h"
#include "plugindata.h"
@@ -110,5 +110,6 @@
#define MAX_MENU_ENTRIES 20
extern void glatex_insert_string(gchar *string, gboolean reset_position);
+gint glatex_count_menu_entries(SubMenuTemplate *tmp, gint categorie);
#endif
Added: trunk/geanylatex/src/latexenvironments.c
===================================================================
--- trunk/geanylatex/src/latexenvironments.c (rev 0)
+++ trunk/geanylatex/src/latexenvironments.c 2009-02-28 12:04:19 UTC (rev 515)
@@ -0,0 +1,58 @@
+/*
+ * latexenvironments.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 "latexenvironments.h"
+
+CategoryName glatex_environment_cat_names[] = {
+ { ENVIRONMENT_CAT_DUMMY, N_("Environments"), TRUE},
+ { 0, NULL, FALSE}
+};
+
+
+SubMenuTemplate glatex_environment_array[] = {
+ {0, "document", "document"},
+ {0, "frame", "frame"},
+ {0, "itemize", "itemize"},
+ {0, NULL, NULL},
+};
+
+
+void glatex_insert_environment(gchar *environment)
+{
+ GeanyDocument *doc = NULL;
+
+ doc = document_get_current();
+
+ if (doc != NULL && environment != NULL)
+ {
+ gint pos = sci_get_current_position(doc->editor->sci);
+ gint len = strlen(environment);
+ gchar *tmp = NULL;
+
+ tmp = g_strconcat("\\begin{", environment, "}\n\n\\end(",
+ environment, "}\n", NULL);
+
+ sci_insert_text(doc->editor->sci, pos, tmp);
+ sci_set_current_position(doc->editor->sci, pos + len + 9, TRUE);
+
+ g_free(tmp);
+ }
+}
Copied: trunk/geanylatex/src/latexenvironments.h (from rev 514, trunk/geanylatex/src/letters.h)
===================================================================
--- trunk/geanylatex/src/latexenvironments.h (rev 0)
+++ trunk/geanylatex/src/latexenvironments.h 2009-02-28 12:04:19 UTC (rev 515)
@@ -0,0 +1,38 @@
+/*
+ * latexenvironments.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 LATEXENVIRONMENTS_H
+#define LATEXENVIRONMENTS_H
+
+#include "geanylatex.h"
+
+enum {
+ ENVIRONMENT_CAT_DUMMY = 0,
+ ENVIRONMENT_CAT_MAX
+};
+
+extern SubMenuTemplate glatex_environment_array[];
+
+extern CategoryName glatex_environment_cat_names[];
+
+void glatex_insert_environment(gchar *environment);
+
+#endif
Modified: trunk/geanylatex/src/letters.h
===================================================================
--- trunk/geanylatex/src/letters.h 2009-02-28 01:35:41 UTC (rev 514)
+++ trunk/geanylatex/src/letters.h 2009-02-28 12:04:19 UTC (rev 515)
@@ -35,5 +35,4 @@
gchar *glatex_get_entity(const gchar *letter);
-
#endif
Modified: trunk/wscript
===================================================================
--- trunk/wscript 2009-02-28 01:35:41 UTC (rev 514)
+++ trunk/wscript 2009-02-28 12:04:19 UTC (rev 515)
@@ -89,7 +89,8 @@
'geanylatex/src/letters.c', 'geanylatex/src/bibtex.c',
'geanylatex/src/bibtexlabels.c', 'geanylatex/src/reftex.c',
'geanylatex/src/latexutils.c', 'geanylatex/src/formatutils.c',
- 'geanylatex/src/formatpatterns.c'],
+ 'geanylatex/src/formatpatterns.c',
+ 'geanylatex/src/latexenvironments.c'],
[ 'geanylatex' ], # include dirs
'0.4dev'),
Plugin('geanylua',
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