-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathAIAgents.cpp
More file actions
118 lines (102 loc) · 4.49 KB
/
Copy pathAIAgents.cpp
File metadata and controls
118 lines (102 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include <winrt/Windows.UI.Xaml.Documents.h>
#include "AIAgents.h"
#include "AIAgents.g.cpp"
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Xaml::Controls;
using namespace winrt::Windows::UI::Xaml::Documents;
using namespace winrt::Windows::UI::Xaml::Media;
using namespace winrt::Windows::UI::Xaml::Navigation;
using namespace winrt::Microsoft::Terminal::Settings::Model;
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
static void _UpdateCustomAgentRemoveVisibility(const Button& button)
{
const auto entry = button.DataContext().try_as<Editor::AgentEntry>();
bool isInExpandedList = false;
for (auto parent = VisualTreeHelper::GetParent(button);
parent;
parent = VisualTreeHelper::GetParent(parent))
{
if (parent.try_as<ItemsPresenter>())
{
isInExpandedList = true;
break;
}
}
const auto visibility =
isInExpandedList && entry ?
entry.RemoveButtonVisibility() :
Visibility::Collapsed;
if (button.Visibility() != visibility)
{
button.Visibility(visibility);
}
}
AIAgents::AIAgents()
{
InitializeComponent();
PageSubtitlePrefix().Text(RS_(L"AIAgents_PageSubtitlePrefix"));
PageSubtitlePrivacyLink().Text(RS_(L"AIAgents_PageSubtitlePrivacyLink"));
const auto customModelsHeader = RS_(L"AIAgents_CustomModels/Header");
const auto customModelsCaption = RS_(L"AIAgents_CustomModels/HelpText");
const auto customModelsLearnMore = RS_(L"AIAgents_CustomModelsLearnMore");
CustomModelsHeaderText().Text(customModelsHeader);
CustomModelsCaptionPrefix().Text(customModelsCaption);
CustomModelsCaptionLink().Text(customModelsLearnMore);
Automation::AutomationProperties::SetName(CustomModelProvidersExpander(), customModelsHeader);
// Auto-error-detection caption + inline "supported shells" hyperlink.
AutoErrorDetectionCaptionPrefix().Text(RS_(L"AIAgents_AutoErrorDetectionCaptionPrefix"));
AutoErrorDetectionCaptionLink().Text(RS_(L"AIAgents_AutoErrorDetectionCaptionLink"));
const auto agentHeader = RS_(L"AIAgents_AcpAgent/Header");
AcpAgentHeaderText().Text(agentHeader);
// Split the description on "ACP" (locked token) so it can be rendered as an inline Hyperlink.
{
const auto descStr = RS_(L"AIAgents_AcpAgent/HelpText");
const std::wstring_view desc{ descStr };
constexpr std::wstring_view token{ L"ACP" };
const auto pos = desc.find(token);
if (pos != std::wstring_view::npos)
{
AcpAgentDescriptionBefore().Text(winrt::hstring{ desc.substr(0, pos) });
AcpAgentDescriptionAcpToken().Text(winrt::hstring{ token });
AcpAgentDescriptionAfter().Text(winrt::hstring{ desc.substr(pos + token.size()) });
}
else
{
// Fallback (shouldn't happen — ACP is locked): degrade to plain text.
AcpAgentDescriptionBefore().Text(winrt::hstring{ desc });
}
}
Automation::AutomationProperties::SetName(AcpAgent(), agentHeader);
}
void AIAgents::CustomAgentRemove_Loaded(
const IInspectable& sender,
const RoutedEventArgs&)
{
const auto button = sender.as<Button>();
_UpdateCustomAgentRemoveVisibility(button);
// ComboBox may reuse an expanded item's template for the collapsed
// selection after Save. Register once per template instance and use
// a weak reference so the handler does not extend its lifetime.
if (!button.Tag())
{
button.Tag(box_value(true));
const auto weakButton = make_weak(button);
button.LayoutUpdated([weakButton](const auto&, const auto&) {
if (const auto button = weakButton.get())
{
_UpdateCustomAgentRemoveVisibility(button);
}
});
}
}
void AIAgents::OnNavigatedTo(const NavigationEventArgs& e)
{
const auto args = e.Parameter().as<Editor::NavigateToPageArgs>();
_ViewModel = args.ViewModel().as<Editor::AIAgentsViewModel>();
BringIntoViewWhenLoaded(args.ElementToFocus());
}
}