Branch: refs/heads/master Author: Frank Lanitz frank@frank.uvena.de Committer: Frank Lanitz frank@frank.uvena.de Date: Thu, 09 Oct 2014 22:08:53 UTC Commit: 83bfbc106ea4dcdc4cb641544aa5cf05d9ff21f5 https://github.com/geany/geany-plugins/commit/83bfbc106ea4dcdc4cb641544aa5cf...
Log Message: ----------- TableConvert: Splitting plugin a little up and adding Geany-file-type independent convert menu
This commit mostly is adding a special menu for converting something to a table without changing Geany's file type settings. Currently it doesn't add much comfort with it, but it will allow in future also to convert e.g. into different wiki syntax stiles.
However, during this work it appeared to make any sense to split plugin into more than just one huge c-file.
Modified Paths: -------------- tableconvert/src/tableconvert.c tableconvert/src/tableconvert.h tableconvert/src/tableconvert_ui.c tableconvert/src/tableconvert_ui.h
Modified: tableconvert/src/tableconvert.c 141 lines changed, 62 insertions(+), 79 deletions(-) =================================================================== @@ -22,11 +22,8 @@ #include "config.h" /* for the gettext domain */ #endif
-#include "geanyplugin.h" - -GeanyPlugin *geany_plugin; -GeanyData *geany_data; -GeanyFunctions *geany_functions; +#include "tableconvert.h" +#include "tableconvert_ui.h"
PLUGIN_VERSION_CHECK(200)
@@ -35,36 +32,14 @@ PLUGIN_SET_TRANSLATABLE_INFO( _("A little plugin to convert lists into tables"), VERSION, "Frank Lanitz frank@frank.uvena.de")
-enum -{ - KB_HTMLTABLE_CONVERT_TO_TABLE, - COUNT_KB -}; - -typedef struct { - const gchar *start; - const gchar *header_start; - const gchar *header_stop; - const gchar *body_start; - const gchar *body_end; - const gchar *columnsplit; - const gchar *linestart; - const gchar *lineend; - /* linesplit should keep empty until you really need some special - * logic there. */ - const gchar *linesplit; - const gchar *end; -} TableConvertRule; - -enum { - TC_LATEX = 0, - TC_HTML, - TC_SQL -}; +GeanyPlugin *geany_plugin; +GeanyData *geany_data; +GeanyFunctions *geany_functions;
TableConvertRule tablerules[] = { /* LaTeX */ { + N_("LaTeX"), "\begin{table}[h]\n\begin{tabular}{}\n", "", "", @@ -78,6 +53,7 @@ TableConvertRule tablerules[] = { }, /* HTML */ { + N_("HTML"), "<table>\n", "<thead>\n", "</thead>\n", @@ -91,6 +67,7 @@ TableConvertRule tablerules[] = { }, /* SQL */ { + N_("SQL"), "", "", "", @@ -105,8 +82,6 @@ TableConvertRule tablerules[] = { };
-static GtkWidget *main_menu_item = NULL; - static gchar* convert_to_table_worker(gchar **rows, gboolean header, const TableConvertRule *rule) { @@ -188,7 +163,7 @@ static gchar* convert_to_table_worker(gchar **rows, gboolean header, return g_string_free(replacement_str, FALSE); }
-static void convert_to_table(gboolean header) +void convert_to_table(gboolean header, gint file_type) { GeanyDocument *doc = NULL; doc = document_get_current(); @@ -218,41 +193,51 @@ static void convert_to_table(gboolean header) /* Checking whether we do have something we can work on - Returning if not */ if (rows != NULL) { - switch (doc->file_type->id) + if (file_type == -1) { - case GEANY_FILETYPES_NONE: - { - g_strfreev(rows); - return; - } - case GEANY_FILETYPES_HTML: - case GEANY_FILETYPES_MARKDOWN: - { - replacement = convert_to_table_worker(rows, - header, - &tablerules[TC_HTML]); - break; - } - case GEANY_FILETYPES_LATEX: + switch (doc->file_type->id) { - replacement = convert_to_table_worker(rows, - header, - &tablerules[TC_LATEX]); - break; - } - case GEANY_FILETYPES_SQL: - { - /* TODO: Check for INTEGER and other datatypes on SQL */ - replacement = convert_to_table_worker(rows, - header, - &tablerules[TC_SQL]); - break; - } - default: - { - /* We just don't do anything */ - } - } /* filetype switch */ + case GEANY_FILETYPES_NONE: + { + g_strfreev(rows); + return; + } + case GEANY_FILETYPES_HTML: + case GEANY_FILETYPES_MARKDOWN: + { + replacement = convert_to_table_worker(rows, + header, + &tablerules[TC_HTML]); + break; + } + case GEANY_FILETYPES_LATEX: + { + replacement = convert_to_table_worker(rows, + header, + &tablerules[TC_LATEX]); + break; + } + case GEANY_FILETYPES_SQL: + { + /* TODO: Check for INTEGER and other datatypes on SQL */ + replacement = convert_to_table_worker(rows, + header, + &tablerules[TC_SQL]); + break; + } + default: + { + /* We just don't do anything */ + } + } /* filetype switch */ + } + else + { + replacement = convert_to_table_worker(rows, + header, + &tablerules[file_type]); + } + } else { @@ -281,7 +266,7 @@ static void kb_convert_to_table(G_GNUC_UNUSED guint key_id) { g_return_if_fail(document_get_current() != NULL);
- convert_to_table(TRUE); + convert_to_table(TRUE, -1); }
@@ -294,27 +279,25 @@ static void init_keybindings(void) _("Convert selection to table"), NULL); }
-static void cb_table_convert(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) +void cb_table_convert(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { - convert_to_table(TRUE); + convert_to_table(TRUE, -1); +} + +void cb_table_convert_type(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) +{ + convert_to_table(TRUE, GPOINTER_TO_INT(gdata)); }
void plugin_init(GeanyData *data) { init_keybindings(); - - /* Build up menu entry */ - main_menu_item = gtk_menu_item_new_with_mnemonic(_("_Convert to table")); - gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), main_menu_item); - ui_widget_set_tooltip_text(main_menu_item, - _("Converts current marked list to a table.")); - g_signal_connect(G_OBJECT(main_menu_item), "activate", G_CALLBACK(cb_table_convert), NULL); - gtk_widget_show_all(main_menu_item); - ui_add_document_sensitive(main_menu_item); + init_menuentries(); }
void plugin_cleanup(void) { gtk_widget_destroy(main_menu_item); + gtk_widget_destroy(menu_tableconvert); }
Modified: tableconvert/src/tableconvert.h 72 lines changed, 72 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,72 @@ +/* + * tableconvert.h + * + * Copyright 2014 Frank Lanitz frank@frank.uvena.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 TABLECONVERT_H +#define TABLECONVERT_H + +#include <geanyplugin.h> +#include <gtk/gtk.h> + + +extern GeanyPlugin *geany_plugin; +extern GeanyData *geany_data; +extern GeanyFunctions *geany_functions; + + +enum +{ + KB_HTMLTABLE_CONVERT_TO_TABLE, + COUNT_KB +}; + +typedef struct { + const gchar *type; + const gchar *start; + const gchar *header_start; + const gchar *header_stop; + const gchar *body_start; + const gchar *body_end; + const gchar *columnsplit; + const gchar *linestart; + const gchar *lineend; + /* linesplit should keep empty until you really need some special + * logic there. */ + const gchar *linesplit; + const gchar *end; +} TableConvertRule; + +enum { + TC_LATEX = 0, + TC_HTML, + TC_SQL, + TC_END +}; + +extern TableConvertRule tablerules[]; + +extern void cb_table_convert(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata); +extern void cb_table_convert_type(G_GNUC_UNUSED GtkMenuItem *menuitem, gpointer gdata); +extern void convert_to_table(gboolean header, gint file_type); + +#endif
Modified: tableconvert/src/tableconvert_ui.c 68 lines changed, 68 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,68 @@ +/* + * tableconvert_ui.c + * + * Copyright 2014 Frank Lanitz frank@frank.uvena.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 "tableconvert_ui.h" + +GtkWidget *main_menu_item = NULL; +GtkWidget *menu_tableconvert = NULL; +GtkWidget *menu_tableconvert_menu = NULL; + +void init_menuentries(void) +{ + int i = 0; + GtkWidget *tmp = NULL; + + /* Build up menu entry for table_convert based on global file type*/ + main_menu_item = gtk_menu_item_new_with_mnemonic(_("_Convert to table")); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), main_menu_item); + ui_widget_set_tooltip_text(main_menu_item, + _("Converts current marked list to a table.")); + g_signal_connect(G_OBJECT(main_menu_item), "activate", G_CALLBACK(cb_table_convert), NULL); + gtk_widget_show_all(main_menu_item); + ui_add_document_sensitive(main_menu_item); + + /* Build up menu entries for table convert based on explicit choice + * This is needed for e.g. different wiki-Syntax or differenz stiles + * within a special file type */ + + menu_tableconvert = gtk_image_menu_item_new_with_mnemonic(_("_More TableConvert")); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), menu_tableconvert); + + menu_tableconvert_menu = gtk_menu_new (); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_tableconvert), + menu_tableconvert_menu); + + for (i = 0; i < TC_END; i++) + { + tmp = NULL; + tmp = gtk_menu_item_new_with_mnemonic(_(tablerules[i].type)); + gtk_container_add(GTK_CONTAINER(menu_tableconvert_menu), tmp); + g_signal_connect(G_OBJECT(tmp), "activate", + G_CALLBACK(cb_table_convert_type), GINT_TO_POINTER(i)); + } + ui_add_document_sensitive(menu_tableconvert); + + /* Show the menu */ + gtk_widget_show_all(menu_tableconvert); +} +
Modified: tableconvert/src/tableconvert_ui.h 38 lines changed, 38 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,38 @@ +/* + * tableconvert_ui.h + * + * Copyright 2014 Frank Lanitz frank@frank.uvena.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 TABLECONVERT_UI_H +#define TABLECONVERT_UI_H + +#include "tableconvert.h" + +/* Variables */ +extern GtkWidget *main_menu_item; +extern GtkWidget *menu_tableconvert; +extern GtkWidget *menu_tableconvert_menu; + +/* functions */ + +void init_menuentries(void); + +#endif
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).