2 * geanylatex.c - Plugin to let Geany better work together with LaTeX
4 * Copyright 2007-2008 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
5 * For long list of friendly supporters please have a look at THANKS.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 /* This plugin improves the work with LaTeX and Geany.*/
27 #include "plugindata.h"
29 #include "filetypes.h"
30 #include "templates.h"
33 #include "keybindings.h"
35 #include "pluginmacros.h"
37 #include "datatypes.h"
39 #include "latexencodings.h"
41 typedef void (*SubMenuCallback
) (G_GNUC_UNUSED GtkMenuItem
* menuitem
, G_GNUC_UNUSED gpointer gdata
);
43 PluginInfo
*plugin_info
;
44 PluginFields
*plugin_fields
;
45 GeanyData
*geany_data
;
46 GeanyFunctions
*geany_functions
;
49 PLUGIN_VERSION_CHECK(68)
50 PLUGIN_SET_INFO(_("LaTeX"), _("Plugin to make Geany better support LaTeX"), "0.2-git",
51 "Frank Lanitz <frank@frank.uvena.de>")
53 GtkWidget
*menu_latex
= NULL
;
54 GtkWidget
*menu_latex_menu
= NULL
;
55 GtkWidget
*menu_latex_wizzard
= NULL
;
56 GtkWidget
*menu_latex_menu_special_char
= NULL
;
57 GtkWidget
*menu_latex_menu_special_char_submenu
= NULL
;
58 GtkWidget
*menu_latex_ref
= NULL
;
59 GtkWidget
*menu_latex_label
= NULL
;
61 /* Doing some basic keybinding stuff */
65 LATEX_INSERT_LABEL_KB
,
70 PLUGIN_KEY_GROUP(geanylatex
, COUNT_KB
)
73 #define TEMPLATE_LATEX "\
74 \\documentclass[{CLASSOPTION}]{{DOCUMENTCLASS}}\n\
83 #define create_sub_menu(base_menu, menu, item, title) \
84 (menu) = gtk_menu_new(); \
85 (item) = gtk_menu_item_new_with_mnemonic((title)); \
86 gtk_menu_item_set_submenu(GTK_MENU_ITEM((item)), (menu)); \
87 gtk_container_add(GTK_CONTAINER(base_menu), (item)); \
88 gtk_widget_show((item));
90 #define MAX_MENU_ENTRIES 20
93 insert_string(gchar
*string
)
95 gint idx
= p_document
->get_cur_idx();
96 if (DOC_IDX_VALID(idx
))
98 gint pos
= p_sci
->get_current_position(documents
[idx
]->sci
);
99 p_sci
->insert_text(documents
[idx
]->sci
, pos
, string
);
105 get_latex_command(gint tab_index
)
107 return char_array
[tab_index
].latex
;
111 char_insert_activated(G_GNUC_UNUSED GtkMenuItem
* menuitem
, G_GNUC_UNUSED gpointer gdata
)
113 insert_string(get_latex_command(GPOINTER_TO_INT(gdata
)));
117 insert_label_activated(G_GNUC_UNUSED GtkMenuItem
* menuitem
, G_GNUC_UNUSED gpointer gdata
)
119 GtkWidget
*dialog
= NULL
;
120 GtkWidget
*vbox
= NULL
;
121 GtkWidget
*label
= NULL
;
122 GtkWidget
*textbox_label
= NULL
;
123 GtkWidget
*table
= NULL
;
125 dialog
= gtk_dialog_new_with_buttons(_("Insert label"),
126 GTK_WINDOW(main_widgets
->window
),
127 GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_STOCK_CANCEL
,
128 GTK_RESPONSE_CANCEL
, GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
,
130 vbox
= p_ui
->dialog_vbox_new(GTK_DIALOG(dialog
));
131 gtk_widget_set_name(dialog
, "GeanyDialog");
132 gtk_box_set_spacing(GTK_BOX(vbox
), 10);
134 table
= gtk_table_new(1, 2, FALSE
);
135 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
136 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
138 label
= gtk_label_new(_("Label name:"));
139 textbox_label
= gtk_entry_new();
141 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
143 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 0, 1);
144 gtk_table_attach_defaults(GTK_TABLE(table
), textbox_label
, 1, 2, 0, 1);
145 gtk_container_add(GTK_CONTAINER(vbox
), table
);
147 gtk_widget_show_all(vbox
);
149 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_ACCEPT
)
151 gchar
*label_str
= NULL
;
152 label_str
= g_strconcat("\\label{", g_strdup(gtk_entry_get_text(GTK_ENTRY(textbox_label
))), "}", NULL
);
153 insert_string(label_str
);
155 gtk_widget_destroy(dialog
);
159 insert_ref_activated(G_GNUC_UNUSED GtkMenuItem
* menuitem
, G_GNUC_UNUSED gpointer gdata
)
162 GtkWidget
*vbox
= NULL
;
163 GtkWidget
*label_ref
= NULL
;
164 GtkWidget
*textbox_ref
= NULL
;
165 GtkWidget
*table
= NULL
;
166 GtkWidget
*radio1
= NULL
;
167 GtkWidget
*radio2
= NULL
;
169 dialog
= gtk_dialog_new_with_buttons(_("Insert reference"),
170 GTK_WINDOW(main_widgets
->window
),
171 GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_STOCK_CANCEL
,
172 GTK_RESPONSE_CANCEL
, GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
,
174 vbox
= p_ui
->dialog_vbox_new(GTK_DIALOG(dialog
));
175 gtk_widget_set_name(dialog
, "GeanyDialog");
176 gtk_box_set_spacing(GTK_BOX(vbox
), 10);
178 table
= gtk_table_new(1, 2, FALSE
);
179 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
180 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
182 label_ref
= gtk_label_new(_("Ref name:"));
183 textbox_ref
= gtk_entry_new();
185 gtk_misc_set_alignment(GTK_MISC(label_ref
), 0, 0.5);
187 gtk_table_attach_defaults(GTK_TABLE(table
), label_ref
, 0, 1, 0, 1);
188 gtk_table_attach_defaults(GTK_TABLE(table
), textbox_ref
, 1, 2, 0, 1);
189 gtk_container_add(GTK_CONTAINER(vbox
), table
);
191 radio1
= gtk_radio_button_new_with_label(NULL
,
192 _("standard reference"));
193 gtk_button_set_focus_on_click(GTK_BUTTON(radio1
), FALSE
);
194 gtk_container_add(GTK_CONTAINER(vbox
), radio1
);
196 radio2
= gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio1
),
197 _("page reference"));
198 gtk_button_set_focus_on_click(GTK_BUTTON(radio2
), FALSE
);
199 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2
), FALSE
);
200 gtk_container_add(GTK_CONTAINER(vbox
), radio2
);
202 gtk_widget_show_all(vbox
);
205 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_ACCEPT
)
207 gchar
*ref_string
= NULL
;
209 ref_string
= g_strdup(gtk_entry_get_text(GTK_ENTRY(textbox_ref
)));
211 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio2
)) == FALSE
)
213 ref_string
= g_strconcat("\\ref{", ref_string
, "}", NULL
);
217 ref_string
= g_strconcat("\\pageref{", ref_string
, "}", NULL
);
220 if (ref_string
!= NULL
)
222 insert_string(ref_string
);
227 gtk_widget_destroy(dialog
);
230 static void character_create_menu_item(GtkWidget
*menu
, const gchar
*label
, gint letter
, SubMenuCallback callback
)
234 tmp
= gtk_menu_item_new_with_label(label
);
235 gtk_widget_show(tmp
);
236 gtk_container_add(GTK_CONTAINER(menu
), tmp
);
237 g_signal_connect((gpointer
) tmp
, "activate", G_CALLBACK(callback
), GINT_TO_POINTER(letter
));
240 /* returns -1, if there are more than gint can work with or any other error
241 * returns 0, if categorie is empty
242 * if gint categorie is -1, function will count every element.
243 * Useful, if there is no need for a categorie check.*/
245 count_menu_entries(SubMenuTemplate
*tmp
, gint categorie
)
247 // TODO: Reset max value for to stop before it's too late
252 for (i
=1; tmp
[i
].label
!= NULL
; i
++)
259 for (i
= 1; tmp
[i
].label
!= NULL
; i
++)
261 if (tmp
[i
].cat
== categorie
)
276 count_menu_cat_entries(CategoryName
*tmp
)
280 for (i
= 0; tmp
[i
].label
!= NULL
; i
++);
284 void sub_menu_init(GtkWidget
*base_menu
, SubMenuTemplate
*menu_template
, CategoryName
*category_name
, SubMenuCallback callback_function
)
288 gint max_menu_entries
= MAX_MENU_ENTRIES
;
289 gint categories
= count_menu_cat_entries(category_name
);
290 GtkWidget
*sub_menu
= NULL
;
291 GtkWidget
*sub_menu_cat
[categories
][2];
292 GtkWidget
*active_submenu
= NULL
;
294 // Creates sub menus based on information from letter.h
295 for (i
= 0; i
< categories
; i
++)
297 if (count_menu_entries(menu_template
, i
) > 0)
299 create_sub_menu(base_menu
, sub_menu_cat
[i
][0],
300 sub_menu_cat
[i
][1], category_name
[i
].label
);
304 // Searching for all categories
305 for (i
= 0; i
< categories
; i
++)
307 gboolean split
= FALSE
;
308 gboolean last_sub_menu
= FALSE
;
309 gboolean sorted
= category_name
[i
].sorted
;
310 gint local_count
= 0; // To check whether we need to build up a new sub sub menu.
311 gint item_count
= count_menu_entries(menu_template
, i
);
316 // Default is, not to split anything to make menu not
317 // deeper than realy needed.
318 if (item_count
> max_menu_entries
)
323 // Setting active sub menu to sub menu of catagorie
324 sub_menu
= sub_menu_cat
[i
][0];
325 active_submenu
= sub_menu
;
326 // Finding entries for each categorie
328 for (j
= 0; menu_template
[j
].latex
!= NULL
; j
++)
330 if (menu_template
[j
].cat
== i
)
332 // Creates a new sub sub menu if needed
333 if (split
== TRUE
&& (local_count
% max_menu_entries
) == 0)
335 gint next_split_point
= 0;
336 GtkWidget
*tmp
= NULL
;
337 GtkWidget
*tmp_item
= NULL
;
339 sub_menu
= active_submenu
;
341 for (next_split_point
= 0;
342 next_split_point
< max_menu_entries
; next_split_point
++)
344 if (menu_template
[j
+next_split_point
].cat
!= i
)
346 last_sub_menu
= TRUE
;
354 create_sub_menu(sub_menu_cat
[i
][0], tmp
, tmp_item
, g_strconcat(menu_template
[j
].label
, " ... ", menu_template
[j
+ next_split_point
-1].label
, NULL
));
358 else if (sorted
== FALSE
)
360 if (last_sub_menu
== FALSE
)
362 create_sub_menu(sub_menu
, tmp
, tmp_item
, _("More"));
363 sub_menu
= active_submenu
;
364 active_submenu
= tmp
;
369 // Sets the counter to keep in track if a new submenu needs to be build up
370 local_count
= local_count
+ 1;
371 character_create_menu_item(sub_menu
, g_strconcat(menu_template
[j
].label
, "\t", menu_template
[j
].latex
, NULL
), j
, callback_function
);
378 find_latex_enc(gint l_geany_enc
)
381 for (i
= 0; i
< LATEX_ENCODINGS_MAX
; i
++)
383 if (latex_encodings
[i
].geany_enc
== l_geany_enc
)
386 return LATEX_ENCODING_NONE
;
391 show_output(const gchar
* output
, const gchar
* name
, const gint local_enc
)
394 GeanyFiletype
*ft
= p_filetypes
->lookup_by_name("LaTeX");
398 idx
= p_document
->new_file(name
, ft
, output
);
399 p_document
->set_encoding(idx
, p_encodings
->get_charset_from_index(latex_encodings
[local_enc
].geany_enc
));
405 wizard_activated(G_GNUC_UNUSED GtkMenuItem
* menuitem
, G_GNUC_UNUSED gpointer gdata
)
408 GString
*code
= NULL
;
409 gchar
*author
= NULL
;
411 gchar
*output
= NULL
;
412 gchar
*classoptions
= NULL
;
414 gchar
*enc_latex_char
= NULL
;
415 gchar
*documentclass_str
= NULL
;
416 gchar
*papersize
= NULL
;
418 gchar
*scriptsize
= NULL
;
419 gint documentclass_int
;
423 GtkWidget
*dialog
= NULL
;
424 GtkWidget
*vbox
= NULL
;
425 GtkWidget
*label_documentclass
= NULL
;
426 GtkWidget
*documentclass_combobox
= NULL
;
427 GtkWidget
*label_encoding
= NULL
;
428 GtkWidget
*encoding_combobox
= NULL
;
429 GtkWidget
*scriptsize_combobox
= NULL
;
430 GtkWidget
*label_scriptsize
= NULL
;
431 GtkWidget
*table
= NULL
;
432 GtkWidget
*checkbox_KOMA
= NULL
;
433 GtkWidget
*author_textbox
= NULL
;
434 GtkWidget
*label_author
= NULL
;
435 GtkWidget
*date_textbox
= NULL
;
436 GtkWidget
*label_date
= NULL
;
437 GtkWidget
*title_textbox
= NULL
;
438 GtkWidget
*label_title
= NULL
;
439 GtkWidget
*papersize_combobox
= NULL
;
440 GtkWidget
*label_papersize
= NULL
;
441 GtkWidget
*checkbox_draft
= NULL
;
442 gboolean KOMA_active
= TRUE
;
443 gboolean draft_active
= FALSE
;
445 GtkTooltips
*tooltip
= NULL
;
447 tooltip
= gtk_tooltips_new();
449 // Creating and formating table
450 table
= gtk_table_new(2, 6, FALSE
);
451 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
452 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
455 label_documentclass
= gtk_label_new(_("Documentclass:"));
456 documentclass_combobox
= gtk_combo_box_new_text();
457 gtk_tooltips_set_tip(tooltip
, documentclass_combobox
,
458 _("Chooce the kind of document you want to write"), NULL
);
459 gtk_combo_box_insert_text(GTK_COMBO_BOX(documentclass_combobox
), 0, "Book");
460 gtk_combo_box_insert_text(GTK_COMBO_BOX(documentclass_combobox
), 1, "Article");
461 gtk_combo_box_insert_text(GTK_COMBO_BOX(documentclass_combobox
), 2, "Report");
463 gtk_combo_box_set_active(GTK_COMBO_BOX(documentclass_combobox
), 0);
465 gtk_misc_set_alignment(GTK_MISC(label_documentclass
), 0, 0.5);
467 gtk_table_attach_defaults(GTK_TABLE(table
), label_documentclass
, 0, 1, 0, 1);
468 gtk_table_attach_defaults(GTK_TABLE(table
), documentclass_combobox
, 1, 2, 0, 1);
471 label_encoding
= gtk_label_new(_("Encoding:"));
473 encoding_combobox
= gtk_combo_box_new_text();
474 gtk_tooltips_set_tip(tooltip
, encoding_combobox
,
475 _("Set the encoding for your new document"), NULL
);
476 for (i
= 0; i
< LATEX_ENCODINGS_MAX
; i
++)
478 gtk_combo_box_insert_text(GTK_COMBO_BOX(encoding_combobox
), i
,
479 latex_encodings
[i
].name
);
482 gtk_combo_box_set_active(GTK_COMBO_BOX(encoding_combobox
), find_latex_enc(geany_data
->file_prefs
->default_new_encoding
));
484 gtk_misc_set_alignment(GTK_MISC(label_encoding
), 0, 0.5);
486 gtk_table_attach_defaults(GTK_TABLE(table
), label_encoding
, 0, 1, 1, 2);
487 gtk_table_attach_defaults(GTK_TABLE(table
), encoding_combobox
, 1, 2, 1, 2);
490 label_scriptsize
= gtk_label_new(_("Scriptsize:"));
491 scriptsize_combobox
= gtk_combo_box_new_text();
492 gtk_tooltips_set_tip(tooltip
, scriptsize_combobox
,
493 _("Set the default script size of your new document"), NULL
);
494 gtk_combo_box_insert_text(GTK_COMBO_BOX(scriptsize_combobox
), 0, "10pt");
495 gtk_combo_box_insert_text(GTK_COMBO_BOX(scriptsize_combobox
), 1, "11pt");
496 gtk_combo_box_insert_text(GTK_COMBO_BOX(scriptsize_combobox
), 2, "12pt");
498 gtk_combo_box_set_active(GTK_COMBO_BOX(scriptsize_combobox
), 0);
500 gtk_misc_set_alignment(GTK_MISC(label_scriptsize
), 0, 0.5);
502 gtk_table_attach_defaults(GTK_TABLE(table
), label_scriptsize
, 0, 1, 2, 3);
503 gtk_table_attach_defaults(GTK_TABLE(table
), scriptsize_combobox
, 1, 2, 2, 3);
506 label_author
= gtk_label_new(_("Author:"));
507 author_textbox
= gtk_entry_new();
508 gtk_tooltips_set_tip(tooltip
, author_textbox
,
509 _("Sets the entry of \\author command. In most cases here should stay your name"), NULL
);
510 if (geany_data
->template_prefs
->developer
!= NULL
)
512 author
= geany_data
->template_prefs
->developer
;
513 gtk_entry_set_text(GTK_ENTRY(author_textbox
), author
);
515 gtk_misc_set_alignment(GTK_MISC(label_author
), 0, 0.5);
516 gtk_table_attach_defaults(GTK_TABLE(table
), label_author
, 0, 1, 3, 4);
517 gtk_table_attach_defaults(GTK_TABLE(table
), author_textbox
, 1, 2, 3, 4);
520 label_date
= gtk_label_new(_("Date:"));
521 date_textbox
= gtk_entry_new();
522 gtk_tooltips_set_tip(tooltip
, date_textbox
,
523 _("Sets the entry of the \\date command inside header of your newly created LaTeX-document. Keeping it at \\today is a good decision if you don't need any fixed date."), NULL
);
524 gtk_entry_set_text(GTK_ENTRY(date_textbox
), "\\today");
525 gtk_misc_set_alignment(GTK_MISC(label_date
), 0, 0.5);
526 gtk_table_attach_defaults(GTK_TABLE(table
), label_date
, 0, 1, 4, 5);
527 gtk_table_attach_defaults(GTK_TABLE(table
), date_textbox
, 1, 2, 4, 5);
529 // Title of the new document
530 label_title
= gtk_label_new(_("Title:"));
531 title_textbox
= gtk_entry_new();
532 gtk_tooltips_set_tip(tooltip
, title_textbox
, _("Sets the title of your newly document."),
534 gtk_misc_set_alignment(GTK_MISC(label_title
), 0, 0.5);
535 gtk_table_attach_defaults(GTK_TABLE(table
), label_title
, 0, 1, 5, 6);
536 gtk_table_attach_defaults(GTK_TABLE(table
), title_textbox
, 1, 2, 5, 6);
539 label_papersize
= gtk_label_new(_("Paper size:"));
540 papersize_combobox
= gtk_combo_box_new_text();
541 gtk_tooltips_set_tip(tooltip
, papersize_combobox
,
542 _("Chooce the paper format for the new created document"), NULL
);
543 gtk_combo_box_insert_text(GTK_COMBO_BOX(papersize_combobox
), 0, "A4");
544 gtk_combo_box_insert_text(GTK_COMBO_BOX(papersize_combobox
), 1, "A5");
545 gtk_combo_box_insert_text(GTK_COMBO_BOX(papersize_combobox
), 2, "A6");
547 gtk_combo_box_set_active(GTK_COMBO_BOX(papersize_combobox
), 0);
549 gtk_misc_set_alignment(GTK_MISC(label_papersize
), 0, 0.5);
551 gtk_table_attach_defaults(GTK_TABLE(table
), label_papersize
, 0, 1, 6, 7);
552 gtk_table_attach_defaults(GTK_TABLE(table
), papersize_combobox
, 1, 2, 6, 7);
554 gtk_widget_show_all(table
);
556 // Buidling the wizard-dialog and showing it
557 dialog
= gtk_dialog_new_with_buttons(_("LaTeX-Wizard"),
558 GTK_WINDOW(main_widgets
->window
),
559 GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_STOCK_CANCEL
,
560 GTK_RESPONSE_CANCEL
, GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
,
562 vbox
= p_ui
->dialog_vbox_new(GTK_DIALOG(dialog
));
563 gtk_widget_set_name(dialog
, "GeanyDialog");
564 gtk_box_set_spacing(GTK_BOX(vbox
), 10);
565 gtk_container_add(GTK_CONTAINER(vbox
), table
);
567 checkbox_KOMA
= gtk_check_button_new_with_label(_("Use KOMA-script classes if possible"));
568 gtk_tooltips_set_tip(tooltip
, checkbox_KOMA
,
570 ("Uses the KOMA-script classes by Markus Kohm.\nKeep in mind: To compile your document these classes have to been installed before."),
572 gtk_button_set_focus_on_click(GTK_BUTTON(checkbox_KOMA
), FALSE
);
573 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox_KOMA
), KOMA_active
);
574 gtk_box_pack_start(GTK_BOX(vbox
), checkbox_KOMA
, FALSE
, FALSE
, 5);
576 checkbox_draft
= gtk_check_button_new_with_label(_("Use draft mode"));
577 gtk_tooltips_set_tip(tooltip
, checkbox_draft
,
578 _("Set the draft flag inside new created documents to get documents with a number of debugging helpers"), NULL
);
579 gtk_button_set_focus_on_click(GTK_BUTTON(checkbox_draft
), FALSE
);
580 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox_draft
), draft_active
);
581 gtk_box_pack_start(GTK_BOX(vbox
), checkbox_draft
, FALSE
, FALSE
, 5);
583 gtk_widget_show_all(vbox
);
585 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_ACCEPT
)
587 KOMA_active
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox_KOMA
));
588 draft_active
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox_draft
));
589 documentclass_int
= gtk_combo_box_get_active(GTK_COMBO_BOX(documentclass_combobox
));
590 encoding_int
= gtk_combo_box_get_active(GTK_COMBO_BOX(encoding_combobox
));
591 enc_latex_char
= g_strconcat("\\usepackage[", latex_encodings
[encoding_int
].latex
,"]{inputenc}\n", NULL
);
592 author
= g_strdup(gtk_entry_get_text(GTK_ENTRY(author_textbox
)));
593 date
= g_strdup(gtk_entry_get_text(GTK_ENTRY(date_textbox
)));
594 title
= g_strdup(gtk_entry_get_text(GTK_ENTRY(title_textbox
)));
595 papersize_int
= gtk_combo_box_get_active(GTK_COMBO_BOX(papersize_combobox
));
596 switch (papersize_int
)
600 papersize
= g_utf8_casefold("a4paper", -1);
605 papersize
= g_utf8_casefold("a5paper", -1);
610 papersize
= g_utf8_casefold("a6paper", -1);
615 scriptsize_int
= gtk_combo_box_get_active(GTK_COMBO_BOX(scriptsize_combobox
));
616 switch (scriptsize_int
)
620 scriptsize
= g_strconcat("10pt", NULL
);
625 scriptsize
= g_strconcat("11pt", NULL
);
630 scriptsize
= g_strconcat("12pt", NULL
);
635 if (papersize
!= NULL
)
637 classoptions
= g_strconcat(papersize
, NULL
);
639 if (classoptions
!= NULL
&& draft_active
== TRUE
)
641 draft
= g_utf8_casefold("draft", -1);
642 classoptions
= g_strconcat(classoptions
,",", draft
, NULL
);
644 else if (classoptions
== NULL
&& draft_active
== TRUE
)
646 draft
= g_utf8_casefold("draft", -1);
647 classoptions
= g_strconcat(draft
, NULL
);
649 if (classoptions
!= NULL
&& scriptsize
!= NULL
)
651 classoptions
= g_strconcat(classoptions
, ",", scriptsize
, NULL
);
653 else if (classoptions
== NULL
&& scriptsize
!= NULL
)
655 classoptions
= g_strconcat(scriptsize
, NULL
);
660 switch (documentclass_int
)
664 documentclass_str
= g_utf8_casefold("scrbook", -1);
669 documentclass_str
= g_utf8_casefold("scrartcl", -1);
674 documentclass_str
= g_utf8_casefold("scrreprt", -1);
681 switch (documentclass_int
)
685 documentclass_str
= g_utf8_casefold("book", -1);
690 documentclass_str
= g_utf8_casefold("article", -1);
695 documentclass_str
= g_utf8_casefold("report", -1);
701 code
= g_string_new(TEMPLATE_LATEX
);
703 if (classoptions
!= NULL
)
705 p_utils
->string_replace_all(code
, "{CLASSOPTION}", classoptions
);
706 g_free(classoptions
);
708 if (documentclass_str
!= NULL
)
710 p_utils
->string_replace_all(code
, "{DOCUMENTCLASS}", documentclass_str
);
711 g_free(documentclass_str
);
713 if (enc_latex_char
!= NULL
)
715 p_utils
->string_replace_all(code
, "{ENCODING}", enc_latex_char
);
716 g_free(enc_latex_char
);
720 if (author
[0] != '\0')
722 author
= g_strconcat("\\author{", author
, "}\n", NULL
);
723 p_utils
->string_replace_all(code
, "{AUTHOR}", author
);
726 p_utils
->string_replace_all(code
, "{AUTHOR}", "\% \\author{}\n");
733 date
= g_strconcat("\\date{", date
, "}\n", NULL
);
734 p_utils
->string_replace_all(code
, "{DATE}", date
);
737 p_utils
->string_replace_all(code
, "{DATE}", "\% \\date{}\n");
742 if (title
[0] != '\0')
744 title
= g_strconcat("\\title{", title
, "}\n", NULL
);
745 p_utils
->string_replace_all(code
, "{TITLE}", title
);
748 p_utils
->string_replace_all(code
, "{TITLE}", "\% \\title{} \n");
751 output
= g_string_free(code
, FALSE
);
752 show_output(output
, NULL
, encoding_int
);
754 gtk_widget_destroy(dialog
);
760 GeanyDocument
*doc
= NULL
;
763 doc
= p_document
->get_current();
764 have_file
= doc
&& doc
->file_name
&& g_path_is_absolute(doc
->file_name
);
768 gtk_widget_set_sensitive(menu_latex_menu_special_char
, TRUE
);
769 gtk_widget_set_sensitive(menu_latex_ref
, TRUE
);
770 gtk_widget_set_sensitive(menu_latex_label
, TRUE
);
774 gtk_widget_set_sensitive(menu_latex_menu_special_char
, FALSE
);
775 gtk_widget_set_sensitive(menu_latex_ref
, FALSE
);
776 gtk_widget_set_sensitive(menu_latex_label
, FALSE
);
779 gtk_widget_set_sensitive(menu_latex_wizzard
, TRUE
);
783 static void kblabel_insert(G_GNUC_UNUSED guint key_id
)
785 insert_label_activated(NULL
, NULL
);
788 static void kbref_insert(G_GNUC_UNUSED guint key_id
)
790 insert_ref_activated(NULL
, NULL
);
793 static void kbwizard(G_GNUC_UNUSED guint key_id
)
795 wizard_activated(NULL
, NULL
);
799 plugin_init(G_GNUC_UNUSED GeanyData
* data
)
801 GtkTooltips
*tooltips
= NULL
;
803 gchar
*kblabel_insert_label
= _("Insert \\label");
804 gchar
*kblabel_insert_ref
= _("Insert \\ref");
805 gchar
*kblabel_wizard
= _("Run LaTeX-Wizard");
807 init_encodings_latex();
809 tooltips
= gtk_tooltips_new();
811 menu_latex
= gtk_menu_item_new_with_mnemonic(_("_LaTeX"));
812 gtk_container_add(GTK_CONTAINER(main_widgets
->tools_menu
), menu_latex
);
813 g_signal_connect((gpointer
) menu_latex
, "activate", G_CALLBACK(update_menu_items
), NULL
);
815 menu_latex_menu
= gtk_menu_new();
816 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_latex
), menu_latex_menu
);
818 menu_latex_wizzard
= gtk_menu_item_new_with_mnemonic(_("LaTeX-_Wizard"));
819 gtk_container_add(GTK_CONTAINER(menu_latex_menu
), menu_latex_wizzard
);
820 gtk_tooltips_set_tip(tooltips
, menu_latex_wizzard
,
821 _("Starts a Wizard to create easily LaTeX-dokuments"), NULL
);
823 g_signal_connect((gpointer
) menu_latex_wizzard
, "activate",
824 G_CALLBACK(wizard_activated
), NULL
);
826 menu_latex_menu_special_char
= gtk_menu_item_new_with_mnemonic(_("Insert _Special Character"));
827 gtk_tooltips_set_tip(tooltips
, menu_latex_menu_special_char
,
828 _("Helps to use some not very common letters and signs"), NULL
);
829 gtk_container_add(GTK_CONTAINER(menu_latex_menu
), menu_latex_menu_special_char
);
831 menu_latex_menu_special_char_submenu
= gtk_menu_new();
832 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_latex_menu_special_char
), menu_latex_menu_special_char_submenu
);
833 sub_menu_init(menu_latex_menu_special_char_submenu
, char_array
, cat_names
, char_insert_activated
);
835 menu_latex_ref
= gtk_menu_item_new_with_mnemonic(_("Insert _Reference"));
836 gtk_tooltips_set_tip(tooltips
, menu_latex_ref
,
837 _("Inserting references to the document"), NULL
);
838 gtk_container_add(GTK_CONTAINER(menu_latex_menu
), menu_latex_ref
);
839 g_signal_connect((gpointer
) menu_latex_ref
, "activate", G_CALLBACK(insert_ref_activated
), NULL
);
841 menu_latex_label
= gtk_menu_item_new_with_mnemonic(_("Insert _Label"));
842 gtk_tooltips_set_tip(tooltips
, menu_latex_label
,
843 _("Helps at inserting labels to a docuemnt"), NULL
);
844 gtk_container_add(GTK_CONTAINER(menu_latex_menu
), menu_latex_label
);
845 g_signal_connect((gpointer
) menu_latex_label
, "activate", G_CALLBACK(insert_label_activated
), NULL
);
847 /* init keybindins */
848 p_keybindings
->set_item(plugin_key_group
, LATEX_WIZZARD_KB
, kbwizard
,
849 0, 0, "run_latex_wizard", kblabel_wizard
, menu_latex_wizzard
);
850 p_keybindings
->set_item(plugin_key_group
, LATEX_INSERT_LABEL_KB
, kblabel_insert
,
851 0, 0, "insert_latex_label", kblabel_insert_label
, menu_latex_wizzard
);
852 p_keybindings
->set_item(plugin_key_group
, LATEX_INSERT_REF_KB
, kbref_insert
,
853 0, 0, "insert_latex_ref", kblabel_insert_ref
, menu_latex_wizzard
);
854 gtk_widget_show_all(menu_latex
);
855 plugin_fields
->menu_item
= menu_latex
;
861 gtk_widget_destroy(plugin_fields
->menu_item
);