When using custom file templates, add the extension of the template file to the filename of the new document.
Make {datetime} wildcard generally available for most template types. Allow use of most available wildcards for custom file templates, too. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3202 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
0e54a39c9b
commit
98cf47a6a8
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
2008-11-10 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||
|
||||
* doc/geany.txt, doc/geany.html, src/templates.c, src/templates.c,
|
||||
src/editor.c:
|
||||
When using custom file templates, add the extension of the template
|
||||
file to the filename of the new document.
|
||||
Make {datetime} wildcard generally available for most template types.
|
||||
Allow use of most available wildcards for custom file templates, too.
|
||||
|
||||
|
||||
2008-11-10 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||
|
||||
* src/about.c, src/treeviews.c, src/treeviews.h, src/symbols.c,
|
||||
|
1175
doc/geany.html
1175
doc/geany.html
File diff suppressed because it is too large
Load Diff
@ -3178,46 +3178,48 @@ Template wildcards
|
||||
|
||||
All wildcards must be enclosed by "{" and "}", e.g. {date}.
|
||||
|
||||
============== ============================================= ==============
|
||||
============== ============================================= =======================================
|
||||
Wildcard Description Available in
|
||||
============== ============================================= ==============
|
||||
developer The name of the developer. filetypes, file header, function
|
||||
description, ChangeLog entry, bsd,
|
||||
gpl, snippets
|
||||
============== ============================================= =======================================
|
||||
developer The name of the developer. filetype templates, file header,
|
||||
function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
initial The developer's initials, e.g. "ET" for filetypes, file header, function
|
||||
Enrico Tröger or "JFD" for John Foobar Doe. description, ChangeLog entry, bsd,
|
||||
gpl, snippets
|
||||
initial The developer's initials, e.g. "ET" for filetype templates, file header,
|
||||
Enrico Tröger or "JFD" for John Foobar Doe. function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
mail The email address of the developer. file header, function description,
|
||||
ChangeLog entry, bsd, gpl, snippets
|
||||
mail The email address of the developer. filetype templates, file header,
|
||||
function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
company The company the developer is working for. filetypes, file header, function
|
||||
description, ChangeLog entry, bsd,
|
||||
gpl, snippets
|
||||
company The company the developer is working for. filetype templates, file header,
|
||||
function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
year [1]_ The current year. Default format is: YYYY filetypes, file header, function
|
||||
description, ChangeLog entry, bsd,
|
||||
gpl, snippets
|
||||
year [1]_ The current year. Default format is: YYYY filetype templates, file header,
|
||||
function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
version The initial version of a new file. filetypes, file header, function
|
||||
description, ChangeLog entry, bsd,
|
||||
gpl, snippets
|
||||
version The initial version of a new file. filetype templates, file header,
|
||||
function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
date [1]_ The current date. Default format: YYYY-MM-DD. filetypes, file header, function
|
||||
description, ChangeLog entry, bsd,
|
||||
gpl, snippets
|
||||
date [1]_ The current date. Default format: YYYY-MM-DD. filetype templates, file header,
|
||||
function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
untitled The string "untitled" (this will be filetypes, file header, function
|
||||
translated to your locale), used in description, ChangeLog entry, bsd,
|
||||
filetype templates. gpl, snippets
|
||||
untitled The string "untitled" (this will be filetype templates, file header,
|
||||
translated to your locale), used in function description, ChangeLog entry,
|
||||
filetype templates. bsd, gpl, snippets
|
||||
|
||||
geanyversion The actual Geany version, e.g. filetypes, file header, function
|
||||
"Geany |(version)|". description, ChangeLog entry, bsd,
|
||||
gpl, snippets
|
||||
geanyversion The actual Geany version, e.g. filetype templates, file header,
|
||||
"Geany |(version)|". function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
datetime [1]_ The current date and time. Default format: file header, function description,
|
||||
DD.MM.YYYY HH:mm:ss ZZZZ. snippets
|
||||
datetime [1]_ The current date and time. Default format: filetype templates, file header,
|
||||
DD.MM.YYYY HH:mm:ss ZZZZ. function description, ChangeLog entry,
|
||||
bsd, gpl, snippets
|
||||
|
||||
filename The filename of the current file. file header, snippets
|
||||
|
||||
@ -3230,10 +3232,10 @@ functionname The function name of the function at the function descriptio
|
||||
replaced in the function description
|
||||
template.
|
||||
|
||||
fileheader The file header template. This wildcard filetypes
|
||||
will only be replaced in filetype
|
||||
fileheader The file header template. This wildcard file header, snippets, custom filetype
|
||||
will only be replaced in filetype templates
|
||||
templates.
|
||||
============== ============================================= ==============
|
||||
============== ============================================= =======================================
|
||||
|
||||
|
||||
.. [1] The format for the ``year``, ``date`` and ``datetime`` wildcards can be changed
|
||||
|
@ -1690,14 +1690,10 @@ static gchar *snippets_replace_wildcards(GeanyEditor *editor, gchar *text)
|
||||
gchar *datetime = utils_get_date_time(template_prefs.datetime_format, NULL);
|
||||
gchar *basename = g_path_get_basename(DOC_FILENAME(editor->document));
|
||||
|
||||
text = templates_replace_all(text, year, date);
|
||||
text = utils_str_replace(text, "{datetime}", datetime);
|
||||
text = templates_replace_all(text, year, date, datetime);
|
||||
text = utils_str_replace(text, "{filename}", basename);
|
||||
|
||||
g_free(year);
|
||||
g_free(date);
|
||||
g_free(datetime);
|
||||
g_free(basename);
|
||||
utils_free_pointers(year, date, datetime, basename, NULL);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ static gchar *ft_templates[GEANY_MAX_BUILT_IN_FILETYPES] = {NULL};
|
||||
|
||||
|
||||
|
||||
static void init_general_templates(const gchar *year, const gchar *date)
|
||||
static void init_general_templates(const gchar *year, const gchar *date, const gchar *datetime)
|
||||
{
|
||||
gchar *template_filename_fileheader = TEMPLATES_GET_FILENAME("fileheader");
|
||||
gchar *template_filename_gpl = TEMPLATES_GET_FILENAME("gpl");
|
||||
@ -261,19 +261,19 @@ static void init_general_templates(const gchar *year, const gchar *date)
|
||||
|
||||
/* read the contents */
|
||||
TEMPLATES_READ_FILE(template_filename_fileheader, &templates[GEANY_TEMPLATE_FILEHEADER]);
|
||||
templates[GEANY_TEMPLATE_FILEHEADER] = templates_replace_all(templates[GEANY_TEMPLATE_FILEHEADER], year, date);
|
||||
templates[GEANY_TEMPLATE_FILEHEADER] = templates_replace_all(templates[GEANY_TEMPLATE_FILEHEADER], year, date, datetime);
|
||||
|
||||
TEMPLATES_READ_FILE(template_filename_gpl, &templates[GEANY_TEMPLATE_GPL]);
|
||||
templates[GEANY_TEMPLATE_GPL] = templates_replace_all(templates[GEANY_TEMPLATE_GPL], year, date);
|
||||
templates[GEANY_TEMPLATE_GPL] = templates_replace_all(templates[GEANY_TEMPLATE_GPL], year, date, datetime);
|
||||
|
||||
TEMPLATES_READ_FILE(template_filename_bsd, &templates[GEANY_TEMPLATE_BSD]);
|
||||
templates[GEANY_TEMPLATE_BSD] = templates_replace_all(templates[GEANY_TEMPLATE_BSD], year, date);
|
||||
templates[GEANY_TEMPLATE_BSD] = templates_replace_all(templates[GEANY_TEMPLATE_BSD], year, date, datetime);
|
||||
|
||||
TEMPLATES_READ_FILE(template_filename_function, &templates[GEANY_TEMPLATE_FUNCTION]);
|
||||
templates[GEANY_TEMPLATE_FUNCTION] = templates_replace_all(templates[GEANY_TEMPLATE_FUNCTION], year, date);
|
||||
templates[GEANY_TEMPLATE_FUNCTION] = templates_replace_all(templates[GEANY_TEMPLATE_FUNCTION], year, date, datetime);
|
||||
|
||||
TEMPLATES_READ_FILE(template_filename_changelog, &templates[GEANY_TEMPLATE_CHANGELOG]);
|
||||
templates[GEANY_TEMPLATE_CHANGELOG] = templates_replace_all(templates[GEANY_TEMPLATE_CHANGELOG], year, date);
|
||||
templates[GEANY_TEMPLATE_CHANGELOG] = templates_replace_all(templates[GEANY_TEMPLATE_CHANGELOG], year, date, datetime);
|
||||
|
||||
/* free the whole stuff */
|
||||
g_free(template_filename_fileheader);
|
||||
@ -284,7 +284,7 @@ static void init_general_templates(const gchar *year, const gchar *date)
|
||||
}
|
||||
|
||||
|
||||
static void init_ft_templates(const gchar *year, const gchar *date)
|
||||
static void init_ft_templates(const gchar *year, const gchar *date, const gchar *datetime)
|
||||
{
|
||||
filetype_id ft_id;
|
||||
|
||||
@ -309,7 +309,7 @@ static void init_ft_templates(const gchar *year, const gchar *date)
|
||||
default: break;
|
||||
}
|
||||
TEMPLATES_READ_FILE(fname, &ft_templates[ft_id]);
|
||||
ft_templates[ft_id] = templates_replace_all(ft_templates[ft_id], year, date);
|
||||
ft_templates[ft_id] = templates_replace_all(ft_templates[ft_id], year, date, datetime);
|
||||
|
||||
g_free(fname);
|
||||
g_free(shortname);
|
||||
@ -357,21 +357,28 @@ static void create_new_menu_items(void)
|
||||
}
|
||||
|
||||
|
||||
static gchar *get_template_from_file(const gchar *locale_fname, GeanyFiletype *ft)
|
||||
static gchar *get_template_from_file(const gchar *locale_fname, const gchar *doc_filename,
|
||||
GeanyFiletype *ft)
|
||||
{
|
||||
GString template = {NULL, 0, 0};
|
||||
GString template = { NULL, 0, 0 };
|
||||
|
||||
g_file_get_contents(locale_fname, &template.str, &template.len, NULL);
|
||||
|
||||
if (template.len > 0)
|
||||
{
|
||||
gchar *file_header;
|
||||
gchar *year = utils_get_date_time(template_prefs.year_format, NULL);
|
||||
gchar *date = utils_get_date_time(template_prefs.date_format, NULL);
|
||||
gchar *datetime = utils_get_date_time(template_prefs.datetime_format, NULL);
|
||||
|
||||
template.allocated_len = template.len + 1;
|
||||
|
||||
file_header = templates_get_template_fileheader(FILETYPE_ID(ft), NULL);
|
||||
file_header = templates_get_template_fileheader(FILETYPE_ID(ft), doc_filename);
|
||||
template.str = templates_replace_all(template.str, year, date, datetime);
|
||||
utils_string_replace_all(&template, "{filename}", doc_filename);
|
||||
utils_string_replace_all(&template, "{fileheader}", file_header);
|
||||
g_free(file_header);
|
||||
|
||||
utils_free_pointers(year, date, datetime, file_header, NULL);
|
||||
}
|
||||
return template.str;
|
||||
}
|
||||
@ -383,17 +390,20 @@ on_new_with_file_template(GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_dat
|
||||
gchar *fname = ui_menu_item_get_text(menuitem);
|
||||
GeanyFiletype *ft;
|
||||
gchar *template;
|
||||
gchar *extension = strrchr(fname, '.'); /* easy way to get the file extension */
|
||||
gchar *new_filename = g_strconcat(GEANY_STRING_UNTITLED, extension, NULL);
|
||||
|
||||
ft = filetypes_detect_from_extension(fname);
|
||||
setptr(fname, utils_get_locale_from_utf8(fname));
|
||||
/* fname is just the basename from the menu item, so prepend the custom files path */
|
||||
setptr(fname, g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_TEMPLATES_SUBDIR,
|
||||
"files", fname, NULL));
|
||||
template = get_template_from_file(fname, ft);
|
||||
template = get_template_from_file(fname, new_filename, ft);
|
||||
g_free(fname);
|
||||
|
||||
document_new_file(NULL, ft, template);
|
||||
document_new_file(new_filename, ft, template);
|
||||
g_free(template);
|
||||
g_free(new_filename);
|
||||
}
|
||||
|
||||
|
||||
@ -484,9 +494,10 @@ void templates_init(void)
|
||||
{
|
||||
gchar *year = utils_get_date_time(template_prefs.year_format, NULL);
|
||||
gchar *date = utils_get_date_time(template_prefs.date_format, NULL);
|
||||
gchar *datetime = utils_get_date_time(template_prefs.datetime_format, NULL);
|
||||
|
||||
init_general_templates(year, date);
|
||||
init_ft_templates(year, date);
|
||||
init_general_templates(year, date, datetime);
|
||||
init_ft_templates(year, date, datetime);
|
||||
|
||||
g_free(date);
|
||||
g_free(year);
|
||||
@ -770,10 +781,12 @@ void templates_free_templates(void)
|
||||
}
|
||||
|
||||
|
||||
gchar *templates_replace_all(gchar *text, const gchar *year, const gchar *date)
|
||||
gchar *templates_replace_all(gchar *text, const gchar *year, const gchar *date,
|
||||
const gchar *datetime)
|
||||
{
|
||||
text = utils_str_replace(text, "{year}", year);
|
||||
text = utils_str_replace(text, "{date}", date);
|
||||
text = utils_str_replace(text, "{datetime}", datetime);
|
||||
text = utils_str_replace(text, "{version}", template_prefs.version);
|
||||
text = utils_str_replace(text, "{initial}", template_prefs.initials);
|
||||
text = utils_str_replace(text, "{developer}", template_prefs.developer);
|
||||
|
@ -67,7 +67,8 @@ gchar *templates_get_template_function(gint filetype_idx, const gchar *func_name
|
||||
|
||||
gchar *templates_get_template_licence(gint filetype_idx, gint licence_type);
|
||||
|
||||
gchar *templates_replace_all(gchar *source, const gchar *year, const gchar *date);
|
||||
gchar *templates_replace_all(gchar *source, const gchar *year, const gchar *date,
|
||||
const gchar *datetime);
|
||||
|
||||
void templates_free_templates(void);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user