using System; using System.IO; using Artemis.Core; using MaterialDesignThemes.Wpf; namespace Artemis.UI.Shared { /// /// Provides utilities for UI-related plugin tasks /// public static class PluginUtilities { /// /// Transforms the provided icon so that it is usable by the control /// /// The plugin the icon belongs to /// /// The icon, may be a string representation of a or a relative path /// pointing to a .svg file /// /// public static object GetPluginIcon(Plugin plugin, string icon) { if (icon == null) return PackIconKind.QuestionMarkCircle; // Icon is provided as a path if (icon.EndsWith(".svg")) { string iconPath = plugin.ResolveRelativePath(icon); if (!File.Exists(iconPath)) return PackIconKind.QuestionMarkCircle; return iconPath; } // Icon is provided as string to avoid having to reference MaterialDesignThemes bool parsedIcon = Enum.TryParse(icon, true, out PackIconKind iconEnum); if (parsedIcon == false) iconEnum = PackIconKind.QuestionMarkCircle; return iconEnum; } } }