Skip to content

A Swiss Army knife for developers.

Added a single-line text input (#779)

Etienne BAUDOUX0e80f67ba4a7
diff --git a/src/app/dev/DevToys.Api/MatchSpan.cs b/src/app/dev/DevToys.Api/MatchSpan.cs
deleted file mode 100644
index 7e7768f0e..000000000
--- a/src/app/dev/DevToys.Api/MatchSpan.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-namespace DevToys.Api;
-
-/// <summary>
-/// Represents a span in text.
-/// </summary>
-public record MatchSpan
-{
- /// <summary>
- /// Gets the position at which the span starts.
- /// </summary>
- public int StartPosition { get; }
-
- /// <summary>
- /// Gets the length of the span.
- /// </summary>
- public int Length { get; }
-
- public MatchSpan(int startPosition, int length)
- {
- StartPosition = startPosition;
- Length = length;
- }
-}
diff --git a/src/app/dev/DevToys.Api/Settings/PredefinedSettings.cs b/src/app/dev/DevToys.Api/Settings/PredefinedSettings.cs
index b73560056..9807653b0 100644
--- a/src/app/dev/DevToys.Api/Settings/PredefinedSettings.cs
+++ b/src/app/dev/DevToys.Api/Settings/PredefinedSettings.cs
@@ -9,4 +9,12 @@ public static class PredefinedSettings
= new(
name: nameof(CompactMode),
defaultValue: false);
+
+ /// <summary>
+ /// Whether when using the Paste command, the text in the editor should be replaced or appended.
+ /// </summary>
+ public static readonly SettingDefinition<bool> TextEditorPasteClearsText
+ = new(
+ name: nameof(TextEditorPasteClearsText),
+ defaultValue: true);
}
diff --git a/src/app/dev/DevToys.Api/TextSpan.cs b/src/app/dev/DevToys.Api/TextSpan.cs
new file mode 100644
index 000000000..57cd148d7
--- /dev/null
+++ b/src/app/dev/DevToys.Api/TextSpan.cs
@@ -0,0 +1,30 @@
+namespace DevToys.Api;
+
+/// <summary>
+/// Represents a span in a text.
+/// </summary>
+public record TextSpan
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TextSpan"/> class.
+ /// </summary>
+ /// <param name="startPosition">The position at which the span starts.</param>
+ /// <param name="length">The length of the span.</param>
+ public TextSpan(int startPosition, int length)
+ {
+ Guard.IsGreaterThanOrEqualTo(startPosition, 0);
+ Guard.IsGreaterThanOrEqualTo(length, 0);
+ StartPosition = startPosition;
+ Length = length;
+ }
+
+ /// <summary>
+ /// Gets the position at which the span starts.
+ /// </summary>
+ public int StartPosition { get; }
+
+ /// <summary>
+ /// Gets the length of the span.
+ /// </summary>
+ public int Length { get; }
+}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDiffTextInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDiffTextInput.cs
new file mode 100644
index 000000000..a1c94c49f
--- /dev/null
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDiffTextInput.cs
@@ -0,0 +1,28 @@
+namespace DevToys.Api;
+
+/// <summary>
+/// A component that can be used to display side by side or inlined texts and highlight differences between them.
+/// This component is powered by Monaco Editor.
+/// </summary>
+public interface IUIDiffTextInput : IUISinglelineTextInput
+{
+ /// <summary>
+ /// Gets the text displayed to the right of the diff view.
+ /// </summary>
+ string RightText { get; }
+
+ /// <summary>
+ /// Gets whether the text diff control should show differences side by side or inlined.
+ /// </summary>
+ bool InlineMode { get; }
+
+ /// <summary>
+ /// Raised when <see cref="RightText"/> is changed.
+ /// </summary>
+ event EventHandler? RightTextChanged;
+
+ /// <summary>
+ /// Raised when <see cref="InlineMode"/> is changed.
+ /// </summary>
+ event EventHandler? InlineModeChanged;
+}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIMultilineLineTextInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIMultilineLineTextInput.cs
index 544cfa7b2..abfd3e7db 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIMultilineLineTextInput.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIMultilineLineTextInput.cs
@@ -1,8 +1,125 @@
-namespace DevToys.Api;
+using System;
+using static System.Net.Mime.MediaTypeNames;
+
+namespace DevToys.Api;
/// <summary>
-/// A component that can be used to display or edit unformatted text.
+/// A component that can be used to display or edit unformatted text on multiple lines.
/// </summary>
-public interface IUIMultilineLineTextInput : IUITextInput
+/// <remarks>
+/// This component is powered by Monaco Editor.
+/// </remarks>
+public interface IUIMultilineLineTextInput : IUISinglelineTextInput
+{
+ /// <summary>
+ /// Gets the list of spans to highlight in the text document.
+ /// </summary>
+ IReadOnlyList<TextSpan> HighlightedSpans { get; }
+
+ /// <summary>
+ /// Gets the programming language name to use when colorizing the text in the control.
+ /// </summary>
+ string SyntaxColorizationLanguageName { get; }
+
+ /// <summary>
+ /// Raised when <see cref="HighlightedSpans"/> is changed.
+ /// </summary>
+ event EventHandler? HighlightedSpansChanged;
+
+ /// <summary>
+ /// Raised when <see cref="SyntaxColorizationLanguageName"/> is changed.
+ /// </summary>
+ event EventHandler? SyntaxColorizationLanguageNameChanged;
+}
+
+[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")]
+internal class UIMultilineTextInput : UISinglelineTextInput, IUIMultilineLineTextInput
+{
+ private IReadOnlyList<TextSpan>? _highlightedSpans;
+ private string? _syntaxColorizationLanguageName;
+
+ internal UIMultilineTextInput(string? id)
+ : base(id)
+ {
+ }
+
+ public IReadOnlyList<TextSpan> HighlightedSpans
+ {
+ get => _highlightedSpans ?? Array.Empty<TextSpan>();
+ internal set
+ {
+ _highlightedSpans = value;
+ HighlightedSpansChanged?.Invoke(this, EventArgs.Empty);
+ }
+ }
+
+ public string SyntaxColorizationLanguageName
+ {
+ get => _syntaxColorizationLanguageName ?? string.Empty;
+ internal set
+ {
+ _syntaxColorizationLanguageName = value;
+ SyntaxColorizationLanguageNameChanged?.Invoke(this, EventArgs.Empty);
+ }
+ }
+
+ public event EventHandler? HighlightedSpansChanged;
+ public event EventHandler? SyntaxColorizationLanguageNameChanged;
+}
+
+public static partial class GUI
{
+ /// <summary>
+ /// A component that can be used to display or edit unformatted text on multiple lines.
+ /// </summary>
+ /// <remarks>
+ /// This component is powered by Monaco Editor.
+ /// </remarks>
+ public static IUIMultilineLineTextInput MultilineTextInput()
+ {
+ return MultilineTextInput(null);
+ }
+
+ /// <summary>
+ /// A component that can be used to display or edit unformatted text on multiple lines.
+ /// </summary>
+ /// <remarks>
+ /// This component is powered by Monaco Editor.
+ /// </remarks>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ public static IUIMultilineLineTextInput MultilineTextInput(string? id)
+ {
+ return new UIMultilineTextInput(id);
+ }
+
+ /// <summary>
+ /// A component that can be used to display or edit unformatted text on multiple lines.
+ /// </summary>
+ /// <remarks>
+ /// This component is powered by Monaco Editor.
+ /// </remarks>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ /// <param name="programmingLanguageName">the programming language name to use to colorize the text in the control.</param>
+ public static IUIMultilineLineTextInput MultilineTextInput(string? id, string programmingLanguageName)
+ {
+ return new UIMultilineTextInput(id).Language(programmingLanguageName);
+ }
+
+ /// <summary>
+ /// Sets the list of spans to highlight in the text document.
+ /// </summary>
+ public static IUIMultilineLineTextInput Hihglight(this IUIMultilineLineTextInput element, params TextSpan[] spans)
+ {
+ ((UIMultilineTextInput)element).HighlightedSpans = spans;
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the programming language name to use to colorize the text in the control.
+ /// </summary>
+ public static IUIMultilineLineTextInput Language(this IUIMultilineLineTextInput element, string programmingLanguageName)
+ {
+ ((UIMultilineTextInput)element).SyntaxColorizationLanguageName = programmingLanguageName;
+ return element;
+ }
}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISinglelineTextInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISinglelineTextInput.cs
index 95a989d44..cf3bf6efd 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISinglelineTextInput.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISinglelineTextInput.cs
@@ -1,8 +1,225 @@
namespace DevToys.Api;
/// <summary>
-/// A component that can be used to display or edit unformatted text.
+/// A component that can be used to display or edit unformatted text on a single line.
/// </summary>
-public interface IUISinglelineTextInput : IUITextInput
+public interface IUISinglelineTextInput : IUITitledElement
{
+ /// <summary>
+ /// Gets whether the user can edit the text or not. Default is false.
+ /// </summary>
+ bool IsReadOnly { get; }
+
+ /// <summary>
+ /// Gets whether the `Copy` button should be displayed on top of the editor, even when it is not read-only. Default is false.
+ /// </summary>
+ bool CanCopyWhenEditable { get; }
+
+ /// <summary>
+ /// Gets the text displayed or typed by the user.
+ /// </summary>
+ string Text { get; }
+
+ /// <summary>
+ /// Gets the primary selection of the text control. When the selection length is 0, the span indicates the caret position.
+ /// </summary>
+ TextSpan Selection { get; }
+
+ /// <summary>
+ /// Raised when <see cref="IsReadOnly"/> is changed.
+ /// </summary>
+ event EventHandler? IsReadOnlyChanged;
+
+ /// <summary>
+ /// Raised when <see cref="CanCopyWhenEditable"/> is changed.
+ /// </summary>
+ event EventHandler? CanCopyWhenEditableChanged;
+
+ /// <summary>
+ /// Raised when <see cref="Text"/> is changed.
+ /// </summary>
+ event EventHandler? TextChanged;
+
+ /// <summary>
+ /// Raised when <see cref="Selection"/> is changed.
+ /// </summary>
+ event EventHandler? SelectionChanged;
+}
+
+[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")]
+internal class UISinglelineTextInput : UITitledElement, IUISinglelineTextInput
+{
+ private string? _text;
+ private bool _isReadOnly;
+ private bool _canCopyWhenEditable;
+ private TextSpan? _selection;
+
+ internal UISinglelineTextInput(string? id)
+ : base(id)
+ {
+ }
+
+ public string Text
+ {
+ get => _text ?? string.Empty;
+ internal set
+ {
+ _text = value;
+ TextChanged?.Invoke(this, EventArgs.Empty);
+ }
+ }
+
+ public bool IsReadOnly
+ {
+ get => _isReadOnly;
+ internal set
+ {
+ _isReadOnly = value;
+ IsReadOnlyChanged?.Invoke(this, EventArgs.Empty);
+ }
+ }
+
+ public bool CanCopyWhenEditable
+ {
+ get => _canCopyWhenEditable;
+ internal set
+ {
+ _canCopyWhenEditable = value;
+ CanCopyWhenEditableChanged?.Invoke(this, EventArgs.Empty);
+ }
+ }
+
+ public TextSpan Selection
+ {
+ get => _selection ?? new TextSpan(0, 0);
+ internal set
+ {
+ _selection = value;
+ if (_selection != null)
+ {
+ if (_selection.StartPosition > Text.Length)
+ {
+ ThrowHelper.ThrowArgumentOutOfRangeException(
+ nameof(TextSpan.StartPosition),
+ "The start position of the selection is greater than the text length.");
+ }
+ else if (_selection.StartPosition + _selection.Length > Text.Length)
+ {
+ ThrowHelper.ThrowArgumentOutOfRangeException(
+ nameof(TextSpan.Length),
+ "The end position of the selection is greater than the text length.");
+ }
+ }
+ SelectionChanged?.Invoke(this, EventArgs.Empty);
+ }
+ }
+
+ public event EventHandler? TextChanged;
+ public event EventHandler? IsReadOnlyChanged;
+ public event EventHandler? CanCopyWhenEditableChanged;
+ public event EventHandler? SelectionChanged;
+}
+
+public static partial class GUI
+{
+ /// <summary>
+ /// Create a component that can be used to display or edit unformatted text on a single line.
+ /// </summary>
+ public static IUISinglelineTextInput SinglelineTextInput()
+ {
+ return SinglelineTextInput(null);
+ }
+
+ /// <summary>
+ /// Create a component that can be used to display or edit unformatted text on a single line.
+ /// </summary>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ public static IUISinglelineTextInput SinglelineTextInput(string? id)
+ {
+ return new UISinglelineTextInput(id);
+ }
+
+ /// <summary>
+ /// Sets the text input control as read-only.
+ /// </summary>
+ public static T ReadOnly<T>(this T element) where T : IUITitledElement
+ {
+ if (element is UISinglelineTextInput strongElement)
+ {
+ strongElement.IsReadOnly = true;
+ }
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the text input control as editable.
+ /// </summary>
+ public static T Editable<T>(this T element) where T : IUITitledElement
+ {
+ if (element is UISinglelineTextInput strongElement)
+ {
+ strongElement.IsReadOnly = false;
+ }
+ return element;
+ }
+
+ /// <summary>
+ /// Shows the "copy" button when the editor is editable.
+ /// </summary>
+ public static T CanCopyWhenEditable<T>(this T element) where T : IUITitledElement
+ {
+ if (element is UISinglelineTextInput strongElement)
+ {
+ strongElement.CanCopyWhenEditable = true;
+ }
+ return element;
+ }
+
+ /// <summary>
+ /// Hides the "copy" button when the editor is editable.
+ /// </summary>
+ public static T CannotCopyWhenEditable<T>(this T element) where T : IUITitledElement
+ {
+ if (element is UISinglelineTextInput strongElement)
+ {
+ strongElement.CanCopyWhenEditable = false;
+ }
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the unformatted text of the control.
+ /// </summary>
+ public static T Text<T>(this T element, string text) where T : IUITitledElement
+ {
+ if (element is UISinglelineTextInput strongElement)
+ {
+ strongElement.Text = text;
+ }
+ return element;
+ }
+
+ /// <summary>
+ /// Selects the given span in the text document.
+ /// </summary>
+ public static T Select<T>(this T element, TextSpan span) where T : IUITitledElement
+ {
+ if (element is UISinglelineTextInput strongElement)
+ {
+ strongElement.Selection = span;
+ }
+ return element;
+ }
+
+ /// <summary>
+ /// Selects the given span in the text document.
+ /// </summary>
+ public static T Select<T>(this T element, int start, int length) where T : IUITitledElement
+ {
+ if (element is UISinglelineTextInput strongElement)
+ {
+ strongElement.Selection = new TextSpan(start, length);
+ }
+ return element;
+ }
}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITextInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITextInput.cs
deleted file mode 100644
index e0053e9ee..000000000
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITextInput.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-namespace DevToys.Api;
-
-/// <summary>
-/// A component that can be used to display or edit unformatted text.
-/// </summary>
-public interface IUITextInput : IUITitledElement
-{
- /// <summary>
- /// Gets whether the user can edit the text or not.
- /// </summary>
- bool IsReadOnly { get; }
-
- /// <summary>
- /// Gets whether the `Copy` button should be displayed on top of the editor, even when it is not read-only.
- /// </summary>
- bool CanCopyWhenEditable { get; }
-
- /// <summary>
- /// Gets the text displayed or typed by the user.
- /// </summary>
- bool Text { get; }
-
- /// <summary>
- /// Raised when <see cref="Text"/> is changed.
- /// </summary>
- event EventHandler? TextChanged;
-}
diff --git a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
index c661ba2eb..c76ae2a90 100644
--- a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
+++ b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
@@ -330,7 +330,7 @@ public sealed partial class GuiToolProvider
if (!tool.NotSearchable // do not search tools marked as non-searchable
&& !string.IsNullOrWhiteSpace(tool.LongDisplayTitle)) // do not search tools without long display name.
{
- SearchTool(searchQueries, tool, out MatchSpan[] matchedSpans, out double weight);
+ SearchTool(searchQueries, tool, out TextSpan[] matchedSpans, out double weight);
if (weight > 0)
{
@@ -599,13 +599,13 @@ public sealed partial class GuiToolProvider
return new SettingDefinition<bool>($"{guiToolInstance.InternalComponentName}_IsFavorite", defaultValue: false);
}
- private static void SearchTool(string[] searchQueries, GuiToolInstance tool, out MatchSpan[] matchedSpans, out double weight)
+ private static void SearchTool(string[] searchQueries, GuiToolInstance tool, out TextSpan[] matchedSpans, out double weight)
{
- var matches = new List<MatchSpan>();
+ var matches = new List<TextSpan>();
weight = 0;
foreach (string? query in searchQueries)
{
- WeightMatch(query, tool.LongDisplayTitle, out double titleWeight, out IReadOnlyList<MatchSpan> spans);
+ WeightMatch(query, tool.LongDisplayTitle, out double titleWeight, out IReadOnlyList<TextSpan> spans);
WeightMatch(query, tool.SearchKeywords, out double searchKeywordsWeight, out _);
WeightMatch(query, tool.Description, out double descriptionWeight, out _);
@@ -623,9 +623,9 @@ public sealed partial class GuiToolProvider
string searchQuery,
string stringToTestAgainst,
out double weight,
- out IReadOnlyList<MatchSpan> matchSpans)
+ out IReadOnlyList<TextSpan> matchSpans)
{
- var matches = new List<MatchSpan>();
+ var matches = new List<TextSpan>();
matchSpans = matches;
weight = 0;
@@ -640,7 +640,7 @@ public sealed partial class GuiToolProvider
int matchIndex = stringToTestAgainst.IndexOf(searchQuery, i, StringComparison.OrdinalIgnoreCase);
if (matchIndex > -1)
{
- matches.Add(new MatchSpan(matchIndex, searchQuery.Length));
+ matches.Add(new TextSpan(matchIndex, searchQuery.Length));
i = matchIndex + searchQuery.Length;
if (matchIndex > 0 && char.IsLetterOrDigit(stringToTestAgainst[matchIndex - 1]))
diff --git a/src/app/dev/DevToys.Core/Tools/ViewItems/GuiToolViewItem.cs b/src/app/dev/DevToys.Core/Tools/ViewItems/GuiToolViewItem.cs
index 374862d42..32265a036 100644
--- a/src/app/dev/DevToys.Core/Tools/ViewItems/GuiToolViewItem.cs
+++ b/src/app/dev/DevToys.Core/Tools/ViewItems/GuiToolViewItem.cs
@@ -11,7 +11,7 @@ public sealed partial class GuiToolViewItem : ObservableObject
{
private readonly bool _showLongDisplayTitle;
- public GuiToolViewItem(GuiToolInstance instance, bool showLongDisplayTitle = true, MatchSpan[]? matchSpans = null)
+ public GuiToolViewItem(GuiToolInstance instance, bool showLongDisplayTitle = true, TextSpan[]? matchSpans = null)
{
Guard.IsNotNull(instance);
ToolInstance = instance;
@@ -28,7 +28,7 @@ public sealed partial class GuiToolViewItem : ObservableObject
/// Gets or sets the list of spans that matched a search.
/// </summary>
[ObservableProperty]
- private MatchSpan[]? _matchedSpans;
+ private TextSpan[]? _matchedSpans;
/// <summary>
/// Gets or sets whether the tool is recommended to be used (for example, after detecting a compatible data from Smart Detection).
diff --git a/src/app/dev/DevToys.Localization/DevToys.Localization.csproj b/src/app/dev/DevToys.Localization/DevToys.Localization.csproj
index 0191cc8e7..5886ddb95 100644
--- a/src/app/dev/DevToys.Localization/DevToys.Localization.csproj
+++ b/src/app/dev/DevToys.Localization/DevToys.Localization.csproj
@@ -2,6 +2,12 @@
<PropertyGroup>
<TargetFrameworks>$(NetCore)</TargetFrameworks>
</PropertyGroup>
+ <ItemGroup>
+ <CompilerVisibleProperty Include="MSBuildProjectFullPath" />
+ <CompilerVisibleProperty Include="RootNamespace" />
+ <CompilerVisibleProperty Include="DefaultLanguage" />
+ <CompilerVisibleProperty Include="OutputType" />
+ </ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Common" />
<PackageReference Include="CommunityToolkit.Diagnostics" />
@@ -32,16 +38,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
- <EmbeddedResource Update="Strings\Settings\Settings.resx">
- <Generator>PublicResXFileCodeGenerator</Generator>
- <LastGenOutput>Settings.Designer.cs</LastGenOutput>
- </EmbeddedResource>
- <EmbeddedResource Update="Strings\MainWindow\MainWindow.resx">
- <Generator>PublicResXFileCodeGenerator</Generator>
- <LastGenOutput>MainWindow.Designer.cs</LastGenOutput>
- </EmbeddedResource>
- </ItemGroup>
- <ItemGroup>
+ <EmbeddedResource Update="**\*.resx" />
<AdditionalFiles Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
@@ -50,14 +47,4 @@
<ItemGroup>
<ProjectReference Include="..\DevToys.Api\DevToys.Api.csproj" />
</ItemGroup>
- <ItemGroup>
- <AdditionalFiles Update="Strings\MainWindow\MainWindow.resx">
- <Generator>PublicResXFileCodeGenerator</Generator>
- <LastGenOutput>MainWindow.Designer.cs</LastGenOutput>
- </AdditionalFiles>
- <AdditionalFiles Update="Strings\ToolGroupPage\ToolGroupPage.resx">
- <Generator>PublicResXFileCodeGenerator</Generator>
- <LastGenOutput>ToolGroupPage.Designer.cs</LastGenOutput>
- </AdditionalFiles>
- </ItemGroup>
</Project>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Localization/Strings/ToolPage/ToolPage.Designer.cs b/src/app/dev/DevToys.Localization/Strings/ToolPage/ToolPage.Designer.cs
index 8ab744f3a..6698b2748 100644
--- a/src/app/dev/DevToys.Localization/Strings/ToolPage/ToolPage.Designer.cs
+++ b/src/app/dev/DevToys.Localization/Strings/ToolPage/ToolPage.Designer.cs
@@ -69,6 +69,60 @@ namespace DevToys.Localization.Strings.ToolPage {
}
}
+ /// <summary>
+ /// Looks up a localized string similar to All Files.
+ /// </summary>
+ public static string AllFileType {
+ get {
+ return ResourceManager.GetString("AllFileType", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Clear.
+ /// </summary>
+ public static string Clear {
+ get {
+ return ResourceManager.GetString("Clear", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Copy.
+ /// </summary>
+ public static string Copy {
+ get {
+ return ResourceManager.GetString("Copy", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to OK.
+ /// </summary>
+ public static string Ok {
+ get {
+ return ResourceManager.GetString("Ok", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Load a file.
+ /// </summary>
+ public static string OpenFile {
+ get {
+ return ResourceManager.GetString("OpenFile", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Paste.
+ /// </summary>
+ public static string Paste {
+ get {
+ return ResourceManager.GetString("Paste", resourceCulture);
+ }
+ }
+
/// <summary>
/// Looks up a localized string similar to Pin to Start.
/// </summary>
@@ -87,6 +141,24 @@ namespace DevToys.Localization.Strings.ToolPage {
}
}
+ /// <summary>
+ /// Looks up a localized string similar to Save as....
+ /// </summary>
+ public static string SaveAs {
+ get {
+ return ResourceManager.GetString("SaveAs", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Transfer to another tool.
+ /// </summary>
+ public static string SendToSmartDetection {
+ get {
+ return ResourceManager.GetString("SendToSmartDetection", resourceCulture);
+ }
+ }
+
/// <summary>
/// Looks up a localized string similar to Toggle keep the window on top (Ctrl+Up).
/// </summary>
@@ -95,5 +167,59 @@ namespace DevToys.Localization.Strings.ToolPage {
return ResourceManager.GetString("ToggleCompactOverlayTooltip", resourceCulture);
}
}
+
+ /// <summary>
+ /// Looks up a localized string similar to On.
+ /// </summary>
+ public static string ToggleSwitchOff {
+ get {
+ return ResourceManager.GetString("ToggleSwitchOff", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Off.
+ /// </summary>
+ public static string ToggleSwitchOn {
+ get {
+ return ResourceManager.GetString("ToggleSwitchOn", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unable to open this file.
+ /// </summary>
+ public static string UnableOpenFile {
+ get {
+ return ResourceManager.GetString("UnableOpenFile", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unable to load the file &apos;{0}&apos;. Only textual files can be opened..
+ /// </summary>
+ public static string UnableOpenFileDescription {
+ get {
+ return ResourceManager.GetString("UnableOpenFileDescription", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unable to save this file.
+ /// </summary>
+ public static string UnableSaveFile {
+ get {
+ return ResourceManager.GetString("UnableSaveFile", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unable to save the file &apos;{0}&apos;. Check the logs to see the internal error..
+ /// </summary>
+ public static string UnableSaveFileDescription {
+ get {
+ return ResourceManager.GetString("UnableSaveFileDescription", resourceCulture);
+ }
+ }
}
}
diff --git a/src/app/dev/DevToys.Localization/Strings/ToolPage/ToolPage.resx b/src/app/dev/DevToys.Localization/Strings/ToolPage/ToolPage.resx
index 2a30df2ed..49858b759 100644
--- a/src/app/dev/DevToys.Localization/Strings/ToolPage/ToolPage.resx
+++ b/src/app/dev/DevToys.Localization/Strings/ToolPage/ToolPage.resx
@@ -120,13 +120,55 @@
<data name="AddToFavorites" xml:space="preserve">
<value>Add to favorites</value>
</data>
+ <data name="AllFileType" xml:space="preserve">
+ <value>All Files</value>
+ </data>
+ <data name="Clear" xml:space="preserve">
+ <value>Clear</value>
+ </data>
+ <data name="Copy" xml:space="preserve">
+ <value>Copy</value>
+ </data>
+ <data name="Ok" xml:space="preserve">
+ <value>OK</value>
+ </data>
+ <data name="OpenFile" xml:space="preserve">
+ <value>Load a file</value>
+ </data>
+ <data name="Paste" xml:space="preserve">
+ <value>Paste</value>
+ </data>
<data name="PinToStart" xml:space="preserve">
<value>Pin to Start</value>
</data>
<data name="RemoveFromFavorites" xml:space="preserve">
<value>Remove from favorites</value>
</data>
+ <data name="SaveAs" xml:space="preserve">
+ <value>Save as...</value>
+ </data>
+ <data name="SendToSmartDetection" xml:space="preserve">
+ <value>Transfer to another tool</value>
+ </data>
<data name="ToggleCompactOverlayTooltip" xml:space="preserve">
<value>Toggle keep the window on top (Ctrl+Up)</value>
</data>
+ <data name="ToggleSwitchOff" xml:space="preserve">
+ <value>On</value>
+ </data>
+ <data name="ToggleSwitchOn" xml:space="preserve">
+ <value>Off</value>
+ </data>
+ <data name="UnableOpenFile" xml:space="preserve">
+ <value>Unable to open this file</value>
+ </data>
+ <data name="UnableOpenFileDescription" xml:space="preserve">
+ <value>Unable to load the file '{0}'. Only textual files can be opened.</value>
+ </data>
+ <data name="UnableSaveFile" xml:space="preserve">
+ <value>Unable to save this file</value>
+ </data>
+ <data name="UnableSaveFileDescription" xml:space="preserve">
+ <value>Unable to save the file '{0}'. Check the logs to see the internal error.</value>
+ </data>
</root>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/Tools/Sample/SampleToolFactory.cs b/src/app/dev/DevToys.Tools/Tools/Sample/SampleToolFactory.cs
index b763377bc..8953c67c0 100644
--- a/src/app/dev/DevToys.Tools/Tools/Sample/SampleToolFactory.cs
+++ b/src/app/dev/DevToys.Tools/Tools/Sample/SampleToolFactory.cs
@@ -54,7 +54,13 @@ internal sealed class SampleCommandLineTool : ICommandLineTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool : IGuiTool
{
- public IUIElement View => null!;
+ public IUIElement View
+ => Stack()
+ .Vertical()
+ .WithChildren(
+ SinglelineTextInput().Title("Read-write text control"),
+ SinglelineTextInput().Title("Read-only text control").ReadOnly(),
+ SinglelineTextInput().Title("Read-write text input with copy").CanCopyWhenEditable());
public void OnDataReceived(string dataTypeName, object? parsedData) { }
}
diff --git a/src/app/dev/DevToys.UI/Assets/Icons/Idea.svg b/src/app/dev/DevToys.UI.Framework/Assets/Icons/Idea.svg
similarity index 100%
rename from src/app/dev/DevToys.UI/Assets/Icons/Idea.svg
rename to src/app/dev/DevToys.UI.Framework/Assets/Icons/Idea.svg
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Windows.cs b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Windows.cs
index b689bf9c2..3a08da75b 100644
--- a/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Windows.cs
+++ b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Windows.cs
@@ -19,6 +19,8 @@ namespace DevToys.UI.Framework.Controls;
public sealed partial class BackdropWindow : Window
{
+ private static bool _firstWindowCreated;
+
private readonly WindowsSystemDispatcherQueueHelper _wsdqHelper;
private MicaController? _micaController;
private SystemBackdropConfiguration? _configurationSource;
@@ -27,11 +29,19 @@ public sealed partial class BackdropWindow : Window
{
_wsdqHelper = new WindowsSystemDispatcherQueueHelper();
_wsdqHelper.EnsureWindowsSystemDispatcherQueueController();
-
+
AppWindow = GetAppWindow();
IsCompactOverlayModeSupported = true;
+
+ if (!_firstWindowCreated)
+ {
+ _firstWindowCreated = true;
+ MainWindowHandle = GetWindowHandle();
+ }
}
+ internal static IntPtr MainWindowHandle { get; private set; }
+
internal AppWindow AppWindow { get; }
public partial void Resize(int width, int height)
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml
index 16916c217..0da823c40 100644
--- a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml
@@ -6,6 +6,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
- Style="{ThemeResource DefaultButtonStyle}"
+ Style="{ThemeResource CustomButtonStyle}"
Click="OnButton_Click">
</Button>
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIDiffTextInputPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIDiffTextInputPresenter.xaml
new file mode 100644
index 000000000..8afef3d78
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIDiffTextInputPresenter.xaml
@@ -0,0 +1,12 @@
+<UserControl
+ x:Class="DevToys.UI.Framework.Controls.GuiTool.UIDiffTextInputPresenter"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="using:DevToys.UI.Framework.Controls.GuiTool"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d">
+ <local:UITextInputHeader>
+ <!-- TODO: Monaco Editor -->
+ </local:UITextInputHeader>
+</UserControl>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIDiffTextInputPresenter.xaml.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIDiffTextInputPresenter.xaml.cs
new file mode 100644
index 000000000..0481afb57
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIDiffTextInputPresenter.xaml.cs
@@ -0,0 +1,27 @@
+using DevToys.Api;
+using Microsoft.UI.Xaml.Controls;
+
+namespace DevToys.UI.Framework.Controls.GuiTool;
+
+public sealed partial class UIDiffTextInputPresenter : UserControl
+{
+ public UIDiffTextInputPresenter()
+ {
+ this.InitializeComponent();
+
+ Loaded += UIDiffTextInputPresenter_Loaded;
+ Unloaded += UIDiffTextInputPresenter_Unloaded;
+ }
+
+ internal IUIDiffTextInput UIDiffTextInput => (IUIDiffTextInput)DataContext;
+
+ private void UIDiffTextInputPresenter_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ }
+
+ private void UIDiffTextInputPresenter_Unloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ Loaded -= UIDiffTextInputPresenter_Loaded;
+ Unloaded -= UIDiffTextInputPresenter_Unloaded;
+ }
+}
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml
index 9c716f10a..8ac01cfb1 100644
--- a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml
@@ -59,6 +59,27 @@
</DataTemplate>
</local:UIElementTemplateSelector.UIDropDownListTemplate>
+ <!-- UIDiffTextInput -->
+ <local:UIElementTemplateSelector.UIDiffTextInputTemplate>
+ <DataTemplate>
+ <local:UIDiffTextInputPresenter/>
+ </DataTemplate>
+ </local:UIElementTemplateSelector.UIDiffTextInputTemplate>
+
+ <!-- UIMultilineTextInput -->
+ <local:UIElementTemplateSelector.UIMultilineTextInputTemplate>
+ <DataTemplate>
+ <local:UIMultilineTextInputPresenter/>
+ </DataTemplate>
+ </local:UIElementTemplateSelector.UIMultilineTextInputTemplate>
+
+ <!-- UISinglelineTextInput -->
+ <local:UIElementTemplateSelector.UISinglelineTextInputTemplate>
+ <DataTemplate>
+ <local:UISinglelineTextInputPresenter/>
+ </DataTemplate>
+ </local:UIElementTemplateSelector.UISinglelineTextInputTemplate>
+
</local:UIElementTemplateSelector>
</Control.Resources>
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementTemplateSelector.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementTemplateSelector.cs
index 4867a8392..4065f4bd7 100644
--- a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementTemplateSelector.cs
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementTemplateSelector.cs
@@ -44,6 +44,21 @@ internal sealed class UIElementTemplateSelector : DataTemplateSelector
/// </summary>
public DataTemplate UIDropDownListTemplate { get; set; } = null!;
+ /// <summary>
+ /// The data template used to display a <see cref="IUIDiffTextInput"/>.
+ /// </summary>
+ public DataTemplate UIDiffTextInputTemplate { get; set; } = null!;
+
+ /// <summary>
+ /// The data template used to display a <see cref="IUIMultilineLineTextInput"/>.
+ /// </summary>
+ public DataTemplate UIMultilineTextInputTemplate { get; set; } = null!;
+
+ /// <summary>
+ /// The data template used to display a <see cref="IUISinglelineTextInput"/>.
+ /// </summary>
+ public DataTemplate UISinglelineTextInputTemplate { get; set; } = null!;
+
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
if (item is null)
@@ -60,6 +75,9 @@ internal sealed class UIElementTemplateSelector : DataTemplateSelector
IUISetting => UISettingTemplate,
IUISwitch => UISwitchTemplate,
IUIDropDownList => UIDropDownListTemplate,
+ IUIDiffTextInput => UIDiffTextInputTemplate,
+ IUIMultilineLineTextInput => UIMultilineTextInputTemplate,
+ IUISinglelineTextInput => UISinglelineTextInputTemplate,
_ => throw new NotSupportedException($"Gui Tool component of type '{item.GetType().FullName}' isn't supported.")
};
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIMultilineTextInputPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIMultilineTextInputPresenter.xaml
new file mode 100644
index 000000000..aa1877cca
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIMultilineTextInputPresenter.xaml
@@ -0,0 +1,12 @@
+<UserControl
+ x:Class="DevToys.UI.Framework.Controls.GuiTool.UIMultilineTextInputPresenter"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="using:DevToys.UI.Framework.Controls.GuiTool"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d">
+ <local:UITextInputHeader>
+ <!-- TODO: Monaco Editor -->
+ </local:UITextInputHeader>
+</UserControl>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIMultilineTextInputPresenter.xaml.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIMultilineTextInputPresenter.xaml.cs
new file mode 100644
index 000000000..b62210f80
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIMultilineTextInputPresenter.xaml.cs
@@ -0,0 +1,27 @@
+using DevToys.Api;
+using Microsoft.UI.Xaml.Controls;
+
+namespace DevToys.UI.Framework.Controls.GuiTool;
+
+public sealed partial class UIMultilineTextInputPresenter : UserControl
+{
+ public UIMultilineTextInputPresenter()
+ {
+ this.InitializeComponent();
+
+ Loaded += UIMultilineTextInputPresenter_Loaded;
+ Unloaded += UIMultilineTextInputPresenter_Unloaded;
+ }
+
+ internal IUIMultilineLineTextInput UIMultilineLineTextInput => (IUIMultilineLineTextInput)DataContext;
+
+ private void UIMultilineTextInputPresenter_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ }
+
+ private void UIMultilineTextInputPresenter_Unloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ Loaded -= UIMultilineTextInputPresenter_Loaded;
+ Unloaded -= UIMultilineTextInputPresenter_Unloaded;
+ }
+}
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISinglelineTextInputPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISinglelineTextInputPresenter.xaml
new file mode 100644
index 000000000..e0778df96
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISinglelineTextInputPresenter.xaml
@@ -0,0 +1,18 @@
+<UserControl
+ x:Class="DevToys.UI.Framework.Controls.GuiTool.UISinglelineTextInputPresenter"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="using:DevToys.UI.Framework.Controls.GuiTool"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d"
+ VerticalAlignment="Top"
+ VerticalContentAlignment="Top">
+ <local:UITextInputHeader>
+ <TextBox
+ x:Name="TextBox"
+ VerticalAlignment="Top"
+ TextChanged="TextBox_TextChanged"
+ SelectionChanged="TextBox_SelectionChanged"/>
+ </local:UITextInputHeader>
+</UserControl>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISinglelineTextInputPresenter.xaml.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISinglelineTextInputPresenter.xaml.cs
new file mode 100644
index 000000000..31a824552
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISinglelineTextInputPresenter.xaml.cs
@@ -0,0 +1,90 @@
+using DevToys.Api;
+using Microsoft.UI.Xaml.Controls;
+
+namespace DevToys.UI.Framework.Controls.GuiTool;
+
+public sealed partial class UISinglelineTextInputPresenter : UserControl
+{
+ private bool _textChangedByUser;
+
+ public UISinglelineTextInputPresenter()
+ {
+ this.InitializeComponent();
+
+ Loaded += UISinglelineTextInputPresenter_Loaded;
+ Unloaded += UISinglelineTextInputPresenter_Unloaded;
+ }
+
+ internal IUISinglelineTextInput UISinglelineTextInput => (IUISinglelineTextInput)DataContext;
+
+ private void UISinglelineTextInputPresenter_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ UISinglelineTextInput.IsReadOnlyChanged += UISinglelineTextInput_IsReadOnlyChanged;
+ UISinglelineTextInput.TextChanged += UISinglelineTextInput_TextChanged;
+ UISinglelineTextInput.SelectionChanged += UISinglelineTextInput_SelectionChanged;
+ TextBox.IsReadOnly = UISinglelineTextInput.IsReadOnly;
+ TextBox.Text = UISinglelineTextInput.Text;
+ if (UISinglelineTextInput.Selection is not null)
+ {
+ TextBox.Select(UISinglelineTextInput.Selection.StartPosition, UISinglelineTextInput.Selection.Length);
+ }
+ }
+
+ private void UISinglelineTextInputPresenter_Unloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ UISinglelineTextInput.IsReadOnlyChanged -= UISinglelineTextInput_IsReadOnlyChanged;
+ UISinglelineTextInput.TextChanged -= UISinglelineTextInput_TextChanged;
+ UISinglelineTextInput.SelectionChanged -= UISinglelineTextInput_SelectionChanged;
+ Loaded -= UISinglelineTextInputPresenter_Loaded;
+ Unloaded -= UISinglelineTextInputPresenter_Unloaded;
+ }
+
+ private void UISinglelineTextInput_SelectionChanged(object? sender, EventArgs e)
+ {
+ if (UISinglelineTextInput.Selection is not null)
+ {
+ if (TextBox.SelectionStart != UISinglelineTextInput.Selection.StartPosition
+ && TextBox.SelectionLength != UISinglelineTextInput.Selection.Length)
+ {
+ TextBox.Select(UISinglelineTextInput.Selection.StartPosition, UISinglelineTextInput.Selection.Length);
+ }
+ }
+ else
+ {
+ TextBox.Select(0, 0);
+ }
+ }
+
+ private void UISinglelineTextInput_TextChanged(object? sender, EventArgs e)
+ {
+ if (!_textChangedByUser)
+ {
+ TextBox.Text = UISinglelineTextInput.Text;
+ }
+ }
+
+ private void UISinglelineTextInput_IsReadOnlyChanged(object? sender, EventArgs e)
+ {
+ TextBox.IsReadOnly = UISinglelineTextInput.IsReadOnly;
+ }
+
+ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ _textChangedByUser = true;
+ UISinglelineTextInput.Text(TextBox.Text);
+ _textChangedByUser = false;
+ }
+
+ private void TextBox_SelectionChanged(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ if (TextBox.SelectionStart > UISinglelineTextInput.Text.Length)
+ {
+ // Looks like the text isn't in sync.
+ _textChangedByUser = true;
+ UISinglelineTextInput.Text(TextBox.Text);
+ _textChangedByUser = false;
+ }
+
+ UISinglelineTextInput.Select(TextBox.SelectionStart, TextBox.SelectionLength);
+ }
+}
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UITextInputHeader.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UITextInputHeader.xaml
new file mode 100644
index 000000000..2c6d2af67
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UITextInputHeader.xaml
@@ -0,0 +1,160 @@
+<UserControl
+ x:Name="Root"
+ x:Class="DevToys.UI.Framework.Controls.GuiTool.UITextInputHeader"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:local="using:DevToys.UI.Framework.Controls.GuiTool"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:str="using:DevToys.UI.Framework.Extensions"
+ xmlns:converters="using:DevToys.UI.Framework.Converters"
+ mc:Ignorable="d"
+ HorizontalAlignment="Stretch"
+ VerticalAlignment="Stretch"
+ HorizontalContentAlignment="Stretch"
+ VerticalContentAlignment="Stretch"
+ SizeChanged="Root_SizeChanged">
+ <UserControl.Resources>
+ <converters:NegateBooleanConverter x:Key="NegateBooleanConverter"/>
+ <converters:NullToBooleanConverter x:Key="StringNullOrWhiteSpaceToFalseConverter" IsInverted="True" EnforceNonWhiteSpaceString="True"/>
+
+ <Style x:Name="SeparatorStyle" TargetType="Rectangle">
+ <Setter Property="Margin" Value="2,0,2,0"/>
+ <Setter Property="Width" Value="1"/>
+ <Setter Property="VerticalAlignment" Value="Stretch"/>
+ <Setter Property="RadiusX" Value="0.5"/>
+ <Setter Property="RadiusY" Value="0.5"/>
+ <Setter Property="Fill" Value="{ThemeResource AppBarSeparatorForeground}"/>
+ </Style>
+
+ <Style TargetType="Button" BasedOn="{StaticResource CustomButtonStyle}"/>
+ </UserControl.Resources>
+
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto"/>
+ <RowDefinition Height="*"/>
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*"/>
+ <ColumnDefinition Width="Auto"/>
+ </Grid.ColumnDefinitions>
+ <TextBlock
+ x:Name="HeaderTextBlock"
+ x:Load="{x:Bind Title, Mode=OneWay, Converter={StaticResource StringNullOrWhiteSpaceToFalseConverter}}"
+ Grid.Row="0"
+ Grid.Column="0"
+ Text="{x:Bind Title, Mode=OneWay}"
+ Margin="{ThemeResource TextBoxTopHeaderMargin}"
+ Style="{ThemeResource BodyTextBlockStyle}"
+ TextWrapping="NoWrap"
+ TextTrimming="WordEllipsis"
+ VerticalAlignment="Bottom"/>
+ <StackPanel
+ x:Name="HeaderStackPanel"
+ Grid.Row="0"
+ Grid.Column="1"
+ Orientation="Horizontal"
+ HorizontalAlignment="Right"
+ Margin="{ThemeResource UITextInputHeaderCommandMargin}"
+ Spacing="4"
+ AutomationProperties.LabeledBy="{x:Bind HeaderTextBlock}">
+ <Button
+ x:Name="PasteButton"
+ x:Load="{x:Bind IsReadOnly, Mode=OneWay, Converter={StaticResource NegateBooleanConverter}}"
+ ToolTipService.ToolTip="{str:StringsExtension Key=Paste}"
+ AutomationProperties.Name="{str:StringsExtension Key=Paste}"
+ Click="PasteButton_Click">
+ <StackPanel Orientation="Horizontal" Spacing="4">
+ <FontIcon Glyph="&#xF2D5;"/>
+ <TextBlock x:Name="PasteButtonText" Text="{str:StringsExtension Key=Paste}"/>
+ </StackPanel>
+ </Button>
+ <Button
+ x:Name="OpenFileButton"
+ x:Load="{x:Bind IsReadOnly, Mode=OneWay, Converter={StaticResource NegateBooleanConverter}}"
+ ToolTipService.ToolTip="{str:StringsExtension Key=OpenFile}"
+ AutomationProperties.Name="{str:StringsExtension Key=OpenFile}"
+ Click="OpenFileButton_Click">
+ <FontIcon Glyph="&#xF378;"/>
+ </Button>
+ <Button
+ x:Name="ClearButton"
+ x:Load="{x:Bind IsReadOnly, Mode=OneWay, Converter={StaticResource NegateBooleanConverter}}"
+ ToolTipService.ToolTip="{str:StringsExtension Key=Clear}"
+ AutomationProperties.Name="{str:StringsExtension Key=Clear}"
+ Click="ClearButton_Click">
+ <FontIcon Glyph="&#xF369;"/>
+ </Button>
+ <Rectangle
+ x:Name="Separator1"
+ x:Load="{x:Bind CanCopyWhenEditable, Mode=OneWay}"
+ Style="{StaticResource SeparatorStyle}"/>
+ <Button
+ x:Name="SaveAsButton"
+ x:Load="{x:Bind IsReadOnlyOrCanCopyWhenEditable, Mode=OneWay}"
+ ToolTipService.ToolTip="{str:StringsExtension Key=SaveAs}"
+ AutomationProperties.Name="{str:StringsExtension Key=SaveAs}"
+ Click="SaveAsButton_Click">
+ <FontIcon Glyph="&#xF67F;"/>
+ </Button>
+ <Button
+ x:Name="CopyButton"
+ x:Load="{x:Bind IsReadOnlyOrCanCopyWhenEditable, Mode=OneWay}"
+ ToolTipService.ToolTip="{str:StringsExtension Key=Copy}"
+ AutomationProperties.Name="{str:StringsExtension Key=Copy}"
+ Click="CopyButton_Click">
+ <StackPanel Orientation="Horizontal" Spacing="4">
+ <FontIcon Glyph="&#xF32B;"/>
+ <TextBlock x:Name="CopyButtonText" Text="{str:StringsExtension Key=Copy}"/>
+ </StackPanel>
+ </Button>
+ <Rectangle
+ x:Name="Separator2"
+ x:Load="{x:Bind IsReadOnlyOrCanCopyWhenEditable, Mode=OneWay}"
+ Style="{StaticResource SeparatorStyle}"/>
+ <DropDownButton
+ x:Name="SmartDetectionDropDownButton"
+ x:Load="{x:Bind IsReadOnlyOrCanCopyWhenEditable, Mode=OneWay}"
+ Padding="{ThemeResource ButtonPadding}"
+ ToolTipService.ToolTip="{str:StringsExtension Key=SendToSmartDetection}"
+ AutomationProperties.Name="{str:StringsExtension Key=SendToSmartDetection}">
+ <DropDownButton.Content>
+ <ImageIcon
+ Source="ms-appx:///DevToys.UI.Framework/Assets/Icons/Idea.svg"
+ Height="22"
+ Width="22" />
+ </DropDownButton.Content>
+ <DropDownButton.Flyout>
+ <MenuFlyout Placement="Bottom">
+ <MenuFlyoutItem Text="TODO">
+ <MenuFlyoutItem.Icon>
+ <FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE725;"/>
+ </MenuFlyoutItem.Icon>
+ </MenuFlyoutItem>
+ <MenuFlyoutItem Text="TODO">
+ <MenuFlyoutItem.Icon>
+ <FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE8CA;"/>
+ </MenuFlyoutItem.Icon>
+ </MenuFlyoutItem>
+ <MenuFlyoutItem Text="TODO">
+ <MenuFlyoutItem.Icon>
+ <FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE8C2;"/>
+ </MenuFlyoutItem.Icon>
+ </MenuFlyoutItem>
+ </MenuFlyout>
+ </DropDownButton.Flyout>
+ </DropDownButton>
+ </StackPanel>
+
+ <ContentControl
+ Grid.Row="1"
+ Grid.ColumnSpan="2"
+ HorizontalAlignment="Stretch"
+ VerticalAlignment="Stretch"
+ HorizontalContentAlignment="Stretch"
+ VerticalContentAlignment="Stretch"
+ Content="{Binding InnerEditor, ElementName=Root, Mode=OneTime}"/>
+ </Grid>
+</UserControl>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UITextInputHeader.xaml.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UITextInputHeader.xaml.cs
new file mode 100644
index 000000000..d9cff6c6c
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UITextInputHeader.xaml.cs
@@ -0,0 +1,357 @@
+using DevToys.Api;
+using DevToys.Localization.Strings.ToolPage;
+using DevToys.UI.Framework.Helpers;
+using DevToys.UI.Framework.Threading;
+using Microsoft.Extensions.Logging;
+using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Automation;
+using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Xaml.Markup;
+using Uno.Extensions;
+using Windows.Storage;
+using Windows.Storage.Pickers;
+using Windows.Storage.Provider;
+
+namespace DevToys.UI.Framework.Controls.GuiTool;
+
+[ContentProperty(Name = nameof(InnerEditor))]
+public sealed partial class UITextInputHeader : UserControl
+{
+ private readonly ILogger _logger;
+
+ public UITextInputHeader()
+ {
+ this.InitializeComponent();
+
+ _logger = this.Log();
+
+ Loaded += UITextInputHeader_Loaded;
+ Unloaded += UITextInputHeader_Unloaded;
+ }
+
+ internal IUISinglelineTextInput UITextInput => (IUISinglelineTextInput)DataContext;
+
+ public static readonly DependencyProperty TitleProperty
+ = DependencyProperty.Register(
+ nameof(Title),
+ typeof(string),
+ typeof(UITextInputHeader),
+ new PropertyMetadata(
+ string.Empty,
+ (d, e) =>
+ {
+ AutomationProperties.SetName(d, (string)e.NewValue);
+ }));
+
+ public string? Title
+ {
+ get => (string?)GetValue(TitleProperty);
+ set => SetValue(TitleProperty, value);
+ }
+
+ public static readonly DependencyProperty IsReadOnlyProperty
+ = DependencyProperty.Register(
+ nameof(IsReadOnly),
+ typeof(bool),
+ typeof(UITextInputHeader),
+ new PropertyMetadata(false));
+
+ public bool IsReadOnly
+ {
+ get => (bool)GetValue(IsReadOnlyProperty);
+ set => SetValue(IsReadOnlyProperty, value);
+ }
+
+ public static readonly DependencyProperty CanCopyWhenEditableProperty
+ = DependencyProperty.Register(
+ nameof(CanCopyWhenEditable),
+ typeof(bool),
+ typeof(UITextInputHeader),
+ new PropertyMetadata(false));
+
+ public bool CanCopyWhenEditable
+ {
+ get => (bool)GetValue(CanCopyWhenEditableProperty);
+ set => SetValue(CanCopyWhenEditableProperty, value);
+ }
+
+ public static readonly DependencyProperty IsReadOnlyOrCanCopyWhenEditableProperty
+ = DependencyProperty.Register(
+ nameof(IsReadOnlyOrCanCopyWhenEditable),
+ typeof(bool),
+ typeof(UITextInputHeader),
+ new PropertyMetadata(false));
+
+ public bool IsReadOnlyOrCanCopyWhenEditable
+ {
+ get => (bool)GetValue(IsReadOnlyOrCanCopyWhenEditableProperty);
+ set => SetValue(IsReadOnlyOrCanCopyWhenEditableProperty, value);
+ }
+
+ public static readonly DependencyProperty InnerEditorProperty
+ = DependencyProperty.Register(
+ nameof(InnerEditor),
+ typeof(object),
+ typeof(UITextInputHeader),
+ new PropertyMetadata(null));
+
+ public object? InnerEditor
+ {
+ get => GetValue(InnerEditorProperty);
+ set => SetValue(InnerEditorProperty, value);
+ }
+
+ private void UITextInputHeader_Loaded(object sender, RoutedEventArgs e)
+ {
+ UITextInput.TitleChanged += UITextInput_TitleChanged;
+ UITextInput.IsReadOnlyChanged += UITextInput_IsReadOnlyChanged;
+ UITextInput.CanCopyWhenEditableChanged += UITextInput_CanCopyWhenEditableChanged;
+ UITextInput.IsEnabledChanged += UITextInput_IsEnabledChanged;
+ UITextInput.IsVisibleChanged += UITextInput_IsVisibleChanged;
+ Title = UITextInput.Title;
+ IsReadOnly = UITextInput.IsReadOnly;
+ CanCopyWhenEditable = UITextInput.CanCopyWhenEditable;
+ IsEnabled = UITextInput.IsEnabled;
+ Visibility = UITextInput.IsVisible ? Visibility.Visible : Visibility.Collapsed;
+ IsReadOnlyOrCanCopyWhenEditable = IsReadOnly || CanCopyWhenEditable;
+ }
+
+ private void UITextInputHeader_Unloaded(object sender, RoutedEventArgs e)
+ {
+ UITextInput.TitleChanged -= UITextInput_TitleChanged;
+ UITextInput.IsReadOnlyChanged -= UITextInput_IsReadOnlyChanged;
+ UITextInput.CanCopyWhenEditableChanged -= UITextInput_CanCopyWhenEditableChanged;
+ UITextInput.IsEnabledChanged -= UITextInput_IsEnabledChanged;
+ UITextInput.IsVisibleChanged -= UITextInput_IsVisibleChanged;
+ Loaded -= UITextInputHeader_Loaded;
+ Unloaded -= UITextInputHeader_Unloaded;
+ }
+
+ private void UITextInput_TitleChanged(object? sender, EventArgs e)
+ {
+ Title = UITextInput.Title;
+ }
+
+ private void UITextInput_IsReadOnlyChanged(object? sender, EventArgs e)
+ {
+ IsReadOnly = UITextInput.IsReadOnly;
+ IsReadOnlyOrCanCopyWhenEditable = IsReadOnly || CanCopyWhenEditable;
+ }
+
+ private void UITextInput_CanCopyWhenEditableChanged(object? sender, EventArgs e)
+ {
+ CanCopyWhenEditable = UITextInput.CanCopyWhenEditable;
+ IsReadOnlyOrCanCopyWhenEditable = IsReadOnly || CanCopyWhenEditable;
+ }
+
+ private void UITextInput_IsEnabledChanged(object? sender, EventArgs e)
+ {
+ IsEnabled = UITextInput.IsEnabled;
+ }
+
+ private void UITextInput_IsVisibleChanged(object? sender, EventArgs e)
+ {
+ Visibility = UITextInput.IsVisible ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ private void Root_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ if (e.NewSize.Width == e.PreviousSize.Width)
+ {
+ return;
+ }
+
+ if (e.NewSize.Width < 500)
+ {
+ if (PasteButtonText != null)
+ {
+ PasteButtonText.Visibility = Visibility.Collapsed;
+ }
+ if (CopyButtonText != null)
+ {
+ CopyButtonText.Visibility = Visibility.Collapsed;
+ }
+ }
+ else
+ {
+ if (PasteButtonText != null)
+ {
+ PasteButtonText.Visibility = Visibility.Visible;
+ }
+ if (CopyButtonText != null)
+ {
+ CopyButtonText.Visibility = Visibility.Visible;
+ }
+ }
+ }
+
+ private void PasteButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.DispatcherQueue.RunOnUIThreadAsync(async () =>
+ {
+ object? clipboardContent = await Parts.Clipboard.GetClipboardDataAsync();
+ if (clipboardContent is string clipboardString)
+ {
+ if (Parts.SettingsProvider.GetSetting(PredefinedSettings.TextEditorPasteClearsText))
+ {
+ UITextInput.Text(clipboardString);
+ }
+ else
+ {
+ UITextInput.Text(UITextInput.Text + clipboardString);
+ }
+ }
+ }).ForgetSafely();
+ }
+
+ private void OpenFileButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.DispatcherQueue.RunOnUIThreadAsync(async () =>
+ {
+ var filePicker = new FileOpenPicker
+ {
+ ViewMode = PickerViewMode.List,
+ SuggestedStartLocation = PickerLocationId.ComputerFolder
+ };
+
+ filePicker.FileTypeFilter.Add("*");
+ filePicker.FileTypeFilter.Add(".txt");
+ filePicker.FileTypeFilter.Add(".js");
+ filePicker.FileTypeFilter.Add(".ts");
+ filePicker.FileTypeFilter.Add(".cs");
+ filePicker.FileTypeFilter.Add(".java");
+ filePicker.FileTypeFilter.Add(".xml");
+ filePicker.FileTypeFilter.Add(".xsd");
+ filePicker.FileTypeFilter.Add(".json");
+ filePicker.FileTypeFilter.Add(".md");
+ filePicker.FileTypeFilter.Add(".sql");
+ filePicker.FileTypeFilter.Add(".html");
+ filePicker.FileTypeFilter.Add(".cshtml");
+ filePicker.FileTypeFilter.Add(".razor");
+ filePicker.FileTypeFilter.Add(".css");
+
+#if __WINDOWS__
+ // Initialize the file picker with the window handle (HWND).
+ WinRT.Interop.InitializeWithWindow.Initialize(filePicker, BackdropWindow.MainWindowHandle);
+#endif
+ StorageFile file = await filePicker.PickSingleFileAsync();
+ if (file is not null)
+ {
+ try
+ {
+ await TaskSchedulerAwaiter.SwitchOffMainThreadAsync(CancellationToken.None);
+
+ string? text = await FileIO.ReadTextAsync(file);
+
+ await this.DispatcherQueue.RunOnUIThreadAsync(() =>
+ {
+ UITextInput.Text(text);
+ });
+ }
+ catch (Exception ex)
+ {
+ LogErrorOpeningFile(ex);
+
+ await this.DispatcherQueue.RunOnUIThreadAsync(async () =>
+ {
+ var dialog = new ContentDialog
+ {
+ // XamlRoot must be set in the case of a ContentDialog running in a Desktop app
+ XamlRoot = this.XamlRoot,
+ Title = ToolPage.UnableOpenFile,
+ Content = string.Format(ToolPage.UnableOpenFileDescription, file.Name),
+ CloseButtonText = ToolPage.Ok,
+ DefaultButton = ContentDialogButton.Close
+ };
+
+ await dialog.ShowAsync();
+ });
+
+ }
+ }
+ }).ForgetSafely();
+ }
+
+ private void ClearButton_Click(object sender, RoutedEventArgs e)
+ {
+ UITextInput.Text(string.Empty);
+ }
+
+ private void SaveAsButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.DispatcherQueue.RunOnUIThreadAsync(async () =>
+ {
+ string text = UITextInput.Text; // make sure to get this value on the UI thread.
+
+ var filePicker = new FileSavePicker
+ {
+ SuggestedStartLocation = PickerLocationId.ComputerFolder
+ };
+
+ filePicker.FileTypeChoices.Add(ToolPage.AllFileType, new List<string> { "." });
+
+#if __WINDOWS__
+ // Initialize the file picker with the window handle (HWND).
+ WinRT.Interop.InitializeWithWindow.Initialize(filePicker, BackdropWindow.MainWindowHandle);
+#endif
+ StorageFile file = await filePicker.PickSaveFileAsync();
+ if (file is not null)
+ {
+ await TaskSchedulerAwaiter.SwitchOffMainThreadAsync(CancellationToken.None);
+
+ // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
+ CachedFileManager.DeferUpdates(file);
+ bool failed = false;
+
+ try
+ {
+ await FileIO.WriteTextAsync(file, text);
+ }
+ catch (Exception ex)
+ {
+ LogErrorSavingFile(ex);
+ failed = true;
+ }
+ finally
+ {
+ // Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
+ // Completing updates may require Windows to ask for user input.
+ FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
+ if (status != FileUpdateStatus.Complete && status != FileUpdateStatus.CompleteAndRenamed)
+ {
+ failed = true;
+ }
+ }
+
+ if (failed)
+ {
+ await this.DispatcherQueue.RunOnUIThreadAsync(async () =>
+ {
+ var dialog = new ContentDialog
+ {
+ // XamlRoot must be set in the case of a ContentDialog running in a Desktop app
+ XamlRoot = this.XamlRoot,
+ Title = ToolPage.UnableSaveFile,
+ Content = string.Format(ToolPage.UnableSaveFileDescription, file.Name),
+ CloseButtonText = ToolPage.Ok,
+ DefaultButton = ContentDialogButton.Close
+ };
+
+ await dialog.ShowAsync();
+ });
+ }
+ }
+ }).ForgetSafely();
+ }
+
+ private void CopyButton_Click(object sender, RoutedEventArgs e)
+ {
+ Parts.Clipboard.SetClipboardTextAsync(UITextInput.Text).ForgetSafely();
+ }
+
+ [LoggerMessage(1, LogLevel.Warning, "Unable to open a file in a text input control.")]
+ partial void LogErrorOpeningFile(Exception ex);
+
+ [LoggerMessage(2, LogLevel.Warning, "Unable to save a file from a text input control.")]
+ partial void LogErrorSavingFile(Exception ex);
+}
diff --git a/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj b/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj
index 9c0d31e6a..3066377b1 100644
--- a/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj
+++ b/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj
@@ -95,6 +95,7 @@
<ItemGroup>
<ProjectReference Include="..\DevToys.Api\DevToys.Api.csproj" />
+ <ProjectReference Include="..\DevToys.Localization\DevToys.Localization.csproj" />
</ItemGroup>
</Project>
diff --git a/src/app/dev/DevToys.UI.Framework/Extensions/HighlighterExtension.cs b/src/app/dev/DevToys.UI.Framework/Extensions/HighlighterExtension.cs
index 06075cdae..6badfbccc 100644
--- a/src/app/dev/DevToys.UI.Framework/Extensions/HighlighterExtension.cs
+++ b/src/app/dev/DevToys.UI.Framework/Extensions/HighlighterExtension.cs
@@ -19,9 +19,9 @@ public sealed class HighlighterExtension : MarkupExtension
public static readonly DependencyProperty HighlightersProperty
= DependencyProperty.RegisterAttached(
"Highlighters",
- typeof(MatchSpan[]),
+ typeof(TextSpan[]),
typeof(HighlighterExtension),
- new PropertyMetadata(Array.Empty<MatchSpan>(), OnHighlightersChanged));
+ new PropertyMetadata(Array.Empty<TextSpan>(), OnHighlightersChanged));
/// <summary>
/// Gets the value of the Highlighters attached property from the specified FrameworkElement.
@@ -50,7 +50,7 @@ public sealed class HighlighterExtension : MarkupExtension
{
if (d is RichTextBlock source)
{
- var value = e.NewValue as MatchSpan[];
+ var value = e.NewValue as TextSpan[];
source.TextHighlighters.Clear();
if (value is not null && value.Length > 0)
diff --git a/src/app/dev/DevToys.UI.Framework/Extensions/Strings.cs b/src/app/dev/DevToys.UI.Framework/Extensions/Strings.cs
new file mode 100644
index 000000000..76835f1de
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Extensions/Strings.cs
@@ -0,0 +1,43 @@
+using System.Resources;
+using DevToys.Localization.Strings.ToolPage;
+using Microsoft.UI.Xaml.Data;
+using Microsoft.UI.Xaml.Markup;
+
+namespace DevToys.UI.Framework.Extensions;
+
+[MarkupExtensionReturnType(ReturnType = typeof(string))]
+public partial class StringsExtension : MarkupExtension
+{
+ public enum KeyEnum
+ {
+ __Undefined = 0,
+ Clear,
+ Copy,
+ OpenFile,
+ Paste,
+ SaveAs,
+ SendToSmartDetection,
+ ToggleSwitchOff,
+ ToggleSwitchOn,
+ }
+
+ private static readonly ResourceManager resourceManager = new ResourceManager("DevToys.Localization.Strings.ToolPage.ToolPage", typeof(ToolPage).Assembly);
+
+ public KeyEnum Key { get; set; }
+
+ public IValueConverter? Converter { get; set; }
+
+ public object? ConverterParameter { get; set; }
+
+ protected override object ProvideValue()
+ {
+ string res;
+ if (Key == KeyEnum.__Undefined)
+ res = "";
+ else
+ {
+ res = resourceManager.GetString(Key.ToString(), culture: null) ?? string.Empty;
+ }
+ return Converter == null ? res : Converter.Convert(res, typeof(string), ConverterParameter, null);
+ }
+}
diff --git a/src/app/dev/DevToys.UI.Framework/Helpers/Parts.cs b/src/app/dev/DevToys.UI.Framework/Helpers/Parts.cs
new file mode 100644
index 000000000..63710985a
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Helpers/Parts.cs
@@ -0,0 +1,11 @@
+using DevToys.Api;
+using DevToys.Api.Core;
+
+namespace DevToys.UI.Framework.Helpers;
+
+public static class Parts
+{
+ public static ISettingsProvider SettingsProvider { internal get; set; } = null!;
+
+ public static IClipboard Clipboard { internal get; set; } = null!;
+}
diff --git a/src/app/dev/DevToys.UI.Framework/Strings/StringsExtension.cs b/src/app/dev/DevToys.UI.Framework/Strings/StringsExtension.cs
deleted file mode 100644
index e9495b1f6..000000000
--- a/src/app/dev/DevToys.UI.Framework/Strings/StringsExtension.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-using Microsoft.UI.Xaml.Markup;
-
-namespace DevToys.UI.Framework.Strings;
-
-// Workaround for an issue where Uno Generator can't find this class during build, because Roslyn would run Uno Generator after the ReswPlus generator.
-[MarkupExtensionReturnType(ReturnType = typeof(string))]
-public partial class ResourcesExtension : MarkupExtension { }
diff --git a/src/app/dev/DevToys.UI.Framework/Strings/en-US/Strings.resw b/src/app/dev/DevToys.UI.Framework/Strings/en-US/Strings.resw
deleted file mode 100644
index fe2e9d9a0..000000000
--- a/src/app/dev/DevToys.UI.Framework/Strings/en-US/Strings.resw
+++ /dev/null
@@ -1,126 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<root>
- <!--
- Microsoft ResX Schema
-
- Version 2.0
-
- The primary goals of this format is to allow a simple XML format
- that is mostly human readable. The generation and parsing of the
- various data types are done through the TypeConverter classes
- associated with the data types.
-
- Example:
-
- ... ado.net/XML headers & schema ...
- <resheader name="resmimetype">text/microsoft-resx</resheader>
- <resheader name="version">2.0</resheader>
- <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
- <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
- <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
- <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
- <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
- <value>[base64 mime encoded serialized .NET Framework object]</value>
- </data>
- <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
- <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
- <comment>This is a comment</comment>
- </data>
-
- There are any number of "resheader" rows that contain simple
- name/value pairs.
-
- Each data row contains a name, and value. The row also contains a
- type or mimetype. Type corresponds to a .NET class that support
- text/value conversion through the TypeConverter architecture.
- Classes that don't support this are serialized and stored with the
- mimetype set.
-
- The mimetype is used for serialized objects, and tells the
- ResXResourceReader how to depersist the object. This is currently not
- extensible. For a given mimetype the value must be set accordingly:
-
- Note - application/x-microsoft.net.object.binary.base64 is the format
- that the ResXResourceWriter will generate, however the reader can
- read any of the formats listed below.
-
- mimetype: application/x-microsoft.net.object.binary.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.soap.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.bytearray.base64
- value : The object must be serialized into a byte array
- : using a System.ComponentModel.TypeConverter
- : and then encoded with base64 encoding.
- -->
- <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
- <xsd:element name="root" msdata:IsDataSet="true">
- <xsd:complexType>
- <xsd:choice maxOccurs="unbounded">
- <xsd:element name="metadata">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" />
- </xsd:sequence>
- <xsd:attribute name="name" use="required" type="xsd:string" />
- <xsd:attribute name="type" type="xsd:string" />
- <xsd:attribute name="mimetype" type="xsd:string" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="assembly">
- <xsd:complexType>
- <xsd:attribute name="alias" type="xsd:string" />
- <xsd:attribute name="name" type="xsd:string" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="data">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
- <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
- <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="resheader">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" />
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- <resheader name="resmimetype">
- <value>text/microsoft-resx</value>
- </resheader>
- <resheader name="version">
- <value>2.0</value>
- </resheader>
- <resheader name="reader">
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <resheader name="writer">
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <data name="ToggleSwitchOff" xml:space="preserve">
- <value>On</value>
- </data>
- <data name="ToggleSwitchOn" xml:space="preserve">
- <value>Off</value>
- </data>
-</root>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.UI.Framework/Themes/Generic.xaml b/src/app/dev/DevToys.UI.Framework/Themes/Generic.xaml
index aa9e76eda..dac1cd75e 100644
--- a/src/app/dev/DevToys.UI.Framework/Themes/Generic.xaml
+++ b/src/app/dev/DevToys.UI.Framework/Themes/Generic.xaml
@@ -1,7 +1,7 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:str="using:DevToys.UI.Framework.Strings"
+ xmlns:str="using:DevToys.UI.Framework.Extensions"
xmlns:converters="using:DevToys.UI.Framework.Converters">
<ResourceDictionary.ThemeDictionaries>
@@ -61,6 +61,11 @@
<Setter Property="OffContent" Value="{str:StringsExtension Key=ToggleSwitchOff}"/>
</Style>
+ <Style x:Key="CustomButtonStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
+ <Setter Property="MinHeight" Value="{ThemeResource ButtonMinHeight}"/>
+ <Setter Property="Padding" Value="{ThemeResource ButtonPadding}"/>
+ </Style>
+
<!-- From https://github.com/morning4coffe-dev/storylines -->
<Style x:Key="RightAlignedToggleSwitchStyle" TargetType="ToggleSwitch">
<Setter Property="Foreground" Value="{ThemeResource ToggleSwitchContentForeground}" />
@@ -668,11 +673,4 @@
</Setter.Value>
</Setter>
</Style>
-
- <Style x:Key="SubTitleTextBlock" TargetType="TextBlock">
- <Setter Property="Foreground" Value="{ThemeResource TextControlHeaderForeground}" />
- <Setter Property="FontSize" Value="14" />
- <Setter Property="FontWeight" Value="Normal" />
- <Setter Property="Margin" Value="0,12,0,0" />
- </Style>
</ResourceDictionary>
diff --git a/src/app/dev/DevToys.UI/Views/MainWindow.xaml b/src/app/dev/DevToys.UI/Views/MainWindow.xaml
index afc8b1f0e..2fa0cc15f 100644
--- a/src/app/dev/DevToys.UI/Views/MainWindow.xaml
+++ b/src/app/dev/DevToys.UI/Views/MainWindow.xaml
@@ -283,7 +283,7 @@
x:Name="NavigationViewItemRecommendedIcon"
x:Load="{x:Bind IsRecommended, Mode=OneWay}"
Grid.Column="1"
- Source="ms-appx:///DevToys.UI/Assets/Icons/Idea.svg"
+ Source="ms-appx:///DevToys.UI.Framework/Assets/Icons/Idea.svg"
Height="16"
Width="16"/>
</Grid>
diff --git a/src/app/dev/DevToys.UI/Views/ToolPage.xaml b/src/app/dev/DevToys.UI/Views/ToolPage.xaml
index 6b2ff31a8..57fe10839 100644
--- a/src/app/dev/DevToys.UI/Views/ToolPage.xaml
+++ b/src/app/dev/DevToys.UI/Views/ToolPage.xaml
@@ -73,7 +73,8 @@
<CommandBar
x:Name="CommandBar"
IsOpen="False"
- DefaultLabelPosition="Right">
+ DefaultLabelPosition="Right"
+ Margin="0,0,-8,0">
<AppBarButton
Command="{x:Bind ViewModel.ToggleSelectedMenuItemFavoriteCommand}"
Visibility="{x:Bind ViewModel.IsSelectedMenuItemSupportFavorite, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
diff --git a/src/app/dev/Directory.Build.props b/src/app/dev/Directory.Build.props
index 166a499a5..9f8d862a0 100644
--- a/src/app/dev/Directory.Build.props
+++ b/src/app/dev/Directory.Build.props
@@ -1,6 +1,5 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
- <Import Project="$(RepoRoot)\tools\ReswPlus.0.1.5-alpha\ReswPlus.props" />
<PropertyGroup>
<!-- Define .NET and C# configuration -->
@@ -38,8 +37,4 @@
<Compile Include="$(RepoRoot)\src\app\dev\shared\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
<Compile Include="$(RepoRoot)\src\app\dev\shared\SharedAssemblyVersion.cs" Link="Properties\SharedAssemblyVersion.cs" />
</ItemGroup>
-
- <ItemGroup>
- <Analyzer Include="$(RepoRoot)\tools\ReswPlus.0.1.5-alpha\ReswPlusSourceGenerator.dll" />
- </ItemGroup>
</Project>
\ No newline at end of file
diff --git a/src/app/dev/platforms/desktop/windows/DevToys.Wasdk/Core/Theme/ThemeListener.cs b/src/app/dev/platforms/desktop/windows/DevToys.Wasdk/Core/Theme/ThemeListener.cs
index 35ab31c95..49ed665f4 100644
--- a/src/app/dev/platforms/desktop/windows/DevToys.Wasdk/Core/Theme/ThemeListener.cs
+++ b/src/app/dev/platforms/desktop/windows/DevToys.Wasdk/Core/Theme/ThemeListener.cs
@@ -145,9 +145,20 @@ internal sealed class ThemeListener : IThemeListener
UpdateAppResource("UISettingPresenterContentPadding", new Thickness(16, 4, 16, 4));
UpdateAppResource("UISettingGroupPresenterContentMargin", new Thickness(0, 4, 0, 4));
+ // UITextInputHeader
+ UpdateAppResource("UITextInputHeaderCommandMargin", new Thickness(0, 0, 0, 4));
+
// ComboBox
UpdateAppResource("ComboBoxMinHeight", 24);
- UpdateAppResource("ComboBoxPadding", new Thickness(12, 1, 0, 3));
+ UpdateAppResource("ComboBoxPadding", new Thickness(8, 1, 0, 1));
+
+ // Button
+ UpdateAppResource("ButtonMinHeight", 24);
+ UpdateAppResource("ButtonPadding", new Thickness(8, 1, 8, 1));
+
+ // TextBox
+ UpdateAppResource("TextControlThemeMinHeight", 24);
+ UpdateAppResource("TextControlThemePadding", new Thickness(2, 2, 6, 2));
}
else
{
@@ -161,9 +172,20 @@ internal sealed class ThemeListener : IThemeListener
UpdateAppResource("UISettingPresenterContentPadding", new Thickness(16));
UpdateAppResource("UISettingGroupPresenterContentMargin", new Thickness(0, 16, 0, 16));
+ // UITextInputHeader
+ UpdateAppResource("UITextInputHeaderCommandMargin", new Thickness(0, 0, 0, 8));
+
// ComboBox
UpdateAppResource("ComboBoxMinHeight", 32);
UpdateAppResource("ComboBoxPadding", new Thickness(12, 5, 0, 7));
+
+ // Button
+ UpdateAppResource("ButtonMinHeight", 32);
+ UpdateAppResource("ButtonPadding", new Thickness(11, 5, 11, 6));
+
+ // TextBox
+ UpdateAppResource("TextControlThemeMinHeight", 32);
+ UpdateAppResource("TextControlThemePadding", new Thickness(10, 5, 6, 6));
}
// Toggle between the themes to force reload the resource styles.
diff --git a/src/app/dev/shared/App.xaml.cs b/src/app/dev/shared/App.xaml.cs
index 02ceb0d9f..45b1199b7 100644
--- a/src/app/dev/shared/App.xaml.cs
+++ b/src/app/dev/shared/App.xaml.cs
@@ -1,4 +1,5 @@
using DevToys.Api;
+using DevToys.Api.Core;
using DevToys.Api.Core.Theme;
using DevToys.Business.ViewModels;
using DevToys.Core.Logging;
@@ -7,6 +8,7 @@ using DevToys.Core.Settings;
using DevToys.Tools;
using DevToys.UI;
using DevToys.UI.Framework.Controls;
+using DevToys.UI.Framework.Helpers;
using DevToys.UI.Views;
using DevToys.Wasdk.Core.FileStorage;
using Microsoft.Extensions.Logging;
@@ -96,6 +98,9 @@ public sealed partial class App : Application
IThemeListener themeListener = _themeListener.Value;
+ Parts.SettingsProvider = _settingsProvider.Value;
+ Parts.Clipboard = _mefProvider.Import<IClipboard>();
+
#if __WINDOWS__
// On Windows 10 version 1607 or later, this code signals that this app wants to participate in prelaunch
CoreApplication.EnablePrelaunch(true);
diff --git a/tools/ReswPlus.0.1.5-alpha/README.md b/tools/ReswPlus.0.1.5-alpha/README.md
deleted file mode 100644
index c6d922702..000000000
--- a/tools/ReswPlus.0.1.5-alpha/README.md
+++ /dev/null
@@ -1,18 +0,0 @@
-C# Source generator built from https://github.com/DotNetPlus/ReswPlus/tree/sourceGenerator
-This binary contains a tiny change to the usings generated [here](https://github.com/DotNetPlus/ReswPlus/blob/c94e47bbc1deff1569345c680e1017984120da3c/src/ReswPlus.Shared/CodeGenerators/CsharpCodeGenerator.cs#L49-L52) that set the proper namespace for non-UWP apps.
-
-In the end, it generates the following:
-
-```
-// File generated automatically by ReswPlus. https://github.com/DotNetPlus/ReswPlus
-// The NuGet package ReswPlusLib is necessary to support Pluralization.
-using System;
-using Windows.ApplicationModel.Resources;
-#if WINDOWS_UWP
-using Windows.UI.Xaml.Markup;
-using Windows.UI.Xaml.Data;
-#else
-using Microsoft.UI.Xaml.Markup;
-using Microsoft.UI.Xaml.Data;
-#endif
-```
\ No newline at end of file
diff --git a/tools/ReswPlus.0.1.5-alpha/ReswPlus.props b/tools/ReswPlus.0.1.5-alpha/ReswPlus.props
deleted file mode 100644
index 3c29de223..000000000
--- a/tools/ReswPlus.0.1.5-alpha/ReswPlus.props
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup>
- <CompilerVisibleProperty Include="MSBuildProjectFullPath" />
- <CompilerVisibleProperty Include="RootNamespace" />
- <CompilerVisibleProperty Include="DefaultLanguage" />
- <CompilerVisibleProperty Include="OutputType" />
- </ItemGroup>
- <PropertyGroup>
- <AdditionalFileItemNames>$(AdditionalFileItemNames);PRIResource</AdditionalFileItemNames>
- </PropertyGroup>
-</Project>
\ No newline at end of file
diff --git a/tools/ReswPlus.0.1.5-alpha/ReswPlusSourceGenerator.dll b/tools/ReswPlus.0.1.5-alpha/ReswPlusSourceGenerator.dll
deleted file mode 100644
index af122ce14..000000000
Binary files a/tools/ReswPlus.0.1.5-alpha/ReswPlusSourceGenerator.dll and /dev/null differ