c# project conversion

This commit is contained in:
grimsace
2026-06-08 10:39:11 -05:00
parent 00c32d5cbe
commit 22c2ef78fd
16 changed files with 750 additions and 499 deletions
+83
View File
@@ -0,0 +1,83 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Finder2eFoundryConverterCS.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="600"
x:Class="Finder2eFoundryConverterCS.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="Finder2e Foundry Converter"
Width="500" Height="600"
DragDrop.AllowDrop="True">
<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext at runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainWindowViewModel/>
</Design.DataContext>
<ScrollViewer>
<StackPanel Margin="20" Spacing="10">
<Label Content="Provider:"/>
<Grid ColumnDefinitions="*,Auto">
<ComboBox Grid.Column="0" HorizontalAlignment="Stretch"
ItemsSource="{Binding Providers}"
SelectedItem="{Binding SelectedProvider}"/>
<Button Grid.Column="1" Content="Address" Command="{Binding ToggleAddressCommand}" Margin="5,0,0,0"/>
</Grid>
<TextBlock Text="{Binding ErrorText}" Foreground="Red" HorizontalAlignment="Center" IsVisible="{Binding IsErrorVisible}"/>
<StackPanel IsVisible="{Binding IsAddressVisible}" Spacing="5">
<Label Content="LM Studio Address:"/>
<TextBox Text="{Binding LmStudioAddress}" PlaceholderText="http://localhost:1234"/>
</StackPanel>
<Label Content="Model:"/>
<Grid ColumnDefinitions="*,Auto">
<ComboBox Grid.Column="0" HorizontalAlignment="Stretch"
ItemsSource="{Binding Models}"
SelectedItem="{Binding SelectedModel}"
PlaceholderText="Select Model"/>
<Button Grid.Column="1" Content="Refresh" Command="{Binding RefreshModelsCommand}" Margin="5,0,0,0"/>
</Grid>
<Label Content="Description:"/>
<TextBox Text="{Binding Description}" AcceptsReturn="True" Height="100" PlaceholderText="Enter description here..."/>
<Label Content="Images:"/>
<ScrollViewer Height="180">
<ItemsControl ItemsSource="{Binding ImageItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="5">
<Border BorderBrush="Gray" BorderThickness="1" CornerRadius="4" ClipToBounds="True">
<Image Source="{Binding Thumbnail}" Width="100" Height="100" Stretch="UniformToFill" />
</Border>
<Button Content="X"
Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).RemoveImageCommand}"
CommandParameter="{Binding}"
HorizontalAlignment="Right" VerticalAlignment="Top"
Background="#80000000" Foreground="White" Padding="5,2"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<Button Content="Select Image" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Click="SelectImage_Click"/>
<Button Content="Generate" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center"
Command="{Binding GenerateCommand}" FontWeight="Bold"/>
<TextBlock Text="{Binding StatusMessage}" TextWrapping="Wrap" Margin="0,10,0,0"/>
</StackPanel>
</ScrollViewer>
</Window>
+134
View File
@@ -0,0 +1,134 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using Finder2eFoundryConverterCS.ViewModels;
namespace Finder2eFoundryConverterCS.Views
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
AddHandler(DragDrop.DropEvent, Drop);
KeyDown += OnKeyDown;
}
private async void OnKeyDown(object? sender, KeyEventArgs e)
{
if (e.Key == Key.V && e.KeyModifiers == KeyModifiers.Control)
{
var topLevel = GetTopLevel(this);
if (topLevel?.Clipboard == null) return;
var vm = DataContext as MainWindowViewModel;
if (vm == null) return;
// Try to get text (for file paths)
var text = await topLevel.Clipboard.TryGetTextAsync();
if (!string.IsNullOrWhiteSpace(text))
{
var path = text.Replace("file://", "").Trim();
if (System.IO.File.Exists(path))
{
var ext = System.IO.Path.GetExtension(path).ToLower();
if (new[] { ".png", ".jpg", ".jpeg", ".webp" }.Contains(ext))
{
vm.AddImagePathCommand.Execute(path);
return;
}
}
}
// Try to get bitmap directly
var bitmap = await topLevel.Clipboard.TryGetBitmapAsync();
if (bitmap != null)
{
// Save bitmap to temp file
var tempDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Finder2eFoundryConverter");
if (!System.IO.Directory.Exists(tempDir)) System.IO.Directory.CreateDirectory(tempDir);
var tempPath = System.IO.Path.Combine(tempDir, $"pasted_image_{DateTime.Now.Ticks}.png");
bitmap.Save(tempPath);
vm.AddImagePathCommand.Execute(tempPath);
}
}
}
private async void SelectImage_Click(object? sender, RoutedEventArgs e)
{
var topLevel = GetTopLevel(this);
if (topLevel == null) return;
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Select Images",
AllowMultiple = true,
FileTypeFilter = new[]
{
new FilePickerFileType("Images")
{
Patterns = new[] { "*.png", "*.jpg", "*.jpeg", "*.webp" }
}
}
});
if (files.Count > 0)
{
var vm = DataContext as MainWindowViewModel;
if (vm == null) return;
foreach (var file in files)
{
vm.AddImagePathCommand.Execute(file.Path.LocalPath);
}
}
}
private async void Drop(object? sender, DragEventArgs e)
{
var files = e.DataTransfer.TryGetFiles();
if (files != null)
{
var vm = DataContext as MainWindowViewModel;
if (vm == null) return;
foreach (var file in files)
{
var path = file.Path.LocalPath;
if (path == null) continue;
var ext = System.IO.Path.GetExtension(path).ToLower();
if (new[] { ".png", ".jpg", ".jpeg", ".webp" }.Contains(ext))
{
vm.AddImagePathCommand.Execute(path);
}
}
}
// Try to get bitmap directly from drop
var bitmap = e.DataTransfer.TryGetBitmap();
if (bitmap != null)
{
var vm = DataContext as MainWindowViewModel;
if (vm != null)
{
var tempDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Finder2eFoundryConverter");
if (!System.IO.Directory.Exists(tempDir)) System.IO.Directory.CreateDirectory(tempDir);
var tempPath = System.IO.Path.Combine(tempDir, $"dropped_image_{DateTime.Now.Ticks}.png");
bitmap.Save(tempPath);
vm.AddImagePathCommand.Execute(tempPath);
}
}
}
}
}