Skip to content

Commit

Permalink
Merge pull request #93 from pver/issue_92
Browse files Browse the repository at this point in the history
Add button to show uncovered classes, Fixes #92
  • Loading branch information
pver committed Aug 12, 2015
2 parents 52e3a46 + 8fd9069 commit cf7e8e7
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 41 deletions.
24 changes: 15 additions & 9 deletions OpenCover.UI/Commands/ResultsToolbarCommands.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Shell.Interop;
using System.Collections.Generic;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell;
using OpenCover.UI.Views;
using OpenCover.UI.Model.Test;
using OpenCover.UI.Helpers;

namespace OpenCover.UI.Commands
{
Expand Down Expand Up @@ -76,6 +68,11 @@ private static void Initialize()
new CommandID(GuidList.GuidOpenCoverTestExplorerContextMenuCommandSet,
(int)PkgCmdIDList.OpenCoverResultsToolbarShowCoverageGlyphsButton)) { Enabled = false, Checked = OpenCoverUIPackage.Instance.Settings.ShowCoverageGlyphs });

// Show colored lines command
_allCommands.Add(new OleMenuCommand((s, e) => ToggleShowUncoveredClasses((OleMenuCommand)s),
new CommandID(GuidList.GuidOpenCoverTestExplorerContextMenuCommandSet,
(int)PkgCmdIDList.OpenCoverResultsToolbarShowUncoveredClassesButton)) { Enabled = false, Checked = OpenCoverUIPackage.Instance.Settings.ShowUncoveredClasses });

_initialized = true;
}
}
Expand All @@ -97,5 +94,14 @@ private static void ToggleShowCoverageGlyphs(OleMenuCommand command)
OpenCoverUIPackage.Instance.Settings.ShowCoverageGlyphs = !OpenCoverUIPackage.Instance.Settings.ShowCoverageGlyphs;
command.Checked = OpenCoverUIPackage.Instance.Settings.ShowCoverageGlyphs;
}

/// <summary>
/// Action executed when user clicks on toolbar button
/// </summary>
private static void ToggleShowUncoveredClasses(OleMenuCommand command)
{
OpenCoverUIPackage.Instance.Settings.ShowUncoveredClasses = !OpenCoverUIPackage.Instance.Settings.ShowUncoveredClasses;
command.Checked = OpenCoverUIPackage.Instance.Settings.ShowUncoveredClasses;
}
}
}
4 changes: 2 additions & 2 deletions OpenCover.UI/Model/CoverageSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public IEnumerable<Module> CoveredModules
{
if (this.Modules != null && this.Modules.Length > 0)
{
return this.Modules.Where(c => c.Summary.SequenceCoverage > 0);
return this.Modules.Where(c => c.Summary.SequenceCoverage >= 0);
}

return null;
Expand All @@ -63,7 +63,7 @@ public IEnumerable<File> GetFiles()
{
if (Modules != null)
{
return Modules.Where(module => module.Summary.SequenceCoverage > 0).SelectMany(module => module.Files);
return Modules.Where(module => module.Summary.SequenceCoverage >= 0).SelectMany(module => module.Files);
}

return null;
Expand Down
5 changes: 2 additions & 3 deletions OpenCover.UI/Model/Module.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//
// This source code is released under the MIT License; Please read license.md file for more details.
//
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace OpenCover.Framework.Model
Expand Down Expand Up @@ -82,7 +81,7 @@ public IEnumerable<Class> CoveredClasses
{
if (this.Classes != null && this.Classes.Length > 0)
{
return this.Classes.Where(c => c.Summary.SequenceCoverage > 0);
return this.Classes.Where(c => c.Summary.SequenceCoverage >= 0);
}

return null;
Expand Down
29 changes: 19 additions & 10 deletions OpenCover.UI/Model/ModuleNode.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//
// This source code is released under the MIT License; Please read license.md file for more details.
//
using ICSharpCode.TreeView;
using OpenCover.Framework.Model;
using OpenCover.UI.Helpers;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.TreeView;
using OpenCover.Framework.Model;
using OpenCover.UI.Helpers;

namespace OpenCover.UI.Model
{
public class CoverageNode : SharpTreeNode
{
CoverageSession _coverageSession;
readonly CoverageSession _coverageSession;

public CoverageNode(CoverageSession coverageSession)
{
Expand Down Expand Up @@ -61,7 +61,7 @@ public override object Text
{
get
{
return System.IO.Path.GetFileName(_module.FullName);
return Path.GetFileName(_module.FullName);
}
}

Expand Down Expand Up @@ -93,8 +93,10 @@ public NamespaceNode(Module module, string @namespace)
_namespace = @namespace;

LazyLoading = true;

foreach (var @class in _module.CoveredClasses


var coveredClasses = _module.CoveredClasses;
foreach (var @class in coveredClasses
.Where(cc => cc.Namespace == _namespace))
{
_visitedSequencePoints += @class.Summary.VisitedSequencePoints;
Expand Down Expand Up @@ -136,7 +138,14 @@ public override object Icon

protected override void LoadChildren()
{
Children.AddRange(_module.CoveredClasses.Where(cc => cc.Namespace == _namespace).Select(@class => new ClassNode(@class)));
var coveredClasses = _module.CoveredClasses;

coveredClasses = OpenCoverUIPackage.Instance.Settings.ShowUncoveredClasses
? coveredClasses.Where(cc => cc.Namespace == _namespace)
: coveredClasses.Where(cc => cc.Namespace == _namespace && cc.Summary.SequenceCoverage > 0);

var classNodes = coveredClasses.Select(@class => new ClassNode(@class));
Children.AddRange(classNodes);
}
}

Expand Down
1 change: 1 addition & 0 deletions OpenCover.UI/OpenCover.UI.VS2013.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
<Link>license.md</Link>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Resource Include="Resources\ShowUncoveredClasses.png" />
<Resource Include="Resources\ShowCodeCoverageGlyphs.png" />
<Resource Include="Resources\ShowCodeCoverageColoring.png" />
<Resource Include="Resources\Successful.png" />
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 @@ -283,6 +283,7 @@
<Link>license.md</Link>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Resource Include="Resources\ShowUncoveredClasses.png" />
<Resource Include="Resources\ShowCodeCoverageGlyphs.png" />
<Resource Include="Resources\ShowCodeCoverageColoring.png" />
<Resource Include="Resources\Successful.png" />
Expand Down
15 changes: 15 additions & 0 deletions OpenCover.UI/OpenCover.UI.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<!--This header contains the command ids for the menus provided by the shell. -->
<Extern href="vsshlids.h"/>

<!--The Commands section is where we the commands, menus and menu groups are defined.
This section uses a Guid to identify the package that provides the command defined inside it. -->
<Commands package="guidOpenCoverUIPkg">
Expand Down Expand Up @@ -186,6 +187,15 @@
<CommandName>OpenCover.UI.ShowCoverageGylphs</CommandName>
<ButtonText>Show Code Coverage glyphs</ButtonText>
</Strings>
</Button>
<Button guid="GuidOpenCoverTestExplorerContextMenuCommandSet" id="OpenCoverResultsToolbarShowUncoveredClassesButton" priority="0x0100" type="Button">
<Parent guid="GuidOpenCoverTestExplorerContextMenuCommandSet" id="OpenCoverResultsToolbarGroup"/>
<Icon guid="guidUncoveredClasses" id="ShowUncoveredClasses" />
<CommandFlag>DefaultDisabled</CommandFlag>
<Strings>
<CommandName>OpenCover.UI.ShowUncoveredClasses</CommandName>
<ButtonText>Show Uncovered Classes</ButtonText>
</Strings>
</Button>
</Buttons>
<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
Expand All @@ -199,6 +209,7 @@
<Bitmap guid="guidRefresh" href="Resources\Refresh.png" usedList="RefreshTestExplorer"/>
<Bitmap guid="guidColoredLines" href="Resources\ShowCodeCoverageColoring.png" usedList="ShowLinesColored"/>
<Bitmap guid="guidCoverageGlyphs" href="Resources\ShowCodeCoverageGlyphs.png" usedList="ShowCoverageGylphs"/>
<Bitmap guid="guidUncoveredClasses" href="Resources\ShowUncoveredClasses.png" usedList="ShowUncoveredClasses"/>
</Bitmaps>

</Commands>
Expand Down Expand Up @@ -230,6 +241,9 @@
</GuidSymbol>
<GuidSymbol name="guidCoverageGlyphs" value="{727b66a9-6d9a-4f06-8ee6-f25ee17590af}" >
<IDSymbol name="ShowCoverageGylphs" value="1" />
</GuidSymbol>
<GuidSymbol name="guidUncoveredClasses" value="{727b66a9-6d9a-4f06-8ee6-f25ee17590df}" >
<IDSymbol name="ShowUncoveredClasses" value="1" />
</GuidSymbol>
<GuidSymbol name="GuidOpenCoverTestExplorerContextMenuCommandSet" value="{81F1321F-B605-47F6-AD43-FB2EC4891225}">
<IDSymbol name="OpenCoverTestExplorerContextMenu" value="0x1000"/>
Expand All @@ -251,6 +265,7 @@
<IDSymbol name="OpenCoverResultsToolbarGroup" value="0x3050" />
<IDSymbol name="OpenCoverResultsToolbarShowLinesColoredButton" value="0x3100" />
<IDSymbol name="OpenCoverResultsToolbarShowCoverageGlyphsButton" value="0x3110" />
<IDSymbol name="OpenCoverResultsToolbarShowUncoveredClassesButton" value="0x3120" />
</GuidSymbol>
</Symbols>
</CommandTable>
1 change: 1 addition & 0 deletions OpenCover.UI/PkgCmdID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ static class PkgCmdIDList
public const int OpenCoverResultsToolbarGroup = 0x3050;
public const int OpenCoverResultsToolbarShowLinesColoredButton = 0x3100;
public const int OpenCoverResultsToolbarShowCoverageGlyphsButton = 0x3110;
public const int OpenCoverResultsToolbarShowUncoveredClassesButton = 0x3120;
};
}
Binary file added OpenCover.UI/Resources/ShowUncoveredClasses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions OpenCover.UI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Settings: INotifyPropertyChanged
{
private bool _showLinesColored;
private bool _showCoverageGlyphs;
private bool _showUncoveredClasses;

private WritableSettingsStore _store;
private const string SETTINGS_PATH = "OpenCoverUI";

Expand All @@ -26,6 +28,7 @@ public Settings(WritableSettingsStore configurationSettingsStore)

_showLinesColored = _store.GetBoolean(SETTINGS_PATH, SettingNames.ShowLinesColored, false);
_showCoverageGlyphs = _store.GetBoolean(SETTINGS_PATH, SettingNames.ShowCoverageGlyphs, true);
_showUncoveredClasses = _store.GetBoolean(SETTINGS_PATH, SettingNames.ShowUncoveredClasses, true);
}

/// <summary>
Expand Down Expand Up @@ -62,6 +65,23 @@ public bool ShowCoverageGlyphs
}
}

/// <summary>
/// Gets or sets whether classes with zero coverage should be displayed
/// </summary>
public bool ShowUncoveredClasses
{
get { return _showUncoveredClasses; }
set
{
if (value != _showUncoveredClasses)
{
_showUncoveredClasses = value;
RaisePropertyChanged();
WriteBoolean(value);
}
}
}

/// <summary>
/// Raises the PropertyChanged event
/// </summary>
Expand Down Expand Up @@ -89,6 +109,7 @@ public static class SettingNames
{
public const string ShowLinesColored = "ShowLinesColored";
public const string ShowCoverageGlyphs = "ShowCoverageGlyphs";
public const string ShowUncoveredClasses = "ShowUncoveredClasses";
}
}
}
45 changes: 30 additions & 15 deletions OpenCover.UI/Views/CodeCoverageResultsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,46 @@ internal void Initialize(OpenCoverUIPackage package)
_package = package;
_package.VSEventsHandler.SolutionClosing += ClearTreeView;
_package.VSEventsHandler.SolutionOpened += ClearTreeView;

_package.Settings.PropertyChanged += PackageSettings_PropertyChanged;

}

/// <summary>
private void PackageSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (string.Equals(e.PropertyName, "ShowUncoveredClasses"))
{
UpdateCoverageResults();
}
}

/// <summary>
/// Updates the coverage results for current OpenCover run on the UI thread.
/// </summary>
/// <param name="data">The CoverageSession data.</param>
public void UpdateCoverageResults(CoverageSession data)
{
CoverageSession = data;

if (CoverageSession != null)
{
Dispatcher.BeginInvoke(new Action(() =>
{
CodeCoverageResultsTreeView.Root = new CoverageNode(data);
IsLoading = false;

if (NewCoverageDataAvailable != null)
NewCoverageDataAvailable(this, EventArgs.Empty);
CoverageSession = data;

}), null);
}
UpdateCoverageResults();
}

/// <summary>
public void UpdateCoverageResults()
{
if (CoverageSession != null)
{
Dispatcher.BeginInvoke(new Action(() =>
{
CodeCoverageResultsTreeView.Root = new CoverageNode(CoverageSession);
IsLoading = false;

if (NewCoverageDataAvailable != null)
NewCoverageDataAvailable(this, EventArgs.Empty);
}), null);
}
}

/// <summary>
/// Clears the TreeView.
/// </summary>
public void ClearTreeView()
Expand Down
3 changes: 1 addition & 2 deletions OpenCover.UI/Views/SettingsControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls;
using Microsoft.Win32;
using OpenCover.UI.Framework.ViewModel;

Expand Down

0 comments on commit cf7e8e7

Please sign in to comment.