Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging - 6/5/24 #3140

Merged
merged 8 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DevHome.sln
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WindowsSandboxExtension", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsSandboxExtension", "extensions\WindowsSandboxExtension\WindowsSandboxExtension.csproj", "{118E20E8-FD8A-40CF-83A5-F912B9187787}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{E768781A-D1F7-4C03-B46D-E76354FAB587}"
ProjectSection(SolutionItems) = preProject
tools\scripts\CaptureDevHomeLogs.ps1 = tools\scripts\CaptureDevHomeLogs.ps1
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|arm64 = Debug|arm64
Expand Down Expand Up @@ -788,6 +793,7 @@ Global
{5F9749BC-F34E-4F45-933F-61E0F3ED521F} = {FAB6FAA7-ADF4-4B65-9831-0C819915E6E1}
{4ACF917D-B2CC-4CF2-8EE1-0EBBB52A69F0} = {DCAF188B-60C3-4EDB-8049-BAA927FBCD7D}
{118E20E8-FD8A-40CF-83A5-F912B9187787} = {4ACF917D-B2CC-4CF2-8EE1-0EBBB52A69F0}
{E768781A-D1F7-4C03-B46D-E76354FAB587} = {A972EC5B-FC61-4964-A6FF-F9633EB75DFD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {030B5641-B206-46BB-BF71-36FF009088FA}
Expand Down
38 changes: 35 additions & 3 deletions build/TriggerReleaseBuild.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
trigger:
- release

steps:
- script: echo Triggering ADO Build
displayName: 'Triggering ADO Build'
resources:
repositories:
- repository: templates_onebranch
type: git
name: OneBranch.Pipelines/GovernedTemplates
ref: refs/heads/main
- repository: m365Pipelines
type: git
name: 1ESPipelineTemplates/M365GPT
ref: refs/tags/release

extends:
template: v1/M365.Official.PipelineTemplate.yml@m365Pipelines
parameters:
sdl:
roslyn:
enabled: true
arrow:
serviceConnection: DevHome Build VM Generation
baseline:
baselineFile: $(Build.SourcesDirectory)\guardian\SDL\.gdnbaselines
pool:
name: Azure-Pipelines-1ESPT-ExDShared
image: windows-2022
os: windows
customBuildTags:
- ES365AIMigrationTooling
stages:
- stage: Trigger_Build
dependsOn: []
jobs:
- job: Trigger_Build
steps:
- script: echo Triggering ADO Build
displayName: 'Triggering ADO Build'
38 changes: 35 additions & 3 deletions build/TriggerStagingBuild.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
trigger:
- staging

steps:
- script: echo Triggering ADO Build
displayName: 'Triggering ADO Build'
resources:
repositories:
- repository: templates_onebranch
type: git
name: OneBranch.Pipelines/GovernedTemplates
ref: refs/heads/main
- repository: m365Pipelines
type: git
name: 1ESPipelineTemplates/M365GPT
ref: refs/tags/release

extends:
template: v1/M365.Official.PipelineTemplate.yml@m365Pipelines
parameters:
sdl:
roslyn:
enabled: true
arrow:
serviceConnection: DevHome Build VM Generation
baseline:
baselineFile: $(Build.SourcesDirectory)\guardian\SDL\.gdnbaselines
pool:
name: Azure-Pipelines-1ESPT-ExDShared
image: windows-2022
os: windows
customBuildTags:
- ES365AIMigrationTooling
stages:
- stage: Trigger_Build
dependsOn: []
jobs:
- job: Trigger_Build
steps:
- script: echo Triggering ADO Build
displayName: 'Triggering ADO Build'
170 changes: 170 additions & 0 deletions common/Renderers/ChooseFileAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using AdaptiveCards.ObjectModel.WinUI3;
using AdaptiveCards.Rendering.WinUI3;
using DevHome.Common.Extensions;
using DevHome.Common.Services;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.Data.Json;
using Windows.Storage.Pickers;
using WinRT.Interop;
using WinUIEx;

namespace DevHome.Common.Renderers;

public class ChooseFileAction : IAdaptiveActionElement
{
// ChooseFile properties
public string FilePath { get; set; } = string.Empty;

public string Verb { get; set; } = string.Empty;

public bool UseIcon { get; set; }

public static readonly string CustomTypeString = "Action.ChooseFile";

// Inherited properties
public ActionType ActionType => ActionType.Custom;

public string ActionTypeString => CustomTypeString;

public JsonObject? AdditionalProperties { get; set; }

public IAdaptiveActionElement? FallbackContent { get; set; }

public FallbackType FallbackType { get; set; } = FallbackType.Drop;

public string IconUrl { get; set; } = string.Empty;

public string? Id { get; set; } = CustomTypeString + "Id";

public bool IsEnabled { get; set; } = true;

public AdaptiveCards.ObjectModel.WinUI3.ActionMode Mode { get; set; }

public ActionRole Role { get; set; }

public string Style { get; set; } = string.Empty;

public string Title { get; set; } = string.Empty;

public string Tooltip { get; set; } = string.Empty;

public JsonObject ToJson()
{
var json = new JsonObject
{
["type"] = JsonValue.CreateStringValue(ActionTypeString),
["filePath"] = JsonValue.CreateStringValue(FilePath),
["verb"] = JsonValue.CreateStringValue(Verb),
};

if (AdditionalProperties != null)
{
foreach (var prop in AdditionalProperties)
{
json.Add(prop.Key, prop.Value);
}
}

return json;
}

/// <summary>Launches the file picker dialog to select a file.</summary>
/// <returns>true if a file was selected, false otherwise.</returns>
public bool LaunchFilePicker()
{
var filePicker = new FileOpenPicker();
filePicker.FileTypeFilter.Add("*");

var mainWindow = Application.Current.GetService<Window>();
if (mainWindow != null)
{
var hwnd = WindowNative.GetWindowHandle(mainWindow);
InitializeWithWindow.Initialize(filePicker, hwnd);
}

var file = filePicker.PickSingleFileAsync().AsTask().Result;
if (file != null)
{
FilePath = file.Path;
return true;
}

return false;
}
}

public class ChooseFileParser : IAdaptiveActionParser
{
public IAdaptiveActionElement FromJson(
JsonObject inputJson,
AdaptiveElementParserRegistration elementParsers,
AdaptiveActionParserRegistration actionParsers,
IList<AdaptiveWarning> warnings)
{
var stringResource = new StringResource("DevHome.Common.pri", "DevHome.Common/Resources");

var chooseFileAction = new ChooseFileAction
{
Title = stringResource.GetLocalized("ChooseFileActionTitle"),
Tooltip = stringResource.GetLocalized("ChooseFileActionToolTip"),

// Parse the JSON properties of the action.
// The Verb ChooseFile is not meant to be localized.
Verb = inputJson.GetNamedString("verb", "ChooseFile"),
UseIcon = inputJson.GetNamedBoolean("useIcon", false),
};

return chooseFileAction;
}
}

public class ChooseFileActionRenderer : IAdaptiveActionRenderer
{
public UIElement Render(IAdaptiveActionElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs)
{
var renderer = new AdaptiveExecuteActionRenderer();

if (element as ChooseFileAction is ChooseFileAction chooseFileElement)
{
// Card author is not allowed to specify a custom icon for the file picker action.
chooseFileElement.IconUrl = string.Empty;

var button = renderer.Render(element, context, renderArgs) as Button;
if (button != null)
{
var content = new StackPanel
{
Orientation = Orientation.Horizontal,
Spacing = 8,
};
if (chooseFileElement.UseIcon)
{
content.Children.Add(new FontIcon
{
Glyph = "\xED25",
});
}

if (!string.IsNullOrEmpty(chooseFileElement.Title))
{
content.Children.Add(new TextBlock
{
Text = chooseFileElement.Title,
});
}

button.Content = content;

return button;
}
}

return renderer.Render(element, context, renderArgs);
}
}
51 changes: 51 additions & 0 deletions common/Renderers/TextInputRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Linq;
using AdaptiveCards.ObjectModel.WinUI3;
using AdaptiveCards.Rendering.WinUI3;
using CommunityToolkit.WinUI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls;

namespace DevHome.Common.Renderers;

public class TextInputRenderer : IAdaptiveElementRenderer
{
public UIElement Render(IAdaptiveCardElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs)
{
var renderer = new AdaptiveTextInputRenderer();
var elementToReturn = renderer.Render(element, context, renderArgs);

if (element as AdaptiveTextInput is AdaptiveTextInput textInputElement)
{
if (textInputElement.InlineAction == null)
{
return elementToReturn;
}

if (textInputElement.InlineAction is not ChooseFileAction)
{
return elementToReturn;
}

// If the Input has an inline action, the element will have a button as a descendant.
// Since guidance suggests inline actions use an icon rather than text, we can safely
// set the content of the button to an icon.
foreach (var descendant in elementToReturn.FindDescendants())
{
if (descendant is Button inlineActionButton)
{
inlineActionButton.Padding = new Thickness(5);
inlineActionButton.Content = new FontIcon
{
Glyph = "\xED25",
};
}
}
}

return elementToReturn;
}
}
2 changes: 2 additions & 0 deletions common/Services/AdaptiveCardRenderingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ private async Task ConfigureAdaptiveCardRendererAsync()
// Add custom Adaptive Card renderer.
_renderer.ElementRenderers.Set(LabelGroup.CustomTypeString, new LabelGroupRenderer());
_renderer.ElementRenderers.Set("Input.ChoiceSet", new AccessibleChoiceSet());
_renderer.ElementRenderers.Set("Input.Text", new TextInputRenderer());
_renderer.ActionRenderers.Set(ChooseFileAction.CustomTypeString, new ChooseFileActionRenderer());

// A different host config is used to render widgets (adaptive cards) in light and dark themes.
await UpdateHostConfig();
Expand Down
6 changes: 6 additions & 0 deletions common/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,10 @@
<value>Go to extensions library</value>
<comment>Text for when the environment page in Dev Home is empty and the user has no extensions installed that support environments</comment>
</data>
<data name="ChooseFileActionTitle" xml:space="preserve">
<value>Choose file</value>
</data>
<data name="ChooseFileActionToolTip" xml:space="preserve">
<value>Choose file</value>
</data>
</root>
2 changes: 2 additions & 0 deletions extensions/CoreWidgetProvider/Widgets/Enums/WidgetAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ public enum WidgetAction
Save,

Cancel,

ChooseFile,
}
Loading
Loading