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" #include "deprecated/gtkrc.h"
#define SIMPLE_ID "gtk-im-context-simple" #define SIMPLE_ID "gtk-im-context-simple"
#define NONE_ID "gtk-im-context-none"
/** /**
* GtkIMContextInfo: * GtkIMContextInfo:
@ -535,7 +536,23 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
#endif #endif
GtkIMContextInfo simple_context_info = { GtkIMContextInfo simple_context_info = {
SIMPLE_ID, 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, GETTEXT_PACKAGE,
#ifdef GTK_LOCALEDIR #ifdef GTK_LOCALEDIR
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); simple_context_info.domain_dirname = g_strdup (simple_context_info.domain_dirname);
correct_localedir_prefix ((char **) &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 #endif
if (n_contexts) if (n_contexts)
*n_contexts = (n_loaded_contexts + 1); *n_contexts = n_loaded_contexts + 2;
if (contexts) if (contexts)
{ {
GSList *tmp_list; GSList *tmp_list;
int i; 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; (*contexts)[n++] = &simple_context_info;
tmp_list = modules_list; tmp_list = modules_list;
@ -587,8 +607,8 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
tmp_list = tmp_list->next; tmp_list = tmp_list->next;
} }
/* fisrt element (Default) should always be at top */ /* first elements (Simple and None) should always be at top */
qsort ((*contexts)+1, n-1, sizeof (GtkIMContextInfo *), (GCompareFunc)compare_gtkimcontextinfo_name); qsort ((*contexts)+2, n-2, sizeof (GtkIMContextInfo *), (GCompareFunc)compare_gtkimcontextinfo_name);
} }
} }
@ -608,6 +628,9 @@ _gtk_im_module_create (const gchar *context_id)
GtkIMModule *im_module; GtkIMModule *im_module;
GtkIMContext *context = NULL; GtkIMContext *context = NULL;
if (strcmp (context_id, NONE_ID) == 0)
return NULL;
if (!contexts_hash) if (!contexts_hash)
gtk_im_module_initialize (); gtk_im_module_initialize ();
@ -694,6 +717,8 @@ lookup_immodule (gchar **immodules_list)
{ {
if (g_strcmp0 (*immodules_list, SIMPLE_ID) == 0) if (g_strcmp0 (*immodules_list, SIMPLE_ID) == 0)
return SIMPLE_ID; return SIMPLE_ID;
else if (g_strcmp0 (*immodules_list, NONE_ID) == 0)
return NONE_ID;
else else
{ {
gboolean found; gboolean found;

View File

@ -38,8 +38,6 @@
*/ */
#define NONE_ID "gtk-im-context-none"
struct _GtkIMMulticontextPrivate struct _GtkIMMulticontextPrivate
{ {
GtkIMContext *slave; GtkIMContext *slave;
@ -274,13 +272,13 @@ gtk_im_multicontext_get_slave (GtkIMMulticontext *multicontext)
priv->context_id = g_strdup (get_effective_context_id (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); slave = _gtk_im_module_create (priv->context_id);
if (slave)
{
gtk_im_multicontext_set_slave (multicontext, slave, FALSE); gtk_im_multicontext_set_slave (multicontext, slave, FALSE);
g_object_unref (slave); g_object_unref (slave);
} }
}
return priv->slave; return priv->slave;
} }
@ -618,19 +616,6 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
gtk_widget_show (menuitem); gtk_widget_show (menuitem);
gtk_menu_shell_append (menushell, 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); _gtk_im_module_list (&contexts, &n_contexts);
for (i = 0; i < n_contexts; i++) 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+ * GTK+. Input method may have a name in the GTK+
* message catalog. * message catalog.
*/ */
translated_name = _(contexts[i]->context_name); translated_name = C_("input method menu", contexts[i]->context_name);
} }
else else
{ {
@ -688,8 +673,7 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
#else #else
translated_name = contexts[i]->context_name; translated_name = contexts[i]->context_name;
#endif #endif
menuitem = gtk_radio_menu_item_new_with_label (group, menuitem = gtk_radio_menu_item_new_with_label (group, translated_name);
translated_name);
if ((priv->context_id_aux && if ((priv->context_id_aux &&
strcmp (contexts[i]->context_id, priv->context_id_aux) == 0)) strcmp (contexts[i]->context_id, priv->context_id_aux) == 0))

View File

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

View File

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

View File

@ -87,7 +87,7 @@ cedilla_init (GtkIMContextSimple *im_context)
static const GtkIMContextInfo cedilla_info = { static const GtkIMContextInfo cedilla_info = {
"cedilla", /* ID */ "cedilla", /* ID */
N_("Cedilla"), /* Human readable name */ NC_("input method menu", "Cedilla"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */ GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain */ GTK_LOCALEDIR, /* Dir for bindtextdomain */
"az:ca:co:fr:gv:oc:pt:sq:tr:wa" /* Languages for which this module is the default */ "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 = { static const GtkIMContextInfo cyrillic_translit_info = {
"cyrillic_translit", /* ID */ "cyrillic_translit", /* ID */
N_("Cyrillic (Transliterated)"), /* Human readable name */ NC_("input menthod menu", "Cyrillic (Transliterated)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */ GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */ GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"" /* Languages for which this module is the default */ "" /* Languages for which this module is the default */

View File

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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,7 @@ GType type_thai = 0;
static const GtkIMContextInfo thai_info = { static const GtkIMContextInfo thai_info = {
"thai", /* ID */ "thai", /* ID */
N_("Thai-Lao"), /* Human readable name */ NC_("input method menu", "Thai-Lao"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */ GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */ GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"lo:th" /* Languages for which this module is the default */ "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 = { static const GtkIMContextInfo ti_er_info = {
"ti_er", /* ID */ "ti_er", /* ID */
N_("Tigrigna-Eritrean (EZ+)"), /* Human readable name */ NC_("input method menu", "Tigrigna-Eritrean (EZ+)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */ GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */ GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"ti" /* Languages for which this module is the default */ "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 = { static const GtkIMContextInfo ti_et_info = {
"ti_et", /* ID */ "ti_et", /* ID */
N_("Tigrigna-Ethiopian (EZ+)"), /* Human readable name */ NC_("input method menu", "Tigrigna-Ethiopian (EZ+)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */ GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */ GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"ti" /* Languages for which this module is the default */ "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 = { static const GtkIMContextInfo viqr_info = {
"viqr", /* ID */ "viqr", /* ID */
N_("Vietnamese (VIQR)"), /* Human readable name */ NC_("input method menu", "Vietnamese (VIQR)"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */ GETTEXT_PACKAGE, /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */ GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"vi" /* Languages for which this module is the default */ "vi" /* Languages for which this module is the default */

View File

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