SF.net SVN: geany: [2575] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Tue May 13 17:18:15 UTC 2008


Revision: 2575
          http://geany.svn.sourceforge.net/geany/?rev=2575&view=rev
Author:   ntrel
Date:     2008-05-13 10:18:14 -0700 (Tue, 13 May 2008)

Log Message:
-----------
Add support for custom file templates found at startup in the
~/.geany/templates/files directory. These are currently shown
underneath filetype templates in the New with Template menu.
Add ui_menu_item_get_text().
Make utils_string_replace_all() ignore empty haystacks.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/TODO
    trunk/doc/geany.html
    trunk/doc/geany.txt
    trunk/src/templates.c
    trunk/src/ui_utils.c
    trunk/src/ui_utils.h
    trunk/src/utils.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-05-12 13:46:19 UTC (rev 2574)
+++ trunk/ChangeLog	2008-05-13 17:18:14 UTC (rev 2575)
@@ -1,3 +1,14 @@
+2008-05-13  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/templates.c, src/utils.c, src/ui_utils.h, src/ui_utils.c,
+   doc/geany.txt, doc/geany.html, TODO:
+   Add support for custom file templates found at startup in the
+   ~/.geany/templates/files directory. These are currently shown
+   underneath filetype templates in the New with Template menu.
+   Add ui_menu_item_get_text().
+   Make utils_string_replace_all() ignore empty haystacks.
+
+
 2008-05-12  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * src/highlighting.c, data/filetypes.xml:

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2008-05-12 13:46:19 UTC (rev 2574)
+++ trunk/TODO	2008-05-13 17:18:14 UTC (rev 2575)
@@ -31,7 +31,6 @@
 	  target...)
 	o (tango-like icons for the symbol list)
 	o (show autocompletion symbol icons - see SCI_REGISTERIMAGE)
-	o (custom template file support)
 	o (GFileMonitor support, if/when GIO gets merged with GLib)
 
 

Modified: trunk/doc/geany.html
===================================================================
--- trunk/doc/geany.html	2008-05-12 13:46:19 UTC (rev 2574)
+++ trunk/doc/geany.html	2008-05-13 17:18:14 UTC (rev 2575)
@@ -340,31 +340,35 @@
 <li><a class="reference" href="#filetype-extensions" id="id131" name="id131">Filetype extensions</a></li>
 <li><a class="reference" href="#templates" id="id132" name="id132">Templates</a><ul>
 <li><a class="reference" href="#template-metadata" id="id133" name="id133">Template metadata</a></li>
-<li><a class="reference" href="#filetype-templates" id="id134" name="id134">Filetype templates</a></li>
-<li><a class="reference" href="#customizing-templates" id="id135" name="id135">Customizing templates</a><ul>
-<li><a class="reference" href="#template-wildcards" id="id136" name="id136">Template wildcards</a></li>
+<li><a class="reference" href="#file-templates" id="id134" name="id134">File templates</a><ul>
+<li><a class="reference" href="#custom-file-templates" id="id135" name="id135">Custom file templates</a></li>
+<li><a class="reference" href="#filetype-templates" id="id136" name="id136">Filetype templates</a></li>
 </ul>
 </li>
+<li><a class="reference" href="#customizing-templates" id="id137" name="id137">Customizing templates</a><ul>
+<li><a class="reference" href="#template-wildcards" id="id138" name="id138">Template wildcards</a></li>
 </ul>
 </li>
 </ul>
 </li>
-<li><a class="reference" href="#contributing-to-this-document" id="id137" name="id137">Contributing to this document</a></li>
-<li><a class="reference" href="#scintilla-keyboard-commands" id="id138" name="id138">Scintilla keyboard commands</a><ul>
-<li><a class="reference" href="#keyboard-commands" id="id139" name="id139">Keyboard commands</a></li>
 </ul>
 </li>
-<li><a class="reference" href="#hidden-preferences" id="id140" name="id140">Hidden preferences</a></li>
-<li><a class="reference" href="#compile-time-options" id="id141" name="id141">Compile-time options</a><ul>
-<li><a class="reference" href="#src-geany-h" id="id142" name="id142">src/geany.h</a></li>
-<li><a class="reference" href="#project-h" id="id143" name="id143">project.h</a></li>
-<li><a class="reference" href="#editor-h" id="id144" name="id144">editor.h</a></li>
-<li><a class="reference" href="#keyfile-c" id="id145" name="id145">keyfile.c</a></li>
+<li><a class="reference" href="#contributing-to-this-document" id="id139" name="id139">Contributing to this document</a></li>
+<li><a class="reference" href="#scintilla-keyboard-commands" id="id140" name="id140">Scintilla keyboard commands</a><ul>
+<li><a class="reference" href="#keyboard-commands" id="id141" name="id141">Keyboard commands</a></li>
 </ul>
 </li>
-<li><a class="reference" href="#gnu-general-public-license" id="id146" name="id146">GNU General Public License</a></li>
-<li><a class="reference" href="#license-for-scintilla-and-scite" id="id147" name="id147">License for Scintilla and SciTE</a></li>
+<li><a class="reference" href="#hidden-preferences" id="id142" name="id142">Hidden preferences</a></li>
+<li><a class="reference" href="#compile-time-options" id="id143" name="id143">Compile-time options</a><ul>
+<li><a class="reference" href="#src-geany-h" id="id144" name="id144">src/geany.h</a></li>
+<li><a class="reference" href="#project-h" id="id145" name="id145">project.h</a></li>
+<li><a class="reference" href="#editor-h" id="id146" name="id146">editor.h</a></li>
+<li><a class="reference" href="#keyfile-c" id="id147" name="id147">keyfile.c</a></li>
 </ul>
+</li>
+<li><a class="reference" href="#gnu-general-public-license" id="id148" name="id148">GNU General Public License</a></li>
+<li><a class="reference" href="#license-for-scintilla-and-scite" id="id149" name="id149">License for Scintilla and SciTE</a></li>
+</ul>
 </div>
 <div class="section">
 <h1><a class="toc-backref" href="#id5" id="introduction" name="introduction">Introduction</a></h1>
@@ -3166,28 +3170,42 @@
 at startup.</p>
 </div>
 <div class="section">
-<h3><a class="toc-backref" href="#id134" id="filetype-templates" name="filetype-templates">Filetype templates</a></h3>
-<p>Filetype templates are templates used as the basis of a new file. To
+<h3><a class="toc-backref" href="#id134" id="file-templates" name="file-templates">File templates</a></h3>
+<p>File templates are templates used as the basis of a new file. To
 use them, choose the <em>New (with Template)</em> menu item from the <em>File</em>
 menu.</p>
-<p>By default, templates are created for some filetypes. Other filetype
+<p>By default, templates are created for some filetypes. Custom file
 templates can be added by creating the appropriate template file and
 restarting Geany. You can also edit the default filetype templates.</p>
+<p>The file's contents are just the text to place in the document,
+except for the optional <tt class="docutils literal"><span class="pre">{fileheader}</span></tt> template wildcard. This can
+be placed anywhere, but is usually on the first line of the file,
+followed by a blank line.</p>
+<div class="section">
+<h4><a class="toc-backref" href="#id135" id="custom-file-templates" name="custom-file-templates">Custom file templates</a></h4>
+<p>These are read from the <tt class="docutils literal"><span class="pre">~/.geany/templates/files</span></tt> directory (created
+the first time Geany is started). The filetype to use is detected from
+the template file's extension, if any. For example, creating a file
+<tt class="docutils literal"><span class="pre">main.c</span></tt> would add a menu item which created a new document with the
+filetype set to 'C'.</p>
+<p>The template file is read from disk when the corresponding menu item is
+clicked, so you don't need to restart Geany after editing a custom file
+template.</p>
+</div>
+<div class="section">
+<h4><a class="toc-backref" href="#id136" id="filetype-templates" name="filetype-templates">Filetype templates</a></h4>
 <p>Filetype template files are read from the <tt class="docutils literal"><span class="pre">~/.geany/templates</span></tt>
 directory, and are named "filetype." followed by the filetype
 name, e.g. "filetype.python", "filetype.sh", etc. If you are
 unsure about the filetype name extensions, they are the same as
 the filetype configuration file extensions, commonly installed in
 <tt class="docutils literal"><span class="pre">/usr/share/geany</span></tt>, with the prefix "filetypes.".</p>
-<p>The file's contents are just the text to place in the document,
-except for the optional <tt class="docutils literal"><span class="pre">{fileheader}</span></tt> template wildcard. This can
-be placed anywhere, but is usually on the first line of the file,
-followed by a blank line.</p>
-<p>There is also a template file <tt class="docutils literal"><span class="pre">template.none</span></tt> which is used when
+<p>There is also a template file <tt class="docutils literal"><span class="pre">filetype.none</span></tt> which is used when
 the New command is used without a filetype. This is empty by default.</p>
 </div>
+</div>
 <div class="section">
-<h3><a class="toc-backref" href="#id135" id="customizing-templates" name="customizing-templates">Customizing templates</a></h3>
+<h3><a class="toc-backref" href="#id137" id="customizing-templates" name="customizing-templates">Customizing templates</a></h3>
 <p>Each template can be customized to your needs. The templates are
 stored in the <tt class="docutils literal"><span class="pre">~/.geany/templates/</span></tt> directory (see the section called
 <a class="reference" href="#command-line-options">Command line options</a> for further information about the configuration
@@ -3195,7 +3213,7 @@
 Geany ;-) ) and edit the template to your needs. There are some
 wildcards which will be automatically replaced by Geany at startup.</p>
 <div class="section">
-<h4><a class="toc-backref" href="#id136" id="template-wildcards" name="template-wildcards">Template wildcards</a></h4>
+<h4><a class="toc-backref" href="#id138" id="template-wildcards" name="template-wildcards">Template wildcards</a></h4>
 <p>All wildcards must be enclosed by "{" and "}", e.g. {date}.</p>
 <table border="1" class="docutils">
 <colgroup>
@@ -3304,7 +3322,7 @@
 </div>
 </div>
 <div class="section">
-<h1><a class="toc-backref" href="#id137" id="contributing-to-this-document" name="contributing-to-this-document">Contributing to this document</a></h1>
+<h1><a class="toc-backref" href="#id139" id="contributing-to-this-document" name="contributing-to-this-document">Contributing to this document</a></h1>
 <p>This document (<tt class="docutils literal"><span class="pre">geany.txt</span></tt>) is written in <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a>
 (or "reST"). The source file for it is located in Geany's <tt class="docutils literal"><span class="pre">doc</span></tt>
 subdirectory.  If you intend on making changes, you should grab the
@@ -3324,7 +3342,7 @@
 and Fedora systems.</p>
 </div>
 <div class="section">
-<h1><a class="toc-backref" href="#id138" id="scintilla-keyboard-commands" name="scintilla-keyboard-commands">Scintilla keyboard commands</a></h1>
+<h1><a class="toc-backref" href="#id140" id="scintilla-keyboard-commands" name="scintilla-keyboard-commands">Scintilla keyboard commands</a></h1>
 <p>Copyright © 1998, 2006 Neil Hodgson <neilh(at)scintilla(dot)org></p>
 <p>This appendix is distributed under the terms of the License for
 Scintilla and SciTE. A copy of this license can be found in the file
@@ -3333,7 +3351,7 @@
 Scintilla and SciTE</a>.</p>
 <p>20 June 2006</p>
 <div class="section">
-<h2><a class="toc-backref" href="#id139" id="keyboard-commands" name="keyboard-commands">Keyboard commands</a></h2>
+<h2><a class="toc-backref" href="#id141" id="keyboard-commands" name="keyboard-commands">Keyboard commands</a></h2>
 <p>Keyboard commands for Scintilla mostly follow common Windows and GTK+
 conventions. All move keys (arrows, page up/down, home and end)
 allows to extend or reduce the stream selection when holding the
@@ -3427,7 +3445,7 @@
 </div>
 </div>
 <div class="section">
-<h1><a class="toc-backref" href="#id140" id="hidden-preferences" name="hidden-preferences">Hidden preferences</a></h1>
+<h1><a class="toc-backref" href="#id142" id="hidden-preferences" name="hidden-preferences">Hidden preferences</a></h1>
 <p>There are some uncommon preferences that are not shown in the Preferences
 dialog. These can be set by editing <tt class="docutils literal"><span class="pre">~/.geany/geany.conf</span></tt>, then
 restarting Geany. Search for the key name, then edit the value. Example:</p>
@@ -3499,7 +3517,7 @@
 </table>
 </div>
 <div class="section">
-<h1><a class="toc-backref" href="#id141" id="compile-time-options" name="compile-time-options">Compile-time options</a></h1>
+<h1><a class="toc-backref" href="#id143" id="compile-time-options" name="compile-time-options">Compile-time options</a></h1>
 <p>There are some options which can only be changed at compile time,
 and some options which are used as the default for configurable
 options. To change these options, edit the appropriate source file
@@ -3511,7 +3529,7 @@
 <p class="last">Most users should not need to change these options.</p>
 </div>
 <div class="section">
-<h2><a class="toc-backref" href="#id142" id="src-geany-h" name="src-geany-h">src/geany.h</a></h2>
+<h2><a class="toc-backref" href="#id144" id="src-geany-h" name="src-geany-h">src/geany.h</a></h2>
 <table border="1" class="docutils">
 <colgroup>
 <col width="33%" />
@@ -3568,7 +3586,7 @@
 </table>
 </div>
 <div class="section">
-<h2><a class="toc-backref" href="#id143" id="project-h" name="project-h">project.h</a></h2>
+<h2><a class="toc-backref" href="#id145" id="project-h" name="project-h">project.h</a></h2>
 <table border="1" class="docutils">
 <colgroup>
 <col width="33%" />
@@ -3593,7 +3611,7 @@
 </table>
 </div>
 <div class="section">
-<h2><a class="toc-backref" href="#id144" id="editor-h" name="editor-h">editor.h</a></h2>
+<h2><a class="toc-backref" href="#id146" id="editor-h" name="editor-h">editor.h</a></h2>
 <table border="1" class="docutils">
 <colgroup>
 <col width="33%" />
@@ -3630,7 +3648,7 @@
 </table>
 </div>
 <div class="section">
-<h2><a class="toc-backref" href="#id145" id="keyfile-c" name="keyfile-c">keyfile.c</a></h2>
+<h2><a class="toc-backref" href="#id147" id="keyfile-c" name="keyfile-c">keyfile.c</a></h2>
 <p>These are default settings that can be overridden in the <a class="reference" href="#preferences">Preferences</a> dialog.</p>
 <table border="1" class="docutils">
 <colgroup>
@@ -3702,7 +3720,7 @@
 </div>
 </div>
 <div class="section">
-<h1><a class="toc-backref" href="#id146" id="gnu-general-public-license" name="gnu-general-public-license">GNU General Public License</a></h1>
+<h1><a class="toc-backref" href="#id148" id="gnu-general-public-license" name="gnu-general-public-license">GNU General Public License</a></h1>
 <pre class="literal-block">
             GNU GENERAL PUBLIC LICENSE
                Version 2, June 1991
@@ -4047,7 +4065,7 @@
 </pre>
 </div>
 <div class="section">
-<h1><a class="toc-backref" href="#id147" id="license-for-scintilla-and-scite" name="license-for-scintilla-and-scite">License for Scintilla and SciTE</a></h1>
+<h1><a class="toc-backref" href="#id149" id="license-for-scintilla-and-scite" name="license-for-scintilla-and-scite">License for Scintilla and SciTE</a></h1>
 <p>Copyright 1998-2003 by Neil Hodgson <neilh(at)scintilla(dot)org></p>
 <p>All Rights Reserved</p>
 <p>Permission to use, copy, modify, and distribute this software and
@@ -4067,7 +4085,7 @@
 <div class="footer">
 <hr class="footer" />
 <a class="reference" href="geany.txt">View document source</a>.
-Generated on: 2008-05-09 14:39 UTC.
+Generated on: 2008-05-13 17:12 UTC.
 Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
 
 </div>

Modified: trunk/doc/geany.txt
===================================================================
--- trunk/doc/geany.txt	2008-05-12 13:46:19 UTC (rev 2574)
+++ trunk/doc/geany.txt	2008-05-13 17:18:14 UTC (rev 2575)
@@ -2884,17 +2884,38 @@
 at startup.
 
 
-Filetype templates
-^^^^^^^^^^^^^^^^^^
+File templates
+^^^^^^^^^^^^^^
 
-Filetype templates are templates used as the basis of a new file. To
+File templates are templates used as the basis of a new file. To
 use them, choose the *New (with Template)* menu item from the *File*
 menu.
 
-By default, templates are created for some filetypes. Other filetype
+By default, templates are created for some filetypes. Custom file
 templates can be added by creating the appropriate template file and
 restarting Geany. You can also edit the default filetype templates.
 
+The file's contents are just the text to place in the document,
+except for the optional ``{fileheader}`` template wildcard. This can
+be placed anywhere, but is usually on the first line of the file,
+followed by a blank line.
+
+Custom file templates
+`````````````````````
+
+These are read from the ``~/.geany/templates/files`` directory (created
+the first time Geany is started). The filetype to use is detected from
+the template file's extension, if any. For example, creating a file
+``main.c`` would add a menu item which created a new document with the
+filetype set to 'C'.
+
+The template file is read from disk when the corresponding menu item is
+clicked, so you don't need to restart Geany after editing a custom file
+template.
+
+Filetype templates
+``````````````````
+
 Filetype template files are read from the ``~/.geany/templates``
 directory, and are named "filetype." followed by the filetype
 name, e.g. "filetype.python", "filetype.sh", etc. If you are
@@ -2902,12 +2923,7 @@
 the filetype configuration file extensions, commonly installed in
 ``/usr/share/geany``, with the prefix "filetypes.".
 
-The file's contents are just the text to place in the document,
-except for the optional ``{fileheader}`` template wildcard. This can
-be placed anywhere, but is usually on the first line of the file,
-followed by a blank line.
-
-There is also a template file ``template.none`` which is used when
+There is also a template file ``filetype.none`` which is used when
 the New command is used without a filetype. This is empty by default.
 
 

Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c	2008-05-12 13:46:19 UTC (rev 2574)
+++ trunk/src/templates.c	2008-05-13 17:18:14 UTC (rev 2575)
@@ -43,6 +43,10 @@
 #define TEMPLATE_DATE_FORMAT "%Y-%m-%d"
 #define TEMPLATE_DATETIME_FORMAT "%d.%m.%Y %H:%M:%S %Z"
 
+
+static GtkWidget *new_with_template_menu = NULL;	/* File menu submenu */
+
+
 /* default templates, only for initial tempate file creation on first start of Geany */
 static const gchar templates_gpl_notice[] = "\
 This program is free software; you can redistribute it and/or modify\n\
@@ -335,7 +339,6 @@
 /* template items for the new file menu */
 static void create_new_menu_items(void)
 {
-	GtkWidget *template_menu = lookup_widget(app->window, "menu_new_with_template1_menu");
 	filetype_id ft_id;
 
 	for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++)
@@ -352,7 +355,7 @@
 		tmp_button = gtk_menu_item_new_with_label(label);
 		gtk_widget_show(tmp_menu);
 		gtk_widget_show(tmp_button);
-		gtk_container_add(GTK_CONTAINER(template_menu), tmp_menu);
+		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_template), (gpointer) ft);
@@ -362,6 +365,106 @@
 }
 
 
+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);
+}
+
+
+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);
+	gboolean ret = list != NULL;
+
+	g_slist_foreach(list, add_file_item, NULL);
+	g_slist_foreach(list, (GFunc) g_free, NULL);
+	g_slist_free(list);
+	g_free(path);
+	return ret;
+}
+
+
+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);
+	}
+}
+
+
 void templates_init(void)
 {
 	gchar *year = utils_get_date_time("%Y", NULL);
@@ -369,10 +472,11 @@
 
 	init_general_templates(year, date);
 	init_ft_templates(year, date);
-	create_new_menu_items();
 
 	g_free(date);
 	g_free(year);
+
+	create_file_template_menus();
 }
 
 

Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c	2008-05-12 13:46:19 UTC (rev 2574)
+++ trunk/src/ui_utils.c	2008-05-13 17:18:14 UTC (rev 2575)
@@ -58,8 +58,6 @@
 widgets;
 
 
-static gchar *menu_item_get_text(GtkMenuItem *menu_item);
-
 static void update_recent_menu(void);
 static void recent_file_loaded(const gchar *utf8_filename);
 static void
@@ -885,7 +883,7 @@
 recent_file_activate_cb                (GtkMenuItem     *menuitem,
                                         G_GNUC_UNUSED gpointer         user_data)
 {
-	gchar *utf8_filename = menu_item_get_text(menuitem);
+	gchar *utf8_filename = ui_menu_item_get_text(menuitem);
 	gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
 
 	if (document_open_file(locale_filename, FALSE, NULL, NULL) > -1)
@@ -921,7 +919,7 @@
 
 
 /* Returns: newly allocated string with the UTF-8 menu text. */
-static gchar *menu_item_get_text(GtkMenuItem *menu_item)
+gchar *ui_menu_item_get_text(GtkMenuItem *menu_item)
 {
 	const gchar *text = NULL;
 
@@ -939,7 +937,7 @@
 
 static gint find_recent_file_item(gconstpointer list_data, gconstpointer user_data)
 {
-	gchar *menu_text = menu_item_get_text(GTK_MENU_ITEM(list_data));
+	gchar *menu_text = ui_menu_item_get_text(GTK_MENU_ITEM(list_data));
 	gint result;
 
 	if (utils_str_equal(menu_text, user_data))

Modified: trunk/src/ui_utils.h
===================================================================
--- trunk/src/ui_utils.h	2008-05-12 13:46:19 UTC (rev 2574)
+++ trunk/src/ui_utils.h	2008-05-13 17:18:14 UTC (rev 2575)
@@ -80,6 +80,8 @@
 
 void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str);
 
+gchar *ui_menu_item_get_text(GtkMenuItem *menu_item);
+
 GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment);
 
 GtkWidget *ui_dialog_vbox_new(GtkDialog *dialog);

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2008-05-12 13:46:19 UTC (rev 2574)
+++ trunk/src/utils.c	2008-05-13 17:18:14 UTC (rev 2575)
@@ -1807,6 +1807,8 @@
 	const gchar *c;
 	gssize pos = -1;
 
+	if (haystack->len == 0)
+		return FALSE;
 	g_return_val_if_fail(NZV(needle), FALSE);
 	g_return_val_if_fail(! NZV(replace) || strstr(replace, needle) == NULL, FALSE);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list