2024-08-22 16:17:12 +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;
|
2025-02-25 22:33:39 +01:00
|
|
|
|
using System.Collections.Generic;
|
2024-08-22 16:17:12 +02:00
|
|
|
|
using System.Text.Json.Serialization;
|
2024-10-18 15:34:09 +02:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
2025-08-20 09:31:52 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.HotkeyConflicts;
|
2024-10-18 15:34:09 +02:00
|
|
|
|
|
2024-08-22 16:17:12 +02:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library;
|
|
|
|
|
|
2024-10-18 15:34:09 +02:00
|
|
|
|
public sealed class AdvancedPasteCustomAction : Observable, IAdvancedPasteAction, ICloneable
|
2024-08-22 16:17:12 +02:00
|
|
|
|
{
|
|
|
|
|
private int _id;
|
|
|
|
|
private string _name = string.Empty;
|
|
|
|
|
private string _prompt = string.Empty;
|
|
|
|
|
private HotkeySettings _shortcut = new();
|
|
|
|
|
private bool _isShown;
|
|
|
|
|
private bool _canMoveUp;
|
|
|
|
|
private bool _canMoveDown;
|
|
|
|
|
private bool _isValid;
|
2025-08-20 09:31:52 +08:00
|
|
|
|
private bool _hasConflict;
|
|
|
|
|
private string _tooltip;
|
2024-08-22 16:17:12 +02:00
|
|
|
|
|
|
|
|
|
[JsonPropertyName("id")]
|
|
|
|
|
public int Id
|
|
|
|
|
{
|
|
|
|
|
get => _id;
|
2024-10-18 15:34:09 +02:00
|
|
|
|
set => Set(ref _id, value);
|
2024-08-22 16:17:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("name")]
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get => _name;
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-10-18 15:34:09 +02:00
|
|
|
|
if (Set(ref _name, value))
|
2024-08-22 16:17:12 +02:00
|
|
|
|
{
|
|
|
|
|
UpdateIsValid();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("prompt")]
|
|
|
|
|
public string Prompt
|
|
|
|
|
{
|
|
|
|
|
get => _prompt;
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-10-18 15:34:09 +02:00
|
|
|
|
if (Set(ref _prompt, value))
|
2024-08-22 16:17:12 +02:00
|
|
|
|
{
|
|
|
|
|
UpdateIsValid();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("shortcut")]
|
|
|
|
|
public HotkeySettings Shortcut
|
|
|
|
|
{
|
|
|
|
|
get => _shortcut;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_shortcut != value)
|
|
|
|
|
{
|
|
|
|
|
// We null-coalesce here rather than outside this branch as we want to raise PropertyChanged when the setter is called
|
|
|
|
|
// with null; the ShortcutControl depends on this.
|
|
|
|
|
_shortcut = value ?? new();
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("isShown")]
|
|
|
|
|
public bool IsShown
|
|
|
|
|
{
|
|
|
|
|
get => _isShown;
|
2024-10-18 15:34:09 +02:00
|
|
|
|
set => Set(ref _isShown, value);
|
2024-08-22 16:17:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public bool CanMoveUp
|
|
|
|
|
{
|
|
|
|
|
get => _canMoveUp;
|
2024-10-18 15:34:09 +02:00
|
|
|
|
set => Set(ref _canMoveUp, value);
|
2024-08-22 16:17:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public bool CanMoveDown
|
|
|
|
|
{
|
|
|
|
|
get => _canMoveDown;
|
2024-10-18 15:34:09 +02:00
|
|
|
|
set => Set(ref _canMoveDown, value);
|
2024-08-22 16:17:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public bool IsValid
|
|
|
|
|
{
|
|
|
|
|
get => _isValid;
|
2024-10-18 15:34:09 +02:00
|
|
|
|
private set => Set(ref _isValid, value);
|
2024-08-22 16:17:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-20 09:31:52 +08:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public bool HasConflict
|
|
|
|
|
{
|
|
|
|
|
get => _hasConflict;
|
|
|
|
|
set => Set(ref _hasConflict, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public string Tooltip
|
|
|
|
|
{
|
|
|
|
|
get => _tooltip;
|
|
|
|
|
set => Set(ref _tooltip, value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-25 22:33:39 +01:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public IEnumerable<IAdvancedPasteAction> SubActions => [];
|
|
|
|
|
|
2024-08-22 16:17:12 +02:00
|
|
|
|
public object Clone()
|
|
|
|
|
{
|
|
|
|
|
AdvancedPasteCustomAction clone = new();
|
|
|
|
|
clone.Update(this);
|
|
|
|
|
return clone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(AdvancedPasteCustomAction other)
|
|
|
|
|
{
|
|
|
|
|
Id = other.Id;
|
|
|
|
|
Name = other.Name;
|
|
|
|
|
Prompt = other.Prompt;
|
|
|
|
|
Shortcut = other.GetShortcutClone();
|
|
|
|
|
IsShown = other.IsShown;
|
|
|
|
|
CanMoveUp = other.CanMoveUp;
|
|
|
|
|
CanMoveDown = other.CanMoveDown;
|
2025-08-20 09:31:52 +08:00
|
|
|
|
HasConflict = other.HasConflict;
|
|
|
|
|
Tooltip = other.Tooltip;
|
2024-08-22 16:17:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HotkeySettings GetShortcutClone()
|
|
|
|
|
{
|
|
|
|
|
object shortcut = null;
|
|
|
|
|
if (Shortcut.TryToCmdRepresentable(out string shortcutString))
|
|
|
|
|
{
|
|
|
|
|
_ = HotkeySettings.TryParseFromCmd(shortcutString, out shortcut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (shortcut as HotkeySettings) ?? new HotkeySettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateIsValid()
|
|
|
|
|
{
|
|
|
|
|
IsValid = !string.IsNullOrWhiteSpace(Name) && !string.IsNullOrWhiteSpace(Prompt);
|
|
|
|
|
}
|
|
|
|
|
}
|