Compare commits

..

3 Commits

Author SHA1 Message Date
Ling 6d5b4a33b9 优化 UI 组件和提示信息格式
在 `MarkdownWpfRenderer.cs` 中,修改 `RenderHtmlBlock` 方法以支持 `<think>` 标签,返回包含进度条的 `Expander` 控件或直接返回文本块。更新 `PromptUtil.cs` 中的 `UsePrompt` 方法,增加当前时间和用户提问的 Excel 列信息格式。

在 `App.xaml` 中移除 `ThemeDictionary` 的 `ColorMode` 属性,简化主题定义。重构 `AiMessageControll.xaml` 的 UI,使用 `DockPanel` 和 `ButtonGroup`,并增加分隔线。

在 `ImportExcelPage.xaml` 中添加上下文菜单,调整 `TabControl` 和 `DataGrid` 属性以支持虚拟化,重构参数配置 UI,使用 `hc:Card` 和 `DockPanel` 结构。

在 `ImportExcelPage.xaml.cs` 中添加按钮点击事件处理程序以切换配置显示状态。在 `ImportViewModel.cs` 中更新 AI 消息处理逻辑,使用新提示格式,并添加 `_showConfig` 属性及其文档注释。
2025-03-05 23:14:54 +08:00
Ling 6d6935c84d 更新项目配置和重构代码逻辑
- 更新 .gitignore 文件以包含 Visual Studio 自动生成的内容。
- 在 launch.json 中添加 .NET Core 启动和附加配置。
- 在 tasks.json 中添加构建、发布和监视任务的配置。
- 修改 MarkdownWpfRenderer.cs 中表格列的遍历逻辑,使用更安全的列索引变量,并添加列对齐方式处理。
- 修改 Excel2Prompt.cs 中 ConverterToPrompt 方法的参数类型,更新列名处理逻辑。
- 重构 AiMessageControll.xaml.cs 中的发送命令逻辑,提取 InvokeSendCommand 方法以减少重复代码。
- 在 ImportViewModel.cs 中添加列名映射字典,更新 GenColumns 方法以使用该映射字典,改进 Excel 数据处理逻辑。
- 添加对 Excel 数据处理的逻辑,以支持使用列名映射。
- 移除不再需要的 GenColumns 方法的旧实现,并将扩展方法 ReplaceMultiple 移到类外部以提高可重用性。
2025-03-04 23:42:16 +08:00
Ling 67d7e93217 添加 CodeSpanControl 及相关功能改进
在 `CodeSpanControl.xaml` 中添加了用户控件,包含可选择的文本块和复制按钮,按钮样式在鼠标悬停时改变透明度。
在 `CodeSpanControl.xaml.cs` 中实现了 `Text` 属性的依赖属性支持,并添加了空的 `Copy_Click` 方法。
修改了 `MarkdownWpfRenderer.cs` 中的代码块渲染逻辑,移除进度条并在特定条件下使用 `CodeSpanControl`。
在 `PromptUtil.cs` 中更新提示文本,增加对 WPS 的支持,并调整思考过程格式。
移除 `ExcelHelper.csproj` 中与 Web 相关的项目项。
在 `Excel2Prompt.cs` 中修改 `ConverterToPrompt` 方法,增加 `sheetName` 参数并调整提示文本格式。
更新 `ImportViewModel.cs` 中对 `Excel2Prompt.ConverterToPrompt` 方法的调用,传递新参数并修改测试 AI 内容格式。
2025-03-04 23:39:58 +08:00
7 changed files with 142 additions and 35 deletions

View File

@ -0,0 +1,32 @@
<UserControl x:Class="EleCho.MdViewer.Controls.CodeSpanControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:EleCho.MdViewer.Controls"
mc:Ignorable="d"
d:DesignHeight="30" d:DesignWidth="160">
<StackPanel Orientation="Horizontal" Margin="5">
<local:SelectableTextBlock Text="{Binding Text}" VerticalAlignment="Center"/>
<Button x:Name="Copy"
Content="复制"
Click="Copy_Click"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Padding="4,0"
Opacity="1"
Height="20"
Background="#AAFFFFFF"
BorderThickness="1">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Value="True">
<Setter Property="Opacity" Value="0.8"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
</UserControl>

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace EleCho.MdViewer.Controls
{
/// <summary>
/// CodeSpanControl.xaml 的交互逻辑
/// </summary>
public partial class CodeSpanControl : UserControl
{
/// <summary>
/// Text
/// </summary>
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
/// <summary>
/// Text property
/// </summary>
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(CodeSpanControl), new PropertyMetadata(string.Empty));
public CodeSpanControl()
{
InitializeComponent();
this.DataContext = this;
}
private void Copy_Click(object sender, RoutedEventArgs e)
{
}
}
}

View File

@ -428,38 +428,49 @@ public class MarkdownWpfRenderer
CornerRadius = new CornerRadius(8),
Margin = new Thickness(0, 0, 0, NormalSize)
};
var codeContentElement = new SelectableTextBlock()
if (!fencedCodeBlock.Info.StartsWith("Excel", StringComparison.CurrentCultureIgnoreCase))
{
TextWrapping = TextWrapping.Wrap,
Padding = new Thickness(NormalSize / 2),
var codeContentElement = new SelectableTextBlock()
{
TextWrapping = TextWrapping.Wrap,
Padding = new Thickness(NormalSize / 2),
FontSize = NormalSize,
FontFamily = GetCodeTextFontFamily(),
};
FontSize = NormalSize,
FontFamily = GetCodeTextFontFamily(),
};
codeElement.Child =
codeContentElement;
codeElement.BindCodeBlockBackground();
codeElement.Child =
codeContentElement;
codeElement.BindCodeBlockBackground();
codeContentElement.BindCodeBlockForeground();
codeContentElement.BindCodeBlockForeground();
var language = ColorCode.Languages.FindById(fencedCodeBlock.Info);
var language = ColorCode.Languages.FindById(fencedCodeBlock.Info);
/*StyleDictionary styleDict = ColorMode switch
/*StyleDictionary styleDict = ColorMode switch
{
ColorMode.Light => StyleDictionary.DefaultLight,
ColorMode.Dark => StyleDictionary.DefaultDark,
_ => StyleDictionary.DefaultLight
};*/
StyleDictionary styleDict = StyleDictionary.DefaultDark;
WpfSyntaxHighLighting writer = new(styleDict);
writer.FormatTextBlock(fencedCodeBlock.Lines.ToString(), language, codeContentElement);
}
else
{
ColorMode.Light => StyleDictionary.DefaultLight,
ColorMode.Dark => StyleDictionary.DefaultDark,
_ => StyleDictionary.DefaultLight
};*/
StyleDictionary styleDict = StyleDictionary.DefaultDark;
WpfSyntaxHighLighting writer = new(styleDict);
writer.FormatTextBlock(fencedCodeBlock.Lines.ToString(), language, codeContentElement);
var codeSpanControl = new CodeSpanControl();
codeSpanControl.SetResourceReference(Control.ForegroundProperty, MarkdownResKey.MainForeground);
codeSpanControl.SetResourceReference(Control.BackgroundProperty, MarkdownResKey.CodeBlockBackground);
codeSpanControl.Text = fencedCodeBlock.Lines.ToString();
codeElement.Child = codeSpanControl;
}
return codeElement;
return codeElement;
}
public FrameworkElement RenderCodeBlock(CodeBlock codeBlock, CancellationToken cancellationToken)
@ -566,7 +577,7 @@ public class MarkdownWpfRenderer
SelectableTextBlock paragraphElement = new SelectableTextBlock()
{
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0, 0, 0, NormalSize),
Margin = new Thickness(0, NormalSize, 0, NormalSize),
FontSize = NormalSize,
};

View File

@ -48,7 +48,9 @@ class PromptUtil
4.
5. 使
6. 使
```Excel_{{}}
=SUM(A1:A100)
";
}

View File

@ -23,6 +23,12 @@
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<OptimizationPreference>Size</OptimizationPreference>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Web\**" />
<EmbeddedResource Remove="Web\**" />
<None Remove="Web\**" />
<Page Remove="Web\**" />
</ItemGroup>
<ItemGroup>
<None Remove="HL\SQL.xshd" />
</ItemGroup>
@ -69,9 +75,6 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="TinyPinyin" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Web\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EleCho.MdViewer\src\EleCho.MdViewer\EleCho.MdViewer.csproj" />
</ItemGroup>

View File

@ -14,7 +14,7 @@ public class Excel2Prompt
/// <param name="columns"></param>
/// <param name="startCell">A</param>
/// <returns></returns>
public static string ConverterToPrompt(IEnumerable<dynamic> excelData, Dictionary<string,string> columns, string startCell)
public static string ConverterToPrompt(IEnumerable<dynamic> excelData, Dictionary<string, string> columns, string startCell,string sheetName)
{
/*
:
@ -37,7 +37,7 @@ public class Excel2Prompt
- Missing values: 7007
*/
var prompts = new List<string>();
prompts.Add("This Excel file contains the following columns:");
prompts.Add($"This Excel file contains the following columns:");
var dataList = excelData.ToList();
// 解析 startCell获取起始列的索引
@ -70,6 +70,8 @@ public class Excel2Prompt
$" - Sample values: ['{string.Join("', '", sampleValues)}']";
prompts.Add(prompt);
}
prompts.Add($"Sheet Name: {sheetName}");
prompts.Add($"Max Row: {excelData.Count()}");
return string.Join(Environment.NewLine + Environment.NewLine, prompts);
}

View File

@ -179,7 +179,7 @@ public partial class ImportViewModel : ObservableRecipient, IViewModel
MaxRow = ExcelData.Count();
ExcelPromptString = Excel2Prompt.ConverterToPrompt(ExcelData, _columnMappings, StartCell);
ExcelPromptString = Excel2Prompt.ConverterToPrompt(excelData, _columnMappings, StartCell,currentSheetName);
}
catch (Exception ex)
{
@ -347,10 +347,16 @@ public partial class ImportViewModel : ObservableRecipient, IViewModel
}
private const string TEST_AI_CONTENT = @"
<think>
1231231
</think>
private static string TEST_AI_CONTENT = @"
```Excel_H
1231231122222222222222222222
123
1
23
12
3
12
```
";
#region Props
[ObservableProperty]