@@ -17,9 +17,9 @@ Function Main {
17
17
# Get xaml files and loop through.
18
18
Get-ChildItem $themesFullDir - Filter * .xaml |
19
19
Foreach-Object {
20
- $xamlString = Get-Content - Path $_.FullName
20
+ $xamlLines = Get-Content - Path $_.FullName
21
21
$file = Select-ControlNameFromFile ($_.Name )
22
- Read-XamlStyles - xamlString $xamlString - file $file
22
+ Read-XamlStyles - xamlLines $xamlLines - file $file
23
23
}
24
24
Set-Defaults
25
25
Format-Output
@@ -33,8 +33,12 @@ Function Format-Output {
33
33
}
34
34
$previousFile = $style.File ;
35
35
36
- $linkAndStyleName = " [$ ( $style.Style ) ]($ ( $baseURL ) /$ ( $latestHash ) /" +
37
- " $ ( $filePathURL ) /MaterialDesignTheme.$ ( $style.File ) .xaml)" ;
36
+ $styleLink = " $ ( $baseURL ) /$ ( $latestHash ) /$ ( $filePathURL ) /MaterialDesignTheme.$ ( $style.File ) .xaml"
37
+ if ($style.LineNumber ) {
38
+ $styleLink += " #L$ ( $style.LineNumber ) "
39
+ }
40
+
41
+ $linkAndStyleName = " [$ ( $style.Style ) ]($styleLink )" ;
38
42
if ($style.IsDefault ) {
39
43
Write-OutputFile (" $listMarkdown $ ( $linkAndStyleName ) $defaultStyleText " -replace ' \s+' , ' ' )
40
44
}
@@ -70,83 +74,95 @@ Function Select-ControlNameFromFile {
70
74
}
71
75
72
76
Function Read-XamlStyles {
73
- Param ($xamlString , $file )
74
- [xml ]$xaml = $xamlString
75
- $xaml.ResourceDictionary.Style |
76
- Foreach-Object {
77
+ Param ($xamlLines , $file )
78
+ [xml ]$xaml = $xamlLines
79
+ $lineNum = 1
80
+ $xaml.ResourceDictionary.Style |
81
+ Foreach-Object {
77
82
Write-Output $_
83
+ # Get line number by Key or TargetType
84
+ $styleLineNumber = $null
85
+ $searchKey = if ($_.Key ) { $_.Key } else { $_.TargetType }
86
+
87
+ for ($i = 0 ; $i -lt $xamlLines.Length ; $i ++ ) {
88
+ if ($xamlLines [$i ] -match [regex ]::Escape($searchKey )) {
89
+ $styleLineNumber = $i + 1
90
+ break
91
+ }
92
+ }
93
+
78
94
if ($file -eq " Defaults" ) {
79
- # Special handeling of Defaults
80
- New-Default - style $_ - file $file
95
+ New-Default - style $_ - file $file - lineNumber $styleLineNumber
81
96
}
82
97
elseif ($file -eq " Generic" ) {
83
- # Special handeling of Generic
84
- New-GenericDefault - style $_ - file $file
98
+ New-GenericDefault - style $_ - file $file - lineNumber $styleLineNumber
85
99
}
86
- else {
87
- New-Style - style $_ - file $file
100
+ else {
101
+ New-Style - style $_ - file $file - lineNumber $styleLineNumber
88
102
}
103
+ $lineNum ++
89
104
}
90
105
}
91
106
92
107
Function New-GenericDefault {
93
- Param ($style , $file )
108
+ Param ($style , $file , $lineNumber )
94
109
$targetType = Read-TargetType ($style | Select-Object TargetType)
95
110
$basedOn = Read-BasedOn ($style | Select-Object BasedOn)
96
111
$styleNameValue = ($style | Select-Object Key).Key
97
112
$defaultStyleName = if ($null -eq $styleNameValue ) { $basedOn } else { $styleNameValue }
98
113
Write-Debug " [$file ] [Type: $targetType ] [StyleNameValue: $styleNameValue ] [BasedOn: $basedOn ] [DefaultStyleName: $defaultStyleName ]"
99
- Add-DefaultStyle - file $file - targetType $targetType - styleName $defaultStyleName
114
+ Add-DefaultStyle - file $file - targetType $targetType - styleName $defaultStyleName - lineNumber $lineNumber
100
115
}
101
116
102
-
103
117
Function New-Default {
104
- Param ($style , $file )
118
+ Param ($style , $file , $lineNumber )
105
119
$targetType = Read-TargetType ($style | Select-Object TargetType)
106
120
$basedOn = Read-BasedOn ($style | Select-Object BasedOn)
107
121
$styleNameValue = ($style | Select-Object Key).Key
108
122
$defaultStyleName = if ($null -eq $styleNameValue ) { $basedOn } else { $styleNameValue }
109
123
Write-Debug " [$file ] [Type: $targetType ] [StyleNameValue: $styleNameValue ] [BasedOn: $basedOn ] [DefaultStyleName: $defaultStyleName ]"
110
- Add-DefaultStyle - file $file - targetType $targetType - styleName $defaultStyleName
124
+ Add-DefaultStyle - file $file - targetType $targetType - styleName $defaultStyleName - lineNumber $lineNumber
111
125
}
112
126
113
127
Function New-Style {
114
- Param ($style , $file )
128
+ Param ($style , $file , $lineNumber )
115
129
$targetType = Read-TargetType ($style | Select-Object TargetType)
116
130
$styleName = ($style | Select-Object Key).Key
117
- $splittedFile = $file.split (' .' ) # Suport for "nested" file names like DataGrid.ComboBox
131
+ $splittedFile = $file.split (' .' ) # Support for "nested" file names like DataGrid.ComboBox
118
132
119
133
if ($targetType -eq $splittedFile [-1 ]) {
120
134
Write-Debug " [Match ] [File: $file ] [Type: $targetType ] [Style: $styleName ]"
121
- Add-Style - targetType $targetType - styleName $styleName - fileName $file
135
+ Add-Style - targetType $targetType - styleName $styleName - fileName $file - lineNumber $lineNumber
122
136
}
123
137
else {
124
- Write-Debug " [Skipped] [File: $file ] [Type: $targetType ] [Style: $styleName ] "
138
+ Write-Debug " [Skipped] [File: $file ] [Type: $targetType ] [Style: $styleName ]"
125
139
}
126
140
}
127
141
128
142
Function Add-Style {
129
- Param ($targetType , $styleName , $fileName )
130
- $temp = Get-Style - targetType $targetType - styleName $styleName - fileName $file
143
+ Param ($targetType , $styleName , $fileName , $lineNumber )
144
+ $temp = Get-Style - targetType $targetType - styleName $styleName - fileName $file - lineNumber $lineNumber
131
145
$discoverdStyles.Add ($temp ) | Out-Null
132
146
}
133
147
134
148
Function Get-Style {
135
- Param ($targetType , $styleName , $fileName )
136
- $temp = " " | Select-Object " Control" , " Style" , " IsDefault" , " File"
149
+ Param ($targetType , $styleName , $fileName , $lineNumber )
150
+ $temp = " " | Select-Object " Control" , " Style" , " IsDefault" , " File" , " LineNumber "
137
151
$temp.Control = $targetType
138
152
$temp.Style = $styleName
139
153
$temp.IsDefault = ! $styleName
140
154
$temp.File = $fileName
155
+ $temp.LineNumber = $lineNumber
141
156
return $temp
142
157
}
143
158
144
159
Function Add-DefaultStyle {
145
- Param ($file , $targetType , $styleName )
146
- $temp = " " | Select-Object " File" , " Type" , " Style"
160
+ Param ($file , $targetType , $styleName , $lineNumber )
161
+ $temp = " " | Select-Object " File" , " Type" , " Style" , " LineNumber "
147
162
$temp.File = $file
148
163
$temp.Type = $targetType
149
164
$temp.Style = $styleName
165
+ $temp.LineNumber = $lineNumber
150
166
$defaults.Add ($temp ) | Out-Null
151
167
}
152
168
0 commit comments