private static Image GetSeverityIconForDiagnostic(DiagnosticData diagnostic) { ImageMoniker?moniker = null; switch (diagnostic.Severity) { case DiagnosticSeverity.Error: moniker = KnownMonikers.StatusError; break; case DiagnosticSeverity.Warning: moniker = KnownMonikers.StatusWarning; break; case DiagnosticSeverity.Info: moniker = KnownMonikers.StatusInformation; break; case DiagnosticSeverity.Hidden: moniker = KnownMonikers.StatusHidden; break; } if (moniker.HasValue) { return(new CrispImage { Moniker = moniker.Value }); } return(null); }
public static BitmapSource GetIconForImageMoniker(ImageMoniker?imageMoniker, int sizeX, int sizeY) { if (imageMoniker == null) { return(null); } var vsIconService = ServiceProvider.GlobalProvider.GetService(typeof(SVsImageService)) as IVsImageService2; if (vsIconService == null) { return(null); } var imageAttributes = new ImageAttributes { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = sizeY, LogicalWidth = sizeX, StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject result = vsIconService.GetImage(imageMoniker.Value, imageAttributes); result.get_Data(out object data); var glyph = data as BitmapSource; glyph?.Freeze(); return(glyph); }
public static TestDependencyModel FromJson( string jsonString, ProjectTreeFlags?flags = null, ImageMoniker?icon = null, ImageMoniker?expandedIcon = null, ImageMoniker?unresolvedIcon = null, ImageMoniker?unresolvedExpandedIcon = null, Dictionary <string, string> properties = null, IEnumerable <string> dependenciesIds = null) { if (string.IsNullOrEmpty(jsonString)) { return(null); } var json = JObject.Parse(jsonString); var data = json.ToObject <TestDependencyModel>(); if (flags.HasValue) { data.Flags += flags.Value; } data.Flags += data.Resolved ? DependencyTreeFlags.ResolvedFlags : DependencyTreeFlags.UnresolvedFlags; if (icon.HasValue) { data.Icon = icon.Value; } if (expandedIcon.HasValue) { data.ExpandedIcon = expandedIcon.Value; } if (unresolvedIcon.HasValue) { data.UnresolvedIcon = unresolvedIcon.Value; } if (unresolvedExpandedIcon.HasValue) { data.UnresolvedExpandedIcon = unresolvedExpandedIcon.Value; } if (properties != null) { data.Properties = ImmutableStringDictionary <string> .EmptyOrdinal.AddRange(properties); } if (dependenciesIds != null) { data.DependencyIDs = ImmutableList <string> .Empty.AddRange(dependenciesIds); } return(data); }
/// <summary> /// Constructor /// </summary> /// <param name="displayText">Text shown in the UI</param> /// <param name="filterText">Text used to filter out items or null to use <paramref name="displayText"/></param> /// <param name="insertionText">Text that gets inserted in the text buffer or null to use <paramref name="displayText"/></param> /// <param name="description">Description or null</param> /// <param name="iconMoniker">Icon moniker or null</param> /// <param name="iconAutomationText">Icon automation text or null</param> /// <param name="attributeIcons">Attribute icons shown on the right side</param> /// <param name="suffix">Text shown after the normal completion text</param> public DsCompletion(string displayText, string filterText = null, string insertionText = null, string description = null, ImageMoniker iconMoniker = default(ImageMoniker), string iconAutomationText = null, IEnumerable<CompletionIcon2> attributeIcons = null, string suffix = null) : base(displayText, insertionText, description, default(ImageMoniker), iconAutomationText, attributeIcons, suffix) { if (displayText == null) throw new ArgumentNullException(nameof(displayText)); FilterText = filterText ?? displayText; InsertionText = insertionText ?? displayText; this.iconMoniker = iconMoniker.Id == 0 && iconMoniker.Guid == Guid.Empty ? (ImageMoniker?)null : iconMoniker; }
/// <summary> /// Returns image source given name of the image moniker /// such as name from http://glyphlist.azurewebsites.net/knownmonikers /// </summary> public ImageSource GetImage(string name) { ImageSource ims = GetImageFromResources(name); if (ims == null) { ImageMoniker?im = FindKnownMoniker(name); ims = im.HasValue ? GetIconForImageMoniker(im.Value) : null; } return(ims); }
/// <summary> /// Constructor /// </summary> /// <param name="displayText">Text shown in the UI</param> /// <param name="filterText">Text used to filter out items or null to use <paramref name="displayText"/></param> /// <param name="insertionText">Text that gets inserted in the text buffer or null to use <paramref name="displayText"/></param> /// <param name="description">Description or null</param> /// <param name="iconMoniker">Icon moniker or null</param> /// <param name="iconAutomationText">Icon automation text or null</param> /// <param name="attributeIcons">Attribute icons shown on the right side</param> /// <param name="suffix">Text shown after the normal completion text</param> public DsCompletion(string displayText, string filterText = null, string insertionText = null, string description = null, ImageMoniker iconMoniker = default, string iconAutomationText = null, IEnumerable <CompletionIcon2> attributeIcons = null, string suffix = null) : base(displayText, insertionText, description, default, iconAutomationText, attributeIcons, suffix) { if (displayText == null) { throw new ArgumentNullException(nameof(displayText)); } FilterText = filterText ?? displayText; InsertionText = insertionText ?? displayText; this.iconMoniker = iconMoniker.Id == 0 && iconMoniker.Guid == Guid.Empty ? (ImageMoniker?)null : iconMoniker; }
public static IDependenciesViewModelFactory Implement( ImageMoniker?getDependenciesRootIcon = null, IEnumerable <IDependencyModel>?createRootViewModel = null, IEnumerable <IDependencyModel>?createTargetViewModel = null, MockBehavior mockBehavior = MockBehavior.Strict) { var mock = new Mock <IDependenciesViewModelFactory>(mockBehavior); if (getDependenciesRootIcon.HasValue) { mock.Setup(x => x.GetDependenciesRootIcon(It.IsAny <DiagnosticLevel>())).Returns(getDependenciesRootIcon.Value); } if (createRootViewModel != null) { foreach (var d in createRootViewModel) { mock.Setup(x => x.CreateGroupNodeViewModel( It.Is <string>(t => string.Equals(t, d.ProviderType, StringComparison.OrdinalIgnoreCase)), DiagnosticLevel.None)) .Returns((d.ToViewModel(DiagnosticLevel.None), null)); mock.Setup(x => x.CreateGroupNodeViewModel( It.Is <string>(t => string.Equals(t, d.ProviderType, StringComparison.OrdinalIgnoreCase)), DiagnosticLevel.Warning)) .Returns((d.ToViewModel(DiagnosticLevel.Warning), null)); mock.Setup(x => x.CreateGroupNodeViewModel( It.Is <string>(t => string.Equals(t, d.ProviderType, StringComparison.OrdinalIgnoreCase)), DiagnosticLevel.Error)) .Returns((d.ToViewModel(DiagnosticLevel.Error), null)); } } if (createTargetViewModel != null) { foreach (var d in createTargetViewModel) { mock.Setup(x => x.CreateTargetViewModel( It.Is <TargetFramework>(t => string.Equals(t.TargetFrameworkAlias, d.Caption, StringComparison.OrdinalIgnoreCase)), DiagnosticLevel.None)) .Returns(d.ToViewModel(DiagnosticLevel.None)); mock.Setup(x => x.CreateTargetViewModel( It.Is <TargetFramework>(t => string.Equals(t.TargetFrameworkAlias, d.Caption, StringComparison.OrdinalIgnoreCase)), DiagnosticLevel.Warning)) .Returns(d.ToViewModel(DiagnosticLevel.Warning)); mock.Setup(x => x.CreateTargetViewModel( It.Is <TargetFramework>(t => string.Equals(t.TargetFrameworkAlias, d.Caption, StringComparison.OrdinalIgnoreCase)), DiagnosticLevel.Error)) .Returns(d.ToViewModel(DiagnosticLevel.Error)); } } return(mock.Object); }
private static HierarchyNode CreateNode( Guid?identifier = null, ImageMoniker?collapsedIcon = null, ImageMoniker?expandedIcon = null ) { return(new HierarchyNode( identifier ?? Guid.NewGuid(), "foo", collapsedIcon ?? KnownMonikers.Abbreviation, expandedIcon ?? KnownMonikers.Abbreviation )); }
public SubTreeRootDependencyNode(string providerType, string caption, ProjectTreeFlags flags, ImageMoniker icon, ImageMoniker?expandedIcon = null, int priority = 0) : base(new DependencyNodeId(providerType, string.Empty, string.Empty), flags, priority, null, resolved: true) { Requires.NotNullOrEmpty(caption, nameof(caption)); Caption = caption; Icon = icon; ExpandedIcon = expandedIcon.HasValue ? expandedIcon.Value : Icon; }
public static ImageSource GetIconForImageMoniker(ImageMoniker?imageMoniker, int sizeX, int sizeY) { if (imageMoniker == null) { return(null); } IVsImageService2 vsIconService = ServiceProvider.GlobalProvider.GetService(typeof(SVsImageService)) as IVsImageService2; if (vsIconService == null) { return(null); } try { ImageAttributes imageAttributes = new ImageAttributes { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags, ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, LogicalHeight = sizeY, LogicalWidth = sizeX, StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; IVsUIObject result = vsIconService.GetImage(imageMoniker.Value, imageAttributes); object data; result.get_Data(out data); ImageSource glyph = data as ImageSource; if (glyph != null) { glyph.Freeze(); } return(glyph); } catch { Debug.Fail("Unable to get image."); } return(null); }
public static IDependenciesViewModelFactory Implement( ImageMoniker?getDependenciesRootIcon = null, IEnumerable <IDependencyModel>?createRootViewModel = null, IEnumerable <IDependencyModel>?createTargetViewModel = null, MockBehavior mockBehavior = MockBehavior.Strict) { var mock = new Mock <IDependenciesViewModelFactory>(mockBehavior); if (getDependenciesRootIcon.HasValue) { mock.Setup(x => x.GetDependenciesRootIcon(It.IsAny <bool>())).Returns(getDependenciesRootIcon.Value); } if (createRootViewModel != null) { foreach (var d in createRootViewModel) { mock.Setup(x => x.CreateRootViewModel( It.Is <string>(t => string.Equals(t, d.ProviderType, System.StringComparison.OrdinalIgnoreCase)), false)) .Returns(d.ToViewModel(false)); mock.Setup(x => x.CreateRootViewModel( It.Is <string>(t => string.Equals(t, d.ProviderType, System.StringComparison.OrdinalIgnoreCase)), true)) .Returns(d.ToViewModel(true)); } } if (createTargetViewModel != null) { foreach (var d in createTargetViewModel) { mock.Setup(x => x.CreateTargetViewModel( It.Is <TargetedDependenciesSnapshot>( t => string.Equals(t.TargetFramework.FullName, d.Caption, System.StringComparison.OrdinalIgnoreCase)))) .Returns(d.ToViewModel(false)); } } return(mock.Object); }
private ImageMoniker?FindKnownMoniker(string name) { ImageMoniker cached; if (_monikerCache.TryGetValue(name, out cached)) { return(cached); } ImageMoniker?moniker = null; Type t = typeof(KnownMonikers); PropertyInfo info = t.GetProperty(name, typeof(ImageMoniker)); if (info != null) { MethodInfo mi = info.GetGetMethod(nonPublic: false); moniker = (ImageMoniker)mi.Invoke(null, new object[0]); _monikerCache[name] = moniker.Value; } return(moniker); }
public Node(string?text = null, ImageMoniker?icon = null) { Text = text; Icon = icon; }
public static IDependency FromJson( string jsonString, ProjectTreeFlags?flags = null, ImageMoniker?icon = null, ImageMoniker?expandedIcon = null, ImageMoniker?unresolvedIcon = null, ImageMoniker?unresolvedExpandedIcon = null, Dictionary <string, string> properties = null, IEnumerable <string> dependenciesIds = null, ITargetFramework targetFramework = null) { if (string.IsNullOrEmpty(jsonString)) { return(null); } var json = JObject.Parse(jsonString); var data = json.ToObject <TestDependency>(); if (flags != null && flags.HasValue) { data.Flags = data.Flags.Union(flags.Value); } if (icon != null && icon.HasValue) { data.Icon = icon.Value; } if (expandedIcon != null && expandedIcon.HasValue) { data.ExpandedIcon = expandedIcon.Value; } if (unresolvedIcon != null && unresolvedIcon.HasValue) { data.UnresolvedIcon = unresolvedIcon.Value; } if (unresolvedExpandedIcon != null && unresolvedExpandedIcon.HasValue) { data.UnresolvedExpandedIcon = unresolvedExpandedIcon.Value; } if (properties != null) { data.Properties = ImmutableStringDictionary <string> .EmptyOrdinal.AddRange(properties); } if (dependenciesIds != null) { data.DependencyIDs = ImmutableList <string> .Empty.AddRange(dependenciesIds); } if (targetFramework != null) { data.TargetFramework = targetFramework; } return(data); }