using System.Windows;
using System.Windows.Controls;
namespace XFEToolBox.QuickTools;
public sealed partial class QuickToolPage
{
private void BuildText()
{
var input = Field("TextInput", Context.Text ?? "", true); var output = Field("TextResult", "", true, true);
input.Height = output.Height = 290;
var count = Hint("");
void CountInput() => count.Text = $"{input.Text.Length:N0} 字符 · {(input.Text.Length == 0 ? 0 : input.Text.Count(c => c == '\n') + 1):N0} 行";
input.TextChanged += (_, _) => CountInput(); CountInput();
var actions = Choices(TextActions.Actions);
async Task Transform(string operation) { string text = input.Text; Result(await Task.Run(() => TextActions.Apply(operation, text), cancellation.Token), output); }
var tools = new TabControl { Margin = new Thickness(0, 0, 0, 12) };
tools.Items.Add(new TabItem { Header = "格式与编码", Content = Actions(actions, Primary("处理文本", () => Transform((string)actions.SelectedItem)), ActionButton("美化 JSON", () => Transform("JSON 格式化")), ActionButton("压缩 JSON", () => Transform("JSON 压缩"))) });
var pattern = Field("RegexPattern", @"\b\w+\b"); pattern.Width = 290;
tools.Items.Add(new TabItem { Header = "正则测试", Content = Stack(Actions(pattern, Primary("测试正则", async () => { string p = pattern.Text, t = input.Text; Result(await Task.Run(() => TextActions.Match(p, t), cancellation.Token), output); })), Hint("左侧为待匹配文本 · 250 ms 超时保护 · 右侧展示匹配位置与分组")) });
var right = Field("DiffInput", "", true); right.Height = 140;
tools.Items.Add(new TabItem { Header = "差异对比", Content = Stack(Hint("旧文本放在左侧输入区,新文本放在下面;结果使用 + / − 标出变化。"), right, Primary("对比差异", async () => { string a = input.Text, b = right.Text; Result(await Task.Run(() => TextActions.Diff(a, b), cancellation.Token), output); })) });
body.Children.Add(tools);
var left = Section("输入", input, Actions(ActionButton("读取剪贴板", () => { input.Text = Clipboard.ContainsText() ? Clipboard.GetText() : ""; status.Text = "已读取本次内容,不记录历史。"; }), ActionButton("清空输入", () => input.Clear())), count);
var result = Section("输出", output, Actions(Copy(output), ActionButton("结果作为输入", () => input.Text = output.Text)), Hint("仅在本机处理 · 不上传文本 · 最多 1 MiB 字符"));
body.Children.Add(Split(left, result));
}
}
using System.Windows;
using System.Windows.Controls;
namespace XFEToolBox.QuickTools;
public sealed partial class QuickToolPage
{
private void BuildText()
{
var input = Field("TextInput", Context.Text ?? "", true); var output = Field("TextResult", "", true, true);
input.Height = output.Height = 290;
var count = Hint("");
void CountInput() => count.Text = $"{input.Text.Length:N0} 字符 · {(input.Text.Length == 0 ? 0 : input.Text.Count(c => c == '\n') + 1):N0} 行";
input.TextChanged += (_, _) => CountInput(); CountInput();
var actions = Choices(TextActions.Actions);
async Task Transform(string operation) { string text = input.Text; Result(await Task.Run(() => TextActions.Apply(operation, text), cancellation.Token), output); }
var tools = new TabControl { Margin = new Thickness(0, 0, 0, 12) };
tools.Items.Add(new TabItem { Header = "格式与编码", Content = Actions(actions, Primary("处理文本", () => Transform((string)actions.SelectedItem)), ActionButton("美化 JSON", () => Transform("JSON 格式化")), ActionButton("压缩 JSON", () => Transform("JSON 压缩"))) });
var pattern = Field("RegexPattern", @"\b\w+\b"); pattern.Width = 290;
tools.Items.Add(new TabItem { Header = "正则测试", Content = Stack(Actions(pattern, Primary("测试正则", async () => { string p = pattern.Text, t = input.Text; Result(await Task.Run(() => TextActions.Match(p, t), cancellation.Token), output); })), Hint("左侧为待匹配文本 · 250 ms 超时保护 · 右侧展示匹配位置与分组")) });
var right = Field("DiffInput", "", true); right.Height = 140;
tools.Items.Add(new TabItem { Header = "差异对比", Content = Stack(Hint("旧文本放在左侧输入区,新文本放在下面;结果使用 + / − 标出变化。"), right, Primary("对比差异", async () => { string a = input.Text, b = right.Text; Result(await Task.Run(() => TextActions.Diff(a, b), cancellation.Token), output); })) });
body.Children.Add(tools);
var left = Section("输入", input, Actions(ActionButton("读取剪贴板", () => { input.Text = Clipboard.ContainsText() ? Clipboard.GetText() : ""; status.Text = "已读取本次内容,不记录历史。"; }), ActionButton("清空输入", () => input.Clear())), count);
var result = Section("输出", output, Actions(Copy(output), ActionButton("结果作为输入", () => input.Text = output.Text)), Hint("仅在本机处理 · 不上传文本 · 最多 1 MiB 字符"));
body.Children.Add(Split(left, result));
}
}