Revision: 1693 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1693&view=re... Author: frlan Date: 2010-10-30 20:12:07 +0000 (Sat, 30 Oct 2010)
Log Message: ----------- GeanyLaTeX: Try to fetch a list of BibTeX entries offered to the user through dialog by checking files inside current working directory.
Modified Paths: -------------- trunk/geanylatex/ChangeLog trunk/geanylatex/src/bibtex.c trunk/geanylatex/src/bibtex.h trunk/geanylatex/src/datatypes.h trunk/geanylatex/src/geanylatex.c trunk/geanylatex/src/latexutils.c trunk/geanylatex/src/reftex.h
Modified: trunk/geanylatex/ChangeLog =================================================================== --- trunk/geanylatex/ChangeLog 2010-10-30 14:04:49 UTC (rev 1692) +++ trunk/geanylatex/ChangeLog 2010-10-30 20:12:07 UTC (rev 1693) @@ -1,3 +1,8 @@ +2010-10-30 Frank Lanitz <frank(at)frank(dot)uvena(dot)de> + + * Try to fetch BibTeX entries from files inside working dir of file. + + 2010-10-29 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
* Added a first version of a dialog supporting inserting a bibtex entry.
Modified: trunk/geanylatex/src/bibtex.c =================================================================== --- trunk/geanylatex/src/bibtex.c 2010-10-30 14:04:49 UTC (rev 1692) +++ trunk/geanylatex/src/bibtex.c 2010-10-30 20:12:07 UTC (rev 1693) @@ -190,3 +190,66 @@ g_free(tmp); }
+/* Parses a given bib file and inserting found references into a given comboboy */ +void glatex_parse_bib_file(const gchar* file, gpointer combobox) +{ + gchar **bib_entries = NULL; + int i = 0; + LaTeXLabel *tmp; + gchar *tmp_label_name = NULL; + + if (file != NULL) + { + /* Return if its not an bib file */ + if (!g_str_has_suffix(file, ".bib")) + { + return; + } + + bib_entries = glatex_read_file_in_array(file); + + if (bib_entries != NULL) + { + for (i = 0; bib_entries[i] != NULL ; i++) + { + if (g_str_has_prefix(bib_entries[i], "@")) + { + tmp = glatex_parseLine_bib(bib_entries[i]); + tmp_label_name = g_strdup(tmp->label_name); + gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), tmp_label_name); + g_free(tmp); + g_free(tmp_label_name); + } + } + g_free(bib_entries); + } + } +} + + +LaTeXLabel* glatex_parseLine_bib(const gchar *line) +{ + LaTeXLabel *label; + const gchar *tmp_string = NULL; + const gchar *x = NULL; + gint l = 0; + + label = g_new0(LaTeXLabel, 1); + + x = line; + + while (*x != '\0' && + *x != '{') + { + x++; + } + tmp_string = x + 1; + g_warning("%s", tmp_string); + while (*x != '\0' && *x != ',') + { + l++; + x++; + } + label->label_name = g_strndup(tmp_string, l - 1); + return label; +}
Modified: trunk/geanylatex/src/bibtex.h =================================================================== --- trunk/geanylatex/src/bibtex.h 2010-10-30 14:04:49 UTC (rev 1692) +++ trunk/geanylatex/src/bibtex.h 2010-10-30 20:12:07 UTC (rev 1693) @@ -84,5 +84,8 @@ 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); +void glatex_parse_bib_file(const gchar* file, gpointer combobox); +LaTeXLabel* glatex_parseLine_bib(const gchar *line);
+ #endif
Modified: trunk/geanylatex/src/datatypes.h =================================================================== --- trunk/geanylatex/src/datatypes.h 2010-10-30 14:04:49 UTC (rev 1692) +++ trunk/geanylatex/src/datatypes.h 2010-10-30 20:12:07 UTC (rev 1693) @@ -69,4 +69,11 @@ gchar *label; } BibTeXType;
+typedef struct +{ + gchar *label_name; + gint page; + gchar *chapter; +} LaTeXLabel; + #endif
Modified: trunk/geanylatex/src/geanylatex.c =================================================================== --- trunk/geanylatex/src/geanylatex.c 2010-10-30 14:04:49 UTC (rev 1692) +++ trunk/geanylatex/src/geanylatex.c 2010-10-30 20:12:07 UTC (rev 1693) @@ -1272,13 +1272,18 @@ on_insert_bibtex_dialog_activate(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { - GtkWidget *dialog = NULL; + GtkWidget *dialog; GtkWidget *vbox = NULL; - GtkWidget *label = NULL; + GtkWidget *label= NULL; GtkWidget *textbox = NULL; GtkWidget *table = NULL; + GtkWidget *tmp_entry = NULL; + GtkTreeModel *model = NULL; + GeanyDocument *doc = NULL;
- dialog = gtk_dialog_new_with_buttons(_("Insert Reference"), + doc = document_get_current(); + + dialog = gtk_dialog_new_with_buttons(_("Insert BibTeX Reference"), GTK_WINDOW(geany->main_widgets->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, @@ -1291,29 +1296,69 @@ 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(); + label = gtk_label_new(_("BiBTeX reference name:")); + textbox = gtk_combo_box_entry_new_text();
+ if (doc->real_path != NULL) + { + GDir *dir; + gchar *tmp_dir; + const gchar *filename; + + tmp_dir = g_path_get_dirname(doc->real_path); + dir = g_dir_open(tmp_dir, 0, NULL); + + g_return_if_fail(dir != NULL); + + foreach_dir(filename, dir) + { + gchar *fullpath = NULL; + fullpath = g_build_path(G_DIR_SEPARATOR_S, tmp_dir, filename, NULL); + + glatex_parse_bib_file(fullpath, textbox); + g_free(fullpath); + } + g_dir_close(dir); + model = gtk_combo_box_get_model(GTK_COMBO_BOX(textbox)); + gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), + 0, GTK_SORT_ASCENDING); + } + + 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", + tmp_entry = gtk_bin_get_child(GTK_BIN(textbox)); + g_signal_connect(G_OBJECT(tmp_entry), "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); + gchar *ref_string = NULL; + GString *template_string = NULL;
- g_free(str); + ref_string = g_strdup(gtk_combo_box_get_active_text( + GTK_COMBO_BOX(textbox))); + + if (ref_string != NULL) + { + glatex_bibtex_insert_cite(ref_string, NULL); + g_free(ref_string); + } + else + { + if (ref_string != NULL) + g_free(ref_string); + if (template_string != NULL) + g_free(template_string); + } } - + gtk_widget_destroy(dialog); }
Modified: trunk/geanylatex/src/latexutils.c =================================================================== --- trunk/geanylatex/src/latexutils.c 2010-10-30 14:04:49 UTC (rev 1692) +++ trunk/geanylatex/src/latexutils.c 2010-10-30 20:12:07 UTC (rev 1693) @@ -26,19 +26,19 @@ { gchar **result = NULL; gchar *data; - - if (filename == NULL) return NULL; - - g_file_get_contents(filename, &data, NULL, NULL); - + GError *error = NULL; + + g_return_val_if_fail((filename != NULL), NULL); + g_return_val_if_fail(g_file_get_contents(filename, &data, NULL, NULL), NULL); + if (data != NULL) { + g_warning("Content eingelesen: \n %s", data); result = g_strsplit_set(data, "\r\n", -1); + g_free(data); + return result; } - - g_free(data); - - return result; + return NULL; }
void glatex_usepackage(const gchar *pkg, const gchar *options)
Modified: trunk/geanylatex/src/reftex.h =================================================================== --- trunk/geanylatex/src/reftex.h 2010-10-30 14:04:49 UTC (rev 1692) +++ trunk/geanylatex/src/reftex.h 2010-10-30 20:12:07 UTC (rev 1693) @@ -24,12 +24,6 @@
#include "geanylatex.h"
-typedef struct -{ - gchar *label_name; - gint page; - gchar *chapter; -} LaTeXLabel;
void glatex_add_Labels(GtkWidget *combobox, GSList *dir);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.