Load font with CSS

Avoid use deprecated method to update font

Co-authored-by: Adwait Rawat <adwait.rawat@gmail.com>
Co-authored-by: Gaurav Agrawal <agrawalgaurav1999@gmail.com>
This commit is contained in:
Adwait Rawat 2019-03-08 00:52:56 +01:00 committed by Gaurav Agrawal
parent ab89872e1b
commit 96f3fada79
9 changed files with 77 additions and 10 deletions

View file

@ -81,6 +81,7 @@ class Dialog : Gtk.Dialog
private GtkSpell.Checker? d_spell_checker;
private Ggit.Diff d_diff;
private bool d_infobar_shown;
private Gtk.CssProvider css_provider;
public Ggit.Diff? diff
{
@ -411,6 +412,8 @@ class Dialog : Gtk.Dialog
construct
{
d_font_settings = new Settings("org.gnome.desktop.interface");
css_provider = new Gtk.CssProvider();
d_source_view_message.get_style_context().add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_SETTINGS);
update_font_settings();
@ -785,10 +788,17 @@ class Dialog : Gtk.Dialog
private void update_font_settings()
{
var mfont = d_font_settings.get_string("monospace-font-name");
var desc = Pango.FontDescription.from_string(mfont);
d_source_view_message.override_font(desc);
var fname = d_font_settings.get_string("monospace-font-name");
var font_desc = Pango.FontDescription.from_string(fname);
var css = "textview { %s }".printf(Dazzle.pango_font_description_to_css(font_desc));
try
{
css_provider.load_from_data(css);
}
catch(Error e)
{
warning("Error applying font: %s", e.message);
}
}
public void show_infobar(string primary_msg,

View file

@ -38,10 +38,13 @@ class CreateTagDialog : Gtk.Dialog
private Gtk.TextTag d_info_tag;
private bool d_is_showing_user_info;
private Settings d_font_settings;
private Gtk.CssProvider css_provider;
construct
{
d_font_settings = new Settings("org.gnome.desktop.interface");
css_provider = new Gtk.CssProvider();
d_text_view_message.get_style_context().add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_SETTINGS);
update_font_settings();
@ -87,10 +90,17 @@ class CreateTagDialog : Gtk.Dialog
private void update_font_settings()
{
var mfont = d_font_settings.get_string("monospace-font-name");
var desc = Pango.FontDescription.from_string(mfont);
d_text_view_message.override_font(desc);
var fname = d_font_settings.get_string("monospace-font-name");
var font_desc = Pango.FontDescription.from_string(fname);
var css = "textview { %s }".printf(Dazzle.pango_font_description_to_css(font_desc));
try
{
css_provider.load_from_data(css);
}
catch(Error e)
{
warning("Error applying font: %s", e.message);
}
}
private void show_user_info()

View file

@ -60,6 +60,7 @@ deps = [
gtkspell_dep,
libgitg_ext_dep,
libpeas_dep,
libdazzle_dep,
]
cflags = warn_flags + [

View file

@ -54,6 +54,7 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
private Gtk.SourceBuffer? d_new_highlight_buffer;
private bool d_old_highlight_ready;
private bool d_new_highlight_ready;
private Gtk.CssProvider css_provider;
private Region[] d_regions;
private bool d_constructed;
@ -199,6 +200,9 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
var settings = Gtk.Settings.get_default();
settings.notify["gtk-application-prefer-dark-theme"].connect(update_theme);
css_provider = new Gtk.CssProvider();
get_style_context().add_provider(css_provider,Gtk.STYLE_PROVIDER_PRIORITY_SETTINGS);
update_theme();
if (can_select)
@ -456,7 +460,16 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
private void update_font()
{
var fname = d_fontsettings.get_string("monospace-font-name");
this.override_font(Pango.FontDescription.from_string(fname));
var font_desc = Pango.FontDescription.from_string(fname);
var css = "textview{%s}".printf(Dazzle.pango_font_description_to_css(font_desc));
try
{
css_provider.load_from_data(css);
}
catch(Error e)
{
warning("Error applying font: %s", e.message);
}
}
private Settings? try_settings(string schema_id)

View file

@ -13,6 +13,7 @@ common_deps = [
glib_dep,
gtk_dep,
libgit2_glib_dep,
libdazzle_dep,
]
sources = files(

View file

@ -137,6 +137,7 @@ libpeas_dep = dependency('libpeas-1.0')
libsecret_dep = dependency('libsecret-1')
libsoup_dep = dependency('libsoup-2.4')
libxml_dep = dependency('libxml-2.0', version: '>= 2.9.0')
libdazzle_dep = dependency('libdazzle-1.0')
config_dep = valac.find_library('config', dirs: vapi_dir)
gitg_platform_support_dep = valac.find_library('gitg-platform-support', dirs: vapi_dir)

View file

@ -143,6 +143,24 @@
}
]
},
{
"name" : "libdazzle",
"config-opt" : [
"--prefix=/opt/gnome",
"--libdir=/opt/gnome/lib"
],
"buildsystem" : "meson",
"builddir" : true,
"cleanup" : [
"/bin"
],
"sources" : [
{
"type" : "git",
"url" : "https://gitlab.gnome.org/GNOME/libdazzle.git"
}
]
},
{
"name" : "gitg",
"buildsystem" : "meson",

View file

@ -39,6 +39,7 @@ namespace GitgFiles
private Gtk.Viewport d_imagevp;
private Gtk.Image d_image;
private Gtk.CssProvider css_provider;
private Gitg.WhenMapped d_whenMapped;
construct
@ -87,7 +88,16 @@ namespace GitgFiles
private void update_font()
{
var fname = d_fontsettings.get_string("monospace-font-name");
d_source.override_font(Pango.FontDescription.from_string(fname));
var font_desc = Pango.FontDescription.from_string(fname);
var css = "textview { %s }".printf(Dazzle.pango_font_description_to_css(font_desc));
try
{
css_provider.load_from_data(css);
}
catch(Error e)
{
warning("Error applying font. %s", e.message);
}
}
private void update_style()
@ -139,6 +149,8 @@ namespace GitgFiles
d_paned = ret["paned_files"] as Gtk.Paned;
d_scrolled = ret["scrolled_window_file"] as Gtk.ScrolledWindow;
css_provider = new Gtk.CssProvider();
d_source.get_style_context().add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_SETTINGS);
d_imagevp = new Gtk.Viewport(null, null);
d_image = new Gtk.Image();
d_imagevp.add(d_image);

View file

@ -12,6 +12,7 @@ plugin_deps = [
libgitg_dep,
libgitg_ext_dep,
libpeas_dep,
libdazzle_dep,
]
plugin_dir = join_paths(gitg_pkglibdir, 'plugins')