Skip to content

A Swiss Army knife for developers.

Added the possibility to hide the whole command bar of a text input. (#999)

Etienne BAUDOUX35d99a26fadf
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 52ddc868d..fb747c3c6 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISinglelineTextInput.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISinglelineTextInput.cs
@@ -25,6 +25,14 @@ public interface IUISingleLineTextInput : IUITitledElementWithChildren
/// </summary>
IUIElement? CommandBarExtraContent { get; }
+ /// <summary>
+ /// Gets whether the command bar should be hidden. Default is false.
+ /// </summary>
+ /// <remarks>
+ /// When true, <see cref="CommandBarExtraContent"/> is ignored.
+ /// </remarks>
+ bool HideCommandBar { get; }
+
/// <summary>
/// Raised when <see cref="IsReadOnly"/> is changed.
/// </summary>
@@ -44,6 +52,11 @@ public interface IUISingleLineTextInput : IUITitledElementWithChildren
/// Raised when <see cref="CommandBarExtraContent"/> is changed.
/// </summary>
event EventHandler? CommandBarExtraContentChanged;
+
+ /// <summary>
+ /// Raised when <see cref="HideCommandBar"/> is changed.
+ /// </summary>
+ event EventHandler? HideCommandBarChanged;
}
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")]
@@ -52,6 +65,7 @@ internal class UISingleLineTextInput : UITitledElementWithChildren, IUISingleLin
private string? _text;
private bool _isReadOnly;
private bool _canCopyWhenEditable;
+ private bool _hideCommandBar;
private IUIElement? _commandBarExtraContent;
internal UISingleLineTextInput(string? id)
@@ -97,12 +111,19 @@ internal class UISingleLineTextInput : UITitledElementWithChildren, IUISingleLin
internal set => SetPropertyValue(ref _commandBarExtraContent, value, CommandBarExtraContentChanged);
}
+ public bool HideCommandBar
+ {
+ get => _hideCommandBar;
+ internal set => SetPropertyValue(ref _hideCommandBar, value, HideCommandBarChanged);
+ }
+
internal Func<string, ValueTask>? ActionOnTextChanged { get; set; }
public event EventHandler? TextChanged;
public event EventHandler? IsReadOnlyChanged;
public event EventHandler? CanCopyWhenEditableChanged;
public event EventHandler? CommandBarExtraContentChanged;
+ public event EventHandler? HideCommandBarChanged;
}
public static partial class GUI
@@ -172,6 +193,31 @@ public static partial class GUI
return element;
}
+ /// <summary>
+ /// Hides the command bar on top of the editor.
+ /// This will also hide the <see cref="IUISingleLineTextInput.CommandBarExtraContent"/>.
+ /// </summary>
+ public static T HideCommandBar<T>(this T element) where T : IUISingleLineTextInput
+ {
+ if (element is UISingleLineTextInput strongElement)
+ {
+ strongElement.HideCommandBar = true;
+ }
+ return element;
+ }
+
+ /// <summary>
+ /// Shows the command bar on top of the editor.
+ /// </summary>
+ public static T ShowCommandBar<T>(this T element) where T : IUISingleLineTextInput
+ {
+ if (element is UISingleLineTextInput strongElement)
+ {
+ strongElement.HideCommandBar = false;
+ }
+ return element;
+ }
+
/// <summary>
/// Sets the unformatted text of the control.
/// </summary>
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UITextInputWrapper.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UITextInputWrapper.razor
index 677106599..d1eac0d8b 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UITextInputWrapper.razor
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UITextInputWrapper.razor
@@ -9,7 +9,7 @@
IsEnabled="@UITextInput.IsEnabled"
HorizontalAlignment="@(_isInFullScreenMode ? UIHorizontalAlignment.Stretch : UITextInput.HorizontalAlignment)"
VerticalAlignment="@(_isInFullScreenMode ? UIVerticalAlignment.Stretch : UITextInput.VerticalAlignment)"
- RowSpacing="6"
+ RowSpacing="@(string.IsNullOrEmpty(UITextInput.Title) && UITextInput.HideCommandBar ? 0 : 6)"
Rows="@(new List<UIGridLength>
{
UIGridLength.Auto,
@@ -22,7 +22,8 @@
UIGridLength.Auto
})">
<GridCell Row="0" Column="0">
- <Grid RowSpacing="0"
+ <Grid IsVisible="@(!string.IsNullOrEmpty(UITextInput.Title))"
+ RowSpacing="0"
Rows="@(new List<UIGridLength>
{
new UIGridLength(1, UIGridUnitType.Fraction),
@@ -38,7 +39,9 @@
</GridCell>
<GridCell Row="0"
Column="1">
- <StackPanel IsEnabled="@(!IsLoadingFile)" Wrap="false">
+ <StackPanel IsEnabled="@(!IsLoadingFile)"
+ IsVisible="@(!UITextInput.HideCommandBar)"
+ Wrap="false">
@if (UITextInput.CommandBarExtraContent is not null)
{
<UIElementPresenter UIElement="@UITextInput.CommandBarExtraContent" />
diff --git a/src/app/dev/DevToys.Blazor/Pages/SubPages/TestPage.razor b/src/app/dev/DevToys.Blazor/Pages/SubPages/TestPage.razor
deleted file mode 100644
index 6d4945289..000000000
--- a/src/app/dev/DevToys.Blazor/Pages/SubPages/TestPage.razor
+++ /dev/null
@@ -1,137 +0,0 @@
-<h3>TestPage</h3>
-
-<CascadingValue Value="this" IsFixed="true">
- @*<ScrollViewer>
- <StackPanel Class="entrance-theme-transition"
- Orientation="UIOrientation.Vertical"
- PaddingLeft="16"
- PaddingBottom="16"
- PaddingRight="16"
- PaddingTop="16">
- <Grid ColumnSpacing="12"
- RowSpacing="12"
- Columns="@(new List<UIGridLength>
- {
- UIGridLength.Auto,
- new UIGridLength(1, UIGridUnitType.Fraction),
- new UIGridLength(250)
- })">
-
- <GridCell Column="0">
- <StackPanel Orientation="UIOrientation.Vertical">
- <ProgressRing IsIndeterminate="true" />
- <ProgressRing Value="75" Size="32" />
- <CheckBox IsChecked="true" Text="An option" />
- <CheckBox IsChecked="true" IsEnabled="false" Text="An option" />
- <CheckBox IsChecked="false" IsEnabled="false" Text="An option" />
- <ToggleSwitch IsOn="true" Text="An option" />
- <ToggleSwitch IsOn="true" IsEnabled="false" Text="An option" />
- <ToggleSwitch IsOn="false" IsEnabled="false" Text="An option" />
- <StackPanel>
- <RadioButton Text="Option 1" Group="Group1" />
- <RadioButton Text="Option 2" Group="Group1" />
- <RadioButton Text="Option 3" Group="Group1" />
- <RadioButton Text="Option 4" Group="Group1" IsEnabled="false" />
- </StackPanel>
- </StackPanel>
- </GridCell>
-
- <GridCell Column="1" ColumnSpan="2">
- <SplitGrid>
- <LeftOrTopCellContent>
- <StackPanel Orientation="UIOrientation.Vertical">
- <TextBlock Appearance="TextBlockAppearance.TitleLarge" Text="Test" />
- <MonacoEditor />
- <Button VerticalAlignment="UIVerticalAlignment.Center" IsEnabled="true">Set favorite</Button>
- <Button HorizontalAlignment="UIHorizontalAlignment.Left" IsEnabled="false">Set favorite</Button>
- <Button HorizontalAlignment="UIHorizontalAlignment.Center" IsEnabled="true" Appearance="ButtonAppearance.Accent">Set favorite</Button>
- <Button HorizontalAlignment="UIHorizontalAlignment.Right" Height="100" Width="200" IsEnabled="false" Appearance="ButtonAppearance.Accent">Set favorite</Button>
- <Button IsEnabled="true" Appearance="ButtonAppearance.Stealth">Set favorite</Button>
- <Button VerticalAlignment="UIVerticalAlignment.Bottom" IsEnabled="false" Appearance="ButtonAppearance.Stealth">Set favorite</Button>
- <TextBox Header="First name" Placeholder="Normal" Style="margin-top: 12px; margin-left: 8px; margin-right: 8px;" />
- <TextBox Header="Middle name" Placeholder="Read only" IsReadOnly="true" Style="margin-top: 12px; margin-left: 8px; margin-right: 8px;" />
- <TextBox Header="Last name" Placeholder="Disabled" IsEnabled="false" Style="margin-top: 12px; margin-left: 8px; margin-right: 8px;" />
- <TextBox Header="Number input" Type="TextBoxTypes.Number" Style="margin-top: 12px; margin-left: 8px; margin-right: 8px;" />
- <TextBox Header="Password input" Type="TextBoxTypes.Password" Style="margin-top: 12px; margin-left: 8px; margin-right: 8px;" />
- <ProgressBar IsIndeterminate="true" Width="150" HorizontalAlignment="UIHorizontalAlignment.Left" />
- <ProgressBar Value="75" />
- </StackPanel>
- </LeftOrTopCellContent>
- <RightOrBottomCellContent>
- <StackPanel Orientation="UIOrientation.Vertical">
- <DropDownButton Header="Drop down list header"
- Items="@(new List<DropDownListItem>
- {
- new DropDownListItem { Text = "Item 1", IconGlyph = '\uE670' },
- new DropDownListItem { Text = "Item 2" },
- new DropDownListItem { Text = "Item 3" },
- new DropDownListItem { Text = "Item 4" },
- new DropDownListItem { Text = "Item 5" },
- new DropDownListItem { Text = "Item 6" },
- new DropDownListItem { Text = "Item 7" },
- new DropDownListItem { Text = "Item 8" },
- new DropDownListItem { Text = "Item 9" },
- new DropDownListItem { Text = "Item 10" },
- new DropDownListItem { Text = "Item 11" },
- new DropDownListItem { Text = "Item 12" },
- new DropDownListItem { Text = "Item 13" },
- new DropDownListItem { Text = "Item 14" },
- new DropDownListItem { Text = "Item 15 - longer text" }
- })">
- <TextBlock Appearance="TextBlockAppearance.Body" Text="Click me!" />
- </DropDownButton>
- <ComboBox Items="@(new List<string>
- {
- "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10",
- "Item 11", "Item 12", "Item 13", "Item 14", "Item 15", "Item 16 - longer text"
- })"
- Context="item"
- @bind-SelectedIndex="@ComboBoxSelectedItem"
- Header="ComboBox header"
- HorizontalAlignment="HorizontalAlignment.Left">
- <ItemTemplate>
- @item
- </ItemTemplate>
- </ComboBox>
- <ListBox Items="@(new List<string>
- {
- "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10",
- "Item 11", "Item 12", "Item 13", "Item 14", "Item 15", "Item 16 - longer text"
- })"
- Context="item"
- SelectedIndex="1">
- <ItemTemplate>
- @item
- </ItemTemplate>
- </ListBox>
- </StackPanel>
- </RightOrBottomCellContent>
- </SplitGrid>
- </GridCell>
- </Grid>
- <InfoBar IsOpen="true" IsClosable="false" Title="Title" Message="Message" />
- <InfoBar IsOpen="true" IsIconVisible="false" Title="Title" Message="Message" />
- <InfoBar IsOpen="true" ActionButtonText="Action" Title="Title" Message="Message" />
- <InfoBar IsOpen="true" ActionButtonText="Action" IsActionButtonAccent="true" Title="Title" Message="Message" />
- <InfoBar IsOpen="true" Title="Title" Message="Message" Severity="InfoBarSeverity.Success" />
- <InfoBar IsOpen="true" Title="Title" Message="Message" Severity="InfoBarSeverity.Warning" />
- <InfoBar IsOpen="true" Title="Title" Message="Message" Severity="InfoBarSeverity.Error" />
- <InfoBar IsOpen="true" ActionButtonText="Action" Title="Title" Message="Sanctus gubergren dolore molestie rebum minim molestie et aliquyam lorem ea. Nulla feugiat dolor elitr kasd vero vero lorem imperdiet stet dolor mazim accusam. Sanctus elit ex possim sit rebum stet dolores. Ipsum eos duis sed accusam et takimata kasd sea diam." />
- <Card Title="Card Title" />
- <Card Title="Card Title" Description="Card Description" />
- <Expander IconGlyph="@('\uEE7A')" Title="Card Title" Description="Card Description">
- <Control>
- <ToggleSwitch IsOn="false" Text="An option" />
- </Control>
- <ChildContent>
- <TextBlock Appearance="@TextBlockAppearance.Display" Text="This text is scaled." />
- </ChildContent>
- </Expander>
- <Card IconGlyph="@('\uEE7A')" Title="Card Title" Description="Lorem kasd dolore vero vulputate rebum sit et vel amet consetetur. Est et velit no consetetur diam et. Eos magna duo amet eu ea clita. Volutpat nulla diam exerci erat labore.">
- <Control>
- <ToggleSwitch IsOn="false" Text="An option" />
- </Control>
- </Card>
- </StackPanel>
- </ScrollViewer>*@
-</CascadingValue>
\ No newline at end of file