Skip to content
Permalink
Browse files

pluma-view: sync the font in context-menu with gsettings key

  • Loading branch information...
sc0w authored and raveit65 committed Jul 23, 2018
1 parent f952be3 commit b2ca8c4cb34f8efae18d4849eb25369c6a6b935b
Showing with 45 additions and 12 deletions.
  1. +41 −12 pluma/pluma-view.c
  2. +4 −0 pluma/pluma-view.h
@@ -648,24 +648,39 @@ pluma_view_scroll_to_cursor (PlumaView *view)

static PangoFontDescription* get_system_font (void)
{
PangoFontDescription *desc = NULL;
GSettings *settings;
char *name;
PangoFontDescription *desc = NULL;
GSettings *settings;
char *name;

settings = g_settings_new ("org.mate.interface");
name = g_settings_get_string (settings, "font-name");
settings = g_settings_new ("org.mate.interface");
name = g_settings_get_string (settings, "font-name");

if (name) {
desc = pango_font_description_from_string (name);
g_free (name);
}
if (name)
{
desc = pango_font_description_from_string (name);
g_free (name);
}

g_object_unref (settings);
g_object_unref (settings);

return desc;
return desc;
}

static void
contextmenu_font_changed_cb (GSettings *settings,
gchar *key,
gpointer user_data)
{
PangoFontDescription *sys_font_desc = NULL;
sys_font_desc = get_system_font ();
if (sys_font_desc)
{
pluma_override_font (".context-menu", GTK_WIDGET (user_data), sys_font_desc);
pango_font_description_free (sys_font_desc);
}
}

void
pluma_override_font (const gchar *item,
GtkWidget *widget,
PangoFontDescription *font)
@@ -699,13 +714,27 @@ pluma_override_font (const gchar *item,
prov_str = gtk_css_provider_to_string (provider);

if (g_str_has_prefix (prov_str, "textview") && g_str_has_prefix (item, ".context-menu"))
{
if (strstr (prov_str, ".context-menu"))
{
prov_str = g_strdelimit (prov_str, "}", '\0');
prov_str = g_strdup_printf ("%s}", prov_str);
}
css = g_strdup_printf ("%s %s { %s %s %s %s }", prov_str, item, family, weight, style, size);
}
else
css = g_strdup_printf ("%s { %s %s %s %s }", item, family, weight, style, size);

gtk_css_provider_load_from_data (provider, css, -1, NULL);

if (!provider_added) {
if (!provider_added)
{
GSettings *settings;
settings = g_settings_new ("org.mate.interface");
g_signal_connect (settings,
"changed::" "font-name",
G_CALLBACK (contextmenu_font_changed_cb), NULL);

gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (widget),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
@@ -99,6 +99,10 @@ void pluma_view_select_all (PlumaView *view);

void pluma_view_scroll_to_cursor (PlumaView *view);

void pluma_override_font (const gchar *item,
GtkWidget *widget,
PangoFontDescription *font);

void pluma_view_set_font (PlumaView *view,
gboolean def,
const gchar *font_name);

0 comments on commit b2ca8c4

Please sign in to comment.
You can’t perform that action at this time.