Skip to content

Commit

Permalink
Merge pull request #71 from pver/code_cleanup
Browse files Browse the repository at this point in the history
Small code cleanup
  • Loading branch information
pver committed May 27, 2015
2 parents ae6457f + 3c3575a commit 965938c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 41 deletions.
1 change: 1 addition & 0 deletions OpenCover.UI/OpenCover.UI.VS2013.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<Compile Include="Glyphs\LineCoverageGlyphFactoryProvider.cs" />
<Compile Include="Helpers\LineCoverageState.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Tagger\ClassificationTypes.cs" />
<Compile Include="Tagger\LineCoverageTag.cs" />
<Compile Include="Tagger\LineCoverageTagger.cs" />
<Compile Include="Commands\CodeCoverageToolWindowCommand.cs" />
Expand Down
1 change: 1 addition & 0 deletions OpenCover.UI/OpenCover.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<Compile Include="Glyphs\LineCoverageGlyphFactoryProvider.cs" />
<Compile Include="Helpers\LineCoverageState.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Tagger\ClassificationTypes.cs" />
<Compile Include="Tagger\LineCoverageTag.cs" />
<Compile Include="Tagger\LineCoverageTagger.cs" />
<Compile Include="Commands\CodeCoverageToolWindowCommand.cs" />
Expand Down
19 changes: 10 additions & 9 deletions OpenCover.UI/Settings.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -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";
}
}
}
8 changes: 8 additions & 0 deletions OpenCover.UI/Tagger/ClassificationTypes.cs
Original file line number Diff line number Diff line change
@@ -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";
}
}
5 changes: 0 additions & 5 deletions OpenCover.UI/Tagger/LineCoverageTag.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
10 changes: 4 additions & 6 deletions OpenCover.UI/Tagger/LineCoverageTagger.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -91,9 +89,9 @@ IEnumerable<ITagSpan<LineCoverageTag>> ITagger<LineCoverageTag>.GetTags(Normaliz
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}

Expand Down
12 changes: 6 additions & 6 deletions OpenCover.UI/Tagger/TextBackground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -24,16 +24,16 @@ public static class CoveredTextBackgroundTypeExports
public static class NotCoveredTextBackgroundTypeExports
{
[Export(typeof(ClassificationTypeDefinition))]
[Name("text-background-notcovered")]
[Name(ClassificationTypes.TextBackgroundNotCovered)]
public static ClassificationTypeDefinition OrdinaryClassificationType;
}

/// <summary>
/// Class defining background color for covered classes
/// </summary>
[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
Expand All @@ -52,8 +52,8 @@ public CoveredTextBackground()
/// Class defining background color for covered classes
/// </summary>
[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
Expand Down
27 changes: 15 additions & 12 deletions OpenCover.UI/Tagger/TextTagger.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -95,7 +94,7 @@ public IEnumerable<ITagSpan<ClassificationTag>> 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<ClassificationTag>(span, tag);
}
Expand All @@ -119,22 +118,26 @@ public static TextTagger GetTagger(ITextView view)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}

/// <summary>
/// <summary>
/// Show spans for line only
/// </summary>
/// <param name="line"></param>
internal void ShowForLine(Microsoft.VisualStudio.Text.Formatting.IWpfTextViewLine line)
internal void ShowForLine(IWpfTextViewLine line)
{
_lineSpans = LineCoverageGlyphFactory.GetSpansForLine(line, _currentSpans);
RaiseAllTagsChanged();
Expand Down
6 changes: 3 additions & 3 deletions OpenCover.UI/Tagger/TextTaggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public ITagger<T> CreateTagger<T>(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);
}

Expand Down

0 comments on commit 965938c

Please sign in to comment.