2024-10-18 15:34:09 +02:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class AdvancedPasteAdditionalActions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class PropertyNames
|
|
|
|
|
|
{
|
|
|
|
|
|
public const string ImageToText = "image-to-text";
|
|
|
|
|
|
public const string PasteAsFile = "paste-as-file";
|
2025-02-25 22:33:39 +01:00
|
|
|
|
public const string Transcode = "transcode";
|
2024-10-18 15:34:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName(PropertyNames.ImageToText)]
|
|
|
|
|
|
public AdvancedPasteAdditionalAction ImageToText { get; init; } = new();
|
|
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName(PropertyNames.PasteAsFile)]
|
|
|
|
|
|
public AdvancedPastePasteAsFileAction PasteAsFile { get; init; } = new();
|
|
|
|
|
|
|
2025-02-25 22:33:39 +01:00
|
|
|
|
[JsonPropertyName(PropertyNames.Transcode)]
|
|
|
|
|
|
public AdvancedPasteTranscodeAction Transcode { get; init; } = new();
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<IAdvancedPasteAction> GetAllActions()
|
|
|
|
|
|
{
|
2025-08-20 09:31:52 +08:00
|
|
|
|
return GetAllActionsRecursive([ImageToText, PasteAsFile, Transcode]);
|
|
|
|
|
|
}
|
2025-02-25 22:33:39 +01:00
|
|
|
|
|
2025-08-20 09:31:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Changed to depth-first traversal to ensure ordered output
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="actions">The collection of actions to traverse</param>
|
|
|
|
|
|
/// <returns>All actions returned in depth-first order</returns>
|
|
|
|
|
|
private static IEnumerable<IAdvancedPasteAction> GetAllActionsRecursive(IEnumerable<IAdvancedPasteAction> actions)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var action in actions)
|
2025-02-25 22:33:39 +01:00
|
|
|
|
{
|
|
|
|
|
|
yield return action;
|
|
|
|
|
|
|
2025-08-20 09:31:52 +08:00
|
|
|
|
foreach (var subAction in GetAllActionsRecursive(action.SubActions))
|
2025-02-25 22:33:39 +01:00
|
|
|
|
{
|
2025-08-20 09:31:52 +08:00
|
|
|
|
yield return subAction;
|
2025-02-25 22:33:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-18 15:34:09 +02:00
|
|
|
|
}
|