本文整理汇总了C#中Mono.Addins.RuntimeAddin.GetFilePath方法的典型用法代码示例。如果您正苦于以下问题:C# RuntimeAddin.GetFilePath方法的具体用法?C# RuntimeAddin.GetFilePath怎么用?C# RuntimeAddin.GetFilePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Addins.RuntimeAddin
的用法示例。
在下文中一共展示了RuntimeAddin.GetFilePath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateLocalizer
public IAddinLocalizer CreateLocalizer (RuntimeAddin addin, NodeElement element)
{
string pkg = element.GetAttribute ("catalog");
if (pkg.Length == 0)
pkg = addin.Id;
string dir = element.GetAttribute ("location");
if (dir.Length == 0)
dir = "locale";
dir = addin.GetFilePath (dir);
domain = new GettextDomain ();
domain.Init (pkg, dir);
return this;
}
示例2: LoadStockIcon
static Xwt.Drawing.Image LoadStockIcon (RuntimeAddin addin, string stockId, string resource, string imageFile, string iconId, Gtk.IconSize iconSize, string animation, bool forceWildcard)
{
try {
Gdk.Pixbuf pixbuf = null, pixbuf2x = null;
AnimatedIcon animatedIcon = null;
Func<Stream[]> imageLoader = null;
if (!string.IsNullOrEmpty (resource) || !string.IsNullOrEmpty (imageFile)) {
// using the stream directly produces a gdk warning.
byte[] buffer;
if (resource != null) {
imageLoader = delegate {
var stream = addin.GetResource (resource);
var stream2x = addin.GetResource2x (resource);
if (stream2x == null)
return new [] { stream };
else
return new [] { stream, stream2x };
};
}
else {
imageLoader = delegate {
var file = addin.GetFilePath (imageFile);
var stream = File.OpenRead (file);
Stream stream2x = null;
var file2x = Path.Combine (Path.GetDirectoryName (file), Path.GetFileNameWithoutExtension (file) + "@2x" + Path.GetExtension (file));
if (File.Exists (file2x))
stream2x = File.OpenRead (file2x);
else {
file2x = file + "@2x";
if (File.Exists (file2x))
stream2x = File.OpenRead (file2x);
}
if (stream2x == null)
return new [] { stream };
else
return new [] { stream, stream2x };
};
}
var streams = imageLoader ();
var st = streams[0];
var st2x = streams.Length > 1 ? streams[1] : null;
using (st) {
if (st == null || st.Length < 0) {
LoggingService.LogError ("Did not find resource '{0}' in addin '{1}' for icon '{2}'",
resource, addin.Id, stockId);
return null;
}
buffer = new byte [st.Length];
st.Read (buffer, 0, (int)st.Length);
}
pixbuf = new Gdk.Pixbuf (buffer);
using (st2x) {
if (st2x != null && st2x.Length >= 0) {
buffer = new byte [st2x.Length];
st2x.Read (buffer, 0, (int)st2x.Length);
pixbuf2x = new Gdk.Pixbuf (buffer);
}
}
} else if (!string.IsNullOrEmpty (iconId)) {
var id = GetStockIdForImageSpec (addin, iconId, iconSize);
pixbuf = GetPixbuf (id, iconSize);
pixbuf2x = Get2xIconVariant (pixbuf);
// This may be an animation, get it
animationFactory.TryGetValue (id, out animatedIcon);
} else if (!string.IsNullOrEmpty (animation)) {
string id = GetStockIdForImageSpec (addin, "animation:" + animation, iconSize);
pixbuf = GetPixbuf (id, iconSize);
// This *should* be an animation
animationFactory.TryGetValue (id, out animatedIcon);
}
Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconSize;
if (pixbuf != null)
AddToIconFactory (stockId, pixbuf, pixbuf2x, size);
if (animatedIcon != null)
AddToAnimatedIconFactory (stockId, animatedIcon);
var img = Xwt.Toolkit.CurrentEngine.WrapImage (pixbuf);
if (pixbuf2x != null) {
var img2x = Xwt.Toolkit.CurrentEngine.WrapImage (pixbuf2x);
img = Xwt.Drawing.Image.CreateMultiResolutionImage (new [] { img, img2x });
}
if (imageLoader != null)
img.SetStreamSource (imageLoader);
return img;
} catch (Exception ex) {
LoggingService.LogError (string.Format ("Error loading icon '{0}'", stockId), ex);
return null;
}
}
示例3: LoadStockIcon
static Xwt.Drawing.Image LoadStockIcon (RuntimeAddin addin, string stockId, string resource, string imageFile, string iconId, Gtk.IconSize iconSize, string animation, bool forceWildcard)
{
try {
AnimatedIcon animatedIcon = null;
Func<Stream[]> imageLoader = null;
Xwt.Drawing.Image img = null;
if (!string.IsNullOrEmpty (resource) || !string.IsNullOrEmpty (imageFile)) {
if (resource != null) {
CustomImageLoader loader;
if (!imageLoaders.TryGetValue (addin, out loader))
loader = imageLoaders [addin] = new CustomImageLoader (addin);
img = Xwt.Drawing.Image.FromCustomLoader (loader, resource);
}
else {
img = Xwt.Drawing.Image.FromFile (addin.GetFilePath (imageFile));
}
} else if (!string.IsNullOrEmpty (iconId)) {
var id = GetStockIdForImageSpec (addin, iconId, iconSize);
img = GetIcon (id, iconSize);
// This may be an animation, get it
animationFactory.TryGetValue (id, out animatedIcon);
} else if (!string.IsNullOrEmpty (animation)) {
string id = GetStockIdForImageSpec (addin, "animation:" + animation, iconSize);
img = GetIcon (id, iconSize);
// This *should* be an animation
animationFactory.TryGetValue (id, out animatedIcon);
}
if (animatedIcon != null)
AddToAnimatedIconFactory (stockId, animatedIcon);
if (imageLoader != null)
img.SetStreamSource (imageLoader);
return img;
} catch (Exception ex) {
LoggingService.LogError (string.Format ("Error loading icon '{0}'", stockId), ex);
return null;
}
}