Revision: 490 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=490&view=rev Author: frlan Date: 2009-02-18 00:21:47 +0000 (Wed, 18 Feb 2009)
Log Message: ----------- GeanyLaTeX: Replace special characters at input with LaTeX replacment
Modified Paths: -------------- trunk/geanylatex/ChangeLog trunk/geanylatex/src/geanylatex.c trunk/geanylatex/src/geanylatex.h trunk/geanylatex/src/letters.c trunk/geanylatex/src/letters.h
Modified: trunk/geanylatex/ChangeLog =================================================================== --- trunk/geanylatex/ChangeLog 2009-02-18 00:21:13 UTC (rev 489) +++ trunk/geanylatex/ChangeLog 2009-02-18 00:21:47 UTC (rev 490) @@ -1,6 +1,8 @@ 2009-02-18 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
* Formating of selected text + * Added feature to replace special characters at input with LaTeX + replacment
2009-02-15 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
Modified: trunk/geanylatex/src/geanylatex.c =================================================================== --- trunk/geanylatex/src/geanylatex.c 2009-02-18 00:21:13 UTC (rev 489) +++ trunk/geanylatex/src/geanylatex.c 2009-02-18 00:21:47 UTC (rev 490) @@ -46,8 +46,15 @@ GtkWidget *menu_latex_format_insert = NULL; GtkWidget *menu_latex_format_insert_submenu = NULL;
+/* doing some global stuff */ +static GtkWidget *menu_latex_replace_toggle = NULL; + +/* Function will be deactivated, when only loaded */ +static gboolean toggle_active = FALSE; + static GtkWidget *main_menu_item = NULL;
+ /* Doing some basic keybinding stuff */ enum { @@ -55,11 +62,83 @@ LATEX_INSERT_LABEL_KB, LATEX_INSERT_REF_KB, LATEX_INSERT_NEWLINE, + LATEX_TOGGLE_ACTIVE, COUNT_KB };
PLUGIN_KEY_GROUP(geanylatex, COUNT_KB)
+ +/* Functions to toggle the status of plugin */ +void glatex_set_latextoggle_status(gboolean new_status) +{ + /* No more function at the moment.*/ + if (toggle_active != new_status) + toggle_active = new_status; +} + +static void toggle_status(G_GNUC_UNUSED GtkMenuItem * menuitem) +{ + if (toggle_active == TRUE) + glatex_set_latextoggle_status(FALSE); + else + glatex_set_latextoggle_status(TRUE); +} + + +static gboolean ht_editor_notify_cb(G_GNUC_UNUSED GObject *object, GeanyEditor *editor, + SCNotification *nt, G_GNUC_UNUSED gpointer data) +{ + g_return_val_if_fail(editor != NULL, FALSE); + + if (toggle_active != TRUE) + return FALSE; + + if (nt->nmhdr.code == SCN_CHARADDED) + { + gchar buf[7]; + gint len; + + len = g_unichar_to_utf8(nt->ch, buf); + if (len > 0) + { + const gchar *entity; + + buf[len] = '\0'; + entity = glatex_get_entity(buf); + + if (entity != NULL) + { + gint pos = sci_get_current_position(editor->sci); + + sci_set_selection_start(editor->sci, pos - len); + sci_set_selection_end(editor->sci, pos); + + sci_replace_sel(editor->sci, entity); + } + } + } + + return FALSE; +} + + +/* Called when keys were pressed */ +static void kblatex_toggle(G_GNUC_UNUSED guint key_id) +{ + if (toggle_active == TRUE) + glatex_set_latextoggle_status(FALSE); + else + glatex_set_latextoggle_status(TRUE); +} + + +PluginCallback plugin_callbacks[] = +{ + { "editor-notify", (GCallback) &ht_editor_notify_cb, FALSE, NULL }, + { NULL, NULL, FALSE, NULL } +}; + void glatex_insert_string(gchar *string, gboolean reset_position) { @@ -863,6 +942,10 @@ 0, 0, "insert_latex_ref", _("Insert \ref"), menu_latex_ref); keybindings_set_item(plugin_key_group, LATEX_INSERT_NEWLINE, kb_insert_newline, 0, 0, "insert_new_line", _("Insert linebreak \\ "), NULL); + 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); + }
void plugin_help() @@ -960,6 +1043,17 @@ G_CALLBACK(glatex_insert_latex_format), GINT_TO_POINTER(i)); }
+ menu_latex_replace_toggle = gtk_check_menu_item_new_with_mnemonic(_ + ("_Special Characters Replacing")); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(menu_latex_replace_toggle), + toggle_active); + + g_signal_connect((gpointer) menu_latex_replace_toggle, "activate", + G_CALLBACK(toggle_status), NULL); + + gtk_container_add(GTK_CONTAINER(menu_latex_menu), + menu_latex_replace_toggle); + init_keybindings();
ui_add_document_sensitive(menu_latex_menu_special_char);
Modified: trunk/geanylatex/src/geanylatex.h =================================================================== --- trunk/geanylatex/src/geanylatex.h 2009-02-18 00:21:13 UTC (rev 489) +++ trunk/geanylatex/src/geanylatex.h 2009-02-18 00:21:47 UTC (rev 490) @@ -45,6 +45,7 @@ #include "latexutils.h" #include "reftex.h" #include "formatutils.h" +#include "Scintilla.h" #include "plugindata.h" #include "geanyfunctions.h"
Modified: trunk/geanylatex/src/letters.c =================================================================== --- trunk/geanylatex/src/letters.c 2009-02-18 00:21:13 UTC (rev 489) +++ trunk/geanylatex/src/letters.c 2009-02-18 00:21:47 UTC (rev 490) @@ -214,3 +214,21 @@ {0, NULL, NULL},
}; + + +gchar *glatex_get_entity(const gchar *letter) +{ + guint i, len; + + len = G_N_ELEMENTS(glatex_char_array); + for (i = 0; i < len; i++) + { + if (utils_str_equal(glatex_char_array[i].label, letter)) + { + return glatex_char_array[i].latex; + } + } + + /* if the char is not in the list */ + return NULL; +}
Modified: trunk/geanylatex/src/letters.h =================================================================== --- trunk/geanylatex/src/letters.h 2009-02-18 00:21:13 UTC (rev 489) +++ trunk/geanylatex/src/letters.h 2009-02-18 00:21:47 UTC (rev 490) @@ -23,10 +23,17 @@ #ifndef LETTERS_H #define LETTER_H
+#include "geanylatex.h" #include "datatypes.h" +#include "ui_utils.h" +#include "support.h" +#include "utils.h"
extern SubMenuTemplate glatex_char_array[];
extern CategoryName glatex_cat_names[];
+gchar *glatex_get_entity(const gchar *letter); + + #endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.