Append locale-specific suffixes to default rc file names, and look these

Mon Dec 14 16:10:05 1998  Owen Taylor  <otaylor@redhat.com>

	* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
	suffixes to default rc file names, and look these
	up in addition to the base filename, to facilitate
	having the correct fontset per-locale.

	move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc

	* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
	New function to set a function to translate menu paths.

	* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
	results of g_strsplit().
This commit is contained in:
Owen Taylor
1998-12-14 23:26:12 +00:00
committed by Owen Taylor
parent c46265c82c
commit 698a11c606
10 changed files with 196 additions and 10 deletions

View File

@ -1,3 +1,18 @@
Mon Dec 14 16:10:05 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
suffixes to default rc file names, and look these
up in addition to the base filename, to facilitate
having the correct fontset per-locale.
move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
New function to set a function to translate menu paths.
* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
results of g_strsplit().
1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt> 1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt>
* configure.in (ALL_LINGUAS): Added 'pt'. * configure.in (ALL_LINGUAS): Added 'pt'.

View File

@ -1,3 +1,18 @@
Mon Dec 14 16:10:05 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
suffixes to default rc file names, and look these
up in addition to the base filename, to facilitate
having the correct fontset per-locale.
move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
New function to set a function to translate menu paths.
* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
results of g_strsplit().
1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt> 1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt>
* configure.in (ALL_LINGUAS): Added 'pt'. * configure.in (ALL_LINGUAS): Added 'pt'.

View File

@ -1,3 +1,18 @@
Mon Dec 14 16:10:05 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
suffixes to default rc file names, and look these
up in addition to the base filename, to facilitate
having the correct fontset per-locale.
move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
New function to set a function to translate menu paths.
* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
results of g_strsplit().
1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt> 1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt>
* configure.in (ALL_LINGUAS): Added 'pt'. * configure.in (ALL_LINGUAS): Added 'pt'.

View File

@ -1,3 +1,18 @@
Mon Dec 14 16:10:05 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
suffixes to default rc file names, and look these
up in addition to the base filename, to facilitate
having the correct fontset per-locale.
move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
New function to set a function to translate menu paths.
* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
results of g_strsplit().
1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt> 1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt>
* configure.in (ALL_LINGUAS): Added 'pt'. * configure.in (ALL_LINGUAS): Added 'pt'.

View File

@ -1,3 +1,18 @@
Mon Dec 14 16:10:05 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
suffixes to default rc file names, and look these
up in addition to the base filename, to facilitate
having the correct fontset per-locale.
move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
New function to set a function to translate menu paths.
* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
results of g_strsplit().
1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt> 1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt>
* configure.in (ALL_LINGUAS): Added 'pt'. * configure.in (ALL_LINGUAS): Added 'pt'.

View File

@ -1,3 +1,18 @@
Mon Dec 14 16:10:05 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
suffixes to default rc file names, and look these
up in addition to the base filename, to facilitate
having the correct fontset per-locale.
move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
New function to set a function to translate menu paths.
* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
results of g_strsplit().
1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt> 1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt>
* configure.in (ALL_LINGUAS): Added 'pt'. * configure.in (ALL_LINGUAS): Added 'pt'.

View File

@ -1,3 +1,18 @@
Mon Dec 14 16:10:05 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.c (gtk_rc_init): Append locale-specific
suffixes to default rc file names, and look these
up in addition to the base filename, to facilitate
having the correct fontset per-locale.
move $(sysconfdir)/gtkrc to $(sysconfdir)/gtk/gtkrc
* gtk/gtkitemfactory.[ch] (gtk_item_factory_set_translate_func):
New function to set a function to translate menu paths.
* gtk/gtkrc.c (gtk_rc_add_initial_default_files): Free
results of g_strsplit().
1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt> 1998-12-14 Nuno Ferreira <nmrf@rnl.ist.utl.pt>
* configure.in (ALL_LINGUAS): Added 'pt'. * configure.in (ALL_LINGUAS): Added 'pt'.

View File

@ -684,6 +684,9 @@ gtk_item_factory_finalize (GtkObject *object)
g_free (ifactory->path); g_free (ifactory->path);
g_assert (ifactory->widget == NULL); g_assert (ifactory->widget == NULL);
if (ifactory->translate_data && ifactory->translate_notify)
ifactory->translate_notify (ifactory->translate_data);
parent_class->finalize (object); parent_class->finalize (object);
} }
@ -893,11 +896,13 @@ gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
} }
static gboolean static gboolean
gtk_item_factory_parse_path (gchar *str, gtk_item_factory_parse_path (GtkItemFactory *ifactory,
gchar *str,
gchar **path, gchar **path,
gchar **parent_path, gchar **parent_path,
gchar **item) gchar **item)
{ {
gchar *translation;
gchar *p, *q; gchar *p, *q;
*path = g_strdup (str); *path = g_strdup (str);
@ -922,7 +927,12 @@ gtk_item_factory_parse_path (gchar *str,
} }
*p = 0; *p = 0;
p = strrchr (str, '/'); if (ifactory->translate_func)
translation = ifactory->translate_func (str, ifactory->translate_data);
else
translation = str;
p = strrchr (translation, '/');
p++; p++;
*item = g_strdup (p); *item = g_strdup (p);
@ -1006,7 +1016,7 @@ gtk_item_factory_create_item (GtkItemFactory *ifactory,
} }
} }
if (!gtk_item_factory_parse_path (entry->path, if (!gtk_item_factory_parse_path (ifactory, entry->path,
&path, &parent_path, &name)) &path, &parent_path, &name))
return; return;
@ -1599,3 +1609,19 @@ gtk_item_factory_parse_rc (const gchar *file_name)
close (fd); close (fd);
} }
void
gtk_item_factory_set_translate_func (GtkItemFactory *ifactory,
GtkTranslateFunc func,
gpointer data,
GtkDestroyNotify notify)
{
g_return_if_fail (ifactory != NULL);
if (ifactory->translate_data && ifactory->translate_notify)
ifactory->translate_notify (ifactory->translate_data);
ifactory->translate_func = func;
ifactory->translate_data = data;
ifactory->translate_notify = notify;
}

View File

@ -35,6 +35,8 @@ extern "C" {
typedef void (*GtkPrintFunc) (gpointer func_data, typedef void (*GtkPrintFunc) (gpointer func_data,
gchar *str); gchar *str);
typedef gchar * (*GtkTranslateFunc) (const gchar *path,
gpointer func_data);
typedef void (*GtkItemFactoryCallback) (); typedef void (*GtkItemFactoryCallback) ();
typedef void (*GtkItemFactoryCallback1) (gpointer callback_data, typedef void (*GtkItemFactoryCallback1) (gpointer callback_data,
guint callback_action, guint callback_action,
@ -63,6 +65,10 @@ struct _GtkItemFactory
GtkAccelGroup *accel_group; GtkAccelGroup *accel_group;
GtkWidget *widget; GtkWidget *widget;
GSList *widgets_by_action; GSList *widgets_by_action;
GtkTranslateFunc translate_func;
gpointer translate_data;
GtkDestroyNotify translate_notify;
}; };
struct _GtkItemFactoryClass struct _GtkItemFactoryClass
@ -185,6 +191,10 @@ void gtk_item_factory_popup_with_data(GtkItemFactory *ifactory,
guint32 time); guint32 time);
gpointer gtk_item_factory_popup_data (GtkItemFactory *ifactory); gpointer gtk_item_factory_popup_data (GtkItemFactory *ifactory);
gpointer gtk_item_factory_popup_data_from_widget (GtkWidget *widget); gpointer gtk_item_factory_popup_data_from_widget (GtkWidget *widget);
void gtk_item_factory_set_translate_func (GtkItemFactory *ifactory,
GtkTranslateFunc func,
gpointer data,
GtkDestroyNotify notify);
/* Compatibility functions for deprecated GtkMenuFactory code /* Compatibility functions for deprecated GtkMenuFactory code
*/ */

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include <X11/Xlocale.h> /* so we get the right setlocale */
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -24,6 +25,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "gtkrc.h" #include "gtkrc.h"
#include "gtkbindings.h" #include "gtkbindings.h"
#include "gtkthemes.h" #include "gtkthemes.h"
@ -333,11 +335,12 @@ gtk_rc_add_initial_default_files (void)
gtk_rc_add_default_file (files[i]); gtk_rc_add_default_file (files[i]);
i++; i++;
} }
g_strfreev (files);
} }
else else
{ {
str = g_malloc (strlen(GTK_SYSCONFDIR) + strlen("/gtkrc") + 1); str = g_malloc (strlen(GTK_SYSCONFDIR) + strlen("/gtk/gtkrc") + 1);
sprintf (str, "%s%s", GTK_SYSCONFDIR, "/gtkrc"); sprintf (str, "%s%s", GTK_SYSCONFDIR, "/gtk/gtkrc");
gtk_rc_add_default_file (str); gtk_rc_add_default_file (str);
var = g_get_home_dir (); var = g_get_home_dir ();
@ -398,7 +401,12 @@ gtk_rc_get_default_files (void)
void void
gtk_rc_init (void) gtk_rc_init (void)
{ {
guint i; gchar *locale_suffixes[3];
gint n_locale_suffixes = 0;
gint i, j;
char *locale = setlocale (LC_MESSAGES, NULL);
guint length;
char *p;
rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash, rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
(GCompareFunc) gtk_rc_style_compare); (GCompareFunc) gtk_rc_style_compare);
@ -409,13 +417,50 @@ gtk_rc_init (void)
gtk_rc_add_initial_default_files (); gtk_rc_add_initial_default_files ();
if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
{
/* Determine locale-specific suffixes for RC files
*/
p = strchr (locale, '@');
length = p ? (p -locale) : strlen (locale);
p = strchr (locale, '.');
if (p)
{
locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
length = p - locale;
}
p = strchr (locale, '_');
if (p)
{
locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
length = p - locale;
}
locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
}
i = 0; i = 0;
while (gtk_rc_default_files[i] != NULL) while (gtk_rc_default_files[i] != NULL)
{ {
/* Try to find a locale specific RC file corresponding to
* to parse before the default file.
*/
for (j=n_locale_suffixes-1; j>=0; j--)
{
struct stat statbuf;
gchar *name = g_strconcat (gtk_rc_default_files[i],
".",
locale_suffixes[j],
NULL);
gtk_rc_parse (name);
}
gtk_rc_parse (gtk_rc_default_files[i]); gtk_rc_parse (gtk_rc_default_files[i]);
i++; i++;
} }
} }
void void
gtk_rc_parse_string (const gchar *rc_string) gtk_rc_parse_string (const gchar *rc_string)