static ImageService() { iconFactory.AddDefault(); IconId.IconNameRequestHandler = delegate(string stockId) { EnsureStockIconIsLoaded(stockId, Gtk.IconSize.Menu); }; AddinManager.AddExtensionNodeHandler("/MonoDevelop/Core/StockIcons", delegate(object sender, ExtensionNodeEventArgs args) { StockIconCodon iconCodon = (StockIconCodon)args.ExtensionNode; switch (args.Change) { case ExtensionChange.Add: if (!iconStock.ContainsKey(iconCodon.StockId)) { iconStock[iconCodon.StockId] = new List <StockIconCodon> (); } iconStock[iconCodon.StockId].Add(iconCodon); break; } }); for (int i = 0; i < iconSizes.Length; i++) { int w, h; if (!Gtk.Icon.SizeLookup((Gtk.IconSize)i, out w, out h)) { w = h = -1; } iconSizes[i].Width = w; iconSizes[i].Height = h; } }
static ImageService() { iconFactory.AddDefault(); AddinManager.AddExtensionNodeHandler(IconsExtensionPath, delegate(object sender, ExtensionNodeEventArgs args) { StockIconCodon iconCodon = (StockIconCodon)args.ExtensionNode; switch (args.Change) { case ExtensionChange.Add: if (!iconStock.ContainsKey(iconCodon.StockId)) { iconStock[iconCodon.StockId] = new List <StockIconCodon> (); } iconStock[iconCodon.StockId].Add(iconCodon); break; } }); for (int i = 0; i < iconSizes.Length; i++) { int w, h; if (!Gtk.Icon.SizeLookup((Gtk.IconSize)i, out w, out h)) { w = h = -1; } iconSizes[i].Width = w; iconSizes[i].Height = h; } if (Platform.IsWindows) { iconSizes[(int)Gtk.IconSize.Menu].Width = 16; iconSizes[(int)Gtk.IconSize.Menu].Height = 16; } }
static ImageService() { iconFactory.AddDefault(); IconId.IconNameRequestHandler = delegate(string stockId) { EnsureStockIconIsLoaded(stockId, Gtk.IconSize.Menu); }; AddinManager.AddExtensionNodeHandler("/MonoDevelop/Core/StockIcons", delegate(object sender, ExtensionNodeEventArgs args) { StockIconCodon iconCodon = (StockIconCodon)args.ExtensionNode; switch (args.Change) { case ExtensionChange.Add: if (iconCodon.File != null) { LoadStockIcon(iconCodon); break; } if (!iconStock.ContainsKey(iconCodon.StockId)) { iconStock[iconCodon.StockId] = new List <StockIconCodon> (); } iconStock[iconCodon.StockId].Add(iconCodon); break; } }); }
static void LoadStockIcon(StockIconCodon iconCodon, bool forceWildcard) { try { Gdk.Pixbuf pixbuf = null; AnimatedIcon animatedIcon = null; if (!string.IsNullOrEmpty(iconCodon.Resource) || !string.IsNullOrEmpty(iconCodon.File)) { // using the stream directly produces a gdk warning. byte[] buffer; Stream stream; if (iconCodon.Resource != null) { stream = iconCodon.Addin.GetResource(iconCodon.Resource); } else { stream = File.OpenRead(iconCodon.Addin.GetFilePath(iconCodon.File)); } using (stream) { if (stream == null || stream.Length < 0) { LoggingService.LogError("Did not find resource '{0}' in addin '{1}' for icon '{2}'", iconCodon.Resource, iconCodon.Addin.Id, iconCodon.StockId); return; } buffer = new byte [stream.Length]; stream.Read(buffer, 0, (int)stream.Length); } pixbuf = new Gdk.Pixbuf(buffer); } else if (!string.IsNullOrEmpty(iconCodon.IconId)) { var id = GetStockIdForImageSpec(iconCodon.Addin, iconCodon.IconId, iconCodon.IconSize); pixbuf = GetPixbuf(id, iconCodon.IconSize); // This may be an animation, get it animationFactory.TryGetValue(id, out animatedIcon); } else if (!string.IsNullOrEmpty(iconCodon.Animation)) { string id = GetStockIdForImageSpec(iconCodon.Addin, "animation:" + iconCodon.Animation, iconCodon.IconSize); pixbuf = GetPixbuf(id, iconCodon.IconSize); // This *should* be an animation animationFactory.TryGetValue(id, out animatedIcon); } Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconCodon.IconSize; if (pixbuf != null) { AddToIconFactory(iconCodon.StockId, pixbuf, size); } if (animatedIcon != null) { AddToAnimatedIconFactory(iconCodon.StockId, animatedIcon); } } catch (Exception ex) { LoggingService.LogError(string.Format("Error loading icon '{0}'", iconCodon.StockId), ex); } }
static void LoadStockIcon(StockIconCodon iconCodon, bool forceWildcard) { try { Gdk.Pixbuf pixbuf = null; if (!string.IsNullOrEmpty(iconCodon.Resource) || !string.IsNullOrEmpty(iconCodon.File)) { // using the stream directly produces a gdk warning. byte[] buffer; Stream stream; if (iconCodon.Resource != null) { stream = iconCodon.Addin.GetResource(iconCodon.Resource); } else { stream = File.OpenRead(iconCodon.Addin.GetFilePath(iconCodon.File)); } using (stream) { if (stream == null || stream.Length < 0) { LoggingService.LogError("Did not find resource '{0}' in addin '{1}' for icon '{2}'", iconCodon.Resource, iconCodon.Addin.Id, iconCodon.StockId); return; } buffer = new byte [stream.Length]; stream.Read(buffer, 0, (int)stream.Length); } pixbuf = new Gdk.Pixbuf(buffer); } else if (!string.IsNullOrEmpty(iconCodon.IconId)) { pixbuf = GetPixbuf(InternalGetStockId(iconCodon.Addin, iconCodon.IconId, iconCodon.IconSize), iconCodon.IconSize); } if (pixbuf != null) { Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconCodon.IconSize; AddToIconFactory(iconCodon.StockId, pixbuf, size); } } catch (Exception ex) { LoggingService.LogError(string.Format("Error loading icon '{0}'", iconCodon.StockId), ex); } }
static ImageService() { iconFactory.AddDefault(); IconId.IconNameRequestHandler = delegate(string stockId) { EnsureStockIconIsLoaded(stockId); }; AddinManager.AddExtensionNodeHandler(IconsExtensionPath, delegate(object sender, ExtensionNodeEventArgs args) { StockIconCodon iconCodon = (StockIconCodon)args.ExtensionNode; switch (args.Change) { case ExtensionChange.Add: if (!iconStock.ContainsKey(iconCodon.StockId)) { iconStock[iconCodon.StockId] = new List <StockIconCodon> (); } iconStock[iconCodon.StockId].Add(iconCodon); break; } }); for (int i = 0; i < iconSizes.Length; i++) { int w, h; if (!Gtk.Icon.SizeLookup((Gtk.IconSize)i, out w, out h)) { w = h = -1; } iconSizes[i].Width = w; iconSizes[i].Height = h; } if (Platform.IsWindows) { iconSizes[(int)Gtk.IconSize.Menu].Width = 16; iconSizes[(int)Gtk.IconSize.Menu].Height = 16; } // Preload icons defined in MD.Ide. Ensures that the gtk icon overrides are available. var current = AddinManager.CurrentAddin; foreach (var id in AddinManager.GetExtensionNodes(IconsExtensionPath).OfType <StockIconCodon> ().Where(c => c.Addin == current).Select(c => c.StockId).Distinct()) { EnsureStockIconIsLoaded(id); } }
static Xwt.Drawing.Image LoadStockIcon(StockIconCodon iconCodon, bool forceWildcard) { return(LoadStockIcon(iconCodon.Addin, iconCodon.StockId, iconCodon.Resource, iconCodon.File, iconCodon.IconId, iconCodon.IconSize, iconCodon.Animation, forceWildcard)); }
static void LoadStockIcon(StockIconCodon iconCodon, bool forceWildcard) { try { Gdk.Pixbuf pixbuf = null; AnimatedIcon animatedIcon = null; if (!string.IsNullOrEmpty (iconCodon.Resource) || !string.IsNullOrEmpty (iconCodon.File)) { // using the stream directly produces a gdk warning. byte[] buffer; Stream stream; if (iconCodon.Resource != null) stream = iconCodon.Addin.GetResource (iconCodon.Resource); else stream = File.OpenRead (iconCodon.Addin.GetFilePath (iconCodon.File)); using (stream) { if (stream == null || stream.Length < 0) { LoggingService.LogError ("Did not find resource '{0}' in addin '{1}' for icon '{2}'", iconCodon.Resource, iconCodon.Addin.Id, iconCodon.StockId); return; } buffer = new byte [stream.Length]; stream.Read (buffer, 0, (int)stream.Length); } pixbuf = new Gdk.Pixbuf (buffer); } else if (!string.IsNullOrEmpty (iconCodon.IconId)) { var id = GetStockIdForImageSpec (iconCodon.Addin, iconCodon.IconId, iconCodon.IconSize); pixbuf = GetPixbuf (id, iconCodon.IconSize); // This may be an animation, get it animationFactory.TryGetValue (id, out animatedIcon); } else if (!string.IsNullOrEmpty (iconCodon.Animation)) { string id = GetStockIdForImageSpec (iconCodon.Addin, "animation:" + iconCodon.Animation, iconCodon.IconSize); pixbuf = GetPixbuf (id, iconCodon.IconSize); // This *should* be an animation animationFactory.TryGetValue (id, out animatedIcon); } Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconCodon.IconSize; if (pixbuf != null) AddToIconFactory (iconCodon.StockId, pixbuf, size); if (animatedIcon != null) AddToAnimatedIconFactory (iconCodon.StockId, animatedIcon); } catch (Exception ex) { LoggingService.LogError (string.Format ("Error loading icon '{0}'", iconCodon.StockId), ex); } }
static Xwt.Drawing.Image LoadStockIcon(StockIconCodon iconCodon, bool forceWildcard) { try { Gdk.Pixbuf pixbuf = null, pixbuf2x = null; AnimatedIcon animatedIcon = null; Func <Stream[]> imageLoader = null; if (!string.IsNullOrEmpty(iconCodon.Resource) || !string.IsNullOrEmpty(iconCodon.File)) { // using the stream directly produces a gdk warning. byte[] buffer; if (iconCodon.Resource != null) { imageLoader = delegate { var stream = iconCodon.Addin.GetResource(iconCodon.Resource); var stream2x = iconCodon.Addin.GetResource2x(iconCodon.Resource); if (stream2x == null) { return new [] { stream } } ; else { return new [] { stream, stream2x } }; }; } else { imageLoader = delegate { var file = iconCodon.Addin.GetFilePath(iconCodon.File); 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}'", iconCodon.Resource, iconCodon.Addin.Id, iconCodon.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(iconCodon.IconId)) { var id = GetStockIdForImageSpec(iconCodon.Addin, iconCodon.IconId, iconCodon.IconSize); pixbuf = GetPixbuf(id, iconCodon.IconSize); pixbuf2x = Get2xIconVariant(pixbuf); // This may be an animation, get it animationFactory.TryGetValue(id, out animatedIcon); } else if (!string.IsNullOrEmpty(iconCodon.Animation)) { string id = GetStockIdForImageSpec(iconCodon.Addin, "animation:" + iconCodon.Animation, iconCodon.IconSize); pixbuf = GetPixbuf(id, iconCodon.IconSize); // This *should* be an animation animationFactory.TryGetValue(id, out animatedIcon); } Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconCodon.IconSize; if (pixbuf != null) { AddToIconFactory(iconCodon.StockId, pixbuf, pixbuf2x, size); } if (animatedIcon != null) { AddToAnimatedIconFactory(iconCodon.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}'", iconCodon.StockId), ex); return(null); } }