using System;
using System.Collections.Generic;
using System.Linq;
// 说明:
// 'text' 参数的文本来源:
// - 快捷键触发时:当前剪贴板内容
// - 历史菜单触发时:选中的历史项内容
// 返回值说明:
// - 作为宏运行时:直接写入剪贴板
// - 返回 null 时:ClipboardFusion 忽略该结果
// - 触发器中执行时:null 会被转为空字符串并传递给下一个动作
public static class ClipboardFusionHelper
{
public static string ProcessText(string text)
{
string spaces = " "; // 8个空格,保持格式对齐
string prompt = "请输入要合并的历史项序号(1-9,不用空格分隔):\n";
prompt += "格式:<序号1><序号2> ... <序号N> (指定合并项,默认换行分隔)\n";
prompt += "示例:\n";
prompt += $"{spaces}//示例 1: 合并第2、1项,换行分隔\n";
prompt += $"{spaces}21\n";
prompt += $"{spaces}//输出:[第2项文本]\n[第1项文本]\n";
prompt += $"\n{spaces}//示例 2: 合并第3、2、1项,换行分隔、无序号\n";
prompt += $"{spaces}321\n";
prompt += $"{spaces}//输出:[第3项文本]\n[第2项文本]\n[第1项文本]\n";
prompt += $"\n{spaces}//示例 3: 仅合并第5、3项(换行分隔、无序号)\n";
prompt += $"{spaces}53";
// 弹出输入框,获取用户参数(默认值为"21")
string inputStr = BFS.Dialog.GetUserInput(prompt, "21");
if (string.IsNullOrWhiteSpace(inputStr))
{
BFS.Dialog.ShowTrayMessage("未输入任何参数,操作取消!");
return null;
}
// 将输入字符串拆分为单个数字的数组
int[] digitArray = inputStr.Select(c => c - '0').ToArray();
// 存储最终拼接结果
string output = string.Empty;
// 遍历数字数组,按序号获取历史项并拼接(换行分隔)
foreach (int index in digitArray)
{
// 获取对应序号的历史项文本(注意:历史项索引从0开始,输入的1对应索引0,2对应索引1...)
string historyText = BFS.ClipboardFusion.GetHistoryText(index - 1);
// 拼接文本,每个历史项后换行
output += historyText + Environment.NewLine;
}
// 去除最后多余的换行符
output = output.TrimEnd(Environment.NewLine.ToCharArray());
// 弹出提示并写入剪贴板
BFS.Dialog.ShowTrayMessage($"成功合并 {digitArray.Length} 条历史项,结果已写入剪贴板!");
BFS.Clipboard.SetText(output);
return output;
}
}