Skip to content

Commit

Permalink
adding CustomEditor control, removing plainer package reference
Browse files Browse the repository at this point in the history
  • Loading branch information
BeepBeepBopBop committed Nov 22, 2024
1 parent 0a67446 commit 5348a24
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 33 deletions.
5 changes: 5 additions & 0 deletions LM-Kit-Maestro/Controls/CustomEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace LMKitMaestro.Controls;

class CustomEditor : Editor
{
}
27 changes: 13 additions & 14 deletions LM-Kit-Maestro/Controls/CustomEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
using Windows.System;
#endif

namespace LMKitMaestro.Controls
namespace LMKitMaestro.Controls;

class CustomEntry : Entry
{
class CustomEntry : Entry
protected override void OnHandlerChanged()
{
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
base.OnHandlerChanged();

#if WINDOWS
TextBox textBox = (TextBox)Handler!.PlatformView!;
TextBox textBox = (TextBox)Handler!.PlatformView!;

textBox.KeyDown += OnKeyDown;
textBox.KeyDown += OnKeyDown;
#endif
}
}

#if WINDOWS
private void OnKeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
private void OnKeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Enter)
{
if (e.Key == VirtualKey.Enter)
{
Unfocus();
}
Unfocus();
}
#endif
}
#endif
}
69 changes: 69 additions & 0 deletions LM-Kit-Maestro/Handlers/CustomEditorHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;

#if ANDROID
using Android.Graphics.Drawables;
using AndroidX.AppCompat.Widget;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
#endif

#if WINDOWS
using Microsoft.UI.Xaml.Controls;
#endif

namespace LMKitMaestro.Handlers;

public partial class CustomEditorHandler : EditorHandler
{
public CustomEditorHandler()
{
}

public CustomEditorHandler(IPropertyMapper mapper = null) : base(mapper)

Check warning on line 24 in LM-Kit-Maestro/Handlers/CustomEditorHandler.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
}
}

#if ANDROID
public partial class EditorViewHandler : EditorHandler
{
protected override AppCompatEditText CreatePlatformView()
{
var nativeView = base.CreatePlatformView();

using (var gradientDrawable = new GradientDrawable())
{
gradientDrawable.SetColor(global::Android.Graphics.Color.Transparent);
nativeView.SetBackground(gradientDrawable);
nativeView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
}

return nativeView;
}
}
#endif

#if IOS || MACCATALYST
public partial class EditorViewHandler : EditorHandler
{
/* No any custom implementation required
* Just keeping this handler to prevent build errors.
*/
}
#endif

#if WINDOWS
public partial class EditorViewHandler : EditorHandler
{
protected override TextBox CreatePlatformView()
{
var nativeView = base.CreatePlatformView();

nativeView.BorderThickness = new Microsoft.UI.Xaml.Thickness(0);
nativeView.Style = null;
return nativeView;
}
}
#endif
1 change: 1 addition & 0 deletions LM-Kit-Maestro/Handlers/MauiHandlerCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static class MauiHandlerCollectionExtensions
public static IMauiHandlersCollection AddCustomHandlers(this IMauiHandlersCollection handlers)
{
handlers.AddHandler(typeof(CustomEntry), typeof(CustomEntryHandler));
handlers.AddHandler(typeof(CustomEditor), typeof(CustomEditorHandler));
handlers.AddHandler(typeof(StatefulContentView), typeof(StatefulContentViewHandler));

return handlers;
Expand Down
1 change: 0 additions & 1 deletion LM-Kit-Maestro/LM-Kit-Maestro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="MetroLog.Maui" Version="2.1.0" />
<PackageReference Include="Mopups" Version="1.3.2" />
<PackageReference Include="Plainer.Maui" Version="1.7.1" />
<PackageReference Include="SimpleToolkit.Core" Version="5.1.2" />
<PackageReference Include="SimpleToolkit.SimpleShell" Version="4.1.3" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
Expand Down
2 changes: 0 additions & 2 deletions LM-Kit-Maestro/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using LMKitMaestro.ViewModels;
using LMKitMaestro.Services;
using LMKitMaestro.Data;
using Plainer.Maui;
using SimpleToolkit.SimpleShell;
using LMKitMaestro.Handlers;
using MetroLog.MicrosoftExtensions;
Expand Down Expand Up @@ -47,7 +46,6 @@ public static MauiApp CreateMauiApp()
.ConfigureMauiHandlers(handlers =>
{
handlers.AddCustomHandlers();
handlers.AddPlainer();
});

builder.Services.AddMauiBlazorWebView();
Expand Down
1 change: 0 additions & 1 deletion LM-Kit-Maestro/UI/ChatConversationsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:vm="clr-namespace:LMKitMaestro.ViewModels"
xmlns:controls="clr-namespace:LMKitMaestro.Controls"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:plainer="clr-namespace:Plainer.Maui.Controls;assembly=Plainer.Maui"
x:DataType="vm:ChatPageViewModel"
x:Class="LMKitMaestro.UI.ChatConversationsView"
x:Name="chatConversationsView"
Expand Down
19 changes: 9 additions & 10 deletions LM-Kit-Maestro/UI/ChatSettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
xmlns:vm="clr-namespace:LMKitMaestro.ViewModels"
xmlns:services="clr-namespace:LMKitMaestro.Services"
xmlns:controls="clr-namespace:LMKitMaestro.Controls"
xmlns:plainer="clr-namespace:Plainer.Maui.Controls;assembly=Plainer.Maui"
xmlns:local="clr-namespace:LMKitMaestro"
x:DataType="vm:SettingsViewModel"
x:Name="chatSettingsView"
Expand Down Expand Up @@ -188,13 +187,13 @@
<Grid StyleClass="SettingGrid">
<Label VerticalOptions="Center" Text="System prompt"/>
<Border
x:Name="systemPromptBorder"
StrokeThickness="0.25"
StrokeShape="RoundRectangle 4"
Padding="0, 8"
Grid.ColumnSpan="2"
Grid.Row="1"
HeightRequest="120">
x:Name="systemPromptBorder"
StrokeThickness="0.25"
StrokeShape="RoundRectangle 4"
Padding="0, 8"
Grid.ColumnSpan="2"
Grid.Row="1"
HeightRequest="120">
<Border.Triggers>
<DataTrigger TargetType="Border" Binding="{Binding Source={x:Reference systemPromptBorder}, Path=IsFocused}" Value="True">
<Setter Property="Stroke" Value="{StaticResource OnSurface}"/>
Expand All @@ -204,7 +203,7 @@
</DataTrigger>
</Border.Triggers>

<plainer:EditorView Unfocused="OnSystemPromptUnfocused" x:Name="systemPromptEditor" BackgroundColor="Transparent" Text="{Binding SystemPrompt, Mode=TwoWay}"/>
<controls:CustomEditor Unfocused="OnSystemPromptUnfocused" x:Name="systemPromptEditor" BackgroundColor="Transparent" Text="{Binding SystemPrompt, Mode=TwoWay}"/>
</Border>
</Grid>

Expand All @@ -224,7 +223,7 @@
</DataTrigger>
</Border.Triggers>

<plainer:EntryView
<controls:CustomEntry
x:Name="maxCompletionTokensEntry"
Unfocused="OnMaxCompletionTokensEntryUnfocused"
Text="{Binding Source={x:Reference chatSettingsView}, Path=MaxCompletionTokensText, Mode=TwoWay}"
Expand Down
1 change: 0 additions & 1 deletion LM-Kit-Maestro/UI/ChatView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
xmlns:controls="clr-namespace:LMKitMaestro.Controls"
xmlns:converters="clr-namespace:LMKitMaestro.Converters"
xmlns:services="clr-namespace:LMKitMaestro.Services"
xmlns:plainer="clr-namespace:Plainer.Maui.Controls;assembly=Plainer.Maui"
x:Class="LMKitMaestro.UI.ChatView"
x:DataType="vm:ConversationViewModel"
IsEnabled="{Binding ., Converter={mct:IsNotNullConverter}}"
Expand Down
1 change: 0 additions & 1 deletion LM-Kit-Maestro/UI/ConversationListItemView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
xmlns:models="clr-namespace:LMKitMaestro.Models"
xmlns:vm="clr-namespace:LMKitMaestro.ViewModels"
xmlns:controls="clr-namespace:LMKitMaestro.Controls"
xmlns:plainer="clr-namespace:Plainer.Maui.Controls;assembly=Plainer.Maui"
x:DataType="vm:ConversationViewModel"
ToolTipProperties.Text="{Binding Title}"
x:Class="LMKitMaestro.UI.ConversationListItemView"
Expand Down
3 changes: 1 addition & 2 deletions LM-Kit-Maestro/UI/Pages/ModelsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:local="clr-namespace:LMKitMaestro"
xmlns:models="clr-namespace:LMKitMaestro.Models"
xmlns:vm="clr-namespace:LMKitMaestro.ViewModels"
xmlns:plainer="clr-namespace:Plainer.Maui.Controls;assembly=Plainer.Maui"
xmlns:converters="clr-namespace:LMKitMaestro.Converters"
x:DataType="vm:ModelsPageViewModel"
x:Class="LMKitMaestro.UI.ModelsPage"
Expand Down Expand Up @@ -267,7 +266,7 @@
BackgroundColor="Transparent"
Stroke="{StaticResource Surface4}">

<plainer:EntryView VerticalOptions="End" IsReadOnly="True" Text="{Binding AppSettingsService.ModelsFolderPath}"/>
<controls:CustomEntry VerticalOptions="End" IsReadOnly="True" Text="{Binding AppSettingsService.ModelsFolderPath}"/>
</Border>

<Button
Expand Down
1 change: 0 additions & 1 deletion LM-Kit-Maestro/UI/Popups/ChatConversationActionPopup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:models="clr-namespace:LMKitMaestro.Models"
xmlns:vm="clr-namespace:LMKitMaestro.ViewModels"
xmlns:controls="clr-namespace:LMKitMaestro.Controls"
xmlns:plainer="clr-namespace:Plainer.Maui.Controls;assembly=Plainer.Maui"
x:DataType="vm:ChatConversationActionPopupViewModel"
x:Class="LMKitMaestro.UI.ChatConversationActionPopup">

Expand Down

0 comments on commit 5348a24

Please sign in to comment.