Revision: 1689 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1689&view=re... Author: frlan Date: 2010-10-29 16:07:23 +0000 (Fri, 29 Oct 2010)
Log Message: ----------- GeanyLaTeX: First steps for adding a insert BibTeX reference function
Modified Paths: -------------- trunk/geanylatex/TODO trunk/geanylatex/src/bibtex.c trunk/geanylatex/src/bibtex.h trunk/geanylatex/src/geanylatex.c trunk/geanylatex/src/geanylatex.h trunk/geanylatex/src/latexkeybindings.c trunk/geanylatex/src/latexkeybindings.h
Modified: trunk/geanylatex/TODO =================================================================== --- trunk/geanylatex/TODO 2010-10-28 21:02:33 UTC (rev 1688) +++ trunk/geanylatex/TODO 2010-10-29 16:07:23 UTC (rev 1689) @@ -27,3 +27,6 @@ * Improve behaviour of levelup and leveldown of structures * Adding a font size chooser to toolbar * Adding support for dtx + +Generell: +* Cleaning up code
Modified: trunk/geanylatex/src/bibtex.c =================================================================== --- trunk/geanylatex/src/bibtex.c 2010-10-28 21:02:33 UTC (rev 1688) +++ trunk/geanylatex/src/bibtex.c 2010-10-29 16:07:23 UTC (rev 1689) @@ -171,3 +171,22 @@ sci_end_undo_action(doc->editor->sci); g_free(tmp); } + +void glatex_bibtex_insert_cite(gchar *reference_name, gchar *option) +{ + gchar *tmp; + + g_return_if_fail(reference_name != NULL); + + if (option != NULL) + { + tmp = g_strconcat("\cite[", option, "]{", reference_name, "}", NULL); + } + else + { + tmp = g_strconcat("\cite{", reference_name, "}", NULL); + } + glatex_insert_string(tmp, TRUE); + g_free(tmp); +} +
Modified: trunk/geanylatex/src/bibtex.h =================================================================== --- trunk/geanylatex/src/bibtex.h 2010-10-28 21:02:33 UTC (rev 1688) +++ trunk/geanylatex/src/bibtex.h 2010-10-29 16:07:23 UTC (rev 1689) @@ -80,11 +80,9 @@ extern BibTeXType glatex_bibtex_types[];
int glatex_push_bibtex_entry(int style, GeanyDocument *doc); - void glatex_insert_bibtex_entry(G_GNUC_UNUSED GtkMenuItem * menuitem, gpointer gdata); - void glatex_bibtex_write_entry(GPtrArray *entry, gint doctype); - GPtrArray *glatex_bibtex_init_empty_entry(void); +void glatex_bibtex_insert_cite(gchar *reference_name, gchar *option);
#endif
Modified: trunk/geanylatex/src/geanylatex.c =================================================================== --- trunk/geanylatex/src/geanylatex.c 2010-10-28 21:02:33 UTC (rev 1688) +++ trunk/geanylatex/src/geanylatex.c 2010-10-29 16:07:23 UTC (rev 1689) @@ -42,7 +42,7 @@ GeanyData *geany_data; GeanyFunctions *geany_functions;
- +/* Widgets for plugin */ static GtkWidget *menu_latex = NULL; static GtkWidget *menu_latex_menu = NULL; static GtkWidget *menu_latex_wizard = NULL; @@ -52,6 +52,7 @@ static GtkWidget *menu_latex_label = NULL; static GtkWidget *menu_latex_bibtex = NULL; static GtkWidget *menu_latex_bibtex_submenu = NULL; +static GtkWidget *menu_latex_insert_bibtex_cite = NULL; static GtkWidget *menu_latex_format_insert = NULL; static GtkWidget *menu_latex_format_insert_submenu = NULL; static GtkWidget *menu_latex_fontsize = NULL; @@ -150,6 +151,7 @@ static void add_wizard_to_generic_toolbar(void); static void remove_wizard_from_generic_toolbar(void);
+ static GtkWidget *init_toolbar() { GtkWidget *toolbar = NULL; @@ -171,6 +173,7 @@ return toolbar; }
+ static void on_configure_response(G_GNUC_UNUSED GtkDialog *dialog, gint response, G_GNUC_UNUSED gpointer user_data) @@ -1265,7 +1268,56 @@
}
+void +on_insert_bibtex_dialog_activate(G_GNUC_UNUSED GtkMenuItem *menuitem, + G_GNUC_UNUSED gpointer gdata) +{ + GtkWidget *dialog = NULL; + GtkWidget *vbox = NULL; + GtkWidget *label = NULL; + GtkWidget *textbox = NULL; + GtkWidget *table = NULL;
+ dialog = gtk_dialog_new_with_buttons(_("Insert Reference"), + 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 = gtk_label_new(_("BibTeX reference:")); + textbox = gtk_entry_new(); + + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); + gtk_table_attach_defaults(GTK_TABLE(table), textbox, 1, 2, 0, 1); + gtk_container_add(GTK_CONTAINER(vbox), table); + + g_signal_connect(G_OBJECT(textbox), "activate", + G_CALLBACK(glatex_enter_key_pressed_in_entry), dialog); + + gtk_widget_show_all(vbox); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) + { + gchar *str = NULL; + str = g_strdup(gtk_entry_get_text(GTK_ENTRY(textbox))); + glatex_bibtex_insert_cite(str, NULL); + + g_free(str); + } + + gtk_widget_destroy(dialog); +} + + static void on_wizard_response(G_GNUC_UNUSED GtkDialog *dialog, gint response, G_GNUC_UNUSED gpointer user_data) @@ -1922,6 +1974,9 @@ keybindings_set_item(key_group, KB_LATEX_USEPACKAGE_DIALOG, glatex_kb_usepackage_dialog, 0, 0, "usepackage_dialog", _("Insert \usepackage{}"), menu_latex_insert_usepackage); + keybindings_set_item(key_group, KB_LATEX_INSERT_CITE, + glatex_kb_insert_bibtex_cite, 0, 0, "insert_cite_dialog", + _("Insert BibTeX reference dialog"), menu_latex_insert_bibtex_cite); }
@@ -2036,10 +2091,12 @@ GtkWidget *tmp = NULL; gint i; GtkMenuShell *menubar; - + + /* First we check for the menubar where to add the LaTeX menu */ menubar = GTK_MENU_SHELL( ui_lookup_widget(geany->main_widgets->window, "menubar1")); - + + /* Then we build up the menu and finally add it */ menu_latex = gtk_menu_item_new_with_mnemonic(_("_LaTeX")); gtk_menu_shell_insert( menubar,menu_latex, g_list_length(menubar->children)- 1); @@ -2097,6 +2154,14 @@ g_signal_connect(menu_latex_insert_usepackage, "activate", G_CALLBACK(glatex_insert_usepackage_dialog), NULL);
+ menu_latex_insert_bibtex_cite = + gtk_menu_item_new_with_mnemonic(_("Insert B_ibTeX reference")); + ui_widget_set_tooltip_text(menu_latex_insert_bibtex_cite, + _("Helps to insert a reference out of BibTeX files")); + gtk_container_add(GTK_CONTAINER(menu_latex_menu), menu_latex_insert_bibtex_cite); + g_signal_connect(menu_latex_insert_bibtex_cite, "activate", + G_CALLBACK(on_insert_bibtex_dialog_activate), NULL); + menu_latex_bibtex = gtk_menu_item_new_with_mnemonic(_("_BibTeX entries")); gtk_container_add(GTK_CONTAINER(menu_latex_menu), menu_latex_bibtex);
Modified: trunk/geanylatex/src/geanylatex.h =================================================================== --- trunk/geanylatex/src/geanylatex.h 2010-10-28 21:02:33 UTC (rev 1688) +++ trunk/geanylatex/src/geanylatex.h 2010-10-29 16:07:23 UTC (rev 1689) @@ -72,4 +72,5 @@ G_GNUC_UNUSED gpointer gdata); void glatex_insert_command_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata); +void on_insert_bibtex_dialog_activate(GtkMenuItem * menuitem, gpointer gdata); #endif
Modified: trunk/geanylatex/src/latexkeybindings.c =================================================================== --- trunk/geanylatex/src/latexkeybindings.c 2010-10-28 21:02:33 UTC (rev 1688) +++ trunk/geanylatex/src/latexkeybindings.c 2010-10-29 16:07:23 UTC (rev 1689) @@ -157,3 +157,9 @@ g_return_if_fail(document_get_current != NULL); glatex_insert_command_activated(NULL, NULL); } + +void glatex_kb_insert_bibtex_cite(G_GNUC_UNUSED guint key_id) +{ + g_return_if_fail(document_get_current != NULL); + on_insert_bibtex_dialog_activate(NULL, NULL); +}
Modified: trunk/geanylatex/src/latexkeybindings.h =================================================================== --- trunk/geanylatex/src/latexkeybindings.h 2010-10-28 21:02:33 UTC (rev 1688) +++ trunk/geanylatex/src/latexkeybindings.h 2010-10-29 16:07:23 UTC (rev 1689) @@ -48,6 +48,7 @@ KB_LATEX_STRUCTURE_LVLDOWN, KB_LATEX_USEPACKAGE_DIALOG, KB_LATEX_INSERT_COMMAND, + KB_LATEX_INSERT_CITE, COUNT_KB };
@@ -72,5 +73,6 @@ void glatex_kb_structure_lvldown(G_GNUC_UNUSED guint key_id); void glatex_kb_usepackage_dialog(G_GNUC_UNUSED guint key_id); void glatex_kb_insert_command_dialog(G_GNUC_UNUSED guint key_id); +void glatex_kb_insert_bibtex_cite(G_GNUC_UNUSED guint key_id);
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.