2002-12-02 Christian Stimming <stimming@tuhh.de>

* src/gnome/window-main.c,
	src/business/business-gnome/business-gnome.scm, src/scm/main.scm:
	Yet more i18n menu insertion fixes.

	* src/gnome-utils/gnc-menu-extensions.[hc]: Added
	gnc_gnome_app_insert_menus to work around i18n problems with stock
	gnome menus. This is now also used from window-acct-tree.c.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7585 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2002-12-02 00:19:45 +00:00
parent 9b670219f6
commit f03a1657de
7 changed files with 194 additions and 12 deletions

View File

@ -1,3 +1,13 @@
2002-12-02 Christian Stimming <stimming@tuhh.de>
* src/gnome/window-main.c,
src/business/business-gnome/business-gnome.scm, src/scm/main.scm:
Yet more i18n menu insertion fixes.
* src/gnome-utils/gnc-menu-extensions.[hc]: Added
gnc_gnome_app_insert_menus to work around i18n problems with stock
gnome menus. This is now also used from window-acct-tree.c.
2002-12-01 Derek Atkins <derek@ihtfp.com> 2002-12-01 Derek Atkins <derek@ihtfp.com>
* move QuickFill and dialog-transfer into gnome-utils * move QuickFill and dialog-transfer into gnome-utils

View File

@ -207,7 +207,7 @@
(gnc:add-extension (gnc:add-extension
(gnc:make-menu-item (N_ "Properties") (gnc:make-menu-item (N_ "Properties")
(N_ "View and edit the properties of this file.") (N_ "View and edit the properties of this file.")
(list "Main" "File" "_Print") (list "Main" "_File" "_Print")
(lambda () (lambda ()
(let* ((book (gnc:get-current-book)) (let* ((book (gnc:get-current-book))
(slots (gnc:book-get-slots book))) (slots (gnc:book-get-slots book)))
@ -218,7 +218,7 @@
(gnc:kvp-option-dialog gnc:id-book (gnc:kvp-option-dialog gnc:id-book
slots "Book Options" slots "Book Options"
changed_cb))))) changed_cb)))))
(gnc:add-extension (gnc:make-separator (list "Main" "File" "_Print"))) (gnc:add-extension (gnc:make-separator (list "Main" "_File" "_Print")))
) )

View File

@ -343,6 +343,161 @@ gnc_add_c_extension(GnomeUIInfo *info, gchar *path)
extension_list = g_slist_append(extension_list, ext_info); extension_list = g_slist_append(extension_list, ext_info);
} }
/* This code is directly copied from libgnomeui's gnome-app-helper.c
* without modifications. */
static gint
g_strncmp_ignore_char( const gchar *first, const gchar *second, gint length, gchar ignored )
{
gint i, j;
for ( i = 0, j = 0; i < length; i++, j++ )
{
while ( first[i] == ignored && i < length ) i++;
while ( second[j] == ignored ) j++;
if ( i == length )
return 0;
if ( first[i] < second[j] )
return -1;
if ( first[i] > second[j] )
return 1;
}
return 0;
}
/* This code is copied from libgnomeui's gnome-app-helper.c
* originally. */
static const gchar *
gnc_gnome_app_helper_gettext (const gchar *str)
{
char *s;
/* First try to look up the string in gettext domain gnome-libs,
* since this is where the original gnome stock labels have been
* translated. */
s = dgettext ("gnome-libs", str);
if ( s == str )
s = gettext (str);
return s;
}
/* This code is directly copied from libgnomeui's gnome-app-helper.c,
* except for the call to the translation lookup . */
/**
* gnome_app_find_menu_pos
* @parent: Root menu shell widget containing menu items to be searched
* @path: Specifies the target menu item by menu path
* @pos: (output) returned item position
*
* Description:
* finds menu item described by path starting
* in the GtkMenuShell top and returns its parent GtkMenuShell and the
* position after this item in pos: gtk_menu_shell_insert(p, w, pos)
* would then insert widget w in GtkMenuShell p right after the menu item
* described by path.
**/
static GtkWidget *
gnc_gnome_app_find_menu_pos (GtkWidget *parent, const gchar *path, gint *pos)
{
GtkBin *item;
gchar *label = NULL;
GList *children;
gchar *name_end;
gchar *part;
const gchar *transl;
gint p;
int path_len;
g_return_val_if_fail (parent != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (pos != NULL, NULL);
children = GTK_MENU_SHELL (parent)->children;
name_end = strchr(path, '/');
if(name_end == NULL)
path_len = strlen(path);
else
path_len = name_end - path;
if (path_len == 0) {
if (children && GTK_IS_TEAROFF_MENU_ITEM(children->data))
/* consider the position after the tear off item as the topmost one. */
*pos = 1;
else
*pos = 0;
return parent;
}
/* this ugly thing should fix the localization problems */
part = g_malloc(path_len + 1);
if(!part)
return NULL;
strncpy(part, path, path_len);
part[path_len] = '\0';
transl = gnc_gnome_app_helper_gettext (part);
path_len = strlen(transl);
p = 0;
while (children){
item = GTK_BIN (children->data);
children = children->next;
label = NULL;
p++;
if (GTK_IS_TEAROFF_MENU_ITEM(item))
label = NULL;
else if (!item->child) /* this is a separator, right? */
label = "<Separator>";
else if (GTK_IS_LABEL (item->child)) /* a simple item with a label */
label = GTK_LABEL (item->child)->label;
else
label = NULL; /* something that we just can't handle */
/*fprintf(stderr, "Transl '%s', Label '%s'\n", transl, label);*/
if (label && (g_strncmp_ignore_char (transl, label, path_len, '_') == 0)){
if (name_end == NULL) {
*pos = p;
g_free(part);
return parent;
}
else if (GTK_MENU_ITEM (item)->submenu) {
g_free(part);
return gnc_gnome_app_find_menu_pos
(GTK_MENU_ITEM (item)->submenu,
(gchar *)(name_end + 1), pos);
}
else {
g_free(part);
return NULL;
}
}
}
g_free(part);
return NULL;
}
/* This code is more or less copied from libgnomeui's gnome-app-helper.c . */
void
gnc_gnome_app_insert_menus (GnomeApp *app, const gchar *path, GnomeUIInfo *menuinfo)
{
GtkWidget *menu_shell;
gint pos;
menu_shell = gnc_gnome_app_find_menu_pos(app->menubar, path, &pos);
if(menu_shell == NULL) {
g_warning("gnc_gnome_app_insert_menus: couldn't find "
"insertion point for menus!");
return;
}
/* create menus and insert them */
gnome_app_fill_menu (GTK_MENU_SHELL (menu_shell), menuinfo,
app->accel_group, TRUE, pos);
}
void void
gnc_extensions_menu_setup(GnomeApp * app, gchar *window) gnc_extensions_menu_setup(GnomeApp * app, gchar *window)
{ {
@ -355,7 +510,7 @@ gnc_extensions_menu_setup(GnomeApp * app, gchar *window)
(strcmp(info->window, WINDOW_NAME_ALL) != 0)) (strcmp(info->window, WINDOW_NAME_ALL) != 0))
continue; continue;
/* fprintf(stderr, "Inserting extension menu at path '%s'\n", info->path); */ /* fprintf(stderr, "Inserting extension menu at path '%s'\n", info->path); */
gnome_app_insert_menus(app, info->path, info->info); gnc_gnome_app_insert_menus(app, info->path, info->info);
gnome_app_install_menu_hints(app, info->info); gnome_app_install_menu_hints(app, info->info);
} }
} }
@ -372,6 +527,7 @@ gnc_extensions_menu_setup_with_data(GnomeApp * app,
if ((strcmp(info->window, window) != 0) && if ((strcmp(info->window, window) != 0) &&
(strcmp(info->window, WINDOW_NAME_ALL) != 0)) (strcmp(info->window, WINDOW_NAME_ALL) != 0))
continue; continue;
/* fprintf(stderr, "Inserting extension menu/w/d at path '%s'\n", info->path); */
gnome_app_insert_menus_with_data(app, info->path, info->info, user_data); gnome_app_insert_menus_with_data(app, info->path, info->info, user_data);
gnome_app_install_menu_hints(app, info->info); gnome_app_install_menu_hints(app, info->info);
} }

View File

@ -34,6 +34,21 @@
void gnc_add_c_extension(GnomeUIInfo *info, gchar *path); void gnc_add_c_extension(GnomeUIInfo *info, gchar *path);
void gnc_add_scm_extension(SCM extension); void gnc_add_scm_extension(SCM extension);
/* Replacement for gnome_app_insert_menus, since the original one will
* fail for i18n. In particular, as soon as the gnome stock menus
* (created through the macros in gnome-app-helper) have a different
* translation in the original gnome libs compared to the gnucash
* message catalog, then the gnome_app_insert_menus will
* fail. Therefore this function looks up the translation of each 'path'
* element in the gettext domain "gnome-libs" first.
*
* This function should be used in all places where the 'path'
* contains a stock gnome menu, created through the macros in
* gnome-app-helper. */
void
gnc_gnome_app_insert_menus (GnomeApp *app, const gchar *path,
GnomeUIInfo *menuinfo);
/* This is called from the window initializing code, when the actual /* This is called from the window initializing code, when the actual
* menu items stored by the above functions should now be inserted in * menu items stored by the above functions should now be inserted in
* the menu of the GnomeApp app. * the menu of the GnomeApp app.

View File

@ -42,6 +42,7 @@
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-gui-query.h" #include "gnc-gui-query.h"
#include "gnc-html.h" #include "gnc-html.h"
#include "gnc-menu-extensions.h"
#include "gnc-split-reg.h" #include "gnc-split-reg.h"
#include "gnc-ui.h" #include "gnc-ui.h"
#include "gtkselect.h" #include "gtkselect.h"
@ -1356,16 +1357,16 @@ gnc_acct_tree_tweak_menu (GNCMDIChildInfo * mc)
* menus and toolbars. What a pain. * menus and toolbars. What a pain.
*/ */
/* Do not i18n these strings!!! */ /* Do not i18n these strings!!! */
if (gnc_mdi_child_find_menu_item(mc, "File/_New Account...")) if (gnc_mdi_child_find_menu_item(mc, "_File/_New Account..."))
return; return;
/* Do not i18n these strings!!! */ /* Do not i18n these strings!!! */
dup_scrub[0].user_data = info; dup_scrub[0].user_data = info;
dup_scrub[1].user_data = info; dup_scrub[1].user_data = info;
dup_scrub[2].user_data = info; dup_scrub[2].user_data = info;
gnome_app_insert_menus (mc->app, "File/_New File", fileitems1); gnc_gnome_app_insert_menus (mc->app, "_File/_New File", fileitems1);
gnome_app_insert_menus (mc->app, "File/Open...", fileitems2); gnc_gnome_app_insert_menus (mc->app, "_File/_Open...", fileitems2);
gnome_app_insert_menus (mc->app, "Edit/Paste", edititems); gnc_gnome_app_insert_menus (mc->app, "_Edit/_Paste", edititems);
gnome_app_insert_menus (mc->app, "_Actions/_Scheduled Transactions", gnome_app_insert_menus (mc->app, "_Actions/_Scheduled Transactions",
actionitems); actionitems);
@ -1385,7 +1386,7 @@ gnc_acct_tree_tweak_menu (GNCMDIChildInfo * mc)
gnc_acct_tree_window_add_sensitive(win, widget); gnc_acct_tree_window_add_sensitive(win, widget);
/* Do not i18n these strings!!! */ /* Do not i18n these strings!!! */
gnc_mdi_child_auto_menu(mc, GNC_AUTO_DISABLE, "File/Close", NULL); gnc_mdi_child_auto_menu(mc, GNC_AUTO_DISABLE, "_File/_Close", NULL);
gnc_mdi_child_auto_toolbar(mc, GNC_AUTO_DISABLE, "Close", NULL); gnc_mdi_child_auto_toolbar(mc, GNC_AUTO_DISABLE, "Close", NULL);
/* Start with all the 'sensitives' disabled. */ /* Start with all the 'sensitives' disabled. */

View File

@ -269,13 +269,13 @@ gnc_main_window_tweak_menus(GNCMDIChildInfo * mc)
{ {
GtkWidget *widget; GtkWidget *widget;
widget = gnc_mdi_child_find_menu_item(mc, "View/_Toolbar"); widget = gnc_mdi_child_find_menu_item(mc, "_View/_Toolbar");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE);
widget = gnc_mdi_child_find_menu_item(mc, "View/_Status Bar"); widget = gnc_mdi_child_find_menu_item(mc, "_View/_Status Bar");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE);
widget = gnc_mdi_child_find_menu_item(mc, "View/S_ummary Bar"); widget = gnc_mdi_child_find_menu_item(mc, "_View/S_ummary Bar");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE);
mc->gnc_mdi->menu_tweaking = NULL; mc->gnc_mdi->menu_tweaking = NULL;

View File

@ -474,7 +474,7 @@ string and 'directories' must be a list of strings."
(gnc:make-menu-item (gnc:make-menu-item
(N_ "_Style Sheets...") (N_ "_Style Sheets...")
(N_ "Edit report style sheets.") (N_ "Edit report style sheets.")
(list gnc:window-name-main "Edit" "_Preferences...") (list gnc:window-name-main "_Edit" "_Preferences...")
(lambda () (lambda ()
(gnc:style-sheet-dialog-open)))) (gnc:style-sheet-dialog-open))))