geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

templates.c
Go to the documentation of this file.
1/*
2 * templates.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2005 The Geany contributors
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21/*
22 * Templates to insert into the current document, or file templates to create a new
23 * document from.
24 */
25
26#ifdef HAVE_CONFIG_H
27# include "config.h"
28#endif
29
30#include "templates.h"
31
32#include "app.h"
33#include "document.h"
34#include "encodingsprivate.h"
35#include "filetypes.h"
36#include "geany.h"
38#include "geanyobject.h"
39#include "spawn.h"
40#include "support.h"
41#include "toolbar.h"
42#include "ui_utils.h"
43#include "utils.h"
44
45#include <time.h>
46#include <string.h>
47#include <gtk/gtk.h>
48
49
51
52static GtkWidget *new_with_template_menu = NULL;
54
55/* TODO: implement custom insertion templates instead? */
56static gchar *templates[GEANY_MAX_TEMPLATES];
57
58
59static void replace_static_values(GString *text);
60static gchar *get_template_fileheader(GeanyFiletype *ft);
61
62/* called by templates_replace_common */
63static void templates_replace_default_dates(GString *text);
64static void templates_replace_command(GString *text, const gchar *file_name,
65 const gchar *file_type, const gchar *func_name);
66
67
68static gchar *read_file(const gchar *locale_fname)
69{
70 gchar *contents;
71 gsize length;
72 GString *str;
73
74 if (! g_file_get_contents(locale_fname, &contents, &length, NULL))
75 return NULL;
76
77 if (! encodings_convert_to_utf8_auto(&contents, &length, NULL, NULL, NULL, NULL))
78 {
79 gchar *utf8_fname = utils_get_utf8_from_locale(locale_fname);
80
81 ui_set_statusbar(TRUE, _("Failed to convert template file \"%s\" to UTF-8"), utf8_fname);
82 g_free(utf8_fname);
83 g_free(contents);
84 return NULL;
85 }
86
87 str = g_string_new(contents);
88 g_free(contents);
89
90 /* convert to LF endings for consistency in mixing templates */
92 return g_string_free(str, FALSE);
93}
94
95
96static void read_template(const gchar *name, gint id)
97{
98 gchar *fname = g_build_path(G_DIR_SEPARATOR_S, app->configdir,
100
101 /* try system if user template doesn't exist */
102 if (!g_file_test(fname, G_FILE_TEST_EXISTS))
103 SETPTR(fname, g_build_path(G_DIR_SEPARATOR_S, app->datadir,
105
106 templates[id] = read_file(fname);
107 g_free(fname);
108}
109
110
111/* called when inserting templates into an existing document */
112static void convert_eol_characters(GString *template, GeanyDocument *doc)
113{
114 gint doc_eol_mode;
115
116 g_return_if_fail(doc == NULL || doc->is_valid);
117
118 if (doc == NULL)
119 doc = document_get_current();
120
121 g_return_if_fail(doc != NULL);
122
123 doc_eol_mode = editor_get_eol_char_mode(doc->editor);
124 utils_ensure_same_eol_characters(template, doc_eol_mode);
125}
126
127
128static void init_general_templates(void)
129{
130 /* read the contents */
131 read_template("fileheader", GEANY_TEMPLATE_FILEHEADER);
132 read_template("gpl", GEANY_TEMPLATE_GPL);
133 read_template("bsd", GEANY_TEMPLATE_BSD);
134 read_template("function", GEANY_TEMPLATE_FUNCTION);
135 read_template("changelog", GEANY_TEMPLATE_CHANGELOG);
136}
137
138
139void templates_replace_common(GString *tmpl, const gchar *fname,
140 GeanyFiletype *ft, const gchar *func_name)
141{
142 gchar *shortname;
143
144 if (fname == NULL)
145 {
146 if (!ft->extension)
147 shortname = g_strdup(GEANY_STRING_UNTITLED);
148 else
149 shortname = g_strconcat(GEANY_STRING_UNTITLED, ".", ft->extension, NULL);
150 }
151 else
152 shortname = g_path_get_basename(fname);
153
155 "{filename}", shortname,
156 "{project}", app->project ? app->project->name : "",
157 "{description}", app->project ? app->project->description : "",
158 NULL);
159 g_free(shortname);
160
162 templates_replace_command(tmpl, fname, ft->name, func_name);
163 /* Bug: command results could have {ob} {cb} strings in! */
164 /* replace braces last */
166 "{ob}", "{",
167 "{cb}", "}",
168 NULL);
169}
170
171
172static gchar *get_template_from_file(const gchar *locale_fname, const gchar *doc_filename,
173 GeanyFiletype *ft)
174{
175 gchar *content;
176
177 content = read_file(locale_fname);
178
179 if (content != NULL)
180 {
181 gchar *file_header;
182 GString *template = g_string_new(content);
183
184 file_header = get_template_fileheader(ft);
186 "{fileheader}", file_header,
187 NULL);
188 templates_replace_common(template, doc_filename, ft, NULL);
189
190 utils_free_pointers(2, file_header, content, NULL);
191 return g_string_free(template, FALSE);
192 }
193 return NULL;
194}
195
196
197static void
198on_new_with_file_template(GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
199{
200 gchar *fname = ui_menu_item_get_text(menuitem);
201 GeanyFiletype *ft;
202 gchar *template;
203 const gchar *extension = strrchr(fname, '.'); /* easy way to get the file extension */
204 gchar *new_filename = g_strconcat(GEANY_STRING_UNTITLED, extension, NULL);
205 gchar *path;
206
208 SETPTR(fname, utils_get_locale_from_utf8(fname));
209
210 /* fname is just the basename from the menu item, so prepend the custom files path */
211 path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_TEMPLATES_SUBDIR,
212 "files", fname, NULL);
213 template = get_template_from_file(path, new_filename, ft);
214 if (!template)
215 {
216 /* try the system path */
217 g_free(path);
218 path = g_build_path(G_DIR_SEPARATOR_S, app->datadir, GEANY_TEMPLATES_SUBDIR,
219 "files", fname, NULL);
220 template = get_template_from_file(path, new_filename, ft);
221 }
222 if (template)
223 {
224 /* line endings will be converted */
225 document_new_file(new_filename, ft, template);
226 }
227 else
228 {
229 SETPTR(fname, utils_get_utf8_from_locale(fname));
230 ui_set_statusbar(TRUE, _("Could not find file '%s'."), fname);
231 }
232 g_free(template);
233 g_free(path);
234 g_free(new_filename);
235 g_free(fname);
236}
237
238
239static void add_file_item(const gchar *fname, GtkWidget *menu)
240{
241 GtkWidget *tmp_button;
242 gchar *label;
243
244 g_return_if_fail(fname);
245 g_return_if_fail(menu);
246
248
249 tmp_button = gtk_menu_item_new_with_label(label);
250 gtk_widget_show(tmp_button);
251 gtk_container_add(GTK_CONTAINER(menu), tmp_button);
252 g_signal_connect(tmp_button, "activate", G_CALLBACK(on_new_with_file_template), NULL);
253
254 g_free(label);
255}
256
257
258static void populate_file_template_menu(GtkWidget *menu)
259{
260 GSList *list = utils_get_config_files(GEANY_TEMPLATES_SUBDIR G_DIR_SEPARATOR_S "files");
261 GSList *node;
262
263 foreach_slist(node, list)
264 {
265 gchar *fname = node->data;
266
267 add_file_item(fname, menu);
268 g_free(fname);
269 }
270 g_slist_free(list);
271}
272
273
275{
276 GtkWidget *item;
277
278 new_with_template_menu = gtk_menu_new();
279 item = ui_lookup_widget(main_widgets.window, "menu_new_with_template1");
280 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), new_with_template_menu);
281
282 new_with_template_toolbar_menu = gtk_menu_new();
283 g_object_ref(new_with_template_toolbar_menu);
286}
287
288
289/* reload templates if any file in the templates path is saved */
290static void on_document_save(G_GNUC_UNUSED GObject *object, GeanyDocument *doc)
291{
292 gchar *path;
293
294 g_return_if_fail(!EMPTY(doc->real_path));
295
296 path = g_build_filename(app->configdir, GEANY_TEMPLATES_SUBDIR, NULL);
297 if (strncmp(doc->real_path, path, strlen(path)) == 0)
298 {
299 /* reload templates */
302 }
303 g_free(path);
304}
305
306
307/* warning: also called when reloading template settings */
309{
310 static gboolean init_done = FALSE;
311
313
314 if (!init_done)
315 {
317 g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL);
318 init_done = TRUE;
319 }
320
323}
324
325
326/* indent is used to make some whitespace between comment char and real start of the line
327 * e.g. indent = 8 prints " * here comes the text of the line"
328 * indent is meant to be the whole amount of characters before the real line content follows, i.e.
329 * 6 characters are filled with whitespace when the comment characters include " *" */
330static void make_comment_block(GString *comment_text, gint filetype_idx, guint indent)
331{
332 gchar *frame_start; /* to add before comment_text */
333 gchar *frame_end; /* to add after comment_text */
334 const gchar *line_prefix; /* to add before every line in comment_text */
335 gchar *tmp;
336 gchar *prefix;
337 gchar **lines;
338 gsize i, len;
339 gint template_eol_mode;
340 const gchar *template_eol_char;
341 GeanyFiletype *ft = filetypes_index(filetype_idx);
342 const gchar *co;
343 const gchar *cc;
344
345 g_return_if_fail(comment_text != NULL);
346 g_return_if_fail(ft != NULL);
347
348 template_eol_mode = utils_get_line_endings(comment_text->str, comment_text->len);
349 template_eol_char = utils_get_eol_char(template_eol_mode);
350
351 filetype_get_comment_open_close(ft, FALSE, &co, &cc);
352 if (!EMPTY(co))
353 {
354 if (!EMPTY(cc))
355 {
356 frame_start = g_strconcat(co, template_eol_char, NULL);
357 frame_end = g_strconcat(cc, template_eol_char, NULL);
358 line_prefix = "";
359 }
360 else
361 {
362 frame_start = NULL;
363 frame_end = NULL;
364 line_prefix = co;
365 }
366 }
367 else
368 { /* use C-like multi-line comments as fallback */
369 frame_start = g_strconcat("/*", template_eol_char, NULL);
370 frame_end = g_strconcat("*/", template_eol_char, NULL);
371 line_prefix = "";
372 }
373
374 /* do some magic to nicely format C-like multi-line comments */
375 if (!EMPTY(frame_start) && frame_start[1] == '*')
376 {
377 /* prefix the string with a space */
378 SETPTR(frame_end, g_strconcat(" ", frame_end, NULL));
379 line_prefix = " *";
380 }
381
382 /* construct the real prefix with given amount of whitespace */
383 i = (indent > strlen(line_prefix)) ? (indent - strlen(line_prefix)) : strlen(line_prefix);
384 tmp = g_strnfill(i, ' ');
385 prefix = g_strconcat(line_prefix, tmp, NULL);
386 g_free(tmp);
387
388 /* add line_prefix to every line of comment_text */
389 lines = g_strsplit(comment_text->str, template_eol_char, -1);
390 len = g_strv_length(lines);
391 if (len > 0) /* prevent unsigned wraparound if comment_text is empty */
392 {
393 for (i = 0; i < len - 1; i++)
394 {
395 tmp = lines[i];
396 lines[i] = g_strconcat(prefix, tmp, NULL);
397 g_free(tmp);
398 }
399 }
400 tmp = g_strjoinv(template_eol_char, lines);
401
402 /* clear old contents */
403 g_string_erase(comment_text, 0, -1);
404
405 /* add frame_end */
406 if (frame_start != NULL)
407 g_string_append(comment_text, frame_start);
408 /* add the new main content */
409 g_string_append(comment_text, tmp);
410 /* add frame_start */
411 if (frame_end != NULL)
412 g_string_append(comment_text, frame_end);
413
414 utils_free_pointers(4, prefix, tmp, frame_start, frame_end, NULL);
415 g_strfreev(lines);
416}
417
418
419gchar *templates_get_template_licence(GeanyDocument *doc, gint licence_type)
420{
421 GString *template;
422
423 g_return_val_if_fail(DOC_VALID(doc), NULL);
424 g_return_val_if_fail(licence_type == GEANY_TEMPLATE_GPL || licence_type == GEANY_TEMPLATE_BSD, NULL);
425
426 template = g_string_new(templates[licence_type]);
427 replace_static_values(template);
430
431 make_comment_block(template, doc->file_type->id, GEANY_TEMPLATES_INDENT);
432 convert_eol_characters(template, doc);
433
434 return g_string_free(template, FALSE);
435}
436
437
439{
440 GString *template = g_string_new(templates[GEANY_TEMPLATE_FILEHEADER]);
441
442 filetypes_load_config(ft->id, FALSE); /* load any user extension setting */
443
445 "{gpl}", templates[GEANY_TEMPLATE_GPL],
446 "{bsd}", templates[GEANY_TEMPLATE_BSD],
447 NULL);
448
449 /* we don't replace other wildcards here otherwise they would get done twice for files */
450 make_comment_block(template, ft->id, GEANY_TEMPLATES_INDENT);
451 return g_string_free(template, FALSE);
452}
453
454
455/* TODO change the signature to take a GeanyDocument? this would break plugin API/ABI */
456GEANY_API_SYMBOL
457gchar *templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
458{
459 GeanyFiletype *ft = filetypes[filetype_idx];
460 gchar *str = get_template_fileheader(ft);
461 GString *template = g_string_new(str);
462
463 g_free(str);
464 templates_replace_common(template, fname, ft, NULL);
465 convert_eol_characters(template, NULL);
466 return g_string_free(template, FALSE);
467}
468
469
470gchar *templates_get_template_function(GeanyDocument *doc, const gchar *func_name)
471{
472 GString *text;
473
474 func_name = (func_name != NULL) ? func_name : "";
475 text = g_string_new(templates[GEANY_TEMPLATE_FUNCTION]);
476
477 templates_replace_valist(text, "{functionname}", func_name, NULL);
480
481 make_comment_block(text, doc->file_type->id, GEANY_TEMPLATES_INDENT);
483
484 return g_string_free(text, FALSE);
485}
486
487
489{
490 GString *result;
491 const gchar *file_type_name;
492
493 g_return_val_if_fail(DOC_VALID(doc), NULL);
494
495 result = g_string_new(templates[GEANY_TEMPLATE_CHANGELOG]);
496 file_type_name = (doc->file_type != NULL) ? doc->file_type->name : "";
497 replace_static_values(result);
499 templates_replace_command(result, DOC_FILENAME(doc), file_type_name, NULL);
500 convert_eol_characters(result, doc);
501
502 return g_string_free(result, FALSE);
503}
504
505
506static void free_template_menu_items(GtkWidget *menu)
507{
508 GList *children, *item;
509
510 children = gtk_container_get_children(GTK_CONTAINER(menu));
511 foreach_list(item, children)
512 gtk_widget_destroy(GTK_WIDGET(item->data));
513 g_list_free(children);
514}
515
516
518{
519 gint i;
520
521 for (i = 0; i < GEANY_MAX_TEMPLATES; i++)
522 g_free(templates[i]);
525}
526
527
528static void replace_static_values(GString *text)
529{
536 utils_string_replace_all(text, "{geanyversion}", "Geany " VERSION);
537}
538
539
540/* Replaces all static template wildcards (version, mail, company, name, ...)
541 * plus those wildcard, value pairs which are passed, e.g.
542 *
543 * templates_replace_valist(text, "{some_wildcard}", "some value",
544 * "{another_wildcard}", "another value", NULL);
545 *
546 * The argument list must be terminated with NULL. */
547void templates_replace_valist(GString *text, const gchar *first_wildcard, ...)
548{
549 va_list args;
550 const gchar *key, *value;
551
552 g_return_if_fail(text != NULL);
553
554 va_start(args, first_wildcard);
555
556 key = first_wildcard;
557 value = va_arg(args, gchar*);
558
559 while (key != NULL)
560 {
561 utils_string_replace_all(text, key, value);
562
563 key = va_arg(args, gchar*);
564 if (key == NULL || text == NULL)
565 break;
566 value = va_arg(args, gchar*);
567 }
568 va_end(args);
569
571}
572
573
575{
579
580 g_return_if_fail(text != NULL);
581
583 "{year}", year,
584 "{date}", date,
585 "{datetime}", datetime,
586 NULL);
587
588 utils_free_pointers(3, year, date, datetime, NULL);
589}
590
591
592static gchar *run_command(const gchar *command, const gchar *file_name,
593 const gchar *file_type, const gchar *func_name)
594{
595 GString *output = g_string_new(NULL);
596 gchar *result = NULL;
597 GError *error = NULL;
598 gchar **env;
599
600 file_name = (file_name != NULL) ? file_name : "";
601 file_type = (file_type != NULL) ? file_type : "";
602 func_name = (func_name != NULL) ? func_name : "";
603
605 "GEANY_FILENAME", file_name,
606 "GEANY_FILETYPE", file_type,
607 "GEANY_FUNCNAME", func_name,
608 NULL);
609
610 if (spawn_sync(NULL, command, NULL, env, NULL, output, NULL, NULL, &error))
611 {
612 result = g_string_free(output, FALSE);
613 }
614 else
615 {
616 g_warning(_("Cannot execute template command \"%s\". "
617 "Hint: incorrect paths in the command are a common cause of errors. "
618 "Error: %s."), command, error->message);
619 g_error_free(error);
620 }
621
622 g_strfreev(env);
623 return result;
624}
625
626
627static void templates_replace_command(GString *text, const gchar *file_name,
628 const gchar *file_type, const gchar *func_name)
629{
630 gchar *match;
631
632 g_return_if_fail(text != NULL);
633
634 while ((match = strstr(text->str, "{command:")) != NULL)
635 {
636 gchar *wildcard;
637 gchar *cmd = match;
638 gchar *result;
639
640 while (*match != '}' && *match != '\0')
641 match++;
642
643 wildcard = g_strndup(cmd, (gsize) (match - cmd + 1));
644 cmd = g_strndup(wildcard + 9, strlen(wildcard) - 10);
645
646 result = run_command(cmd, file_name, file_type, func_name);
647 if (result != NULL)
648 {
649 result = g_strstrip(result);
650 utils_string_replace_first(text, wildcard, result);
651 g_free(result);
652 }
653 else
654 utils_string_replace_first(text, wildcard, "");
655
656 g_free(wildcard);
657 g_free(cmd);
658 }
659}
#define SC_EOL_LF
Definition: Scintilla.h:90
Contains the GeanyApp.
const gchar * command
Definition: build.c:2677
const gchar * label
Definition: build.c:2676
GeanyDocument * document_get_current(void)
Finds the current document.
Definition: document.c:371
const gchar * name
Definition: document.c:3219
GeanyDocument * document_new_file(const gchar *utf8_filename, GeanyFiletype *ft, const gchar *text)
Creates a new document.
Definition: document.c:824
Document related actions: new, save, open, etc.
#define DOC_VALID(doc_ptr)
Null-safe way to check GeanyDocument::is_valid.
Definition: document.h:162
#define DOC_FILENAME(doc)
Returns the filename of the document passed or GEANY_STRING_UNTITLED (e.g.
Definition: document.h:170
gint editor_get_eol_char_mode(GeanyEditor *editor)
Retrieves the end of line characters mode (LF, CR/LF, CR) in the given editor.
Definition: editor.c:4279
static gchar indent[100]
Definition: editor.c:91
gchar * text
Definition: editor.c:83
gboolean encodings_convert_to_utf8_auto(gchar **buf, gsize *size, const gchar *forced_enc, gchar **used_encoding, gboolean *has_bom, gboolean *partial)
Definition: encodings.c:1057
void error(const errorSelection selection, const char *const format,...)
Definition: error.c:53
Filetype detection, file extensions and filetype menu items.
#define filetypes
Wraps GeanyData::filetypes_array so it can be used with C array syntax.
Definition: filetypes.h:178
#define GEANY_TEMPLATES_SUBDIR
Definition: geany.h:42
#define GEANY_STRING_UNTITLED
Definition: geany.h:49
tokenInfo * list
static bool match(const unsigned char *line, const char *word)
Definition: geany_tcl.c:55
void geany_menu_button_action_set_menu(GeanyMenubuttonAction *action, GtkWidget *menu)
#define GEANY_MENU_BUTTON_ACTION(obj)
GObject * geany_object
Definition: geanyobject.c:41
GeanyApp * app
Definition: libmain.c:86
#define NULL
Definition: rbtree.h:150
char * strstr(const char *str, const char *substr)
Definition: routines.c:304
gboolean spawn_sync(const gchar *working_directory, const gchar *command_line, gchar **argv, gchar **envp, SpawnWriteData *stdin_data, GString *stdout_data, GString *stderr_data, gint *exit_status, GError **error)
Executes a child synchronously.
Definition: spawn.c:1357
Portable and convenient process spawning and communication.
GeanyFiletype * filetypes_index(gint idx)
Accessor function for GeanyData::filetypes_array items.
Definition: filetypes.c:1489
GeanyFiletype * filetypes_detect_from_extension(const gchar *utf8_filename)
Definition: filetypes.c:517
void filetypes_load_config(guint ft_id, gboolean reload)
Definition: filetypes.c:1089
gboolean filetype_get_comment_open_close(const GeanyFiletype *ft, gboolean single_first, const gchar **co, const gchar **cc)
Definition: filetypes.c:1536
gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button)
long lines
Definition: stats.c:32
struct GeanyProject * project
Currently active project or NULL if none is open.
Definition: app.h:49
gchar * configdir
User configuration directory, usually ~/.config/geany.
Definition: app.h:45
gchar * datadir
Definition: app.h:46
Structure for representing an open tab with all its properties.
Definition: document.h:81
GeanyFiletype * file_type
The filetype for this document, it's only a reference to one of the elements of the global filetypes ...
Definition: document.h:101
gchar * real_path
The link-dereferenced, locale-encoded file name.
Definition: document.h:115
gboolean is_valid
Flag used to check if this document is valid when iterating GeanyData::documents_array.
Definition: document.h:83
GeanyEditor * editor
The editor associated with the document.
Definition: document.h:98
Represents a filetype.
Definition: filetypes.h:144
gchar * name
Untranslated short name, such as "C", "None".
Definition: filetypes.h:152
GeanyFiletypeID id
Index in filetypes.
Definition: filetypes.h:145
gchar * extension
Default file extension for new files, or NULL.
Definition: filetypes.h:155
GtkWidget * window
Main window.
Definition: ui_utils.h:80
gchar * description
Short description of the project.
Definition: project.h:37
gchar * name
The name of the project.
Definition: project.h:36
Template preferences.
Definition: templates.h:39
gchar * initials
Initials.
Definition: templates.h:43
gchar * mail
Email.
Definition: templates.h:42
gchar * year_format
Definition: templates.h:45
gchar * company
Company.
Definition: templates.h:41
gchar * version
Initial version.
Definition: templates.h:44
gchar * datetime_format
Definition: templates.h:47
gchar * date_format
Definition: templates.h:46
gchar * developer
Name.
Definition: templates.h:40
Defines internationalization macros.
#define _(String)
Definition: support.h:42
gchar * templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
Definition: templates.c:457
void templates_replace_common(GString *tmpl, const gchar *fname, GeanyFiletype *ft, const gchar *func_name)
Definition: templates.c:139
static void make_comment_block(GString *comment_text, gint filetype_idx, guint indent)
Definition: templates.c:330
static void convert_eol_characters(GString *template, GeanyDocument *doc)
Definition: templates.c:112
static void free_template_menu_items(GtkWidget *menu)
Definition: templates.c:506
gchar * templates_get_template_changelog(GeanyDocument *doc)
Definition: templates.c:488
void templates_init(void)
Definition: templates.c:308
static void populate_file_template_menu(GtkWidget *menu)
Definition: templates.c:258
GeanyTemplatePrefs template_prefs
Definition: templates.c:50
static void add_file_item(const gchar *fname, GtkWidget *menu)
Definition: templates.c:239
static gchar * get_template_fileheader(GeanyFiletype *ft)
Definition: templates.c:438
void templates_free_templates(void)
Definition: templates.c:517
static gchar * read_file(const gchar *locale_fname)
Definition: templates.c:68
static void on_document_save(G_GNUC_UNUSED GObject *object, GeanyDocument *doc)
Definition: templates.c:290
static void templates_replace_default_dates(GString *text)
Definition: templates.c:574
static void init_general_templates(void)
Definition: templates.c:128
static void templates_replace_command(GString *text, const gchar *file_name, const gchar *file_type, const gchar *func_name)
Definition: templates.c:627
static void create_file_template_menu(void)
Definition: templates.c:274
static gchar * get_template_from_file(const gchar *locale_fname, const gchar *doc_filename, GeanyFiletype *ft)
Definition: templates.c:172
gchar * templates_get_template_function(GeanyDocument *doc, const gchar *func_name)
Definition: templates.c:470
static void on_new_with_file_template(GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
Definition: templates.c:198
static void replace_static_values(GString *text)
Definition: templates.c:528
static GtkWidget * new_with_template_menu
Definition: templates.c:52
static GtkWidget * new_with_template_toolbar_menu
Definition: templates.c:53
static gchar * templates[GEANY_MAX_TEMPLATES]
Definition: templates.c:56
static void read_template(const gchar *name, gint id)
Definition: templates.c:96
static gchar * run_command(const gchar *command, const gchar *file_name, const gchar *file_type, const gchar *func_name)
Definition: templates.c:592
gchar * templates_get_template_licence(GeanyDocument *doc, gint licence_type)
Definition: templates.c:419
void templates_replace_valist(GString *text, const gchar *first_wildcard,...)
Definition: templates.c:547
Templates (prefs).
GtkAction * toolbar_get_action_by_name(const gchar *name)
Definition: toolbar.c:152
Toolbar (prefs).
gchar * ui_menu_item_get_text(GtkMenuItem *menu_item)
Definition: ui_utils.c:1264
GeanyMainWidgets main_widgets
Definition: ui_utils.c:72
void ui_set_statusbar(gboolean log, const gchar *format,...)
Displays text on the statusbar.
Definition: ui_utils.c:168
GtkWidget * ui_lookup_widget(GtkWidget *widget, const gchar *widget_name)
Returns a widget from a name in a component, usually created by Glade.
Definition: ui_utils.c:2743
User Interface general utility functions.
gchar ** utils_copy_environment(const gchar **exclude_vars, const gchar *first_varname,...)
Copies the current environment into a new array.
Definition: utils.c:1956
guint utils_string_replace_all(GString *haystack, const gchar *needle, const gchar *replace)
Replaces all occurrences of needle in haystack with replace.
Definition: utils.c:1529
GSList * utils_get_config_files(const gchar *subdir)
Definition: utils.c:1867
gchar * utils_get_utf8_from_locale(const gchar *locale_text)
Converts the given string (in locale encoding) into UTF-8 encoding.
Definition: utils.c:1272
gchar * utils_get_date_time(const gchar *format, time_t *time_to_use)
Retrieves a formatted date/time string from strftime().
Definition: utils.c:736
void utils_ensure_same_eol_characters(GString *string, gint target_eol_mode)
Definition: utils.c:405
gint utils_get_line_endings(const gchar *buffer, gsize size)
Definition: utils.c:102
const gchar * utils_get_eol_char(gint eol_mode)
Definition: utils.c:393
void utils_free_pointers(gsize arg_count,...)
Definition: utils.c:1293
gchar * utils_get_locale_from_utf8(const gchar *utf8_text)
Converts the given UTF-8 encoded string into locale encoding.
Definition: utils.c:1243
guint utils_string_replace_first(GString *haystack, const gchar *needle, const gchar *replace)
Replaces only the first occurrence of needle in haystack with replace.
Definition: utils.c:1563
General utility functions, non-GTK related.
#define foreach_slist(node, list)
Iterates all the nodes in list.
Definition: utils.h:121
#define foreach_list(node, list)
Iterates all the nodes in list.
Definition: utils.h:115
#define SETPTR(ptr, result)
Assigns result to ptr, then frees the old value.
Definition: utils.h:50
#define EMPTY(ptr)
Returns TRUE if ptr is NULL or *ptr is FALSE.
Definition: utils.h:38