mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 06:10:21 +00:00
builder: Improve type name mangling
When looking for the get_type function for GThemedIcon, try both g_themed_icon_get_type and gthemed_icon_get_type The former is what gio has, the latter is still supported to avoid breaking gweather_location_get_type. Update tests to cover this new case.
This commit is contained in:
parent
e4fb4116fd
commit
47285c6642
@ -187,12 +187,14 @@ gtk_builder_cscope_get_module (GtkBuilderCScope *self)
|
||||
* GtkWindow -> gtk_window_get_type
|
||||
* GtkHBox -> gtk_hbox_get_type
|
||||
* GtkUIManager -> gtk_ui_manager_get_type
|
||||
* GWeatherLocation -> gweather_location_get_type
|
||||
* GWeatherLocation -> gweather_location_get_type (split_first_cap == FALSE)
|
||||
* GThemedIcon -> g_themed_icon_get_type (slit_first_cap == TRUE)
|
||||
*
|
||||
* Keep in sync with testsuite/gtk/typename.c !
|
||||
*/
|
||||
static gchar *
|
||||
type_name_mangle (const gchar *name)
|
||||
type_name_mangle (const gchar *name,
|
||||
gboolean split_first_cap)
|
||||
{
|
||||
GString *symbol_name = g_string_new ("");
|
||||
gint i;
|
||||
@ -201,8 +203,9 @@ type_name_mangle (const gchar *name)
|
||||
{
|
||||
/* skip if uppercase, first or previous is uppercase */
|
||||
if ((name[i] == g_ascii_toupper (name[i]) &&
|
||||
i > 0 && name[i-1] != g_ascii_toupper (name[i-1])) ||
|
||||
(i > 2 && name[i] == g_ascii_toupper (name[i]) &&
|
||||
((i > 0 && name[i-1] != g_ascii_toupper (name[i-1])) ||
|
||||
(i == 1 && name[0] == g_ascii_toupper (name[0]) && split_first_cap))) ||
|
||||
(i > 2 && name[i] == g_ascii_toupper (name[i]) &&
|
||||
name[i-1] == g_ascii_toupper (name[i-1]) &&
|
||||
name[i-2] == g_ascii_toupper (name[i-2])))
|
||||
g_string_append_c (symbol_name, '_');
|
||||
@ -219,14 +222,21 @@ gtk_builder_cscope_resolve_type_lazily (GtkBuilderCScope *self,
|
||||
{
|
||||
GModule *module;
|
||||
GType (*func) (void);
|
||||
gchar *symbol;
|
||||
char *symbol;
|
||||
GType gtype = G_TYPE_INVALID;
|
||||
|
||||
module = gtk_builder_cscope_get_module (self);
|
||||
if (!module)
|
||||
return G_TYPE_INVALID;
|
||||
|
||||
symbol = type_name_mangle (name);
|
||||
symbol = type_name_mangle (name, TRUE);
|
||||
|
||||
if (g_module_symbol (module, symbol, (gpointer)&func))
|
||||
gtype = func ();
|
||||
|
||||
g_free (symbol);
|
||||
|
||||
symbol = type_name_mangle (name, FALSE);
|
||||
|
||||
if (g_module_symbol (module, symbol, (gpointer)&func))
|
||||
gtype = func ();
|
||||
|
@ -20,7 +20,8 @@
|
||||
|
||||
/* Keep in sync with gtkbuilder.c ! */
|
||||
static gchar *
|
||||
type_name_mangle (const gchar *name)
|
||||
type_name_mangle (const gchar *name,
|
||||
gboolean split_first_cap)
|
||||
{
|
||||
GString *symbol_name = g_string_new ("");
|
||||
gint i;
|
||||
@ -29,8 +30,9 @@ type_name_mangle (const gchar *name)
|
||||
{
|
||||
/* skip if uppercase, first or previous is uppercase */
|
||||
if ((name[i] == g_ascii_toupper (name[i]) &&
|
||||
i > 0 && name[i-1] != g_ascii_toupper (name[i-1])) ||
|
||||
(i > 2 && name[i] == g_ascii_toupper (name[i]) &&
|
||||
((i > 0 && name[i-1] != g_ascii_toupper (name[i-1])) ||
|
||||
(i == 1 && name[0] == g_ascii_toupper (name[0]) && split_first_cap))) ||
|
||||
(i > 2 && name[i] == g_ascii_toupper (name[i]) &&
|
||||
name[i-1] == g_ascii_toupper (name[i-1]) &&
|
||||
name[i-2] == g_ascii_toupper (name[i-2])))
|
||||
g_string_append_c (symbol_name, '_');
|
||||
@ -42,22 +44,27 @@ type_name_mangle (const gchar *name)
|
||||
}
|
||||
|
||||
static void
|
||||
check (const gchar *TN, const gchar *gtf)
|
||||
check (const gchar *TN, const gchar *gtf, const char *gtf_splitcap)
|
||||
{
|
||||
gchar *symbol;
|
||||
|
||||
symbol = type_name_mangle (TN);
|
||||
symbol = type_name_mangle (TN, FALSE);
|
||||
g_assert_cmpstr (symbol, ==, gtf);
|
||||
g_free (symbol);
|
||||
|
||||
symbol = type_name_mangle (TN, TRUE);
|
||||
g_assert_cmpstr (symbol, ==, gtf_splitcap ? gtf_splitcap : gtf);
|
||||
g_free (symbol);
|
||||
}
|
||||
|
||||
static void test_GtkWindow (void) { check ("GtkWindow", "gtk_window_get_type"); }
|
||||
static void test_GtkHBox (void) { check ("GtkHBox", "gtk_hbox_get_type"); }
|
||||
static void test_GtkUIManager (void) { check ("GtkUIManager", "gtk_ui_manager_get_type"); }
|
||||
static void test_GtkCList (void) { check ("GtkCList", "gtk_clist_get_type"); }
|
||||
static void test_GtkIMContext (void) { check ("GtkIMContext", "gtk_im_context_get_type"); }
|
||||
static void test_Me2Shell (void) { check ("Me2Shell", "me_2shell_get_type"); }
|
||||
static void test_GWeather (void) { check ("GWeatherLocation", "gweather_location_get_type"); }
|
||||
static void test_GtkWindow (void) { check ("GtkWindow", "gtk_window_get_type", NULL); }
|
||||
static void test_GtkHBox (void) { check ("GtkHBox", "gtk_hbox_get_type", NULL); }
|
||||
static void test_GtkUIManager (void) { check ("GtkUIManager", "gtk_ui_manager_get_type", NULL); }
|
||||
static void test_GtkCList (void) { check ("GtkCList", "gtk_clist_get_type", NULL); }
|
||||
static void test_GtkIMContext (void) { check ("GtkIMContext", "gtk_im_context_get_type", NULL); }
|
||||
static void test_Me2Shell (void) { check ("Me2Shell", "me_2shell_get_type", NULL); }
|
||||
static void test_GWeather (void) { check ("GWeatherLocation", "gweather_location_get_type", "g_weather_location_get_type"); }
|
||||
static void test_GThemedIcon (void) { check ("GThemedIcon", "gthemed_icon_get_type", "g_themed_icon_get_type"); }
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
@ -71,6 +78,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/builder/get-type/GtkIMContext", test_GtkIMContext);
|
||||
g_test_add_func ("/builder/get-type/Me2Shell", test_Me2Shell);
|
||||
g_test_add_func ("/builder/get-type/GWeather", test_GWeather);
|
||||
g_test_add_func ("/builder/get-type/GThemedIcon", test_GThemedIcon);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user