mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-11 04:38:24 -06:00
Load build time index for search
- Adds referential XAML names to components of interest. - Adds a script that generates the build time entries to be loaded - Invokes the script in Editor.vcxproj
This commit is contained in:
parent
e01ff4faf0
commit
1b8c99dff8
@ -37,7 +37,8 @@
|
||||
</Button>
|
||||
</Border>
|
||||
<StackPanel Margin="{StaticResource StandardControlMargin}">
|
||||
<local:SettingContainer x:Uid="AddProfile_Duplicate">
|
||||
<local:SettingContainer x:Uid="AddProfile_Duplicate"
|
||||
x:Name="DuplicateProfile">
|
||||
<ComboBox x:Name="Profiles"
|
||||
AutomationProperties.AccessibilityView="Content"
|
||||
ItemsSource="{x:Bind State.Settings.AllProfiles, Mode=OneWay}"
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include "NewTabMenu.h"
|
||||
#include "..\types\inc\utils.hpp"
|
||||
#include <..\WinRTUtils\inc\Utils.h>
|
||||
#include "GeneratedSettingsIndex.g.h"
|
||||
|
||||
#include <LibraryResources.h>
|
||||
#include <dwmapi.h>
|
||||
|
||||
@ -165,6 +165,7 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="Utils.h" />
|
||||
<ClInclude Include="PreviewConnection.h" />
|
||||
<ClInclude Include="$(GeneratedFilesDir)GeneratedSettingsIndex.g.h" />
|
||||
</ItemGroup>
|
||||
<!-- ========================= XAML files ======================== -->
|
||||
<ItemGroup>
|
||||
@ -363,6 +364,7 @@
|
||||
<ClCompile Include="PreviewConnection.cpp">
|
||||
<DependentUpon>PreviewConnection.h</DependentUpon>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(GeneratedFilesDir)GeneratedSettingsIndex.g.cpp" />
|
||||
</ItemGroup>
|
||||
<!-- ========================= idl Files ======================== -->
|
||||
<ItemGroup>
|
||||
@ -534,4 +536,10 @@
|
||||
<!-- This -must- go after cppwinrt.build.post.props because that includes many VS-provided props including appcontainer.common.props, which stomps on what cppwinrt.targets did. -->
|
||||
<Import Project="$(OpenConsoleDir)src\common.nugetversions.targets" />
|
||||
<Import Project="$(SolutionDir)build\rules\CollectWildcardResources.targets" />
|
||||
<Target Name="GenerateSettingsIndex"
|
||||
Inputs="@(Page);$(OpenConsoleDir)tools\GenerateSettingsIndex.ps1"
|
||||
Outputs="$(GeneratedFilesDir)GeneratedSettingsIndex.g.h;$(GeneratedFilesDir)GeneratedSettingsIndex.g.cpp"
|
||||
BeforeTargets="ClCompile">
|
||||
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted "$(OpenConsoleDir)tools\GenerateSettingsIndex.ps1" -SourceDir "$(MSBuildThisFileDirectory)." -OutputDir "$(MSBuildThisFileDirectory)$(GeneratedFilesDir)."" />
|
||||
</Target>
|
||||
</Project>
|
||||
@ -325,6 +325,7 @@
|
||||
|
||||
<!-- Name -->
|
||||
<local:SettingContainer x:Uid="NewTabMenu_CurrentFolderName"
|
||||
x:Name="CurrentFolderName"
|
||||
Grid.Row="0"
|
||||
CurrentValue="{x:Bind ViewModel.CurrentFolderName, Mode=OneWay}"
|
||||
Style="{StaticResource ExpanderSettingContainerStyle}">
|
||||
@ -334,6 +335,7 @@
|
||||
|
||||
<!-- Inlining -->
|
||||
<local:SettingContainer x:Uid="NewTabMenu_CurrentFolderInlining"
|
||||
x:Name="CurrentFolderInlining"
|
||||
Grid.Row="1">
|
||||
<ToggleSwitch IsOn="{x:Bind ViewModel.CurrentFolderInlining, Mode=TwoWay}"
|
||||
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
|
||||
@ -341,6 +343,7 @@
|
||||
|
||||
<!-- Allow Empty -->
|
||||
<local:SettingContainer x:Uid="NewTabMenu_CurrentFolderAllowEmpty"
|
||||
x:Name="CurrentFolderAllowEmpty"
|
||||
Grid.Row="2">
|
||||
<ToggleSwitch IsOn="{x:Bind ViewModel.CurrentFolderAllowEmpty, Mode=TwoWay}"
|
||||
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
|
||||
@ -354,6 +357,7 @@
|
||||
|
||||
<!-- Add Profile -->
|
||||
<local:SettingContainer x:Uid="NewTabMenu_AddProfile"
|
||||
x:Name="AddProfile"
|
||||
FontIconGlyph=""
|
||||
Style="{StaticResource SettingContainerWithIcon}">
|
||||
|
||||
@ -403,6 +407,7 @@
|
||||
|
||||
<!-- Add Separator -->
|
||||
<local:SettingContainer x:Uid="NewTabMenu_AddSeparator"
|
||||
x:Name="AddSeparator"
|
||||
FontIconGlyph=""
|
||||
Style="{StaticResource SettingContainerWithIcon}">
|
||||
<Button x:Name="AddSeparatorButton"
|
||||
@ -419,6 +424,7 @@
|
||||
|
||||
<!-- Add Folder -->
|
||||
<local:SettingContainer x:Uid="NewTabMenu_AddFolder"
|
||||
x:Name="AddFolder"
|
||||
FontIconGlyph=""
|
||||
Style="{StaticResource SettingContainerWithIcon}">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
@ -445,6 +451,7 @@
|
||||
|
||||
<!-- Add Match Profiles -->
|
||||
<local:SettingContainer x:Uid="NewTabMenu_AddMatchProfiles"
|
||||
x:Name="AddMatchProfiles"
|
||||
FontIconGlyph=""
|
||||
Style="{StaticResource ExpanderSettingContainerStyleWithIcon}">
|
||||
<StackPanel Spacing="8">
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
Style="{StaticResource SettingsStackStyle}">
|
||||
<!-- Antialiasing Mode -->
|
||||
<local:SettingContainer x:Uid="Profile_AntialiasingMode"
|
||||
x:Name="AntialiasingMode"
|
||||
ClearSettingValue="{x:Bind Profile.ClearAntialiasingMode}"
|
||||
HasSettingValue="{x:Bind Profile.HasAntialiasingMode, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.AntialiasingModeOverrideSource, Mode=OneWay}">
|
||||
@ -50,6 +51,7 @@
|
||||
|
||||
<!-- AltGr Aliasing -->
|
||||
<local:SettingContainer x:Uid="Profile_AltGrAliasing"
|
||||
x:Name="AltGrAliasing"
|
||||
ClearSettingValue="{x:Bind Profile.ClearAltGrAliasing}"
|
||||
HasSettingValue="{x:Bind Profile.HasAltGrAliasing, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.AltGrAliasingOverrideSource, Mode=OneWay}">
|
||||
@ -59,6 +61,7 @@
|
||||
|
||||
<!-- Snap On Input -->
|
||||
<local:SettingContainer x:Uid="Profile_SnapOnInput"
|
||||
x:Name="SnapOnInput"
|
||||
ClearSettingValue="{x:Bind Profile.ClearSnapOnInput}"
|
||||
HasSettingValue="{x:Bind Profile.HasSnapOnInput, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.SnapOnInputOverrideSource, Mode=OneWay}">
|
||||
@ -68,6 +71,7 @@
|
||||
|
||||
<!-- History Size -->
|
||||
<local:SettingContainer x:Uid="Profile_HistorySize"
|
||||
x:Name="HistorySize"
|
||||
ClearSettingValue="{x:Bind Profile.ClearHistorySize}"
|
||||
HasSettingValue="{x:Bind Profile.HasHistorySize, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.HistorySizeOverrideSource, Mode=OneWay}">
|
||||
@ -81,6 +85,7 @@
|
||||
|
||||
<!-- Close On Exit -->
|
||||
<local:SettingContainer x:Uid="Profile_CloseOnExit"
|
||||
x:Name="CloseOnExit"
|
||||
ClearSettingValue="{x:Bind Profile.ClearCloseOnExit}"
|
||||
HasSettingValue="{x:Bind Profile.HasCloseOnExit, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.CloseOnExitOverrideSource, Mode=OneWay}">
|
||||
@ -93,6 +98,7 @@
|
||||
|
||||
<!-- Bell Style -->
|
||||
<local:SettingContainer x:Uid="Profile_BellStyle"
|
||||
x:Name="BellStyle"
|
||||
ClearSettingValue="{x:Bind Profile.ClearBellStyle}"
|
||||
CurrentValue="{x:Bind Profile.BellStylePreview, Mode=OneWay}"
|
||||
HasSettingValue="{x:Bind Profile.HasBellStyle, Mode=OneWay}"
|
||||
@ -110,6 +116,7 @@
|
||||
|
||||
<!-- Bell Sound -->
|
||||
<local:SettingContainer x:Uid="Profile_BellSound"
|
||||
x:Name="BellSound"
|
||||
ClearSettingValue="{x:Bind Profile.ClearBellSound}"
|
||||
CurrentValue="{x:Bind Profile.BellSoundPreview, Mode=OneWay}"
|
||||
HasSettingValue="{x:Bind Profile.HasBellSound, Mode=OneWay}"
|
||||
@ -191,6 +198,7 @@
|
||||
|
||||
<!-- RightClickContextMenu -->
|
||||
<local:SettingContainer x:Uid="Profile_RightClickContextMenu"
|
||||
x:Name="RightClickContextMenu"
|
||||
ClearSettingValue="{x:Bind Profile.ClearRightClickContextMenu}"
|
||||
HasSettingValue="{x:Bind Profile.HasRightClickContextMenu, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.RightClickContextMenuOverrideSource, Mode=OneWay}">
|
||||
@ -200,6 +208,7 @@
|
||||
|
||||
<!-- ShowMarks -->
|
||||
<local:SettingContainer x:Uid="Profile_ShowMarks"
|
||||
x:Name="ShowMarks"
|
||||
ClearSettingValue="{x:Bind Profile.ClearShowMarks}"
|
||||
HasSettingValue="{x:Bind Profile.HasShowMarks, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.ShowMarksOverrideSource, Mode=OneWay}"
|
||||
@ -210,6 +219,7 @@
|
||||
|
||||
<!-- AutoMarkPrompts -->
|
||||
<local:SettingContainer x:Uid="Profile_AutoMarkPrompts"
|
||||
x:Name="AutoMarkPrompts"
|
||||
ClearSettingValue="{x:Bind Profile.ClearAutoMarkPrompts}"
|
||||
HasSettingValue="{x:Bind Profile.HasAutoMarkPrompts, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.AutoMarkPromptsOverrideSource, Mode=OneWay}"
|
||||
@ -220,6 +230,7 @@
|
||||
|
||||
<!-- ReloadEnvVars -->
|
||||
<local:SettingContainer x:Uid="Profile_ReloadEnvVars"
|
||||
x:Name="ReloadEnvVars"
|
||||
ClearSettingValue="{x:Bind Profile.ClearReloadEnvironmentVariables}"
|
||||
HasSettingValue="{x:Bind Profile.HasReloadEnvironmentVariables, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.ReloadEnvironmentVariablesOverrideSource, Mode=OneWay}">
|
||||
@ -229,6 +240,7 @@
|
||||
|
||||
<!-- RepositionCursorWithMouse -->
|
||||
<local:SettingContainer x:Uid="Profile_RepositionCursorWithMouse"
|
||||
x:Name="RepositionCursorWithMouse"
|
||||
ClearSettingValue="{x:Bind Profile.ClearRepositionCursorWithMouse}"
|
||||
HasSettingValue="{x:Bind Profile.HasRepositionCursorWithMouse, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.RepositionCursorWithMouseOverrideSource, Mode=OneWay}"
|
||||
@ -239,6 +251,7 @@
|
||||
|
||||
<!-- RainbowSuggestions -->
|
||||
<local:SettingContainer x:Uid="Profile_RainbowSuggestions"
|
||||
x:Name="RainbowSuggestions"
|
||||
ClearSettingValue="{x:Bind Profile.ClearRainbowSuggestions}"
|
||||
HasSettingValue="{x:Bind Profile.HasRainbowSuggestions, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.RainbowSuggestionsOverrideSource, Mode=OneWay}">
|
||||
@ -248,6 +261,7 @@
|
||||
|
||||
<!-- Path Translation -->
|
||||
<local:SettingContainer x:Uid="Profile_PathTranslationStyle"
|
||||
x:Name="PathTranslationStyle"
|
||||
ClearSettingValue="{x:Bind Profile.ClearPathTranslationStyle}"
|
||||
HasSettingValue="{x:Bind Profile.HasPathTranslationStyle, Mode=OneWay}"
|
||||
SettingOverrideSource="{x:Bind Profile.PathTranslationStyleOverrideSource, Mode=OneWay}">
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
|
||||
<StackPanel Style="{StaticResource SettingsStackStyle}">
|
||||
<!-- Delete Button -->
|
||||
<local:SettingContainer x:Uid="Profile_Delete_Orphaned">
|
||||
<local:SettingContainer x:Uid="Profile_Delete_Orphaned"
|
||||
x:Name="DeleteOrphaned">
|
||||
<local:SettingContainer.Content>
|
||||
<Button x:Name="DeleteButton"
|
||||
Click="DeleteConfirmation_Click"
|
||||
@ -40,7 +41,8 @@
|
||||
</local:SettingContainer.Content>
|
||||
</local:SettingContainer>
|
||||
|
||||
<local:SettingContainer x:Uid="Profile_Name">
|
||||
<local:SettingContainer x:Uid="Profile_Name"
|
||||
x:Name="Name">
|
||||
<local:SettingContainer.Content>
|
||||
<TextBlock FontFamily="Segoe UI, Segoe Fluent Icons, Segoe MDL2 Assets"
|
||||
Style="{StaticResource SettingsPageItemDescriptionStyle}"
|
||||
@ -48,7 +50,8 @@
|
||||
</local:SettingContainer.Content>
|
||||
</local:SettingContainer>
|
||||
|
||||
<local:SettingContainer x:Uid="Profile_Source_Orphaned">
|
||||
<local:SettingContainer x:Uid="Profile_Source_Orphaned"
|
||||
x:Name="Source">
|
||||
<local:SettingContainer.Content>
|
||||
<TextBlock FontFamily="Segoe UI, Segoe Fluent Icons, Segoe MDL2 Assets"
|
||||
Style="{StaticResource SettingsPageItemDescriptionStyle}"
|
||||
|
||||
159
tools/GenerateSettingsIndex.ps1
Normal file
159
tools/GenerateSettingsIndex.ps1
Normal file
@ -0,0 +1,159 @@
|
||||
<#
|
||||
Copyright (c) Microsoft Corporation.
|
||||
Licensed under the MIT license.
|
||||
.SYNOPSIS
|
||||
Scans XAML files for local:SettingContainer entries and generates GeneratedSettingsIndex.g.h / .g.cpp.
|
||||
|
||||
.PARAMETER SourceDir
|
||||
Directory to scan recursively for .xaml files.
|
||||
|
||||
.PARAMETER OutputDir
|
||||
Directory to place generated C++ files.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$SourceDir,
|
||||
[Parameter(Mandatory=$true)][string]$OutputDir
|
||||
)
|
||||
|
||||
# Prohibited UIDs (exact match, case-insensitive by default)
|
||||
$ProhibitedUids = @(
|
||||
'NewTabMenu_AddRemainingProfiles'
|
||||
)
|
||||
|
||||
# Prohibited XAML files (full paths preferred)
|
||||
$ProhibitedXamlFiles = @(
|
||||
# 'd:\projects\terminal\src\cascadia\TerminalSettingsEditor\SomePage.xaml'
|
||||
)
|
||||
|
||||
if (-not (Test-Path $SourceDir)) { throw "SourceDir not found: $SourceDir" }
|
||||
if (-not (Test-Path $OutputDir)) { New-Item -ItemType Directory -Path $OutputDir | Out-Null }
|
||||
|
||||
$entries = @()
|
||||
|
||||
Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
|
||||
$file = $_.FullName
|
||||
|
||||
# Skip whole file if prohibited
|
||||
if ($ProhibitedXamlFiles -contains $file) { return }
|
||||
|
||||
$text = Get-Content -Raw -LiteralPath $file
|
||||
|
||||
# Extract Page x:Class
|
||||
$pageClass = $null
|
||||
if ($text -match '<Page\b[^>]*\bx:Class="([^"]+)"') {
|
||||
$pageClass = $matches[1]
|
||||
} elseif ($text -match '<UserControl\b[^>]*\bx:Class="([^"]+)"') {
|
||||
# Needed for Appearances.xaml
|
||||
$pageClass = $matches[1]
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
# Convert XAML namespace dots to C++ scope operators
|
||||
$cppPageType = ($pageClass -replace '\.', '::')
|
||||
|
||||
# Find all local:SettingContainer start tags
|
||||
$pattern = '<local:SettingContainer\b([^>/]*)(/?>)'
|
||||
$matchesAll = [System.Text.RegularExpressions.Regex]::Matches($text, $pattern, 'IgnoreCase')
|
||||
|
||||
foreach ($m in $matchesAll) {
|
||||
$attrBlock = $m.Groups[1].Value
|
||||
|
||||
if ($attrBlock -match '\bx:Uid="([^"]+)"') {
|
||||
$uid = $matches[1]
|
||||
}
|
||||
else {
|
||||
continue
|
||||
}
|
||||
|
||||
if ($attrBlock -match '\bx:Name="([^"]+)"') {
|
||||
$name = $matches[1]
|
||||
}
|
||||
elseif ($attrBlock -match '\bName="([^"]+)"') {
|
||||
$name = $matches[1]
|
||||
}
|
||||
else {
|
||||
$name = ""
|
||||
}
|
||||
|
||||
# Skip entry if UID prohibited
|
||||
if ($ProhibitedUids -contains $uid) { continue }
|
||||
|
||||
$entries += [pscustomobject]@{
|
||||
PageClass = $pageClass
|
||||
CppPageType = $cppPageType
|
||||
Uid = $uid
|
||||
Name = $name
|
||||
File = $file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Ensure there aren't any duplicate entries (PageClass, Uid, Name)
|
||||
$entries = $entries | Sort-Object PageClass, Uid, Name -Unique
|
||||
|
||||
$headerPath = Join-Path $OutputDir 'GeneratedSettingsIndex.g.h'
|
||||
$cppPath = Join-Path $OutputDir 'GeneratedSettingsIndex.g.cpp'
|
||||
|
||||
$header = @"
|
||||
/*++
|
||||
Copyright (c) Microsoft Corporation
|
||||
Licensed under the MIT license.
|
||||
--*/
|
||||
#pragma once
|
||||
#include <winrt/Windows.UI.Xaml.Interop.h>
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
{
|
||||
struct IndexEntry
|
||||
{
|
||||
std::wstring_view ElementName;
|
||||
std::wstring_view ElementUID;
|
||||
winrt::Windows::UI::Xaml::Interop::TypeName ParentPage;
|
||||
};
|
||||
|
||||
std::span<const IndexEntry> LoadBuildTimeIndex();
|
||||
}
|
||||
"@
|
||||
|
||||
$entryLines = foreach ($e in $entries) {
|
||||
# Ensure we emit valid wide string literals (escape backslashes and quotes)
|
||||
$uidEsc = ($e.Uid -replace '\\','\\\\') -replace '"','\"'
|
||||
$nameEsc = ($e.Name -replace '\\','\\\\') -replace '"','\"'
|
||||
" { L`"$nameEsc`", L`"$uidEsc`", winrt::xaml_typename<$($e.CppPageType)>() }"
|
||||
}
|
||||
|
||||
$cpp = @"
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#include "pch.h"
|
||||
#include <winrt/Microsoft.Terminal.Settings.Editor.h>
|
||||
#include "GeneratedSettingsIndex.g.h"
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
{
|
||||
namespace
|
||||
{
|
||||
static const IndexEntry s_entries[] =
|
||||
{
|
||||
$( ($entryLines -join ",`r`n") )
|
||||
};
|
||||
}
|
||||
|
||||
std::span<const IndexEntry> LoadBuildTimeIndex()
|
||||
{
|
||||
static auto entries = std::span<const IndexEntry>(s_entries, std::size(s_entries));
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
Set-Content -LiteralPath $headerPath -Value $header -NoNewline
|
||||
Set-Content -LiteralPath $cppPath -Value $cpp -NoNewline
|
||||
|
||||
Write-Host "Generated:"
|
||||
Write-Host " $headerPath"
|
||||
Write-Host " $cppPath"
|
||||
Write-Host "Entries: $($entries.Count)"
|
||||
Loading…
x
Reference in New Issue
Block a user