Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A lot of improvements #14

Merged
merged 13 commits into from
Nov 13, 2023
Merged
1 change: 1 addition & 0 deletions src/ChatPrisma/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ResourceDictionary Source="/Themes/ContextMenuStyles.xaml" />
<ResourceDictionary Source="/Themes/ButtonStyles.xaml" />
<ResourceDictionary Source="/Themes/TextBoxStyles.xaml" />
<ResourceDictionary Source="/Themes/ScrollBarStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
1 change: 1 addition & 0 deletions src/ChatPrisma/Options/TextEnhancementOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public class TextEnhancementOptions
{
public int TextSize { get; set; }
public string? CustomInstructions { get; set; }
}
31 changes: 20 additions & 11 deletions src/ChatPrisma/Services/ChatBot/ChatPrompts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ namespace ChatPrisma.Services.ChatBot;

public static class ChatPrompts
{
public static string System(string text) => $"""
You are "Chat Prisma," an expert assistant focused on elevating the quality of written content.
Your task is to rigorously fine-tune the user's text according to their precise specifications.
Respond exclusively with the improved text, omitting any additional commentary.
Collaborate with the user in iterative cycles until the text meets their satisfaction.
Always build upon the most recent version of the text, rather than reverting to the original.

The current iteration of the text is as follows:
{text}
""";
}
public static string System(string? customInstructions)
{
customInstructions = string.IsNullOrWhiteSpace(customInstructions)
? null
: customInstructions;

return $"""
You are "Chat Prisma," an expert assistant focused on helping users improve their written text.
Your task is to fine-tune the user's text according to their precise specifications.
Respond exclusively with the improved text, omitting any additional commentary.
Collaborate with the user in iterative cycles until the user is satisfied.
Always build upon the most recent version of the text, rather than reverting to the original.

Also consider the following instructions from the user:
{customInstructions ?? "None"}

The current iteration of the text is in the next message.
""";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static bool AnyKeyPressed()
var task = Task.Delay(TimeSpan.FromMilliseconds(hotkeyOptions.CurrentValue.ClipboardDelayInMilliseconds));
var watch = Stopwatch.StartNew();

// Either wait until the task is completed or the user releases all keys
// Either wait until the task is completed or we got some text in the clipboard
while (task.IsCompleted is false)
{
var dataObject = Clipboard.GetDataObject();
Expand Down
19 changes: 12 additions & 7 deletions src/ChatPrisma/Themes/ButtonStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@

<Style TargetType="Button">
<Setter Property="Foreground" Value="White" />
<Setter Property="Height" Value="30" />
<Setter Property="Padding" Value="5, 6, 5, 6" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" CornerRadius="6" BorderBrush="#4D4D4D" BorderThickness="1">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1.5">
<GradientStop Color="#802F66" Offset="0.0"/>
<GradientStop Color="#26234D" Offset="1.0"/>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#333333" Offset="0.0"/>
<GradientStop Color="#262626" Offset="1.0"/>
</LinearGradientBrush>
</Border.Background>
<Grid>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="{TemplateBinding Padding}" />

<Border Name="PressedOverlay" CornerRadius="6" Visibility="Hidden">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1" Opacity="1">
Expand All @@ -23,21 +27,22 @@
</LinearGradientBrush>
</Border.Background>
</Border>

<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush">
<Setter.Value>
<SolidColorBrush Color="#99FFFFFF" />
<SolidColorBrush Color="#60FFFFFF" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="PressedOverlay" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="PressedOverlay" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Globalization;
using System.Windows.Data;

namespace ChatPrisma.Themes.Converters;

public class NumberWidthPlaceholderTextConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not int intValue)
return string.Empty;

// Use character "4" as a placeholder, because it seems to be even wider than 0
return new string('4', intValue.ToString().Length);
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
36 changes: 22 additions & 14 deletions src/ChatPrisma/Themes/GroupBoxStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<wpf:SymbolIcon Symbol="{Binding RelativeSource={RelativeSource AncestorType=GroupBox}, Path=(themes:Attached.Icon)}"
FontSize="24"
Margin="-3, -4, 5, -4" />
<TextBlock Text="{Binding}" />
</StackPanel>
<TextBlock Text="{Binding}" />
</DataTemplate>
</Setter.Value>
</Setter>
Expand Down Expand Up @@ -77,14 +72,27 @@
</Border>

<!-- Header -->
<ContentPresenter Grid.Row="0"
Margin="10, 7, 10, 7"
Visibility="{DXBinding '@p.Header != null ? $Visibility.Visible : $Visibility.Collapsed'}"
TextBlock.FontSize="16"
TextBlock.FontWeight="SemiBold"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}" />
<Grid Grid.Row="0"
Margin="10, 7, 10, 7"
HorizontalAlignment="Stretch"
Visibility="{DXBinding '@p.Header != null ? $Visibility.Visible : $Visibility.Collapsed'}"
TextBlock.FontSize="16"
TextBlock.FontWeight="SemiBold">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<wpf:SymbolIcon Grid.Column="0"
Symbol="{Binding RelativeSource={RelativeSource AncestorType=GroupBox}, Path=(themes:Attached.Icon)}"
FontSize="24"
Margin="-3, -4, 5, -4" />

<ContentPresenter Grid.Column="1"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}" />
</Grid>

<!-- Animated Header Line -->
<Border x:Name="InnerBorder"
Expand Down
38 changes: 38 additions & 0 deletions src/ChatPrisma/Themes/ScrollBarStyles.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0, 0" EndPoint="0, 1">
<GradientStop Color="LightGray" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Width="6"
CornerRadius="3"
Background="{TemplateBinding Background}"
Opacity="0.7" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ScrollBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Grid>
<Track Name="PART_Track" IsDirectionReversed="True" HorizontalAlignment="Right">
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" />
</Track.Thumb>
</Track>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
49 changes: 49 additions & 0 deletions src/ChatPrisma/Themes/Stepper.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<UserControl x:Class="ChatPrisma.Themes.Stepper"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ChatPrisma.Themes"
xmlns:converters="clr-namespace:ChatPrisma.Themes.Converters"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<UserControl.Resources>
<converters:NumberWidthPlaceholderTextConverter x:Key="WidthPlaceholderTextConverter" />
</UserControl.Resources>

<GroupBox VerticalAlignment="Stretch">
<StackPanel Orientation="Horizontal" Margin="-8, -6, -8, -8"> <!-- Sneak closely up to the GroupBox border -->
<Button Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:Stepper}}, Path=PreviousCommand}"
Content="-"
Width="20"
VerticalAlignment="Stretch">
<Button.Padding>0, -4, 0, 0</Button.Padding> <!-- Fix placement of the content -->
</Button>

<Grid>
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:Stepper}}, Path=Value, Mode=OneWay}"
Margin="8, 0, 8, 0"
HorizontalAlignment="Center"
VerticalAlignment="Center" />

<!--
This hidden textblock makes sure we have a consistent width of the stepper for values with 1 digit, 2 digits etc
If we don't have this, then the width changes between values "1" and "2", and that looks ugly
-->
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:Stepper}}, Path=Value, Converter={StaticResource WidthPlaceholderTextConverter}, Mode=OneWay}"
Margin="8, 0, 8, 0"
HorizontalAlignment="Center"
VerticalAlignment="Center"

Visibility="Hidden"/>
</Grid>

<Button Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:Stepper}}, Path=NextCommand}"
Content="+"
Width="20"
VerticalAlignment="Stretch">
<Button.Padding>0, -4, 0, 0</Button.Padding> <!-- Fix placement of the content -->
</Button>
</StackPanel>
</GroupBox>
</UserControl>
41 changes: 41 additions & 0 deletions src/ChatPrisma/Themes/Stepper.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Windows;
using System.Windows.Input;

namespace ChatPrisma.Themes;

public partial class Stepper
{
public Stepper()
{
this.InitializeComponent();
}

public static readonly DependencyProperty PreviousCommandProperty = DependencyProperty.Register(
nameof(PreviousCommand), typeof(ICommand), typeof(Stepper), new PropertyMetadata(default(ICommand)));

public ICommand PreviousCommand
{
get { return (ICommand)GetValue(PreviousCommandProperty); }
set { SetValue(PreviousCommandProperty, value); }
}

public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
nameof(Value), typeof(int), typeof(Stepper), new PropertyMetadata(default(int)));

#pragma warning disable CA1721
public int Value
{
get { return (int)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
#pragma warning restore CA1721

public static readonly DependencyProperty NextCommandProperty = DependencyProperty.Register(
nameof(NextCommand), typeof(ICommand), typeof(Stepper), new PropertyMetadata(default(ICommand)));

public ICommand NextCommand
{
get { return (ICommand)GetValue(NextCommandProperty); }
set { SetValue(NextCommandProperty, value); }
}
}
1 change: 1 addition & 0 deletions src/ChatPrisma/Themes/WindowStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@

<Button Grid.Column="2"
Width="40"
Height="32"
Click="CloseButton_Click"
WindowChrome.IsHitTestVisibleInChrome="True">
<Button.Template>
Expand Down
46 changes: 42 additions & 4 deletions src/ChatPrisma/Views/TextEnhancement/TextEnhancementView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,63 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<GroupBox Grid.Row="0" Header="Text" themes:Attached.Icon="TextEditStyle">
<ScrollViewer VerticalScrollBarVisibility="Auto" x:Name="TextScrollViewer">
<emoji:TextBlock x:Name="TextTextBlock"
<GroupBox Grid.Row="0" Header="{Binding}" themes:Attached.Icon="TextEditStyle">
<GroupBox.HeaderTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="Text" />

<Grid IsEnabled="{DXBinding '!ApplyInstructionCommand.IsRunning'}"
HorizontalAlignment="Right">
<themes:Stepper Height="24"
Margin="0, -2"
PreviousCommand="{Binding PreviousVersionCommand}"
Value="{Binding CurrentVersion}"
NextCommand="{Binding NextVersionCommand}">
<themes:Stepper.ToolTip>
<TextBlock>
<Run Text="Die Version des aktuell angezeigten Textes." />
<LineBreak /><LineBreak />
<Bold>Vorherige Version:</Bold><LineBreak />
<Run Text="ALT+Links" />
<LineBreak /><LineBreak />
<Bold>Nächste Version:</Bold><LineBreak />
<Run Text="ALT+Rechts" />
</TextBlock>
</themes:Stepper.ToolTip>
</themes:Stepper>
</Grid>
</Grid>
</DataTemplate>
</GroupBox.HeaderTemplate>
<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"/>
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>
</ScrollViewer>
</GroupBox>

<GroupBox Grid.Row="1" Header="Änderungen" themes:Attached.Icon="InkingTool">
<Grid>
<TextBox x:Name="InstructionTextBox"
themes:Attached.Placeholder="Anweisung"
IsReadOnly="{Binding ApplyInstructionCommand.IsRunning}"
Text="{Binding Instruction, UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding ApplyInstructionCommand}" />
<KeyBinding Key="Enter" Modifiers="Control" Command="{Binding AcceptTextCommand}" />
<KeyBinding Key="Escape" Command="{Binding ApplyInstructionCancelCommand}" />

<KeyBinding Key="Left" Modifiers="Alt" Command="{Binding PreviousVersionCommand}" />
<KeyBinding Key="Right" Modifiers="Alt" Command="{Binding NextVersionCommand}" />
</TextBox.InputBindings>
</TextBox>
</Grid>
Expand Down
Loading