Skip to content

Commit

Permalink
Added a multiline-line text input (#780)
Browse files Browse the repository at this point in the history
* Added a single-line text input

* Added a multiline-line text input

* Added font detection & support

* Revert unnecessary change

* Removed a "TODO".

* Added drag & drop support

* Reverted unnecessary changes
  • Loading branch information
veler authored Apr 5, 2023
1 parent 0e80f67 commit 41a4874
Show file tree
Hide file tree
Showing 46 changed files with 1,061 additions and 393 deletions.
11 changes: 4 additions & 7 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
<CommunityToolkitWinUINuGetVersion>7.1.2</CommunityToolkitWinUINuGetVersion>
<DotNetVersion>7.0.0</DotNetVersion>
<MicrosoftFastComponentsFluentUIVersion>2.0.1</MicrosoftFastComponentsFluentUIVersion>
<MicrosoftNETCoreUniversalWindowsPlatformVersion>6.2.14</MicrosoftNETCoreUniversalWindowsPlatformVersion>
<MicrosoftWindowsSDKBuildToolsVersion>10.0.22621.755</MicrosoftWindowsSDKBuildToolsVersion>
<UnoVersion>4.7.37</UnoVersion>
<UnoCommunityToolkitWinUINuGetVersion>7.1.100</UnoCommunityToolkitWinUINuGetVersion>
<UnoWasmBootstrapVersion>8.0.0-dev.65</UnoWasmBootstrapVersion>
<WebView2Version>1.0.1462.37</WebView2Version>
<MicrosoftTypeScriptMSBuildVersion>4.9.4</MicrosoftTypeScriptMSBuildVersion>
<WpfGridLayoutBlazorVersion>1.2.0</WpfGridLayoutBlazorVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommunityToolkit.Common" Version="$(CommunityToolkitVersion)" />
Expand All @@ -34,14 +30,15 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="$(DotNetVersion)" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="$(DotNetVersion)" />
<PackageVersion Include="Microsoft.Fast.Components.FluentUI" Version="$(MicrosoftFastComponentsFluentUIVersion)" />
<PackageVersion Include="Microsoft.Graphics.Win2D" Version="1.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageVersion Include="Microsoft.TypeScript.MSBuild" Version="$(MicrosoftTypeScriptMSBuildVersion)" />
<PackageVersion Include="Microsoft.UI.Xaml" Version="2.8.1" />
<PackageVersion Include="Microsoft.Web.WebView2" Version="$(WebView2Version)" />
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.1462.37" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="$(DotNetVersion)" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.2.188-beta" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="$(MicrosoftWindowsSDKBuildToolsVersion)" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.2.230118.102" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.2.230313.1" />
<PackageVersion Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9"/>
<PackageVersion Include="Moq" Version="4.18.2" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down
12 changes: 12 additions & 0 deletions src/app/dev/DevToys.Api/Core/IFontProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace DevToys.Api.Core;

/// <summary>
/// Provides a platform agnostic way to retrieve information about fonts installed on the operating system.
/// </summary>
public interface IFontProvider
{
/// <summary>
/// Retrieves the list of font families available on the operating system.
/// </summary>
string[] GetFontFamilies();
}
70 changes: 70 additions & 0 deletions src/app/dev/DevToys.Api/Settings/PredefinedSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,76 @@ public static readonly SettingDefinition<bool> CompactMode
name: nameof(CompactMode),
defaultValue: false);

/// <summary>
/// Preferred default fonts. The app will the first font in this list that is available on the system.
/// </summary>
public static readonly string[] DefaultFonts
= new[]
{
// Popular fonts developers install. If it's on the system, users likely want to use it.
"Fira Code",
"Source Code Pro",
"DejaVu Sans Mono",
"Hack",

// Default Visual Studio fonts.
"Cascadia Mono",
"Cascadia Code",

// Fonts included on MacOS.
"Menlo",
"Monaco",
"SF Mono",
"SF Pro",

// Fonts included on Windows and MacOS.
"Consolas",
"Courier New",

// Fonts included on Windows.
"Segoe UI",
};

/// <summary>
/// The font family name to use in the text editor.
/// </summary>
public static readonly SettingDefinition<string> TextEditorFont
= new(
name: nameof(TextEditorFont),
defaultValue: string.Empty); // Default value will be defined by the app depending on the operating system.

/// <summary>
/// Whether the text in the text editor should wrap.
/// </summary>
public static readonly SettingDefinition<bool> TextEditorTextWrapping
= new(
name: nameof(TextEditorTextWrapping),
defaultValue: false);

/// <summary>
/// Whether the line numbers should be displayed in the text editor.
/// </summary>
public static readonly SettingDefinition<bool> TextEditorLineNumbers
= new(
name: nameof(TextEditorLineNumbers),
defaultValue: true);

/// <summary>
/// Whether the line where the caret is should be highlighted in the text editor.
/// </summary>
public static readonly SettingDefinition<bool> TextEditorHighlightCurrentLine
= new(
name: nameof(TextEditorHighlightCurrentLine),
defaultValue: true);

/// <summary>
/// Whether white spaces should be rendered in the text editor.
/// </summary>
public static readonly SettingDefinition<bool> TextEditorRenderWhitespace
= new(
name: nameof(TextEditorRenderWhitespace),
defaultValue: false);

/// <summary>
/// Whether when using the Paste command, the text in the editor should be replaced or appended.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ internal set
public static partial class GUI
{
/// <summary>
/// Create component that represents a button, which reacts when clicking on it.
/// Create a component that represents a button, which reacts when clicking on it.
/// </summary>
public static IUIButton Button()
{
return Button(null);
}

/// <summary>
/// Create component that represents a button, which reacts when clicking on it.
/// Create a component that represents a button, which reacts when clicking on it.
/// </summary>
/// <param name="id">An optional unique identifier for this UI element.</param>
public static IUIButton Button(string? id)
Expand All @@ -66,7 +66,7 @@ public static IUIButton Button(string? id)
}

/// <summary>
/// Create component that represents a button, which reacts when clicking on it.
/// Create a component that represents a button, which reacts when clicking on it.
/// </summary>
/// <param name="id">An optional unique identifier for this UI element.</param>
/// <param name="text">The text to display in the button.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static IUIMultilineLineTextInput MultilineTextInput(string? id, string pr
/// <summary>
/// Sets the list of spans to highlight in the text document.
/// </summary>
public static IUIMultilineLineTextInput Hihglight(this IUIMultilineLineTextInput element, params TextSpan[] spans)
public static IUIMultilineLineTextInput Highlight(this IUIMultilineLineTextInput element, params TextSpan[] spans)
{
((UIMultilineTextInput)element).HighlightedSpans = spans;
return element;
Expand Down
4 changes: 1 addition & 3 deletions src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace DevToys.Api;
namespace DevToys.Api;

/// <summary>
/// A component that represents a setting, with a title, description, icon and <see cref="IUIElement"/> for the option value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static IUISinglelineTextInput SinglelineTextInput(string? id)
/// <summary>
/// Sets the text input control as read-only.
/// </summary>
public static T ReadOnly<T>(this T element) where T : IUITitledElement
public static T ReadOnly<T>(this T element) where T : IUISinglelineTextInput
{
if (element is UISinglelineTextInput strongElement)
{
Expand All @@ -154,7 +154,7 @@ public static T ReadOnly<T>(this T element) where T : IUITitledElement
/// <summary>
/// Sets the text input control as editable.
/// </summary>
public static T Editable<T>(this T element) where T : IUITitledElement
public static T Editable<T>(this T element) where T : IUISinglelineTextInput
{
if (element is UISinglelineTextInput strongElement)
{
Expand All @@ -166,7 +166,7 @@ public static T Editable<T>(this T element) where T : IUITitledElement
/// <summary>
/// Shows the "copy" button when the editor is editable.
/// </summary>
public static T CanCopyWhenEditable<T>(this T element) where T : IUITitledElement
public static T CanCopyWhenEditable<T>(this T element) where T : IUISinglelineTextInput
{
if (element is UISinglelineTextInput strongElement)
{
Expand All @@ -178,7 +178,7 @@ public static T CanCopyWhenEditable<T>(this T element) where T : IUITitledElemen
/// <summary>
/// Hides the "copy" button when the editor is editable.
/// </summary>
public static T CannotCopyWhenEditable<T>(this T element) where T : IUITitledElement
public static T CannotCopyWhenEditable<T>(this T element) where T : IUISinglelineTextInput
{
if (element is UISinglelineTextInput strongElement)
{
Expand All @@ -190,7 +190,7 @@ public static T CannotCopyWhenEditable<T>(this T element) where T : IUITitledEle
/// <summary>
/// Sets the unformatted text of the control.
/// </summary>
public static T Text<T>(this T element, string text) where T : IUITitledElement
public static T Text<T>(this T element, string text) where T : IUISinglelineTextInput
{
if (element is UISinglelineTextInput strongElement)
{
Expand All @@ -202,7 +202,7 @@ public static T Text<T>(this T element, string text) where T : IUITitledElement
/// <summary>
/// Selects the given span in the text document.
/// </summary>
public static T Select<T>(this T element, TextSpan span) where T : IUITitledElement
public static T Select<T>(this T element, TextSpan span) where T : IUISinglelineTextInput
{
if (element is UISinglelineTextInput strongElement)
{
Expand All @@ -214,7 +214,7 @@ public static T Select<T>(this T element, TextSpan span) where T : IUITitledElem
/// <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
public static T Select<T>(this T element, int start, int length) where T : IUISinglelineTextInput
{
if (element is UISinglelineTextInput strongElement)
{
Expand Down
Loading

0 comments on commit 41a4874

Please sign in to comment.