2 * Sylpheed templates subsystem
3 * Copyright (C) 2001 Alexander Barinov
4 * Copyright (C) 2001-2007 Hiroyuki Yamamoto and the Claws Mail team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include <glib/gi18n.h>
26 #include <gdk/gdkkeysyms.h>
33 #include "prefs_gtk.h"
37 #include "alertpanel.h"
38 #include "manage_window.h"
40 #include "addr_compl.h"
41 #include "quote_fmt.h"
42 #include "prefs_common.h"
48 TEMPL_AUTO_DATA, /*!< auto pointer */
52 static struct Templates {
56 GtkWidget *entry_name;
57 GtkWidget *entry_subject;
61 GtkWidget *text_value;
64 static int modified = FALSE;
66 /* widget creating functions */
67 static void prefs_template_window_create (void);
68 static void prefs_template_window_setup (void);
69 static void prefs_template_clear (void);
71 static GSList *prefs_template_get_list (void);
74 static gint prefs_template_deleted_cb (GtkWidget *widget,
77 static gboolean prefs_template_key_pressed_cb (GtkWidget *widget,
80 static void prefs_template_cancel_cb (void);
81 static void prefs_template_ok_cb (void);
82 static void prefs_template_register_cb (void);
83 static void prefs_template_substitute_cb (void);
84 static void prefs_template_delete_cb (void);
86 static GtkListStore* prefs_template_create_data_store (void);
87 static void prefs_template_list_view_insert_template (GtkWidget *list_view,
88 GtkTreeIter *row_iter,
89 const gchar *template,
92 static GtkWidget *prefs_template_list_view_create (void);
93 static void prefs_template_create_list_view_columns (GtkWidget *list_view);
94 static gboolean prefs_template_selected (GtkTreeSelection *selector,
97 gboolean currently_selected,
100 /* Called from mainwindow.c */
101 void prefs_template_open(void)
105 if (!templates.window)
106 prefs_template_window_create();
108 prefs_template_window_setup();
109 gtk_widget_show(templates.window);
113 *\brief Save Gtk object size to prefs dataset
115 static void prefs_template_size_allocate_cb(GtkWidget *widget,
116 GtkAllocation *allocation)
118 g_return_if_fail(allocation != NULL);
120 prefs_common.templateswin_width = allocation->width;
121 prefs_common.templateswin_height = allocation->height;
124 static void prefs_template_window_create(void)
126 /* window structure ;) */
130 GtkWidget *table; /* including : entry_[name|to|cc|bcc|subject] */
132 GtkWidget *text_value;
138 GtkWidget *subst_btn;
142 GtkWidget *list_view;
143 GtkWidget *confirm_area;
145 GtkWidget *cancel_btn;
147 static GdkGeometry geometry;
149 GtkTooltips *tooltips;
151 debug_print("Creating templates configuration window...\n");
154 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_template");
155 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
156 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
157 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
159 /* vpaned to separate template settings from templates list */
160 vpaned = gtk_vpaned_new();
161 gtk_widget_show(vpaned);
162 gtk_container_add(GTK_CONTAINER(window), vpaned);
164 /* vbox to handle template name and content */
165 vbox1 = gtk_vbox_new(FALSE, 6);
166 gtk_widget_show(vbox1);
167 gtk_container_set_border_width(GTK_CONTAINER(vbox1), 8);
168 gtk_paned_pack1(GTK_PANED(vpaned), vbox1, FALSE, FALSE);
170 table = gtk_table_new(5, 2, FALSE);
171 gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
172 gtk_table_set_col_spacings (GTK_TABLE (table), 4);
173 gtk_widget_show(table);
174 gtk_box_pack_start (GTK_BOX (vbox1), table, FALSE, FALSE, 0);
176 tooltips = gtk_tooltips_new();
185 {_("Name"), &templates.entry_name, FALSE,
186 _("This name is used as the Menu item")},
187 {_("To"), &templates.entry_to, TRUE, NULL},
188 {_("Cc"), &templates.entry_cc, TRUE, NULL},
189 {_("Bcc"), &templates.entry_bcc, TRUE, NULL},
190 {_("Subject"), &templates.entry_subject, FALSE, NULL},
191 {NULL, NULL, FALSE, NULL}
194 for (i=0; tab[i].label; i++) {
198 label = gtk_label_new(tab[i].label);
199 gtk_widget_show(label);
200 gtk_table_attach(GTK_TABLE(table), label, 0, 1, i, (i + 1),
201 (GtkAttachOptions) (GTK_FILL),
202 (GtkAttachOptions) 0, 0, 0);
203 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
205 *(tab[i].entry) = gtk_entry_new();
206 gtk_widget_show(*(tab[i].entry));
207 gtk_table_attach(GTK_TABLE(table), *(tab[i].entry), 1, 2, i, (i + 1),
208 (GtkAttachOptions) (GTK_EXPAND|GTK_SHRINK|GTK_FILL),
209 (GtkAttachOptions) 0, 0, 0);
210 gtk_tooltips_set_tip(tooltips, *(tab[i].entry), tab[i].tooltips, NULL);
213 address_completion_register_entry(
214 GTK_ENTRY(*(tab[i].entry)), TRUE);
217 /* template content */
218 scroll2 = gtk_scrolled_window_new(NULL, NULL);
219 gtk_widget_show(scroll2);
220 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll2),
221 GTK_POLICY_AUTOMATIC,
222 GTK_POLICY_AUTOMATIC);
223 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll2),
225 gtk_box_pack_start(GTK_BOX(vbox1), scroll2, TRUE, TRUE, 0);
227 text_value = gtk_text_view_new();
228 if (prefs_common.textfont) {
229 PangoFontDescription *font_desc;
231 font_desc = pango_font_description_from_string
232 (prefs_common.textfont);
234 gtk_widget_modify_font(text_value, font_desc);
235 pango_font_description_free(font_desc);
238 gtk_widget_show(text_value);
239 gtk_widget_set_size_request(text_value, -1, 120);
240 gtk_container_add(GTK_CONTAINER(scroll2), text_value);
241 gtk_text_view_set_editable(GTK_TEXT_VIEW(text_value), TRUE);
242 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_value), GTK_WRAP_WORD);
244 /* vbox for buttons and templates list */
245 vbox2 = gtk_vbox_new(FALSE, 6);
246 gtk_widget_show(vbox2);
247 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 8);
248 gtk_paned_pack2(GTK_PANED(vpaned), vbox2, TRUE, FALSE);
250 /* register | substitute | delete */
251 hbox2 = gtk_hbox_new(FALSE, 4);
252 gtk_widget_show(hbox2);
253 gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
255 arrow1 = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
256 gtk_widget_show(arrow1);
257 gtk_box_pack_start(GTK_BOX(hbox2), arrow1, FALSE, FALSE, 0);
258 gtk_widget_set_size_request(arrow1, -1, 16);
260 hbox3 = gtk_hbox_new(TRUE, 4);
261 gtk_widget_show(hbox3);
262 gtk_box_pack_start(GTK_BOX(hbox2), hbox3, FALSE, FALSE, 0);
264 reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
265 gtk_widget_show(reg_btn);
266 gtk_box_pack_start(GTK_BOX(hbox3), reg_btn, FALSE, TRUE, 0);
267 g_signal_connect(G_OBJECT (reg_btn), "clicked",
268 G_CALLBACK (prefs_template_register_cb), NULL);
270 subst_btn = gtkut_get_replace_btn(_("Replace"));
271 gtk_widget_show(subst_btn);
272 gtk_box_pack_start(GTK_BOX(hbox3), subst_btn, FALSE, TRUE, 0);
273 g_signal_connect(G_OBJECT(subst_btn), "clicked",
274 G_CALLBACK(prefs_template_substitute_cb),
277 del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
278 gtk_widget_show(del_btn);
279 gtk_box_pack_start(GTK_BOX(hbox3), del_btn, FALSE, TRUE, 0);
280 g_signal_connect(G_OBJECT(del_btn), "clicked",
281 G_CALLBACK(prefs_template_delete_cb), NULL);
283 #if GTK_CHECK_VERSION(2, 8, 0)
284 desc_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
286 desc_btn = gtk_button_new_with_label(_(" Symbols... "));
288 gtk_widget_show(desc_btn);
289 gtk_box_pack_end(GTK_BOX(hbox2), desc_btn, FALSE, FALSE, 0);
290 g_signal_connect(G_OBJECT(desc_btn), "clicked",
291 G_CALLBACK(quote_fmt_quote_description), NULL);
294 scroll1 = gtk_scrolled_window_new(NULL, NULL);
295 gtk_widget_show(scroll1);
296 gtk_box_pack_start(GTK_BOX(vbox2), scroll1, TRUE, TRUE, 0);
297 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll1),
298 GTK_POLICY_AUTOMATIC,
299 GTK_POLICY_AUTOMATIC);
301 list_view = prefs_template_list_view_create();
302 gtk_widget_show(list_view);
303 gtk_widget_set_size_request(scroll1, -1, 140);
304 gtk_container_add(GTK_CONTAINER(scroll1), list_view);
306 /* help | cancel | ok */
307 gtkut_stock_button_set_create_with_help(&confirm_area, &help_btn,
308 &cancel_btn, GTK_STOCK_CANCEL,
309 &ok_btn, GTK_STOCK_OK,
311 gtk_widget_show(confirm_area);
312 gtk_box_pack_end(GTK_BOX(vbox2), confirm_area, FALSE, FALSE, 0);
313 gtk_widget_grab_default(ok_btn);
315 gtk_window_set_title(GTK_WINDOW(window), _("Template configuration"));
317 g_signal_connect(G_OBJECT(window), "delete_event",
318 G_CALLBACK(prefs_template_deleted_cb), NULL);
319 g_signal_connect(G_OBJECT(window), "size_allocate",
320 G_CALLBACK(prefs_template_size_allocate_cb), NULL);
321 g_signal_connect(G_OBJECT(window), "key_press_event",
322 G_CALLBACK(prefs_template_key_pressed_cb), NULL);
323 MANAGE_WINDOW_SIGNALS_CONNECT(window);
324 g_signal_connect(G_OBJECT(ok_btn), "clicked",
325 G_CALLBACK(prefs_template_ok_cb), NULL);
326 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
327 G_CALLBACK(prefs_template_cancel_cb), NULL);
328 g_signal_connect(G_OBJECT(help_btn), "clicked",
329 G_CALLBACK(manual_open_with_anchor_cb),
330 MANUAL_ANCHOR_TEMPLATES);
332 address_completion_start(window);
334 if (!geometry.min_height) {
335 geometry.min_width = 440;
336 geometry.min_height = 500;
339 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
341 gtk_widget_set_size_request(window, prefs_common.templateswin_width,
342 prefs_common.templateswin_height);
344 templates.window = window;
345 templates.ok_btn = ok_btn;
346 templates.list_view = list_view;
347 templates.text_value = text_value;
350 static void prefs_template_window_setup(void)
356 GtkTextBuffer *buffer;
358 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
359 (templates.list_view)));
361 manage_window_set_transient(GTK_WINDOW(templates.window));
362 gtk_widget_grab_focus(templates.ok_btn);
364 gtk_list_store_clear(store);
366 prefs_template_list_view_insert_template(templates.list_view,
370 tmpl_list = template_read_config();
372 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
373 tmpl = (Template *)cur->data;
374 prefs_template_list_view_insert_template(templates.list_view,
379 gtk_entry_set_text(GTK_ENTRY(templates.entry_name), "");
380 gtk_entry_set_text(GTK_ENTRY(templates.entry_to), "");
381 gtk_entry_set_text(GTK_ENTRY(templates.entry_cc), "");
382 gtk_entry_set_text(GTK_ENTRY(templates.entry_bcc), "");
383 gtk_entry_set_text(GTK_ENTRY(templates.entry_subject), "");
385 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(templates.text_value));
386 gtk_text_buffer_set_text(buffer, "", -1);
388 g_slist_free(tmpl_list);
391 static void prefs_template_clear(void)
395 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
396 (templates.list_view)));
397 gtk_list_store_clear(store);
400 static gint prefs_template_deleted_cb(GtkWidget *widget, GdkEventAny *event,
403 prefs_template_cancel_cb();
407 static gboolean prefs_template_key_pressed_cb(GtkWidget *widget,
408 GdkEventKey *event, gpointer data)
410 if (event && event->keyval == GDK_Escape)
411 prefs_template_cancel_cb();
413 GtkWidget *focused = gtkut_get_focused_child(
414 GTK_CONTAINER(widget));
415 if (focused && GTK_IS_EDITABLE(focused)) {
422 static void prefs_template_ok_cb(void)
426 if (modified && alertpanel(_("Entry not saved"),
427 _("The entry was not saved. Close anyway?"),
428 GTK_STOCK_CLOSE, _("+_Continue editing"),
429 NULL) != G_ALERTDEFAULT) {
433 tmpl_list = prefs_template_get_list();
434 template_set_config(tmpl_list);
435 compose_reflect_prefs_all();
436 prefs_template_clear();
437 gtk_widget_hide(templates.window);
441 static void prefs_template_cancel_cb(void)
443 if (modified && alertpanel(_("Entry not saved"),
444 _("The entry was not saved. Close anyway?"),
445 GTK_STOCK_CLOSE, _("+_Continue editing"),
446 NULL) != G_ALERTDEFAULT) {
450 prefs_template_clear();
451 gtk_widget_hide(templates.window);
456 *\brief Request list for storage. New list is owned
459 static GSList *prefs_template_get_list(void)
461 GSList *tmpl_list = NULL;
466 model = gtk_tree_view_get_model(GTK_TREE_VIEW(templates.list_view));
467 if (!gtk_tree_model_get_iter_first(model, &iter))
471 gtk_tree_model_get(model, &iter,
478 ntmpl = g_new(Template, 1);
479 ntmpl->name = tmpl->name && *(tmpl->name)
480 ? g_strdup(tmpl->name)
482 ntmpl->subject = tmpl->subject && *(tmpl->subject)
483 ? g_strdup(tmpl->subject)
485 ntmpl->to = tmpl->to && *(tmpl->to)
488 ntmpl->cc = tmpl->cc && *(tmpl->cc)
491 ntmpl->bcc = tmpl->bcc && *(tmpl->bcc)
492 ? g_strdup(tmpl->bcc)
494 ntmpl->value = tmpl->value && *(tmpl->value)
495 ? g_strdup(tmpl->value)
497 tmpl_list = g_slist_append(tmpl_list, ntmpl);
500 } while (gtk_tree_model_iter_next(model, &iter));
505 gboolean prefs_template_string_is_valid(gchar *string)
507 if (string && *string != '\0') {
511 memset(&dummyinfo, 0, sizeof(MsgInfo));
512 quote_fmt_init(&dummyinfo, NULL, NULL, TRUE, NULL);
513 quote_fmt_scan_string(string);
515 parsed_buf = quote_fmt_get_buffer();
518 quote_fmt_reset_vartable();
523 static gboolean prefs_template_list_view_set_row(GtkTreeIter *row)
524 /* return TRUE if the row could be modified */
533 GtkTextBuffer *buffer;
534 GtkTextIter start, end;
537 model = gtk_tree_view_get_model(GTK_TREE_VIEW(templates.list_view));
539 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(templates.text_value));
540 gtk_text_buffer_get_start_iter(buffer, &start);
541 gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
542 value = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
544 if (value && *value == '\0') {
548 if (!prefs_template_string_is_valid(value)) {
549 alertpanel_error(_("Template body format error."));
554 name = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_name),
557 alertpanel_error(_("Template name is not set."));
560 to = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_to),
562 cc = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_cc),
564 bcc = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_bcc),
566 subject = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_subject),
569 if (to && *to == '\0') {
573 if (cc && *cc == '\0') {
577 if (bcc && *bcc == '\0') {
581 if (subject && *subject == '\0') {
586 if (!prefs_template_string_is_valid(to)) {
587 alertpanel_error(_("Template To format error."));
591 if (!prefs_template_string_is_valid(cc)) {
592 alertpanel_error(_("Template Cc format error."));
596 if (!prefs_template_string_is_valid(bcc)) {
597 alertpanel_error(_("Template Bcc format error."));
601 if (!prefs_template_string_is_valid(subject)) {
602 alertpanel_error(_("Template subject format error."));
607 tmpl = g_new(Template, 1);
609 tmpl->subject = subject;
615 prefs_template_list_view_insert_template(templates.list_view,
616 row, tmpl->name, tmpl, TRUE);
620 static void prefs_template_register_cb(void)
622 modified = !prefs_template_list_view_set_row(NULL);
625 static void prefs_template_substitute_cb(void)
629 GtkTreeSelection *selection;
632 selection = gtk_tree_view_get_selection
633 (GTK_TREE_VIEW(templates.list_view));
635 if (!gtk_tree_selection_get_selected(selection, &model, &row))
638 gtk_tree_model_get(model, &row,
644 modified = !prefs_template_list_view_set_row(&row);
647 static void prefs_template_delete_cb(void)
651 GtkTreeSelection *selection;
654 selection = gtk_tree_view_get_selection
655 (GTK_TREE_VIEW(templates.list_view));
657 if (!gtk_tree_selection_get_selected(selection, &model, &row))
660 gtk_tree_model_get(model, &row,
667 if (alertpanel(_("Delete template"),
668 _("Do you really want to delete this template?"),
669 GTK_STOCK_CANCEL, GTK_STOCK_DELETE,
670 NULL) != G_ALERTALTERNATE)
673 gtk_list_store_remove(GTK_LIST_STORE(model), &row);
676 static GtkListStore* prefs_template_create_data_store(void)
678 return gtk_list_store_new(N_TEMPL_COLUMNS,
685 static gboolean prefs_template_list_view_find_insertion_point(GtkTreeModel* model,
686 const gchar* template,
692 if ((gtk_tree_model_get_iter_first(model, &i))) {
693 for ( ; gtk_tree_model_iter_next(model, &i); ) {
694 gtk_tree_model_get(model, &i, TEMPL_TEXT, &text, -1);
695 if (strcmp(text, template) >= 0) {
703 /* cannot add before (need to append) */
707 static void prefs_template_list_view_insert_template(GtkWidget *list_view,
708 GtkTreeIter *row_iter,
709 const gchar *template,
714 GtkTreeModel *model = gtk_tree_view_get_model
715 (GTK_TREE_VIEW(list_view));
716 GtkListStore *list_store = GTK_LIST_STORE(model);
719 if (row_iter == NULL) {
721 GtkTreeIter insertion_point;
724 if (prefs_template_list_view_find_insertion_point(model,
725 template, &insertion_point)) {
726 gtk_list_store_insert_before(list_store, &iter,
729 gtk_list_store_append(list_store, &iter);
733 gtk_list_store_append(list_store, &iter);
736 /* modify the existing */
740 GtkTreeIter insertion_point;
743 /* force re-sorting if template's name changed */
744 gtk_tree_model_get(model, row_iter, TEMPL_TEXT, &text, -1);
745 if (strcmp(text, template) != 0) {
747 /* move the modified template */
748 if (prefs_template_list_view_find_insertion_point(model,
749 template, &insertion_point)) {
750 gtk_list_store_move_before(list_store, row_iter,
753 /* move to the end */
754 gtk_list_store_move_before(list_store, row_iter,
762 auto_data = g_auto_pointer_new_with_free(data, (GFreeFunc) template_free);
764 /* if replacing data in an existing row, the auto pointer takes care
765 * of destroying the Template data */
766 gtk_list_store_set(list_store, &iter,
767 TEMPL_TEXT, template,
769 TEMPL_AUTO_DATA, auto_data,
772 g_auto_pointer_free(auto_data);
775 static GtkWidget *prefs_template_list_view_create(void)
777 GtkTreeView *list_view;
778 GtkTreeSelection *selector;
781 model = GTK_TREE_MODEL(prefs_template_create_data_store());
782 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
783 g_object_unref(model);
785 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
787 selector = gtk_tree_view_get_selection(list_view);
788 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
789 gtk_tree_selection_set_select_function(selector, prefs_template_selected,
792 /* create the columns */
793 prefs_template_create_list_view_columns(GTK_WIDGET(list_view));
795 return GTK_WIDGET(list_view);
798 static void prefs_template_create_list_view_columns(GtkWidget *list_view)
800 GtkTreeViewColumn *column;
801 GtkCellRenderer *renderer;
803 renderer = gtk_cell_renderer_text_new();
804 column = gtk_tree_view_column_new_with_attributes
805 (_("Current templates"),
809 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
812 static gboolean prefs_template_selected(GtkTreeSelection *selector,
815 gboolean currently_selected,
820 GtkTextBuffer *buffer;
824 if (currently_selected)
827 if (!gtk_tree_model_get_iter(model, &titer, path))
830 tmpl_def.name = _("Template");
831 tmpl_def.subject = "";
837 gtk_tree_model_get(model, &titer,
844 gtk_entry_set_text(GTK_ENTRY(templates.entry_name), tmpl->name);
845 gtk_entry_set_text(GTK_ENTRY(templates.entry_to),
846 tmpl->to ? tmpl->to : "");
847 gtk_entry_set_text(GTK_ENTRY(templates.entry_cc),
848 tmpl->cc ? tmpl->cc : "");
849 gtk_entry_set_text(GTK_ENTRY(templates.entry_bcc),
850 tmpl->bcc ? tmpl->bcc : "");
851 gtk_entry_set_text(GTK_ENTRY(templates.entry_subject),
852 tmpl->subject ? tmpl->subject : "");
854 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(templates.text_value));
855 gtk_text_buffer_set_text(buffer, "", -1);
856 gtk_text_buffer_get_start_iter(buffer, &iter);
857 gtk_text_buffer_insert(buffer, &iter, tmpl->value, -1);