Use embedded resources in CssProvider.LoadFromResource (#238)

This commit is contained in:
zii-dmg 2021-04-22 17:50:39 +03:00 committed by GitHub
parent c81830ad50
commit aa1095a02d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,27 @@
namespace Gtk
{
using System;
using System.IO;
using System.Reflection;
public partial class CssProvider
{
public bool LoadFromResource(string resource) => LoadFromResource(Assembly.GetCallingAssembly(), resource);
public bool LoadFromResource(Assembly assembly, string resource)
{
if (assembly == null)
assembly = Assembly.GetCallingAssembly();
Stream stream = assembly.GetManifestResourceStream(resource);
if (stream == null)
throw new ArgumentException("'" + resource + "' is not a valid resource name of assembly '" + assembly + "'.", nameof(resource));
using (var reader = new StreamReader(stream))
{
string data = reader.ReadToEnd();
return LoadFromData(data);
}
}
}
}

View file

@ -1017,6 +1017,8 @@
<attr path="/api/namespace/object[@cname='GtkIconInfo']/method[@name='LoadSymbolicAsync']/*/*[@name='callback']" name="scope">async</attr>
<attr path="/api/namespace/object[@cname='GtkIconInfo']/method[@name='LoadSymbolicForContextAsync']/*/*[@name='callback']" name="scope">async</attr>
<attr path="/api/namespace/object[@cname='GtkCssProvider']/method[@name='LoadFromResource']" name="hidden">1</attr>
<!-- Mark reserved fields as padding -->
<attr path="//*[contains(@cname, 'gtk_reserved')]" name="padding">true</attr>
<attr path="//*[contains(@vm, 'gtk_reserved')]" name="padding">true</attr>