65 const gchar *file_type,
const gchar *func_name);
74 if (! g_file_get_contents(locale_fname, &contents, &length,
NULL))
81 ui_set_statusbar(TRUE,
_(
"Failed to convert template file \"%s\" to UTF-8"), utf8_fname);
87 str = g_string_new(contents);
92 return g_string_free(str, FALSE);
98 gchar *fname = g_build_path(G_DIR_SEPARATOR_S,
app->
configdir,
102 if (!g_file_test(fname, G_FILE_TEST_EXISTS))
121 g_return_if_fail(doc !=
NULL);
152 shortname = g_path_get_basename(fname);
155 "{filename}", shortname,
182 GString *
template = g_string_new(content);
186 "{fileheader}", file_header,
191 return g_string_free(
template, FALSE);
203 const gchar *extension = strrchr(fname,
'.');
212 "files", fname,
NULL);
219 "files", fname,
NULL);
234 g_free(new_filename);
241 GtkWidget *tmp_button;
244 g_return_if_fail(fname);
245 g_return_if_fail(menu);
249 tmp_button = gtk_menu_item_new_with_label(
label);
250 gtk_widget_show(tmp_button);
265 gchar *fname = node->data;
297 if (strncmp(doc->
real_path, path, strlen(path)) == 0)
310 static gboolean init_done = FALSE;
334 const gchar *line_prefix;
339 gint template_eol_mode;
340 const gchar *template_eol_char;
345 g_return_if_fail(comment_text !=
NULL);
346 g_return_if_fail(ft !=
NULL);
356 frame_start = g_strconcat(co, template_eol_char,
NULL);
357 frame_end = g_strconcat(cc, template_eol_char,
NULL);
369 frame_start = g_strconcat(
"/*", template_eol_char,
NULL);
370 frame_end = g_strconcat(
"*/", template_eol_char,
NULL);
375 if (!
EMPTY(frame_start) && frame_start[1] ==
'*')
378 SETPTR(frame_end, g_strconcat(
" ", frame_end,
NULL));
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);
389 lines = g_strsplit(comment_text->str, template_eol_char, -1);
390 len = g_strv_length(
lines);
393 for (i = 0; i < len - 1; i++)
396 lines[i] = g_strconcat(prefix, tmp,
NULL);
400 tmp = g_strjoinv(template_eol_char,
lines);
403 g_string_erase(comment_text, 0, -1);
406 if (frame_start !=
NULL)
407 g_string_append(comment_text, frame_start);
409 g_string_append(comment_text, tmp);
411 if (frame_end !=
NULL)
412 g_string_append(comment_text, frame_end);
424 g_return_val_if_fail(licence_type == GEANY_TEMPLATE_GPL || licence_type == GEANY_TEMPLATE_BSD,
NULL);
426 template = g_string_new(
templates[licence_type]);
434 return g_string_free(
template, FALSE);
440 GString *
template = g_string_new(
templates[GEANY_TEMPLATE_FILEHEADER]);
451 return g_string_free(
template, FALSE);
461 GString *
template = g_string_new(str);
466 return g_string_free(
template, FALSE);
474 func_name = (func_name !=
NULL) ? func_name :
"";
484 return g_string_free(
text, FALSE);
491 const gchar *file_type_name;
495 result = g_string_new(
templates[GEANY_TEMPLATE_CHANGELOG]);
502 return g_string_free(result, FALSE);
508 GList *children, *item;
510 children = gtk_container_get_children(GTK_CONTAINER(menu));
512 gtk_widget_destroy(GTK_WIDGET(item->data));
513 g_list_free(children);
521 for (i = 0; i < GEANY_MAX_TEMPLATES; i++)
550 const gchar *key, *value;
554 va_start(args, first_wildcard);
556 key = first_wildcard;
557 value = va_arg(args, gchar*);
563 key = va_arg(args, gchar*);
566 value = va_arg(args, gchar*);
585 "{datetime}", datetime,
593 const gchar *file_type,
const gchar *func_name)
595 GString *output = g_string_new(
NULL);
596 gchar *result =
NULL;
600 file_name = (file_name !=
NULL) ? file_name :
"";
601 file_type = (file_type !=
NULL) ? file_type :
"";
602 func_name = (func_name !=
NULL) ? func_name :
"";
605 "GEANY_FILENAME", file_name,
606 "GEANY_FILETYPE", file_type,
607 "GEANY_FUNCNAME", func_name,
612 result = g_string_free(output, FALSE);
616 g_warning(
_(
"Cannot execute template command \"%s\". "
617 "Hint: incorrect paths in the command are a common cause of errors. "
628 const gchar *file_type,
const gchar *func_name)
643 wildcard = g_strndup(cmd, (gsize) (
match - cmd + 1));
644 cmd = g_strndup(wildcard + 9, strlen(wildcard) - 10);
646 result =
run_command(cmd, file_name, file_type, func_name);
649 result = g_strstrip(result);
GeanyDocument * document_get_current(void)
Finds the current document.
GeanyDocument * document_new_file(const gchar *utf8_filename, GeanyFiletype *ft, const gchar *text)
Creates a new document.
Document related actions: new, save, open, etc.
#define DOC_VALID(doc_ptr)
Null-safe way to check GeanyDocument::is_valid.
#define DOC_FILENAME(doc)
Returns the filename of the document passed or GEANY_STRING_UNTITLED (e.g.
gint editor_get_eol_char_mode(GeanyEditor *editor)
Retrieves the end of line characters mode (LF, CR/LF, CR) in the given editor.
gboolean encodings_convert_to_utf8_auto(gchar **buf, gsize *size, const gchar *forced_enc, gchar **used_encoding, gboolean *has_bom, gboolean *partial)
void error(const errorSelection selection, const char *const format,...)
Filetype detection, file extensions and filetype menu items.
#define filetypes
Wraps GeanyData::filetypes_array so it can be used with C array syntax.
#define GEANY_TEMPLATES_SUBDIR
#define GEANY_STRING_UNTITLED
static bool match(const unsigned char *line, const char *word)
char * strstr(const char *str, const char *substr)
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.
Portable and convenient process spawning and communication.
GeanyFiletype * filetypes_index(gint idx)
Accessor function for GeanyData::filetypes_array items.
GeanyFiletype * filetypes_detect_from_extension(const gchar *utf8_filename)
void filetypes_load_config(guint ft_id, gboolean reload)
gboolean filetype_get_comment_open_close(const GeanyFiletype *ft, gboolean single_first, const gchar **co, const gchar **cc)
gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button)
struct GeanyProject * project
Currently active project or NULL if none is open.
gchar * configdir
User configuration directory, usually ~/.config/geany.
Structure for representing an open tab with all its properties.
GeanyFiletype * file_type
The filetype for this document, it's only a reference to one of the elements of the global filetypes ...
gchar * real_path
The link-dereferenced, locale-encoded file name.
gboolean is_valid
Flag used to check if this document is valid when iterating GeanyData::documents_array.
GeanyEditor * editor
The editor associated with the document.
gchar * name
Untranslated short name, such as "C", "None".
GeanyFiletypeID id
Index in filetypes.
gchar * extension
Default file extension for new files, or NULL.
GtkWidget * window
Main window.
gchar * description
Short description of the project.
gchar * name
The name of the project.
gchar * initials
Initials.
gchar * version
Initial version.
Defines internationalization macros.
gchar * templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
void templates_replace_common(GString *tmpl, const gchar *fname, GeanyFiletype *ft, const gchar *func_name)
static void make_comment_block(GString *comment_text, gint filetype_idx, guint indent)
static void convert_eol_characters(GString *template, GeanyDocument *doc)
static void free_template_menu_items(GtkWidget *menu)
gchar * templates_get_template_changelog(GeanyDocument *doc)
void templates_init(void)
static void populate_file_template_menu(GtkWidget *menu)
GeanyTemplatePrefs template_prefs
static void add_file_item(const gchar *fname, GtkWidget *menu)
static gchar * get_template_fileheader(GeanyFiletype *ft)
void templates_free_templates(void)
static gchar * read_file(const gchar *locale_fname)
static void on_document_save(G_GNUC_UNUSED GObject *object, GeanyDocument *doc)
static void templates_replace_default_dates(GString *text)
static void init_general_templates(void)
static void templates_replace_command(GString *text, const gchar *file_name, const gchar *file_type, const gchar *func_name)
static void create_file_template_menu(void)
static gchar * get_template_from_file(const gchar *locale_fname, const gchar *doc_filename, GeanyFiletype *ft)
gchar * templates_get_template_function(GeanyDocument *doc, const gchar *func_name)
static void on_new_with_file_template(GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
static void replace_static_values(GString *text)
static GtkWidget * new_with_template_menu
static GtkWidget * new_with_template_toolbar_menu
static gchar * templates[GEANY_MAX_TEMPLATES]
static void read_template(const gchar *name, gint id)
static gchar * run_command(const gchar *command, const gchar *file_name, const gchar *file_type, const gchar *func_name)
gchar * templates_get_template_licence(GeanyDocument *doc, gint licence_type)
void templates_replace_valist(GString *text, const gchar *first_wildcard,...)
gchar * ui_menu_item_get_text(GtkMenuItem *menu_item)
GeanyMainWidgets main_widgets
void ui_set_statusbar(gboolean log, const gchar *format,...)
Displays text on the statusbar.
GtkWidget * ui_lookup_widget(GtkWidget *widget, const gchar *widget_name)
Returns a widget from a name in a component, usually created by Glade.
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.
guint utils_string_replace_all(GString *haystack, const gchar *needle, const gchar *replace)
Replaces all occurrences of needle in haystack with replace.
GSList * utils_get_config_files(const gchar *subdir)
gchar * utils_get_utf8_from_locale(const gchar *locale_text)
Converts the given string (in locale encoding) into UTF-8 encoding.
gchar * utils_get_date_time(const gchar *format, time_t *time_to_use)
Retrieves a formatted date/time string from strftime().
void utils_ensure_same_eol_characters(GString *string, gint target_eol_mode)
gint utils_get_line_endings(const gchar *buffer, gsize size)
const gchar * utils_get_eol_char(gint eol_mode)
void utils_free_pointers(gsize arg_count,...)
gchar * utils_get_locale_from_utf8(const gchar *utf8_text)
Converts the given UTF-8 encoded string into locale encoding.
guint utils_string_replace_first(GString *haystack, const gchar *needle, const gchar *replace)
Replaces only the first occurrence of needle in haystack with replace.
General utility functions, non-GTK related.
#define foreach_slist(node, list)
Iterates all the nodes in list.
#define foreach_list(node, list)
Iterates all the nodes in list.
#define SETPTR(ptr, result)
Assigns result to ptr, then frees the old value.
#define EMPTY(ptr)
Returns TRUE if ptr is NULL or *ptr is FALSE.