diff --git a/OpenCover.UI/OpenCover.UI.VS2013.csproj b/OpenCover.UI/OpenCover.UI.VS2013.csproj index 54988b8..f3262c3 100644 --- a/OpenCover.UI/OpenCover.UI.VS2013.csproj +++ b/OpenCover.UI/OpenCover.UI.VS2013.csproj @@ -179,6 +179,7 @@ + diff --git a/OpenCover.UI/OpenCover.UI.csproj b/OpenCover.UI/OpenCover.UI.csproj index 0d04014..7b58371 100644 --- a/OpenCover.UI/OpenCover.UI.csproj +++ b/OpenCover.UI/OpenCover.UI.csproj @@ -179,6 +179,7 @@ + diff --git a/OpenCover.UI/Settings.cs b/OpenCover.UI/Settings.cs index 95e2c4b..d823a23 100644 --- a/OpenCover.UI/Settings.cs +++ b/OpenCover.UI/Settings.cs @@ -1,11 +1,6 @@ -using Microsoft.VisualStudio.Settings; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; +using System.ComponentModel; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; +using Microsoft.VisualStudio.Settings; namespace OpenCover.UI { @@ -29,8 +24,8 @@ public Settings(WritableSettingsStore configurationSettingsStore) { _store = configurationSettingsStore; - _showLinesColored = _store.GetBoolean(SETTINGS_PATH, "ShowLinesColored", false); - _showCoverageGlyphs = _store.GetBoolean(SETTINGS_PATH, "ShowCoverageGlyphs", true); + _showLinesColored = _store.GetBoolean(SETTINGS_PATH, SettingNames.ShowLinesColored, false); + _showCoverageGlyphs = _store.GetBoolean(SETTINGS_PATH, SettingNames.ShowCoverageGlyphs, true); } /// @@ -89,5 +84,11 @@ private void WriteBoolean(bool value, [CallerMemberName] string propertyName = n _store.SetBoolean(SETTINGS_PATH, propertyName, value); } + + public static class SettingNames + { + public const string ShowLinesColored = "ShowLinesColored"; + public const string ShowCoverageGlyphs = "ShowCoverageGlyphs"; + } } } diff --git a/OpenCover.UI/Tagger/ClassificationTypes.cs b/OpenCover.UI/Tagger/ClassificationTypes.cs new file mode 100644 index 0000000..543d2b4 --- /dev/null +++ b/OpenCover.UI/Tagger/ClassificationTypes.cs @@ -0,0 +1,8 @@ +namespace OpenCover.UI.Tagger +{ + public static class ClassificationTypes + { + public const string TextBackgroundCovered = "text-background-covered"; + public const string TextBackgroundNotCovered = "text-background-notcovered"; + } +} diff --git a/OpenCover.UI/Tagger/LineCoverageTag.cs b/OpenCover.UI/Tagger/LineCoverageTag.cs index c51cef1..cca709a 100644 --- a/OpenCover.UI/Tagger/LineCoverageTag.cs +++ b/OpenCover.UI/Tagger/LineCoverageTag.cs @@ -1,9 +1,4 @@ using Microsoft.VisualStudio.Text.Editor; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace OpenCover.UI.Tagger { diff --git a/OpenCover.UI/Tagger/LineCoverageTagger.cs b/OpenCover.UI/Tagger/LineCoverageTagger.cs index f54eeb5..dedbe1a 100644 --- a/OpenCover.UI/Tagger/LineCoverageTagger.cs +++ b/OpenCover.UI/Tagger/LineCoverageTagger.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; +using System.ComponentModel; using Microsoft.VisualStudio.Text; -using Microsoft.VisualStudio.Text.Tagging; -using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Classification; -using Microsoft.VisualStudio.Utilities; +using Microsoft.VisualStudio.Text.Tagging; using OpenCover.UI.Views; namespace OpenCover.UI.Tagger @@ -91,9 +89,9 @@ IEnumerable> ITagger.GetTags(Normaliz /// /// /// - void OnSettingsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + void OnSettingsChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == "ShowCoverageGlyphs") + if (e.PropertyName == Settings.SettingNames.ShowCoverageGlyphs) RaiseAllTagsChanged(); } diff --git a/OpenCover.UI/Tagger/TextBackground.cs b/OpenCover.UI/Tagger/TextBackground.cs index 716121d..a5fc62c 100644 --- a/OpenCover.UI/Tagger/TextBackground.cs +++ b/OpenCover.UI/Tagger/TextBackground.cs @@ -14,7 +14,7 @@ namespace OpenCover.UI.Tagger public static class CoveredTextBackgroundTypeExports { [Export(typeof(ClassificationTypeDefinition))] - [Name("text-background-covered")] + [Name(ClassificationTypes.TextBackgroundCovered)] public static ClassificationTypeDefinition OrdinaryClassificationType; } @@ -24,7 +24,7 @@ public static class CoveredTextBackgroundTypeExports public static class NotCoveredTextBackgroundTypeExports { [Export(typeof(ClassificationTypeDefinition))] - [Name("text-background-notcovered")] + [Name(ClassificationTypes.TextBackgroundNotCovered)] public static ClassificationTypeDefinition OrdinaryClassificationType; } @@ -32,8 +32,8 @@ public static class NotCoveredTextBackgroundTypeExports /// Class defining background color for covered classes /// [Export(typeof(EditorFormatDefinition))] - [ClassificationType(ClassificationTypeNames = "text-background-covered")] - [Name("text-background-covered")] + [ClassificationType(ClassificationTypeNames = ClassificationTypes.TextBackgroundCovered)] + [Name(ClassificationTypes.TextBackgroundCovered)] [UserVisible(true)] [Order(After = Priority.High)] public sealed class CoveredTextBackground : ClassificationFormatDefinition @@ -52,8 +52,8 @@ public CoveredTextBackground() /// Class defining background color for covered classes /// [Export(typeof(EditorFormatDefinition))] - [ClassificationType(ClassificationTypeNames = "text-background-notcovered")] - [Name("text-background-notcovered")] + [ClassificationType(ClassificationTypeNames = ClassificationTypes.TextBackgroundNotCovered)] + [Name(ClassificationTypes.TextBackgroundNotCovered)] [UserVisible(true)] [Order(After = Priority.High)] public sealed class NotCoveredTextBackground : ClassificationFormatDefinition diff --git a/OpenCover.UI/Tagger/TextTagger.cs b/OpenCover.UI/Tagger/TextTagger.cs index 1aec564..2889911 100644 --- a/OpenCover.UI/Tagger/TextTagger.cs +++ b/OpenCover.UI/Tagger/TextTagger.cs @@ -1,19 +1,18 @@ // // This source code is released under the GPL License; Please read license.md file for more details. // -using Microsoft.VisualStudio.Shell; + +using System; +using System.Collections.Generic; +using System.ComponentModel; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Classification; using Microsoft.VisualStudio.Text.Editor; +using Microsoft.VisualStudio.Text.Formatting; using Microsoft.VisualStudio.Text.Operations; using Microsoft.VisualStudio.Text.Tagging; using OpenCover.UI.Glyphs; using OpenCover.UI.Helper; -using OpenCover.UI.Helpers; -using OpenCover.UI.Views; -using System; -using System.Collections.Generic; -using System.Linq; namespace OpenCover.UI.Tagger { @@ -95,7 +94,7 @@ public IEnumerable> GetTags(NormalizedSnapshotSpanCo foreach (var span in spansToSerach) { - var covered = _spanCoverage.ContainsKey(span) ? _spanCoverage[span] : false; + var covered = _spanCoverage.ContainsKey(span) && _spanCoverage[span]; var tag = covered ? new ClassificationTag(_coveredType) : new ClassificationTag(_notCoveredType); yield return new TagSpan(span, tag); } @@ -119,22 +118,26 @@ public static TextTagger GetTagger(ITextView view) /// /// /// - void OnSettingsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + void OnSettingsChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == "ShowLinesColored") + if (e.PropertyName == Settings.SettingNames.ShowLinesColored) RaiseAllTagsChanged(); } private void OnViewClosed(object sender, EventArgs e) { - _instances.Remove(sender as ITextView); + var key = sender as ITextView; + if (key != null) + { + _instances.Remove(key); + } } - /// + /// /// Show spans for line only /// /// - internal void ShowForLine(Microsoft.VisualStudio.Text.Formatting.IWpfTextViewLine line) + internal void ShowForLine(IWpfTextViewLine line) { _lineSpans = LineCoverageGlyphFactory.GetSpansForLine(line, _currentSpans); RaiseAllTagsChanged(); diff --git a/OpenCover.UI/Tagger/TextTaggerProvider.cs b/OpenCover.UI/Tagger/TextTaggerProvider.cs index daa2810..66890ac 100644 --- a/OpenCover.UI/Tagger/TextTaggerProvider.cs +++ b/OpenCover.UI/Tagger/TextTaggerProvider.cs @@ -54,9 +54,9 @@ public ITagger CreateTagger(ITextView textView, ITextBuffer buffer) where // create new instance if (instance == null) - { - var coveredClassType = Registry.GetClassificationType("text-background-covered"); - var notCoveredClassType = Registry.GetClassificationType("text-background-notcovered"); + { + var coveredClassType = Registry.GetClassificationType(ClassificationTypes.TextBackgroundCovered); + var notCoveredClassType = Registry.GetClassificationType(ClassificationTypes.TextBackgroundNotCovered); instance = new TextTagger(textView, TextSearchService, coveredClassType, notCoveredClassType); }