Skip to content

Commit 9df88e8

Browse files
authored
Clear UI command (#139)
Add button for clearing the ui fixes #132 Should consider a file watcher
1 parent e7d0ff5 commit 9df88e8

File tree

7 files changed

+124
-5
lines changed

7 files changed

+124
-5
lines changed

FineCodeCoverage/FineCodeCoverage.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<Compile Include="Options\IAppOptions.cs" />
171171
<Compile Include="Options\IAppOptionsProvider.cs" />
172172
<Compile Include="Options\IAppOptionsStorageProvider.cs" />
173+
<Compile Include="Output\ClearUICommand.cs" />
173174
<Compile Include="Output\IProcess.cs" />
174175
<Compile Include="Output\OutputToolWindow.cs" />
175176
<Compile Include="Output\OutputToolWindowCommand.cs" />
@@ -228,6 +229,7 @@
228229
<Link>Resources\LICENSE</Link>
229230
<IncludeInVSIX>true</IncludeInVSIX>
230231
</Content>
232+
<Content Include="Output\Resources\ClearUICommand.png" />
231233
<Content Include="Output\Resources\OutputToolWindowCommand.png" />
232234
<Content Include="ZippedTools\coverlet.console.3.0.3.zip">
233235
<IncludeInVSIX>true</IncludeInVSIX>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.ComponentModel.Design;
3+
using System.Globalization;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using FineCodeCoverage.Engine;
7+
using Microsoft.VisualStudio.Shell;
8+
using Microsoft.VisualStudio.Shell.Interop;
9+
using Task = System.Threading.Tasks.Task;
10+
11+
namespace FineCodeCoverage.Output
12+
{
13+
/// <summary>
14+
/// Command handler
15+
/// </summary>
16+
internal sealed class ClearUICommand
17+
{
18+
/// <summary>
19+
/// Command ID.
20+
/// </summary>
21+
public const int CommandId = 256;
22+
23+
/// <summary>
24+
/// Command menu group (command set GUID).
25+
/// </summary>
26+
public static readonly Guid CommandSet = new Guid("d58a999f-4a1b-42df-839a-cb31a0a4fed7");
27+
28+
private readonly IFCCEngine fccEngine;
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="ClearUICommand"/> class.
32+
/// Adds our command handlers for menu (commands must exist in the command table file)
33+
/// </summary>
34+
/// <param name="package">Owner package, not null.</param>
35+
/// <param name="commandService">Command service to add command to, not null.</param>
36+
private ClearUICommand(OleMenuCommandService commandService, IFCCEngine fccEngine)
37+
{
38+
this.fccEngine = fccEngine;
39+
commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
40+
41+
var menuCommandID = new CommandID(CommandSet, CommandId);
42+
var menuItem = new MenuCommand(this.Execute, menuCommandID);
43+
commandService.AddCommand(menuItem);
44+
}
45+
46+
/// <summary>
47+
/// Gets the instance of the command.
48+
/// </summary>
49+
public static ClearUICommand Instance
50+
{
51+
get;
52+
private set;
53+
}
54+
55+
/// <summary>
56+
/// Initializes the singleton instance of the command.
57+
/// </summary>
58+
/// <param name="package">Owner package, not null.</param>
59+
public static async Task InitializeAsync(AsyncPackage package, IFCCEngine fccEngine)
60+
{
61+
// Switch to the main thread - the call to AddCommand in ClearUICommand's constructor requires
62+
// the UI thread.
63+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
64+
65+
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
66+
Instance = new ClearUICommand(commandService, fccEngine);
67+
}
68+
69+
/// <summary>
70+
/// This function is the callback used to execute the command when the menu item is clicked.
71+
/// See the constructor to see how the menu item is associated with this function using
72+
/// OleMenuCommandService service and MenuCommand class.
73+
/// </summary>
74+
/// <param name="sender">Event sender.</param>
75+
/// <param name="e">Event args.</param>
76+
private void Execute(object sender, EventArgs e)
77+
{
78+
ThreadHelper.ThrowIfNotOnUIThread();
79+
fccEngine.ClearUI();
80+
}
81+
82+
}
83+
}

FineCodeCoverage/Output/OutputToolWindowPackage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
7575
componentModel = sp.GetService(typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel)) as Microsoft.VisualStudio.ComponentModelHost.IComponentModel;
7676
Assumes.Present(componentModel);
7777
await OutputToolWindowCommand.InitializeAsync(this);
78+
await ClearUICommand.InitializeAsync(this, componentModel.GetService<IFCCEngine>());
7879
}
7980

8081
protected override System.Threading.Tasks.Task<object> InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken)

FineCodeCoverage/Output/OutputToolWindowPackage.vsct

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
defining some of the constants that we will use inside the file. -->
1616

1717
<!--This is the file that defines the IDs for all the commands exposed by VisualStudio. -->
18-
<Extern href="stdidcmd.h"/>
18+
<Extern href="stdidcmd.h" />
1919

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

2323
<!--The Commands section is where commands, menus, and menu groups are defined.
2424
This section uses a Guid to identify the package that provides the command defined inside it. -->
@@ -43,12 +43,19 @@
4343
<CommandFlag>DynamicVisibility</CommandFlag>
4444
If you do not want an image next to your command, remove the Icon node /> -->
4545
<Button guid="guidOutputToolWindowPackageCmdSet" id="OutputToolWindowCommandId" priority="0x0100" type="Button">
46-
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1"/>
46+
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1" />
4747
<Icon guid="guidImages" id="bmpPic1" />
4848
<Strings>
4949
<ButtonText>Fine Code Coverage</ButtonText>
5050
</Strings>
5151
</Button>
52+
<Button guid="guidOutputToolWindowPackageCmdSet1" id="cmdidClearUICommand" priority="0x0100" type="Button">
53+
<Parent guid="guidOutputToolWindowPackageCmdSet1" id="MyMenuGroup" />
54+
<Icon guid="guidImages1" id="bmpPic1" />
55+
<Strings>
56+
<ButtonText>FCC Clear UI</ButtonText>
57+
</Strings>
58+
</Button>
5259
</Buttons>
5360

5461
<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
@@ -58,8 +65,14 @@
5865
bitmap strip containing the bitmaps and then there are the numeric ids of the elements used
5966
inside a button definition. An important aspect of this declaration is that the element id
6067
must be the actual index (1-based) of the bitmap inside the bitmap strip. -->
61-
<Bitmap guid="guidImages" href="Resources\OutputToolWindowCommand.png" usedList="bmpPic1"/>
68+
<Bitmap guid="guidImages" href="Resources\OutputToolWindowCommand.png" usedList="bmpPic1" />
69+
<Bitmap guid="guidImages1" href="Resources\ClearUICommand.png" usedList="bmpPic1" />
6270
</Bitmaps>
71+
<Groups>
72+
<Group guid="guidOutputToolWindowPackageCmdSet1" id="MyMenuGroup" priority="0x0600">
73+
<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />
74+
</Group>
75+
</Groups>
6376
</Commands>
6477

6578
<Symbols>
@@ -71,7 +84,16 @@
7184
<IDSymbol name="OutputToolWindowCommandId" value="0x0100" />
7285
</GuidSymbol>
7386

74-
<GuidSymbol name="guidImages" value="{297e101c-4afa-47b1-b382-087cfb4618b0}" >
87+
<GuidSymbol name="guidImages" value="{297e101c-4afa-47b1-b382-087cfb4618b0}">
88+
<IDSymbol name="bmpPic1" value="1" />
89+
</GuidSymbol>
90+
91+
<GuidSymbol value="{d58a999f-4a1b-42df-839a-cb31a0a4fed7}" name="guidOutputToolWindowPackageCmdSet1">
92+
<IDSymbol value="4128" name="MyMenuGroup" />
93+
<IDSymbol value="256" name="cmdidClearUICommand" />
94+
</GuidSymbol>
95+
96+
<GuidSymbol value="{8252a6d7-bcf3-4518-ae22-ad20ef8d4b63}" name="guidImages1">
7597
<IDSymbol name="bmpPic1" value="1" />
7698
</GuidSymbol>
7799
</Symbols>

FineCodeCoverage/Output/OutputToolWindowPackage1.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ internal sealed partial class PackageGuids
2020

2121
public const string guidImagesString = "297e101c-4afa-47b1-b382-087cfb4618b0";
2222
public static Guid guidImages = new Guid(guidImagesString);
23+
24+
public const string guidOutputToolWindowPackageCmdSet1String = "d58a999f-4a1b-42df-839a-cb31a0a4fed7";
25+
public static Guid guidOutputToolWindowPackageCmdSet1 = new Guid(guidOutputToolWindowPackageCmdSet1String);
26+
27+
public const string guidImages1String = "8252a6d7-bcf3-4518-ae22-ad20ef8d4b63";
28+
public static Guid guidImages1 = new Guid(guidImages1String);
2329
}
2430
/// <summary>
2531
/// Helper class that encapsulates all CommandIDs uses across VS Package.
@@ -28,5 +34,7 @@ internal sealed partial class PackageIds
2834
{
2935
public const int OutputToolWindowCommandId = 0x0100;
3036
public const int bmpPic1 = 0x0001;
37+
public const int MyMenuGroup = 0x1020;
38+
public const int cmdidClearUICommand = 0x0100;
3139
}
3240
}
735 Bytes
Loading

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Introduction
1515

1616
Fine Code Coverage works by reacting to the visual studio test explorer, providing coverage from each test project containing tests that you have selected
1717
to run. This coverage is presented as a single unified report as well as coloured margins alongside your code.
18+
This coverage is not dynamic and represents the coverage obtained from the last time you executed tests.
19+
When the coverage becomes outdated, you can click the 'FCC Clear UI' button in Tools or run coverage again.
20+
1821
The coverage is provided by either [OpenCover](https://github.com/OpenCover/opencover) for old style projects and [Coverlet](https://github.com/coverlet-coverage/coverlet)
1922
for new style sdk projects. FCC provides an abstraction over both so that it is possible to ignore the differences between the two but there are circumstances where
2023
it is important to be aware of cover tool that will be run. This is most apparent when Coverlet is used, please read on for the specifics.

0 commit comments

Comments
 (0)