Skip to content

Commit 953e73b

Browse files
authored
Reportgenerator tidy (#203)
* opacity 0 to visibility hidden as was still clickable * remove unused variable * rename theme method * remove selector that was having no effect * change variable name - theme instead of colours * file per type * exception handling for ThemeResourceKeyProvider
1 parent df92cef commit 953e73b

File tree

7 files changed

+198
-147
lines changed

7 files changed

+198
-147
lines changed

SharedProject/Core/ReportGenerator/IReportColours.cs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -54,52 +54,4 @@ internal interface IReportColours
5454
Color TextBoxTextColour { get; }
5555
}
5656

57-
internal class ReportColours : IReportColours
58-
{
59-
public Color BackgroundColour { get; set; }
60-
61-
public Color ComboBoxBorderColour { get; set; }
62-
63-
public Color ComboBoxColour { get; set; }
64-
65-
public Color ComboBoxTextColour { get; set; }
66-
67-
public Color CoverageTableActiveSortColour { get; set; }
68-
69-
public Color CoverageTableExpandCollapseIconColour { get; set; }
70-
71-
public Color CoverageTableHeaderFontColour { get; set; }
72-
73-
public Color CoverageTableInactiveSortColour { get; set; }
74-
75-
public Color CoverageTableRowHoverBackgroundColour { get; set; }
76-
77-
public Color DivHeaderBackgroundColour { get; set; }
78-
79-
public Color FontColour { get; set; }
80-
81-
public Color GrayCoverage { get; set; }
82-
83-
public Color HeaderBorderColour { get; set; }
84-
85-
public Color HeaderFontColour { get; set; }
86-
87-
public Color LinkColour { get; set; }
88-
89-
public Color ScrollBarArrowColour { get; set; }
90-
91-
public Color ScrollBarThumbColour { get; set; }
92-
93-
public Color ScrollBarTrackColour { get; set; }
94-
95-
public Color TabBackgroundColour { get; set; }
96-
97-
public Color TableBorderColour { get; set; }
98-
99-
public Color TextBoxBorderColour { get; set; }
100-
101-
public Color TextBoxColour { get; set; }
102-
103-
public Color TextBoxTextColour { get; set; }
104-
}
10557
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Microsoft.VisualStudio.Shell;
5+
6+
namespace FineCodeCoverage.Engine.ReportGenerator
7+
{
8+
internal interface IThemeResourceKeyProvider
9+
{
10+
ThemeResourceKey Provide(string reportPart);
11+
}
12+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Drawing;
5+
6+
namespace FineCodeCoverage.Engine.ReportGenerator
7+
{
8+
internal class ReportColours : IReportColours
9+
{
10+
public Color BackgroundColour { get; set; }
11+
12+
public Color ComboBoxBorderColour { get; set; }
13+
14+
public Color ComboBoxColour { get; set; }
15+
16+
public Color ComboBoxTextColour { get; set; }
17+
18+
public Color CoverageTableActiveSortColour { get; set; }
19+
20+
public Color CoverageTableExpandCollapseIconColour { get; set; }
21+
22+
public Color CoverageTableHeaderFontColour { get; set; }
23+
24+
public Color CoverageTableInactiveSortColour { get; set; }
25+
26+
public Color CoverageTableRowHoverBackgroundColour { get; set; }
27+
28+
public Color DivHeaderBackgroundColour { get; set; }
29+
30+
public Color FontColour { get; set; }
31+
32+
public Color GrayCoverage { get; set; }
33+
34+
public Color HeaderBorderColour { get; set; }
35+
36+
public Color HeaderFontColour { get; set; }
37+
38+
public Color LinkColour { get; set; }
39+
40+
public Color ScrollBarArrowColour { get; set; }
41+
42+
public Color ScrollBarThumbColour { get; set; }
43+
44+
public Color ScrollBarTrackColour { get; set; }
45+
46+
public Color TabBackgroundColour { get; set; }
47+
48+
public Color TableBorderColour { get; set; }
49+
50+
public Color TextBoxBorderColour { get; set; }
51+
52+
public Color TextBoxColour { get; set; }
53+
54+
public Color TextBoxTextColour { get; set; }
55+
}
56+
57+
}

SharedProject/Core/ReportGenerator/ReportColoursProvider.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,11 @@
11
using Microsoft.VisualStudio.PlatformUI;
22
using Microsoft.VisualStudio.Shell;
33
using System;
4-
using System.Collections.Generic;
54
using System.ComponentModel.Composition;
6-
using System.IO;
7-
using System.Linq;
85
using System.Reflection;
9-
using System.Text;
10-
using System.Xml.Linq;
116

127
namespace FineCodeCoverage.Engine.ReportGenerator
138
{
14-
internal interface IThemeResourceKeyProvider
15-
{
16-
ThemeResourceKey Provide(string reportPart);
17-
}
18-
19-
// could watch
20-
[Export(typeof(IThemeResourceKeyProvider))]
21-
internal class ThemeResourceKeyProvider : IThemeResourceKeyProvider
22-
{
23-
private XElement root;
24-
public ThemeResourceKeyProvider()
25-
{
26-
var fccExtensionsDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
27-
var fccResourcesDirectory = Path.Combine(fccExtensionsDirectory, "Resources");
28-
var reportPartsPath = Path.Combine(fccResourcesDirectory, "reportparts.xml");
29-
root = XElement.Load(reportPartsPath);
30-
}
31-
public ThemeResourceKey Provide(string reportPart)
32-
{
33-
var matchingElement = root.Elements("ReportPart").First(reportPartElement => reportPartElement.Attribute("Name").Value == reportPart);
34-
if (matchingElement != null)
35-
{
36-
// probably should change the attribute name
37-
var themeResourceKeyString = matchingElement.Attribute("SelectedThemeColourName").Value;
38-
var parts = themeResourceKeyString.Split('.');
39-
if(parts.Length == 2 && !String.IsNullOrWhiteSpace(parts[1]))
40-
{
41-
var @class = parts[0];
42-
Type classType = null;
43-
switch (@class)
44-
{
45-
case "EnvironmentColors":
46-
classType = typeof(EnvironmentColors);
47-
break;
48-
case "CommonControlsColors":
49-
classType = typeof(CommonControlsColors);
50-
break;
51-
}
52-
if(classType != null)
53-
{
54-
//try ?
55-
var themeResourceKeyProperty = classType.GetProperty(parts[1], BindingFlags.Public | BindingFlags.Static);
56-
if(themeResourceKeyProperty != null)
57-
{
58-
return themeResourceKeyProperty.GetValue(null) as ThemeResourceKey;
59-
}
60-
}
61-
}
62-
}
63-
return null;
64-
}
65-
}
66-
679
[Export(typeof(IReportColoursProvider))]
6810
internal class ReportColoursProvider : IReportColoursProvider
6911
{

SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public void Initialize(string appDataFolder)
9292

9393
public async Task<ReportGeneratorResult> GenerateAsync(IEnumerable<string> coverOutputFiles, string reportOutputFolder, bool throwError = false)
9494
{
95-
var darkMode = false;
9695
var title = "ReportGenerator Run";
9796

9897
var unifiedHtmlFile = Path.Combine(reportOutputFolder, "index.html");
@@ -181,7 +180,7 @@ async Task<bool> run(string outputReportType, string inputReports)
181180
182181
}
183182
184-
private void SetInitialStyle(HtmlAgilityPack.HtmlDocument document)
183+
private void SetInitialTheme(HtmlAgilityPack.HtmlDocument document)
185184
{
186185
187186
var backgroundColor = ToJsColour(reportColours.BackgroundColour);
@@ -277,7 +276,7 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo
277276
278277
279278
doc.LoadHtml(htmlForProcessing);
280-
SetInitialStyle(doc);
279+
SetInitialTheme(doc);
281280
htmlForProcessing = null;
282281
283282
doc.DocumentNode.QuerySelectorAll(".footer").ToList().ForEach(x => x.SetAttributeValue("style", "display:none"));
@@ -374,8 +373,8 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo
374373
table,tr,th,td {{ font-size: small; }}
375374
body {{ -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none }}
376375
table.overview th, table.overview td {{ font-size: small; white-space: nowrap; word-break: normal; padding-left:10px;padding-right:10px; }}
377-
coverage-info div.customizebox div:nth-child(2) {{ opacity:0;font-size:1px;height:1px;padding:0;border:0;margin:0 }} */
378-
coverage-info div.customizebox div:nth-child(2) * {{ opacity:0;font-size:1px;height:1px;padding:0;border:0;margin:0 }} */
376+
coverage-info div.customizebox div:nth-child(2) {{ visibility:hidden;font-size:1px;height:1px;padding:0;border:0;margin:0 }}
377+
coverage-info div.customizebox div:nth-child(2) * {{ visibility:hidden;font-size:1px;height:1px;padding:0;border:0;margin:0 }}
379378
table,tr,th,td {{ border: 1px solid; font-size: small; }}
380379
input[type=text] {{ color:{ToJsColour(reportColours.TextBoxTextColour)}; background-color:{ToJsColour(reportColours.TextBoxColour)};border-color:{ToJsColour(reportColours.TextBoxBorderColour)} }}
381380
select {{ color:{ToJsColour(reportColours.ComboBoxTextColour)}; background-color:{ToJsColour(reportColours.ComboBoxColour)};border-color:{ToJsColour(reportColours.ComboBoxBorderColour)} }}
@@ -405,79 +404,79 @@ function getStyleSheetById(id){{
405404
}}
406405
}}
407406
}}
408-
function {ThemeChangedJSFunctionName}(colours){{
407+
function {ThemeChangedJSFunctionName}(theme){{
409408
var fccMediaStylesheet = getStyleSheetById('fccMediaStyle');
410409
var highContrastRule = fccMediaStylesheet.cssRules[1]
411410
var highContrastRules = highContrastRule.cssRules
412-
getStyleBySelector(highContrastRules,'table.coverage > td.gray').setProperty('background-color',colours.{nameof(JsThemeStyling.GrayCoverage)});
411+
getStyleBySelector(highContrastRules,'table.coverage > td.gray').setProperty('background-color',theme.{nameof(JsThemeStyling.GrayCoverage)});
413412
414413
var fccStyleSheet1Rules = getStyleSheetById('fccStyle1').cssRules;
415414
416415
var scrollBarStyle = getStyleBySelector(fccStyleSheet1Rules,'body, html');
417-
scrollBarStyle.setProperty('scrollbar-arrow-color',colours.{nameof(JsThemeStyling.ScrollBarArrow)});
418-
scrollBarStyle.setProperty('scrollbar-track-color',colours.{nameof(JsThemeStyling.ScrollBarTrack)});
419-
scrollBarStyle.setProperty('scrollbar-face-color',colours.{nameof(JsThemeStyling.ScrollBarThumb)});
420-
scrollBarStyle.setProperty('scrollbar-shadow-color',colours.{nameof(JsThemeStyling.ScrollBarThumb)});
421-
scrollBarStyle.setProperty('scrollbar-highlight-color',colours.{nameof(JsThemeStyling.ScrollBarThumb)});
422-
scrollBarStyle.setProperty('scrollbar-3dlight-color',colours.{nameof(JsThemeStyling.ScrollBarThumb)});
423-
scrollBarStyle.setProperty('scrollbar-darkshadow-color',colours.{nameof(JsThemeStyling.ScrollBarThumb)});
424-
425-
getStyleBySelector(fccStyleSheet1Rules,'*, body').setProperty('color',colours.{nameof(JsThemeStyling.FontColour)});
416+
scrollBarStyle.setProperty('scrollbar-arrow-color',theme.{nameof(JsThemeStyling.ScrollBarArrow)});
417+
scrollBarStyle.setProperty('scrollbar-track-color',theme.{nameof(JsThemeStyling.ScrollBarTrack)});
418+
scrollBarStyle.setProperty('scrollbar-face-color',theme.{nameof(JsThemeStyling.ScrollBarThumb)});
419+
scrollBarStyle.setProperty('scrollbar-shadow-color',theme.{nameof(JsThemeStyling.ScrollBarThumb)});
420+
scrollBarStyle.setProperty('scrollbar-highlight-color',theme.{nameof(JsThemeStyling.ScrollBarThumb)});
421+
scrollBarStyle.setProperty('scrollbar-3dlight-color',theme.{nameof(JsThemeStyling.ScrollBarThumb)});
422+
scrollBarStyle.setProperty('scrollbar-darkshadow-color',theme.{nameof(JsThemeStyling.ScrollBarThumb)});
423+
424+
getStyleBySelector(fccStyleSheet1Rules,'*, body').setProperty('color',theme.{nameof(JsThemeStyling.FontColour)});
426425
var textStyle = getStyleBySelector(fccStyleSheet1Rules,'input[type=text]');
427-
textStyle.setProperty('color',colours.{nameof(JsThemeStyling.TextBoxTextColour)});
428-
textStyle.setProperty('background-color',colours.{nameof(JsThemeStyling.TextBoxColour)});
429-
textStyle.setProperty('border-color',colours.{nameof(JsThemeStyling.TextBoxBorderColour)});
426+
textStyle.setProperty('color',theme.{nameof(JsThemeStyling.TextBoxTextColour)});
427+
textStyle.setProperty('background-color',theme.{nameof(JsThemeStyling.TextBoxColour)});
428+
textStyle.setProperty('border-color',theme.{nameof(JsThemeStyling.TextBoxBorderColour)});
430429
431430
var comboStyle = getStyleBySelector(fccStyleSheet1Rules,'select');
432-
comboStyle.setProperty('color',colours.{nameof(JsThemeStyling.ComboBoxText)});
433-
comboStyle.setProperty('background-color',colours.{nameof(JsThemeStyling.ComboBox)});
434-
comboStyle.setProperty('border-color',colours.{nameof(JsThemeStyling.ComboBoxBorder)});
431+
comboStyle.setProperty('color',theme.{nameof(JsThemeStyling.ComboBoxText)});
432+
comboStyle.setProperty('background-color',theme.{nameof(JsThemeStyling.ComboBox)});
433+
comboStyle.setProperty('border-color',theme.{nameof(JsThemeStyling.ComboBoxBorder)});
435434
436435
var fccStyleSheet2Rules = getStyleSheetById('fccStyle2').cssRules;
437-
getStyleBySelector(fccStyleSheet2Rules,'#divHeader').setProperty('background-color',colours.{nameof(JsThemeStyling.DivHeaderBackgroundColour)});
436+
getStyleBySelector(fccStyleSheet2Rules,'#divHeader').setProperty('background-color',theme.{nameof(JsThemeStyling.DivHeaderBackgroundColour)});
438437
var headerTabsStyle = getStyleBySelector(fccStyleSheet2Rules,'table#headerTabs td');
439-
headerTabsStyle.setProperty('color',colours.{nameof(JsThemeStyling.HeaderFontColour)});
440-
headerTabsStyle.setProperty('border-color',colours.{nameof(JsThemeStyling.HeaderBorderColour)});
441-
getStyleBySelector(fccStyleSheet2Rules,'table#headerTabs td.tab').setProperty('background-color',colours.{nameof(JsThemeStyling.TabBackgroundColour)});
438+
headerTabsStyle.setProperty('color',theme.{nameof(JsThemeStyling.HeaderFontColour)});
439+
headerTabsStyle.setProperty('border-color',theme.{nameof(JsThemeStyling.HeaderBorderColour)});
440+
getStyleBySelector(fccStyleSheet2Rules,'table#headerTabs td.tab').setProperty('background-color',theme.{nameof(JsThemeStyling.TabBackgroundColour)});
442441
443442
var mainStyle = document.styleSheets[0];
444443
var mainRules = mainStyle.cssRules;
445444
446-
getStyleBySelector(mainRules,'.gray').setProperty('background-color',colours.{nameof(JsThemeStyling.GrayCoverage)});
445+
getStyleBySelector(mainRules,'.gray').setProperty('background-color',theme.{nameof(JsThemeStyling.GrayCoverage)});
447446
448-
getStyleBySelector(mainRules,'html').setProperty('background-color',colours.{nameof(JsThemeStyling.BackgroundColour)});
449-
getStyleBySelector(mainRules,'.container').setProperty('background-color',colours.{nameof(JsThemeStyling.BackgroundColour)});
447+
getStyleBySelector(mainRules,'html').setProperty('background-color',theme.{nameof(JsThemeStyling.BackgroundColour)});
448+
getStyleBySelector(mainRules,'.container').setProperty('background-color',theme.{nameof(JsThemeStyling.BackgroundColour)});
450449
451-
var overviewTableBorder = '1px solid ' + colours.{nameof(JsThemeStyling.TableBorderColour)};
450+
var overviewTableBorder = '1px solid ' + theme.{nameof(JsThemeStyling.TableBorderColour)};
452451
var overviewStyle = getStyleBySelector(mainRules,'.overview');
453452
overviewStyle.setProperty('border',overviewTableBorder);
454453
var overviewThStyle = getStyleBySelector(mainRules,'.overview th');
455-
overviewThStyle.setProperty('background-color',colours.{nameof(JsThemeStyling.BackgroundColour)});
454+
overviewThStyle.setProperty('background-color',theme.{nameof(JsThemeStyling.BackgroundColour)});
456455
overviewThStyle.setProperty('border',overviewTableBorder);
457456
var overviewTdStyle = getStyleBySelector(mainRules,'.overview td');
458457
overviewTdStyle.setProperty('border',overviewTableBorder);
459458
460459
var overviewHeaderLinksStyle = getStyleBySelector(mainRules,'.overview th a');
461-
overviewHeaderLinksStyle.setProperty('color',colours.{nameof(JsThemeStyling.CoverageTableHeaderFontColour)});
460+
overviewHeaderLinksStyle.setProperty('color',theme.{nameof(JsThemeStyling.CoverageTableHeaderFontColour)});
462461
463462
var overviewTrHoverStyle = getStyleBySelector(mainRules,'.overview tr:hover');
464-
overviewTrHoverStyle.setProperty('background',colours.{nameof(JsThemeStyling.CoverageTableRowHoverBackgroundColour)});
463+
overviewTrHoverStyle.setProperty('background',theme.{nameof(JsThemeStyling.CoverageTableRowHoverBackgroundColour)});
465464
466465
var linkStyle = getStyleBySelector(mainRules,'a');
467466
var linkHoverStyle = getStyleBySelector(mainRules,'a:hover');
468-
linkStyle.setProperty('color',colours.{nameof(JsThemeStyling.LinkColour)});
469-
linkHoverStyle.setProperty('color',colours.{nameof(JsThemeStyling.LinkColour)});
467+
linkStyle.setProperty('color',theme.{nameof(JsThemeStyling.LinkColour)});
468+
linkHoverStyle.setProperty('color',theme.{nameof(JsThemeStyling.LinkColour)});
470469
471470
var iconPlusStyle = getStyleBySelector(mainRules,'.icon-plus');
472-
iconPlusStyle.setProperty('background-image',colours.{nameof(JsThemeStyling.PlusBase64)});
471+
iconPlusStyle.setProperty('background-image',theme.{nameof(JsThemeStyling.PlusBase64)});
473472
var iconMinusStyle = getStyleBySelector(mainRules,'.icon-minus');
474-
iconMinusStyle.setProperty('background-image',colours.{nameof(JsThemeStyling.MinusBase64)});
473+
iconMinusStyle.setProperty('background-image',theme.{nameof(JsThemeStyling.MinusBase64)});
475474
var iconDownActiveStyle = getStyleBySelector(mainRules,'.icon-down-dir_active');
476-
iconDownActiveStyle.setProperty('background-image',colours.{nameof(JsThemeStyling.DownActiveBase64)});
475+
iconDownActiveStyle.setProperty('background-image',theme.{nameof(JsThemeStyling.DownActiveBase64)});
477476
var iconDownInactiveStyle = getStyleBySelector(mainRules,'.icon-down-dir');
478-
iconDownInactiveStyle.setProperty('background-image',colours.{nameof(JsThemeStyling.DownInactiveBase64)});
477+
iconDownInactiveStyle.setProperty('background-image',theme.{nameof(JsThemeStyling.DownInactiveBase64)});
479478
var iconUpActiveStyle = getStyleBySelector(mainRules,'.icon-up-dir_active');
480-
iconUpActiveStyle.setProperty('background-image',colours.{nameof(JsThemeStyling.UpActiveBase64)});
479+
iconUpActiveStyle.setProperty('background-image',theme.{nameof(JsThemeStyling.UpActiveBase64)});
481480
}}
482481
var htmlExtension = '.html';
483482
@@ -528,7 +527,6 @@ function getStyleSheetById(id){{
528527
529528
htmlSb.Replace("</head>", $@"
530529
<style type=""text/css"" id='fccMediaStyle'>
531-
table.overview.table-fixed.stripped > thead > tr > th:nth-of-type(4) > a:nth-of-type(2) {{ display: none; }}
532530
@media screen and (-ms-high-contrast:active){{
533531
table.coverage > td.green{{ background-color: windowText }}
534532
table.coverage > td.gray{{

0 commit comments

Comments
 (0)