Make gtk-im-context-none work

This was added a few years ago, as a way to have _no_ im context
at all. But it didn't actually work. Make it work, and streamline
the handling of none by moving it all to gtkimmodule.c.

As part of this, add context to the translated names of all
im modules we ship.
This commit is contained in:
Matthias Clasen 2015-02-23 22:00:55 -05:00
parent aba2de3443
commit b0b38c106d
16 changed files with 62 additions and 53 deletions

View File

@ -65,6 +65,7 @@
#include "deprecated/gtkrc.h"
#define SIMPLE_ID "gtk-im-context-simple"
#define NONE_ID "gtk-im-context-none"
/**
* GtkIMContextInfo:
@ -520,7 +521,7 @@ compare_gtkimcontextinfo_name(const GtkIMContextInfo **a,
* The structures it points are statically allocated and should
* not be modified or freed.
* @n_contexts: the length of the array stored in @contexts
*
*
* List all available types of input method context
*/
void
@ -535,7 +536,23 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
#endif
GtkIMContextInfo simple_context_info = {
SIMPLE_ID,
N_("Simple"),
NC_("input method menu", "Simple"),
GETTEXT_PACKAGE,
#ifdef GTK_LOCALEDIR
GTK_LOCALEDIR,
#else
"",
#endif
""
};
static
#ifndef G_OS_WIN32
const
#endif
GtkIMContextInfo none_context_info = {
NONE_ID,
NC_("input method menu", "None"),
GETTEXT_PACKAGE,
#ifdef GTK_LOCALEDIR
GTK_LOCALEDIR,
@ -561,19 +578,22 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
*/
simple_context_info.domain_dirname = g_strdup (simple_context_info.domain_dirname);
correct_localedir_prefix ((char **) &simple_context_info.domain_dirname);
none_context_info.domain_dirname = g_strdup (none_context_info.domain_dirname);
correct_localedir_prefix ((char **) &none_context_info.domain_dirname);
}
#endif
if (n_contexts)
*n_contexts = (n_loaded_contexts + 1);
*n_contexts = n_loaded_contexts + 2;
if (contexts)
{
GSList *tmp_list;
int i;
*contexts = g_new (const GtkIMContextInfo *, n_loaded_contexts + 1);
*contexts = g_new (const GtkIMContextInfo *, n_loaded_contexts + 2);
(*contexts)[n++] = &none_context_info;
(*contexts)[n++] = &simple_context_info;
tmp_list = modules_list;
@ -583,12 +603,12 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
for (i=0; i<module->n_contexts; i++)
(*contexts)[n++] = module->contexts[i];
tmp_list = tmp_list->next;
}
/* fisrt element (Default) should always be at top */
qsort ((*contexts)+1, n-1, sizeof (GtkIMContextInfo *), (GCompareFunc)compare_gtkimcontextinfo_name);
/* first elements (Simple and None) should always be at top */
qsort ((*contexts)+2, n-2, sizeof (GtkIMContextInfo *), (GCompareFunc)compare_gtkimcontextinfo_name);
}
}
@ -607,7 +627,10 @@ _gtk_im_module_create (const gchar *context_id)
{
GtkIMModule *im_module;
GtkIMContext *context = NULL;
if (strcmp (context_id, NONE_ID) == 0)
return NULL;
if (!contexts_hash)
gtk_im_module_initialize ();
@ -625,12 +648,12 @@ _gtk_im_module_create (const gchar *context_id)
context = im_module->create (context_id);
g_type_module_unuse (G_TYPE_MODULE (im_module));
}
if (!context)
g_warning ("Loading IM context type '%s' failed", context_id);
}
}
if (!context)
return gtk_im_context_simple_new ();
else
@ -694,6 +717,8 @@ lookup_immodule (gchar **immodules_list)
{
if (g_strcmp0 (*immodules_list, SIMPLE_ID) == 0)
return SIMPLE_ID;
else if (g_strcmp0 (*immodules_list, NONE_ID) == 0)
return NONE_ID;
else
{
gboolean found;

View File

@ -38,8 +38,6 @@
*/
#define NONE_ID "gtk-im-context-none"
struct _GtkIMMulticontextPrivate
{
GtkIMContext *slave;
@ -274,12 +272,12 @@ gtk_im_multicontext_get_slave (GtkIMMulticontext *multicontext)
priv->context_id = g_strdup (get_effective_context_id (multicontext));
if (g_strcmp0 (priv->context_id, NONE_ID) == 0)
return NULL;
slave = _gtk_im_module_create (priv->context_id);
gtk_im_multicontext_set_slave (multicontext, slave, FALSE);
g_object_unref (slave);
if (slave)
{
gtk_im_multicontext_set_slave (multicontext, slave, FALSE);
g_object_unref (slave);
}
}
return priv->slave;
@ -618,19 +616,6 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
gtk_widget_show (menuitem);
gtk_menu_shell_append (menushell, menuitem);
menuitem = gtk_radio_menu_item_new_with_label (group, C_("input method menu", "None"));
if (g_strcmp0 (priv->context_id_aux, NONE_ID) == 0)
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
g_object_set_data (G_OBJECT (menuitem), I_("gtk-context-id"), NONE_ID);
g_signal_connect (menuitem, "activate", G_CALLBACK (activate_cb), context);
gtk_widget_show (menuitem);
gtk_menu_shell_append (menushell, menuitem);
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
menuitem = gtk_separator_menu_item_new ();
gtk_widget_show (menuitem);
gtk_menu_shell_append (menushell, menuitem);
_gtk_im_module_list (&contexts, &n_contexts);
for (i = 0; i < n_contexts; i++)
@ -649,7 +634,7 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
* GTK+. Input method may have a name in the GTK+
* message catalog.
*/
translated_name = _(contexts[i]->context_name);
translated_name = C_("input method menu", contexts[i]->context_name);
}
else
{
@ -688,9 +673,8 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
#else
translated_name = contexts[i]->context_name;
#endif
menuitem = gtk_radio_menu_item_new_with_label (group,
translated_name);
menuitem = gtk_radio_menu_item_new_with_label (group, translated_name);
if ((priv->context_id_aux &&
strcmp (contexts[i]->context_id, priv->context_id_aux) == 0))
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
@ -704,10 +688,10 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
text = g_strdup_printf (C_("input method menu", "System (%s)"), translated_name);
gtk_label_set_text (GTK_LABEL (label), text);
g_free (text);
}
}
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
g_object_set_data (G_OBJECT (menuitem), I_("gtk-context-id"),
(char *)contexts[i]->context_id);
g_signal_connect (menuitem, "activate",

View File

@ -449,7 +449,7 @@ am_et_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo am_et_info = {
"am_et", /* ID */
N_("Amharic (EZ+)"), /* Human readable name */
NC_("input method menu", "Amharic (EZ+)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"am" /* Languages for which this module is the default */

View File

@ -48,7 +48,7 @@ static GObjectClass *parent_class;
static const GtkIMContextInfo imbroadway_info =
{
"broadway", /* ID */
"Broadway", /* Human readable name */
NC_("input method menu", "Broadway"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"", /* Languages for which this module is the default */

View File

@ -87,7 +87,7 @@ cedilla_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo cedilla_info = {
"cedilla", /* ID */
N_("Cedilla"), /* Human readable name */
NC_("input method menu", "Cedilla"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain */
"az:ca:co:fr:gv:oc:pt:sq:tr:wa" /* Languages for which this module is the default */

View File

@ -212,7 +212,7 @@ cyrillic_translit_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo cyrillic_translit_info = {
"cyrillic_translit", /* ID */
N_("Cyrillic (Transliterated)"), /* Human readable name */
NC_("input menthod menu", "Cyrillic (Transliterated)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"" /* Languages for which this module is the default */

View File

@ -27,8 +27,8 @@
static const GtkIMContextInfo ime_info = {
"ime",
"Windows IME",
"gtk+",
NC_("input method menu", "Windows IME"),
GETTEXT_PACKAGE,
"",
"ja:ko:zh",
};

View File

@ -122,7 +122,7 @@ inuktitut_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo inuktitut_info = {
"inuktitut", /* ID */
N_("Inuktitut (Transliterated)"), /* Human readable name */
NC_("input method menu", "Inuktitut (Transliterated)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"iu" /* Languages for which this module is the default */

View File

@ -140,7 +140,7 @@ ipa_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo ipa_info = {
"ipa", /* ID */
N_("IPA"), /* Human readable name */
NC_("input method menu", "IPA"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"" /* Languages for which this module is the default */

View File

@ -27,7 +27,7 @@
*/
static const GtkIMContextInfo info = {
CONTEXT_ID, /* ID */
N_("Multipress"), /* Human readable name */
NC_("input method menu", "Multipress"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain. Defined in configure.ac */
MULTIPRESS_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+"). Defined in the Makefile.am */
"" /* Languages for which this module is the default */

View File

@ -55,7 +55,7 @@ static GObjectClass *parent_class;
static const GtkIMContextInfo imquartz_info =
{
"quartz",
"Mac OS X Quartz",
NC_("input method menu", "Mac OS X Quartz"),
GETTEXT_PACKAGE,
GTK_LOCALEDIR,
"ja:ko:zh:*",

View File

@ -30,7 +30,7 @@ GType type_thai = 0;
static const GtkIMContextInfo thai_info = {
"thai", /* ID */
N_("Thai-Lao"), /* Human readable name */
NC_("input method menu", "Thai-Lao"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"lo:th" /* Languages for which this module is the default */

View File

@ -448,7 +448,7 @@ ti_er_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo ti_er_info = {
"ti_er", /* ID */
N_("Tigrigna-Eritrean (EZ+)"), /* Human readable name */
NC_("input method menu", "Tigrigna-Eritrean (EZ+)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"ti" /* Languages for which this module is the default */

View File

@ -448,7 +448,7 @@ ti_et_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo ti_et_info = {
"ti_et", /* ID */
N_("Tigrigna-Ethiopian (EZ+)"), /* Human readable name */
NC_("input method menu", "Tigrigna-Ethiopian (EZ+)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"ti" /* Languages for which this module is the default */

View File

@ -239,7 +239,7 @@ viqr_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo viqr_info = {
"viqr", /* ID */
N_("Vietnamese (VIQR)"), /* Human readable name */
NC_("input method menu", "Vietnamese (VIQR)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"vi" /* Languages for which this module is the default */

View File

@ -23,7 +23,7 @@
static const GtkIMContextInfo xim_ja_info = {
"xim", /* ID */
N_("X Input Method"), /* Human readable name */
NC_("input method menu", "X Input Method"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"ko:ja:th:zh" /* Languages for which this module is the default */