2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
* templates.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2005-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-05-10 19:54:44 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
2005-12-20 17:50:11 +00:00
|
|
|
* $Id$
|
2005-11-22 12:26:26 +00:00
|
|
|
*/
|
|
|
|
|
2007-02-24 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* Templates to insert into the current document, or filetype templates to create a new
|
|
|
|
* document from.
|
|
|
|
*/
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
#include <time.h>
|
2007-01-06 15:03:53 +00:00
|
|
|
#include <string.h>
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
#include "geany.h"
|
|
|
|
|
|
|
|
#include "templates.h"
|
|
|
|
#include "support.h"
|
|
|
|
#include "utils.h"
|
2006-08-20 15:47:18 +00:00
|
|
|
#include "document.h"
|
2007-08-15 15:37:21 +00:00
|
|
|
#include "filetypes.h"
|
2007-08-23 11:34:06 +00:00
|
|
|
#include "ui_utils.h"
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-09-17 19:58:04 +00:00
|
|
|
|
2007-11-11 09:03:01 +00:00
|
|
|
#define TEMPLATE_DATE_FORMAT "%Y-%m-%d"
|
|
|
|
#define TEMPLATE_DATETIME_FORMAT "%d.%m.%Y %H:%M:%S %Z"
|
|
|
|
|
2008-05-13 17:18:14 +00:00
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
GeanyTemplatePrefs template_prefs;
|
|
|
|
|
2008-05-13 17:18:14 +00:00
|
|
|
static GtkWidget *new_with_template_menu = NULL; /* File menu submenu */
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* default templates, only for initial tempate file creation on first start of Geany */
|
2006-09-17 19:58:04 +00:00
|
|
|
static const gchar templates_gpl_notice[] = "\
|
2007-01-06 15:03:53 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify\n\
|
|
|
|
it under the terms of the GNU General Public License as published by\n\
|
|
|
|
the Free Software Foundation; either version 2 of the License, or\n\
|
|
|
|
(at your option) any later version.\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
\n\
|
2007-01-06 15:03:53 +00:00
|
|
|
This program is distributed in the hope that it will be useful,\n\
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
|
|
|
|
GNU General Public License for more details.\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
\n\
|
2007-01-06 15:03:53 +00:00
|
|
|
You should have received a copy of the GNU General Public License\n\
|
|
|
|
along with this program; if not, write to the Free Software\n\
|
2007-03-31 11:39:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n\
|
|
|
|
MA 02110-1301, USA.\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
";
|
|
|
|
|
2007-01-06 15:38:44 +00:00
|
|
|
static const gchar templates_bsd_notice[] = "\
|
|
|
|
Redistribution and use in source and binary forms, with or without\n\
|
|
|
|
modification, are permitted provided that the following conditions are\n\
|
|
|
|
met:\n\
|
|
|
|
\n\
|
|
|
|
* Redistributions of source code must retain the above copyright\n\
|
|
|
|
notice, this list of conditions and the following disclaimer.\n\
|
|
|
|
* Redistributions in binary form must reproduce the above\n\
|
|
|
|
copyright notice, this list of conditions and the following disclaimer\n\
|
|
|
|
in the documentation and/or other materials provided with the\n\
|
|
|
|
distribution.\n\
|
|
|
|
* Neither the name of the {company} nor the names of its\n\
|
|
|
|
contributors may be used to endorse or promote products derived from\n\
|
|
|
|
this software without specific prior written permission.\n\
|
|
|
|
\n\
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\
|
|
|
|
\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n\
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n\
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n\
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n\
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n\
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n\
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n\
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\
|
|
|
|
";
|
|
|
|
|
2006-09-17 19:58:04 +00:00
|
|
|
static const gchar templates_function_description[] = "\
|
2007-01-06 15:03:53 +00:00
|
|
|
\n\
|
|
|
|
name: {functionname}\n\
|
|
|
|
@param\n\
|
|
|
|
@return\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
";
|
|
|
|
|
|
|
|
static const gchar templates_multiline[] = "\
|
|
|
|
\n\
|
2007-01-06 15:03:53 +00:00
|
|
|
\n\
|
|
|
|
";
|
2006-09-17 19:58:04 +00:00
|
|
|
|
|
|
|
static const gchar templates_fileheader[] = "\
|
2007-01-06 15:03:53 +00:00
|
|
|
{filename}\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
\n\
|
2007-01-06 15:03:53 +00:00
|
|
|
Copyright {year} {developer} <{mail}>\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
\n\
|
|
|
|
{gpl}\
|
2007-01-06 15:03:53 +00:00
|
|
|
";
|
2006-09-17 19:58:04 +00:00
|
|
|
|
|
|
|
static const gchar templates_changelog[] = "\
|
|
|
|
{date} {developer} <{mail}>\n\
|
|
|
|
\n\
|
|
|
|
* \n\n\n";
|
|
|
|
|
|
|
|
static const gchar templates_filetype_none[] = "";
|
|
|
|
|
2007-03-31 11:39:56 +00:00
|
|
|
static const gchar templates_filetype_c[] = "{fileheader}\n\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
#include <stdio.h>\n\
|
|
|
|
\n\
|
|
|
|
int main(int argc, char** argv)\n\
|
|
|
|
{\n\
|
|
|
|
\n\
|
|
|
|
return 0;\n\
|
|
|
|
}\n\
|
|
|
|
";
|
|
|
|
|
2007-03-31 11:39:56 +00:00
|
|
|
static const gchar templates_filetype_cpp[] = "{fileheader}\n\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
#include <iostream>\n\
|
|
|
|
\n\
|
|
|
|
int main(int argc, char** argv)\n\
|
|
|
|
{\n\
|
|
|
|
\n\
|
|
|
|
return 0;\n\
|
|
|
|
}\n\
|
|
|
|
";
|
|
|
|
|
2007-03-31 11:39:56 +00:00
|
|
|
static const gchar templates_filetype_d[] = "{fileheader}\n\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
import std.stdio;\n\
|
|
|
|
\n\
|
|
|
|
int main(char[][] args)\n\
|
|
|
|
{\n\
|
2006-10-02 11:14:36 +00:00
|
|
|
\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
return 0;\n\
|
|
|
|
}\n\
|
|
|
|
";
|
|
|
|
|
2007-12-01 11:27:03 +00:00
|
|
|
static const gchar templates_filetype_php[] = "\
|
|
|
|
<?php\n\
|
|
|
|
{fileheader}\
|
|
|
|
?>\n\n\
|
2007-03-31 11:39:56 +00:00
|
|
|
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\
|
|
|
|
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\
|
|
|
|
\n\
|
|
|
|
<head>\n\
|
|
|
|
<title>{untitled}</title>\n\
|
|
|
|
<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />\n\
|
|
|
|
<meta name=\"generator\" content=\"{geanyversion}\" />\n\
|
|
|
|
</head>\n\
|
|
|
|
\n\
|
|
|
|
<body>\n\
|
2006-10-02 11:14:36 +00:00
|
|
|
\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
</body>\n\
|
|
|
|
</html>\n\
|
|
|
|
";
|
|
|
|
|
2007-03-31 11:39:56 +00:00
|
|
|
static const gchar templates_filetype_html[] = "{fileheader}\n\
|
|
|
|
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\
|
|
|
|
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\
|
|
|
|
\n\
|
|
|
|
<head>\n\
|
|
|
|
<title>{untitled}</title>\n\
|
|
|
|
<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />\n\
|
|
|
|
<meta name=\"generator\" content=\"{geanyversion}\" />\n\
|
|
|
|
</head>\n\
|
|
|
|
\n\
|
|
|
|
<body>\n\
|
2006-10-02 11:14:36 +00:00
|
|
|
\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
</body>\n\
|
|
|
|
</html>\n\
|
|
|
|
";
|
|
|
|
|
2007-03-31 11:39:56 +00:00
|
|
|
static const gchar templates_filetype_pascal[] = "{fileheader}\n\n\
|
2007-01-06 15:03:53 +00:00
|
|
|
program {untitled};\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
\n\
|
|
|
|
uses crt;\n\
|
|
|
|
var i : byte;\n\
|
|
|
|
\n\
|
|
|
|
BEGIN\n\
|
|
|
|
\n\
|
|
|
|
\n\
|
|
|
|
END.\n\
|
|
|
|
";
|
|
|
|
|
2007-03-31 11:39:56 +00:00
|
|
|
static const gchar templates_filetype_java[] = "{fileheader}\n\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
public class {untitled} {\n\
|
|
|
|
\n\
|
2007-01-06 15:03:53 +00:00
|
|
|
public static void main (String args[]) {\
|
2006-09-17 19:58:04 +00:00
|
|
|
\n\
|
|
|
|
\n\
|
|
|
|
}\n\
|
|
|
|
}\n\
|
|
|
|
";
|
|
|
|
|
2007-03-31 11:39:56 +00:00
|
|
|
static const gchar templates_filetype_ruby[] = "{fileheader}\n\n\
|
2006-09-17 19:58:04 +00:00
|
|
|
class StdClass\n\
|
|
|
|
def initialize\n\
|
|
|
|
\n\
|
|
|
|
end\n\
|
|
|
|
end\n\
|
|
|
|
\n\
|
|
|
|
x = StdClass.new\n\
|
|
|
|
";
|
|
|
|
|
2007-12-23 15:22:55 +00:00
|
|
|
static const gchar templates_filetype_python[] = "#!/usr/bin/env python\n#\n\
|
|
|
|
{fileheader}\n\n\
|
|
|
|
\n\
|
|
|
|
def main():\n\
|
|
|
|
\n\
|
|
|
|
return 0\n\
|
|
|
|
\n\
|
|
|
|
if __name__ == '__main__': main()\n\
|
|
|
|
";
|
|
|
|
|
2006-09-17 19:58:04 +00:00
|
|
|
static gchar *templates[GEANY_MAX_TEMPLATES];
|
2008-05-07 11:34:38 +00:00
|
|
|
static gchar *ft_templates[GEANY_MAX_BUILT_IN_FILETYPES] = {NULL};
|
2006-09-17 19:58:04 +00:00
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* some simple macros to reduce code size and make the code readable */
|
2007-02-19 13:26:06 +00:00
|
|
|
#define TEMPLATES_GET_FILENAME(shortname) \
|
|
|
|
g_strconcat(app->configdir, \
|
|
|
|
G_DIR_SEPARATOR_S GEANY_TEMPLATES_SUBDIR G_DIR_SEPARATOR_S, shortname, NULL)
|
|
|
|
|
|
|
|
#define TEMPLATES_CREATE_FILE(fname, text) \
|
|
|
|
if (! g_file_test(fname, G_FILE_TEST_EXISTS)) \
|
|
|
|
utils_write_file(fname, text)
|
|
|
|
|
|
|
|
#define TEMPLATES_READ_FILE(fname, contents_ptr) \
|
|
|
|
g_file_get_contents(fname, contents_ptr, NULL, NULL);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* prototype, because this function should never be used outside of templates.c */
|
2007-02-19 13:26:06 +00:00
|
|
|
static gchar *templates_replace_all(gchar *source, const gchar *year, const gchar *date);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2007-02-19 13:26:06 +00:00
|
|
|
static void init_general_templates(const gchar *year, const gchar *date)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-01-06 18:00:34 +00:00
|
|
|
gchar *template_filename_fileheader = TEMPLATES_GET_FILENAME("fileheader");
|
|
|
|
gchar *template_filename_gpl = TEMPLATES_GET_FILENAME("gpl");
|
|
|
|
gchar *template_filename_bsd = TEMPLATES_GET_FILENAME("bsd");
|
|
|
|
gchar *template_filename_function = TEMPLATES_GET_FILENAME("function");
|
|
|
|
gchar *template_filename_changelog = TEMPLATES_GET_FILENAME("changelog");
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* create the template files in the configuration directory, if they don't exist */
|
2007-01-06 15:03:53 +00:00
|
|
|
TEMPLATES_CREATE_FILE(template_filename_fileheader, templates_fileheader);
|
|
|
|
TEMPLATES_CREATE_FILE(template_filename_gpl, templates_gpl_notice);
|
2007-01-06 15:38:44 +00:00
|
|
|
TEMPLATES_CREATE_FILE(template_filename_bsd, templates_bsd_notice);
|
2007-01-06 15:03:53 +00:00
|
|
|
TEMPLATES_CREATE_FILE(template_filename_function, templates_function_description);
|
|
|
|
TEMPLATES_CREATE_FILE(template_filename_changelog, templates_changelog);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* read the contents */
|
2007-01-06 15:03:53 +00:00
|
|
|
TEMPLATES_READ_FILE(template_filename_fileheader, &templates[GEANY_TEMPLATE_FILEHEADER]);
|
2005-11-22 12:26:26 +00:00
|
|
|
templates[GEANY_TEMPLATE_FILEHEADER] = templates_replace_all(templates[GEANY_TEMPLATE_FILEHEADER], year, date);
|
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
TEMPLATES_READ_FILE(template_filename_gpl, &templates[GEANY_TEMPLATE_GPL]);
|
2007-01-06 15:38:44 +00:00
|
|
|
templates[GEANY_TEMPLATE_GPL] = templates_replace_all(templates[GEANY_TEMPLATE_GPL], year, date);
|
|
|
|
|
|
|
|
TEMPLATES_READ_FILE(template_filename_bsd, &templates[GEANY_TEMPLATE_BSD]);
|
|
|
|
templates[GEANY_TEMPLATE_BSD] = templates_replace_all(templates[GEANY_TEMPLATE_BSD], year, date);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
TEMPLATES_READ_FILE(template_filename_function, &templates[GEANY_TEMPLATE_FUNCTION]);
|
2005-11-22 12:26:26 +00:00
|
|
|
templates[GEANY_TEMPLATE_FUNCTION] = templates_replace_all(templates[GEANY_TEMPLATE_FUNCTION], year, date);
|
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
TEMPLATES_READ_FILE(template_filename_changelog, &templates[GEANY_TEMPLATE_CHANGELOG]);
|
2005-11-22 12:26:26 +00:00
|
|
|
templates[GEANY_TEMPLATE_CHANGELOG] = templates_replace_all(templates[GEANY_TEMPLATE_CHANGELOG], year, date);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* free the whole stuff */
|
2007-02-19 13:26:06 +00:00
|
|
|
g_free(template_filename_fileheader);
|
|
|
|
g_free(template_filename_gpl);
|
|
|
|
g_free(template_filename_bsd);
|
|
|
|
g_free(template_filename_function);
|
|
|
|
g_free(template_filename_changelog);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2007-02-19 13:26:06 +00:00
|
|
|
static void init_ft_templates(const gchar *year, const gchar *date)
|
|
|
|
{
|
|
|
|
filetype_id ft_id;
|
2006-07-09 14:41:53 +00:00
|
|
|
|
2008-05-07 11:34:38 +00:00
|
|
|
for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++)
|
2007-02-19 13:26:06 +00:00
|
|
|
{
|
|
|
|
gchar *ext = filetypes_get_conf_extension(ft_id);
|
|
|
|
gchar *shortname = g_strconcat("filetype.", ext, NULL);
|
|
|
|
gchar *fname = TEMPLATES_GET_FILENAME(shortname);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-02-19 13:26:06 +00:00
|
|
|
switch (ft_id)
|
|
|
|
{
|
2008-05-07 13:54:21 +00:00
|
|
|
case GEANY_FILETYPES_NONE: TEMPLATES_CREATE_FILE(fname, templates_filetype_none); break;
|
2007-02-19 13:26:06 +00:00
|
|
|
case GEANY_FILETYPES_C: TEMPLATES_CREATE_FILE(fname, templates_filetype_c); break;
|
|
|
|
case GEANY_FILETYPES_CPP: TEMPLATES_CREATE_FILE(fname, templates_filetype_cpp); break;
|
|
|
|
case GEANY_FILETYPES_D: TEMPLATES_CREATE_FILE(fname, templates_filetype_d); break;
|
|
|
|
case GEANY_FILETYPES_JAVA: TEMPLATES_CREATE_FILE(fname, templates_filetype_java); break;
|
|
|
|
case GEANY_FILETYPES_PASCAL:TEMPLATES_CREATE_FILE(fname, templates_filetype_pascal); break;
|
|
|
|
case GEANY_FILETYPES_PHP: TEMPLATES_CREATE_FILE(fname, templates_filetype_php); break;
|
|
|
|
case GEANY_FILETYPES_HTML: TEMPLATES_CREATE_FILE(fname, templates_filetype_html); break;
|
|
|
|
case GEANY_FILETYPES_RUBY: TEMPLATES_CREATE_FILE(fname, templates_filetype_ruby); break;
|
2007-12-23 15:22:55 +00:00
|
|
|
case GEANY_FILETYPES_PYTHON: TEMPLATES_CREATE_FILE(fname, templates_filetype_python); break;
|
2007-02-19 13:26:06 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
TEMPLATES_READ_FILE(fname, &ft_templates[ft_id]);
|
|
|
|
ft_templates[ft_id] = templates_replace_all(ft_templates[ft_id], year, date);
|
|
|
|
|
|
|
|
g_free(fname);
|
|
|
|
g_free(shortname);
|
|
|
|
g_free(ext);
|
|
|
|
}
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2007-02-19 13:26:06 +00:00
|
|
|
static void
|
|
|
|
on_new_with_template (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2007-09-03 16:09:53 +00:00
|
|
|
filetype *ft = user_data;
|
|
|
|
gchar *template = templates_get_template_new_file(ft);
|
|
|
|
|
|
|
|
document_new_file(NULL, ft, template);
|
|
|
|
g_free(template);
|
2007-02-19 13:26:06 +00:00
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-09-05 16:55:40 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* template items for the new file menu */
|
2008-02-20 11:24:23 +00:00
|
|
|
static void create_new_menu_items(void)
|
2007-02-19 13:26:06 +00:00
|
|
|
{
|
|
|
|
filetype_id ft_id;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-05-07 11:34:38 +00:00
|
|
|
for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++)
|
2007-02-19 13:26:06 +00:00
|
|
|
{
|
|
|
|
GtkWidget *tmp_menu, *tmp_button;
|
|
|
|
filetype *ft = filetypes[ft_id];
|
|
|
|
const gchar *label = ft->title;
|
|
|
|
|
|
|
|
if (ft_templates[ft_id] == NULL)
|
|
|
|
continue;
|
2008-05-07 13:54:21 +00:00
|
|
|
if (ft_id == GEANY_FILETYPES_NONE)
|
2007-09-03 16:09:53 +00:00
|
|
|
label = _("None");
|
2007-02-19 13:26:06 +00:00
|
|
|
tmp_menu = gtk_menu_item_new_with_label(label);
|
|
|
|
tmp_button = gtk_menu_item_new_with_label(label);
|
|
|
|
gtk_widget_show(tmp_menu);
|
|
|
|
gtk_widget_show(tmp_button);
|
2008-05-13 17:18:14 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(new_with_template_menu), tmp_menu);
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(ui_widgets.new_file_menu), tmp_button);
|
2007-02-19 13:26:06 +00:00
|
|
|
g_signal_connect((gpointer) tmp_menu, "activate",
|
|
|
|
G_CALLBACK(on_new_with_template), (gpointer) ft);
|
|
|
|
g_signal_connect((gpointer) tmp_button, "activate",
|
|
|
|
G_CALLBACK(on_new_with_template), (gpointer) ft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-13 17:18:14 +00:00
|
|
|
static gchar *get_template_from_file(const gchar *locale_fname, filetype *ft)
|
|
|
|
{
|
|
|
|
GString template = {NULL, 0, 0};
|
|
|
|
|
|
|
|
g_file_get_contents(locale_fname, &template.str, &template.len, NULL);
|
|
|
|
|
|
|
|
if (template.len > 0)
|
|
|
|
{
|
|
|
|
gchar *file_header;
|
|
|
|
|
|
|
|
template.allocated_len = template.len + 1;
|
|
|
|
|
|
|
|
file_header = templates_get_template_fileheader(FILETYPE_ID(ft), NULL);
|
|
|
|
utils_string_replace_all(&template, "{fileheader}", file_header);
|
|
|
|
g_free(file_header);
|
|
|
|
}
|
|
|
|
return template.str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_new_with_file_template(GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
|
|
|
|
{
|
|
|
|
gchar *fname = ui_menu_item_get_text(menuitem);
|
|
|
|
filetype *ft;
|
|
|
|
gchar *template;
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_free(fname);
|
|
|
|
|
|
|
|
document_new_file(NULL, ft, template);
|
|
|
|
g_free(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void add_file_item(gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *tmp_menu, *tmp_button;
|
|
|
|
gchar *label;
|
|
|
|
|
|
|
|
g_return_if_fail(data);
|
|
|
|
|
|
|
|
label = utils_get_utf8_from_locale(data);
|
|
|
|
|
|
|
|
tmp_menu = gtk_menu_item_new_with_label(label);
|
|
|
|
tmp_button = gtk_menu_item_new_with_label(label);
|
|
|
|
|
|
|
|
g_free(label);
|
|
|
|
|
|
|
|
gtk_widget_show(tmp_menu);
|
|
|
|
gtk_widget_show(tmp_button);
|
|
|
|
gtk_container_add(GTK_CONTAINER(new_with_template_menu), tmp_menu);
|
|
|
|
gtk_container_add(GTK_CONTAINER(ui_widgets.new_file_menu), tmp_button);
|
|
|
|
g_signal_connect((gpointer) tmp_menu, "activate",
|
|
|
|
G_CALLBACK(on_new_with_file_template), NULL);
|
|
|
|
g_signal_connect((gpointer) tmp_button, "activate",
|
|
|
|
G_CALLBACK(on_new_with_file_template), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-14 11:31:07 +00:00
|
|
|
static gint compare_filenames_by_filetype(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
filetype *ft_a = filetypes_detect_from_extension(a);
|
|
|
|
filetype *ft_b = filetypes_detect_from_extension(b);
|
|
|
|
|
|
|
|
/* sort by filetype name first */
|
|
|
|
if (ft_a != ft_b)
|
|
|
|
{
|
|
|
|
/* None filetypes should come first */
|
|
|
|
if (ft_a->id == GEANY_FILETYPES_NONE)
|
|
|
|
return -1;
|
|
|
|
if (ft_b->id == GEANY_FILETYPES_NONE)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return g_strcasecmp(ft_a->name, ft_b->name);
|
|
|
|
}
|
|
|
|
return g_strcasecmp(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-13 17:18:14 +00:00
|
|
|
static gboolean add_custom_template_items(void)
|
|
|
|
{
|
|
|
|
gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_TEMPLATES_SUBDIR,
|
|
|
|
"files", NULL);
|
|
|
|
GSList *list = utils_get_file_list(path, NULL, NULL);
|
|
|
|
|
2008-05-13 17:30:28 +00:00
|
|
|
if (list == NULL)
|
|
|
|
{
|
|
|
|
utils_mkdir(path, FALSE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-05-14 11:31:07 +00:00
|
|
|
list = g_slist_sort(list, compare_filenames_by_filetype);
|
2008-05-13 17:18:14 +00:00
|
|
|
g_slist_foreach(list, add_file_item, NULL);
|
|
|
|
g_slist_foreach(list, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free(list);
|
|
|
|
g_free(path);
|
2008-05-13 17:30:28 +00:00
|
|
|
return TRUE;
|
2008-05-13 17:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void create_file_template_menus(void)
|
|
|
|
{
|
|
|
|
GtkWidget *sep1, *sep2;
|
|
|
|
|
|
|
|
new_with_template_menu = lookup_widget(app->window, "menu_new_with_template1_menu");
|
|
|
|
create_new_menu_items();
|
|
|
|
|
|
|
|
sep1 = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(new_with_template_menu), sep1);
|
|
|
|
sep2 = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(ui_widgets.new_file_menu), sep2);
|
|
|
|
|
|
|
|
if (add_custom_template_items())
|
|
|
|
{
|
|
|
|
gtk_widget_show(sep1);
|
|
|
|
gtk_widget_show(sep2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-19 13:26:06 +00:00
|
|
|
void templates_init(void)
|
|
|
|
{
|
2007-11-17 13:09:19 +00:00
|
|
|
gchar *year = utils_get_date_time("%Y", NULL);
|
|
|
|
gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT, NULL);
|
2007-02-19 13:26:06 +00:00
|
|
|
|
|
|
|
init_general_templates(year, date);
|
|
|
|
init_ft_templates(year, date);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
g_free(date);
|
|
|
|
g_free(year);
|
2008-05-13 17:18:14 +00:00
|
|
|
|
|
|
|
create_file_template_menus();
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
/* indent is used to make some whitespace between comment char and real start of the line
|
|
|
|
* e.g. indent = 8 prints " * here comes the text of the line"
|
|
|
|
* indent is meant to be the whole amount of characters before the real line content follows, i.e.
|
|
|
|
* 6 characters are filled with whitespace when the comment characters include " *" */
|
2007-01-07 13:07:09 +00:00
|
|
|
static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, guint indent)
|
2006-11-14 16:03:25 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
gchar *frame_start = ""; /* to add before comment_text */
|
|
|
|
gchar *frame_end = ""; /* to add after comment_text */
|
|
|
|
gchar *line_prefix; /* to add before every line in comment_text */
|
2007-01-06 15:03:53 +00:00
|
|
|
gchar *result;
|
|
|
|
gchar *tmp;
|
|
|
|
gchar *prefix;
|
|
|
|
gchar **lines;
|
2007-01-07 13:07:09 +00:00
|
|
|
guint i;
|
2007-01-06 15:03:53 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/** TODO the following switch could be replaced by some intelligent code which reads
|
|
|
|
** frame_start, frame_end and line_prefix from the filetype definition files */
|
2007-01-03 16:21:44 +00:00
|
|
|
switch (filetype_idx)
|
2006-11-14 16:03:25 +00:00
|
|
|
{
|
|
|
|
case GEANY_FILETYPES_HTML:
|
2007-01-06 15:03:53 +00:00
|
|
|
case GEANY_FILETYPES_XML:
|
|
|
|
case GEANY_FILETYPES_DOCBOOK:
|
|
|
|
{
|
|
|
|
frame_start = "<!--\n";
|
|
|
|
frame_end = "-->\n";
|
|
|
|
line_prefix = "";
|
|
|
|
break;
|
2006-11-14 16:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case GEANY_FILETYPES_PYTHON:
|
|
|
|
case GEANY_FILETYPES_RUBY:
|
|
|
|
case GEANY_FILETYPES_SH:
|
|
|
|
case GEANY_FILETYPES_MAKE:
|
|
|
|
case GEANY_FILETYPES_PERL:
|
2007-01-06 15:03:53 +00:00
|
|
|
case GEANY_FILETYPES_DIFF:
|
|
|
|
case GEANY_FILETYPES_TCL:
|
|
|
|
case GEANY_FILETYPES_OMS:
|
|
|
|
case GEANY_FILETYPES_CONF:
|
|
|
|
{
|
|
|
|
line_prefix = "#";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-13 20:16:09 +00:00
|
|
|
case GEANY_FILETYPES_JS:
|
2007-07-26 09:50:12 +00:00
|
|
|
case GEANY_FILETYPES_HAXE:
|
2007-01-13 20:16:09 +00:00
|
|
|
{
|
|
|
|
line_prefix = "//";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
case GEANY_FILETYPES_LATEX:
|
|
|
|
{
|
|
|
|
line_prefix = "%";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-05-31 13:55:00 +00:00
|
|
|
case GEANY_FILETYPES_HASKELL:
|
2007-01-06 15:03:53 +00:00
|
|
|
case GEANY_FILETYPES_VHDL:
|
2007-01-13 20:16:09 +00:00
|
|
|
case GEANY_FILETYPES_LUA:
|
2007-01-06 15:03:53 +00:00
|
|
|
{
|
|
|
|
line_prefix = "--";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GEANY_FILETYPES_FORTRAN:
|
|
|
|
{
|
|
|
|
line_prefix = "c";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GEANY_FILETYPES_ASM:
|
|
|
|
{
|
|
|
|
line_prefix = ";";
|
|
|
|
break;
|
|
|
|
}
|
2006-11-14 16:03:25 +00:00
|
|
|
|
2007-06-22 17:34:31 +00:00
|
|
|
case GEANY_FILETYPES_BASIC:
|
|
|
|
{
|
|
|
|
line_prefix = "'";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-11-14 16:03:25 +00:00
|
|
|
case GEANY_FILETYPES_PASCAL:
|
2007-01-06 15:03:53 +00:00
|
|
|
{
|
|
|
|
frame_start = "{\n";
|
|
|
|
frame_end = "}\n";
|
|
|
|
line_prefix = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GEANY_FILETYPES_CAML:
|
|
|
|
{
|
|
|
|
frame_start = "(*\n";
|
|
|
|
frame_end = " *)\n";
|
|
|
|
line_prefix = " *";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-07 13:54:21 +00:00
|
|
|
case GEANY_FILETYPES_NONE:
|
2007-01-06 15:03:53 +00:00
|
|
|
{
|
|
|
|
line_prefix = "";
|
|
|
|
break;
|
|
|
|
}
|
2006-11-14 16:03:25 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
default: /* assume C-like multi-line comment is appropriate */
|
2007-01-06 15:03:53 +00:00
|
|
|
{
|
|
|
|
frame_start = "/*\n";
|
|
|
|
frame_end = " */\n";
|
|
|
|
line_prefix = " *";
|
|
|
|
}
|
2006-11-14 16:03:25 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* construct the real prefix with given amount of whitespace */
|
2007-01-06 15:03:53 +00:00
|
|
|
i = (indent > strlen(line_prefix)) ? (indent - strlen(line_prefix)) : strlen(line_prefix);
|
|
|
|
tmp = g_strnfill(i, ' ');
|
|
|
|
prefix = g_strconcat(line_prefix, tmp, NULL);
|
|
|
|
g_free(tmp);
|
2006-11-14 16:03:25 +00:00
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* add line_prefix to every line of comment_text */
|
2007-01-06 15:03:53 +00:00
|
|
|
lines = g_strsplit(comment_text, "\n", -1);
|
|
|
|
for (i = 0; i < (g_strv_length(lines) - 1); i++)
|
2006-11-14 16:03:25 +00:00
|
|
|
{
|
2007-01-06 15:03:53 +00:00
|
|
|
tmp = lines[i];
|
|
|
|
lines[i] = g_strconcat(prefix, tmp, NULL);
|
|
|
|
g_free(tmp);
|
|
|
|
}
|
|
|
|
tmp = g_strjoinv("\n", lines);
|
2006-11-14 16:03:25 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* add frame_start and frame_end */
|
2007-01-06 15:03:53 +00:00
|
|
|
result = g_strconcat(frame_start, tmp, frame_end, NULL);
|
2006-11-14 16:03:25 +00:00
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
g_free(prefix);
|
|
|
|
g_free(tmp);
|
|
|
|
g_strfreev(lines);
|
|
|
|
return result;
|
2006-11-14 16:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-06 15:38:44 +00:00
|
|
|
gchar *templates_get_template_licence(gint filetype_idx, gint licence_type)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-01-06 15:38:44 +00:00
|
|
|
if (licence_type != GEANY_TEMPLATE_GPL && licence_type != GEANY_TEMPLATE_BSD)
|
|
|
|
return NULL;
|
2007-01-06 15:03:53 +00:00
|
|
|
|
2007-01-06 15:38:44 +00:00
|
|
|
return make_comment_block(templates[licence_type], filetype_idx, 8);
|
2007-01-06 15:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-04 11:32:33 +00:00
|
|
|
gchar *templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
|
2007-01-06 15:03:53 +00:00
|
|
|
{
|
|
|
|
gchar *template = g_strdup(templates[GEANY_TEMPLATE_FILEHEADER]);
|
2006-11-14 16:03:25 +00:00
|
|
|
gchar *shortname;
|
2007-01-06 15:03:53 +00:00
|
|
|
gchar *result;
|
2007-11-17 13:09:19 +00:00
|
|
|
gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL);
|
2007-07-04 11:32:33 +00:00
|
|
|
filetype_id ft_id = filetype_idx;
|
|
|
|
filetype *ft = filetypes[ft_id];
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
filetypes_load_config(ft_id); /* load any user extension setting */
|
2007-11-11 09:03:01 +00:00
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
if (fname == NULL)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-05-07 13:54:21 +00:00
|
|
|
if (ft_id == GEANY_FILETYPES_NONE)
|
2006-11-14 16:03:25 +00:00
|
|
|
shortname = g_strdup(GEANY_STRING_UNTITLED);
|
2007-01-06 15:03:53 +00:00
|
|
|
else
|
|
|
|
shortname = g_strconcat(GEANY_STRING_UNTITLED, ".", ft->extension, NULL);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
else
|
2007-01-06 15:03:53 +00:00
|
|
|
shortname = g_path_get_basename(fname);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
template = utils_str_replace(template, "{filename}", shortname);
|
|
|
|
template = utils_str_replace(template, "{gpl}", templates[GEANY_TEMPLATE_GPL]);
|
2007-01-06 15:38:44 +00:00
|
|
|
template = utils_str_replace(template, "{bsd}", templates[GEANY_TEMPLATE_BSD]);
|
2007-01-06 15:03:53 +00:00
|
|
|
template = utils_str_replace(template, "{datetime}", date);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-07-04 11:32:33 +00:00
|
|
|
result = make_comment_block(template, ft_id, 8);
|
2006-11-14 16:03:25 +00:00
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
g_free(template);
|
|
|
|
g_free(shortname);
|
|
|
|
g_free(date);
|
|
|
|
return result;
|
2006-11-14 16:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gchar *get_file_template(filetype *ft)
|
|
|
|
{
|
2007-02-19 13:26:06 +00:00
|
|
|
filetype_id ft_id = FILETYPE_ID(ft);
|
|
|
|
|
|
|
|
return g_strdup(ft_templates[ft_id]);
|
2006-11-14 16:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-04 11:32:33 +00:00
|
|
|
gchar *templates_get_template_new_file(struct filetype *ft)
|
2006-11-14 16:03:25 +00:00
|
|
|
{
|
|
|
|
gchar *ft_template = NULL;
|
|
|
|
gchar *file_header = NULL;
|
|
|
|
|
2008-05-07 13:54:21 +00:00
|
|
|
if (FILETYPE_ID(ft) == GEANY_FILETYPES_NONE)
|
2006-11-14 16:03:25 +00:00
|
|
|
return get_file_template(ft);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
file_header = templates_get_template_fileheader(ft->id, NULL); /* file template only used for new files */
|
2006-11-14 16:03:25 +00:00
|
|
|
ft_template = get_file_template(ft);
|
2007-03-31 11:39:56 +00:00
|
|
|
ft_template = utils_str_replace(ft_template, "{fileheader}", file_header);
|
2006-11-14 16:03:25 +00:00
|
|
|
g_free(file_header);
|
2007-03-31 11:39:56 +00:00
|
|
|
return ft_template;
|
2006-11-14 16:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
gchar *templates_get_template_generic(gint template)
|
|
|
|
{
|
|
|
|
return g_strdup(templates[template]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
gchar *templates_get_template_function(gint filetype_idx, const gchar *func_name)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-01-06 15:03:53 +00:00
|
|
|
gchar *template = g_strdup(templates[GEANY_TEMPLATE_FUNCTION]);
|
2007-11-17 13:09:19 +00:00
|
|
|
gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT, NULL);
|
|
|
|
gchar *datetime = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL);
|
2007-01-06 15:03:53 +00:00
|
|
|
gchar *result;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
template = utils_str_replace(template, "{date}", date);
|
|
|
|
template = utils_str_replace(template, "{datetime}", datetime);
|
|
|
|
template = utils_str_replace(template, "{functionname}", (func_name) ? func_name : "");
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
result = make_comment_block(template, filetype_idx, 3);
|
|
|
|
|
|
|
|
g_free(template);
|
2005-11-22 12:26:26 +00:00
|
|
|
g_free(date);
|
|
|
|
g_free(datetime);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-01-06 15:03:53 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
gchar *templates_get_template_changelog(void)
|
|
|
|
{
|
2007-11-17 13:09:19 +00:00
|
|
|
gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL);
|
2005-11-22 12:26:26 +00:00
|
|
|
gchar *result = g_strdup(templates[GEANY_TEMPLATE_CHANGELOG]);
|
|
|
|
result = utils_str_replace(result, "{date}", date);
|
|
|
|
|
|
|
|
g_free(date);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void templates_free_templates(void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
for (i = 0; i < GEANY_MAX_TEMPLATES; i++)
|
|
|
|
{
|
|
|
|
g_free(templates[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-19 13:26:06 +00:00
|
|
|
static gchar *templates_replace_all(gchar *text, const gchar *year, const gchar *date)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
|
|
|
text = utils_str_replace(text, "{year}", year);
|
|
|
|
text = utils_str_replace(text, "{date}", date);
|
2008-05-16 12:08:39 +00:00
|
|
|
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);
|
|
|
|
text = utils_str_replace(text, "{mail}", template_prefs.mail);
|
|
|
|
text = utils_str_replace(text, "{company}", template_prefs.company);
|
2005-11-22 12:26:26 +00:00
|
|
|
text = utils_str_replace(text, "{untitled}", GEANY_STRING_UNTITLED);
|
2006-02-01 16:05:40 +00:00
|
|
|
text = utils_str_replace(text, "{geanyversion}", "Geany " VERSION);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2007-06-14 13:10:51 +00:00
|
|
|
|