Skip to content

Commit

Permalink
Replace emoji:TextBlock with a default WPF textbox, so the user can s…
Browse files Browse the repository at this point in the history
…elect parts of the text and use it
  • Loading branch information
haefele committed Nov 21, 2023
1 parent f0129fd commit 59aa506
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/ChatPrisma/ChatPrisma.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.8" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="DevExpressMvvm" Version="22.1.3" />
<PackageReference Include="Emoji.Wpf" Version="0.3.4" />
<PackageReference Include="GlobalKeyInterceptor" Version="1.0.0" />
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0-rc.2.23479.6" />
Expand Down
43 changes: 43 additions & 0 deletions src/ChatPrisma/Themes/TextBoxStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,47 @@
</Setter.Value>
</Setter>
</Style>

<Style x:Key="EmptyTextBox" TargetType="TextBox">
<Setter Property="Foreground" Value="White"/>
<Setter Property="CaretBrush" Value="White"/>
<Setter Property="Margin" Value="6, 7, 6, 7" />
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Command="Cut">
<MenuItem.Icon>
<wpf:SymbolIcon Symbol="Cut" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="Copy">
<MenuItem.Icon>
<wpf:SymbolIcon Symbol="Copy" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="Paste">
<MenuItem.Icon>
<wpf:SymbolIcon Symbol="ClipboardPaste" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid Margin="{TemplateBinding Margin}">
<TextBlock Text="{Binding Path=(themes:Attached.Placeholder), RelativeSource={RelativeSource TemplatedParent}}"
Margin="2, 0, 0, 0"
Foreground="Gray"
Visibility="{DXBinding '@p.Text != null and @p.Text.Length > 0 ? $Visibility.Collapsed : $Visibility.Visible'}" />

<ScrollViewer x:Name="PART_ContentHost"
VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}"
HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
1 change: 0 additions & 1 deletion src/ChatPrisma/Views/OpenSource/OpenSourceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public partial class OpenSourceViewModel(IOptionsMonitor<ApplicationOptions> app
new ThirdPartyLibrary("GlobalKeyInterceptor", new("https://github.com/arcanexhoax/GlobalKeyInterceptor"), "MIT", new Uri("https://github.com/arcanexhoax/GlobalKeyInterceptor/blob/main/LICENSE")),
new ThirdPartyLibrary("NLog", new("https://nlog-project.org/"), "BSD 3-Clause", new Uri("https://github.com/NLog/NLog/blob/dev/LICENSE.txt")),
new ThirdPartyLibrary("Hardcodet WPF NotifyIcon", new("https://github.com/hardcodet/wpf-notifyicon"), "CPOL", new Uri("https://github.com/hardcodet/wpf-notifyicon/blob/develop/LICENSE")),
new ThirdPartyLibrary("Emoji.Wpf", new("https://github.com/samhocevar/emoji.wpf"), "WTFPL", new Uri("https://github.com/samhocevar/emoji.wpf/blob/main/COPYING")),
new ThirdPartyLibrary("DevExpress.Mvvm", new("https://github.com/DevExpress/DevExpress.Mvvm.Free"), "MIT", new Uri("https://github.com/DevExpress/DevExpress.Mvvm.Free/blob/main/LICENSE")),
new ThirdPartyLibrary("Nerdbank.GitVersioning", new("https://github.com/dotnet/Nerdbank.GitVersioning"), "MIT", new Uri("https://github.com/dotnet/Nerdbank.GitVersioning/blob/main/LICENSE")),
new ThirdPartyLibrary("SingleInstanceCore", new("https://github.com/soheilkd/SingleInstanceCore"), "MIT", new Uri("https://github.com/soheilkd/SingleInstanceCore/blob/master/LICENSE")),
Expand Down
21 changes: 11 additions & 10 deletions src/ChatPrisma/Views/TextEnhancement/TextEnhancementView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ChatPrisma.Views.TextEnhancement"
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
xmlns:themes="clr-namespace:ChatPrisma.Themes"
xmlns:wpf="clr-namespace:FluentIcons.WPF;assembly=FluentIcons.WPF"

Expand Down Expand Up @@ -77,15 +76,17 @@
<ScrollViewer x:Name="TextScrollViewer"
VerticalScrollBarVisibility="Auto"
Padding="0, -8, 0, -10"> <!-- Make the content stretch fully vertically inside the GroupBox (same values as GroupBox inner margin) -->
<emoji:TextBlock x:Name="TextTextBlock"
Text="{Binding CurrentText}"
FontSize="{Binding TextSize}"
TextWrapping="Wrap"
SizeChanged="TextTextBlock_OnSizeChanged">
<emoji:TextBlock.Margin>
<Thickness>0, 8, 0, 10</Thickness> <!-- Give it some inner margin back (same values as GroupBox inner margin) -->
</emoji:TextBlock.Margin>
</emoji:TextBlock>
<TextBox x:Name="TextTextBox"
Style="{StaticResource EmptyTextBox}"
Text="{Binding CurrentText}"
FontSize="{Binding TextSize}"
TextWrapping="Wrap"
IsReadOnly="True"
SizeChanged="TextTextBox_OnSizeChanged">
<TextBox.Margin>
<Thickness>0, 4, 0, 6</Thickness> <!-- Give it some inner margin back so it looks good -->
</TextBox.Margin>
</TextBox>
</ScrollViewer>
</GroupBox>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void ViewModelOnApplyInstructionCancelled(object? sender, EventArgs e)
this.InstructionTextBox.Select(this.InstructionTextBox.Text.Length, 0);
}

private void TextTextBlock_OnSizeChanged(object sender, SizeChangedEventArgs e)
private void TextTextBox_OnSizeChanged(object sender, SizeChangedEventArgs e)
{
// Keep the ScrollViewer scrolled to the bottom while the text is generating
this.ScrollToBottom();
Expand Down

0 comments on commit 59aa506

Please sign in to comment.