변경 목적: Agent Compare 아래 비교본의 개발 문서와 런처 소스를 기준으로 현재 AX Commander에 빠져 있던 신규 런처 기능을 동일한 흐름으로 옮겨, 비교본 수준의 기능 폭을 현재 제품에 반영했습니다. 핵심 수정사항: 비교본의 신규 런처 핸들러 다수를 src/AxCopilot/Handlers로 이식하고 App.xaml.cs 등록 흐름에 연결했습니다. 빠른 링크, 파일 태그, 알림 센터, 포모도로, 파일 브라우저, 핫키 관리, OCR, 세션/스케줄/매크로, Git/정규식/네트워크/압축/해시/UUID/JWT/QR 등 AX Commander 기능을 추가했습니다. 핵심 수정사항: 신규 기능이 실제 동작하도록 AppSettings 확장, SchedulerService/FileTagService/NotificationCenterService/IconCacheService/UrlTemplateEngine/PomodoroService 추가, 배치 이름변경/세션/스케줄/매크로 편집 창 추가, NotificationService와 Symbols 보강, QR/OCR용 csproj 의존성과 Windows 타겟 프레임워크를 반영했습니다. 문서 반영: README.md와 docs/DEVELOPMENT.md에 비교본 기반 런처 기능 이식 이력과 검증 결과를 업데이트했습니다. 검증 결과: dotnet build src/AxCopilot/AxCopilot.csproj -c Release -v minimal -p:OutputPath=bin\\verify\\ -p:IntermediateOutputPath=obj\\verify\\ 실행 기준 경고 0개, 오류 0개를 확인했습니다.
252 lines
9.5 KiB
C#
252 lines
9.5 KiB
C#
using System.Text;
|
|
using System.Windows;
|
|
using AxCopilot.SDK;
|
|
using AxCopilot.Services;
|
|
using AxCopilot.Themes;
|
|
|
|
namespace AxCopilot.Handlers;
|
|
|
|
/// <summary>
|
|
/// L12-3: 모스 부호 변환기 핸들러. "morse" 프리픽스로 사용합니다.
|
|
///
|
|
/// 예: morse hello → 텍스트 → 모스 부호
|
|
/// morse .- -... -.-. → 모스 부호 → 텍스트 (공백으로 구분)
|
|
/// morse SOS → SOS 모스 부호
|
|
/// morse → 클립보드 자동 감지·변환
|
|
/// Enter → 결과를 클립보드에 복사.
|
|
/// </summary>
|
|
public class MorseHandler : IActionHandler
|
|
{
|
|
public string? Prefix => "morse";
|
|
|
|
public PluginMetadata Metadata => new(
|
|
"Morse",
|
|
"모스 부호 변환기 — 텍스트 ↔ 모스 부호",
|
|
"1.0",
|
|
"AX");
|
|
|
|
// ── 모스 부호 사전 ────────────────────────────────────────────────────────
|
|
private static readonly Dictionary<char, string> TextToMorse = new()
|
|
{
|
|
['A'] = ".-", ['B'] = "-...", ['C'] = "-.-.", ['D'] = "-..",
|
|
['E'] = ".", ['F'] = "..-.", ['G'] = "--.", ['H'] = "....",
|
|
['I'] = "..", ['J'] = ".---", ['K'] = "-.-", ['L'] = ".-..",
|
|
['M'] = "--", ['N'] = "-.", ['O'] = "---", ['P'] = ".--.",
|
|
['Q'] = "--.-", ['R'] = ".-.", ['S'] = "...", ['T'] = "-",
|
|
['U'] = "..-", ['V'] = "...-", ['W'] = ".--", ['X'] = "-..-",
|
|
['Y'] = "-.--", ['Z'] = "--..",
|
|
['0'] = "-----", ['1'] = ".----", ['2'] = "..---", ['3'] = "...--",
|
|
['4'] = "....-", ['5'] = ".....", ['6'] = "-....", ['7'] = "--...",
|
|
['8'] = "---..", ['9'] = "----.",
|
|
['.'] = ".-.-.-", [','] = "--..--", ['?'] = "..--..", ['!'] = "-.-.--",
|
|
['/'] = "-..-.", ['-'] = "-....-", ['('] = "-.--.", [')'] = "-.--.-",
|
|
['@'] = ".--.-.", ['='] = "-...-", ['+'] = ".-.-.", [':'] = "---...",
|
|
[';'] = "-.-.-.", ['"'] = ".-..-.", ['\''] = ".----.", ['_'] = "..--.-",
|
|
[' '] = "/",
|
|
};
|
|
|
|
private static readonly Dictionary<string, char> MorseToText;
|
|
|
|
// 번개 부호 / 대문자 표
|
|
private static readonly string[] ProsignCodes = ["SOS", "AR", "AS", "BT", "KN", "SK"];
|
|
private static readonly Dictionary<string, string> ProsignMorse = new()
|
|
{
|
|
["SOS"] = "... --- ...",
|
|
["AR"] = ".-.-.",
|
|
["AS"] = ".-...",
|
|
["BT"] = "-...-",
|
|
["KN"] = "-.--.",
|
|
["SK"] = "...-.-",
|
|
};
|
|
|
|
static MorseHandler()
|
|
{
|
|
MorseToText = TextToMorse
|
|
.Where(kv => kv.Key != ' ')
|
|
.ToDictionary(kv => kv.Value, kv => kv.Key);
|
|
}
|
|
|
|
public Task<IEnumerable<LauncherItem>> GetItemsAsync(string query, CancellationToken ct)
|
|
{
|
|
var q = query.Trim();
|
|
var items = new List<LauncherItem>();
|
|
|
|
if (string.IsNullOrWhiteSpace(q))
|
|
{
|
|
// 클립보드 자동 감지
|
|
var clip = GetClipboard();
|
|
if (!string.IsNullOrWhiteSpace(clip))
|
|
{
|
|
if (IsMorseCode(clip))
|
|
items.AddRange(BuildMorseToText(clip));
|
|
else if (clip.Length <= 100)
|
|
items.AddRange(BuildTextToMorse(clip));
|
|
}
|
|
|
|
if (items.Count == 0)
|
|
{
|
|
items.Add(new LauncherItem("모스 부호 변환기",
|
|
"예: morse hello / morse .- -... -.-.",
|
|
null, null, Symbol: "\uE8C4"));
|
|
items.Add(new LauncherItem("morse SOS", "SOS 모스 부호", null, null, Symbol: "\uE8C4"));
|
|
items.Add(new LauncherItem("morse hello", "텍스트 → 모스", null, null, Symbol: "\uE8C4"));
|
|
items.Add(new LauncherItem("morse .- -...", "모스 → 텍스트", null, null, Symbol: "\uE8C4"));
|
|
}
|
|
return Task.FromResult<IEnumerable<LauncherItem>>(items);
|
|
}
|
|
|
|
// 프로사인 키워드 우선
|
|
if (ProsignMorse.TryGetValue(q.ToUpperInvariant(), out var psCode))
|
|
{
|
|
items.Add(new LauncherItem(
|
|
$"{q.ToUpper()} = {psCode}",
|
|
"모스 부호 프로사인 · Enter 복사",
|
|
null, ("copy", psCode), Symbol: "\uE8C4"));
|
|
items.AddRange(BuildTextToMorse(q.ToUpper()));
|
|
return Task.FromResult<IEnumerable<LauncherItem>>(items);
|
|
}
|
|
|
|
// 모스 부호 입력 감지
|
|
if (IsMorseCode(q))
|
|
{
|
|
items.AddRange(BuildMorseToText(q));
|
|
}
|
|
else
|
|
{
|
|
items.AddRange(BuildTextToMorse(q));
|
|
}
|
|
|
|
return Task.FromResult<IEnumerable<LauncherItem>>(items);
|
|
}
|
|
|
|
public Task ExecuteAsync(LauncherItem item, CancellationToken ct)
|
|
{
|
|
if (item.Data is ("copy", string text))
|
|
{
|
|
try
|
|
{
|
|
System.Windows.Application.Current.Dispatcher.Invoke(
|
|
() => Clipboard.SetText(text));
|
|
NotificationService.Notify("Morse", "클립보드에 복사했습니다.");
|
|
}
|
|
catch { /* 비핵심 */ }
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
// ── 변환 로직 ─────────────────────────────────────────────────────────────
|
|
|
|
private static IEnumerable<LauncherItem> BuildTextToMorse(string text)
|
|
{
|
|
var upper = text.ToUpperInvariant();
|
|
var words = upper.Split(' ');
|
|
var morseSb = new StringBuilder();
|
|
var unknown = new List<char>();
|
|
|
|
foreach (var word in words)
|
|
{
|
|
if (morseSb.Length > 0) morseSb.Append("/ "); // 단어 구분
|
|
foreach (var ch in word)
|
|
{
|
|
if (TextToMorse.TryGetValue(ch, out var code))
|
|
morseSb.Append(code + " ");
|
|
else
|
|
unknown.Add(ch);
|
|
}
|
|
}
|
|
|
|
var morseStr = morseSb.ToString().TrimEnd();
|
|
if (string.IsNullOrEmpty(morseStr))
|
|
{
|
|
yield return new LauncherItem("변환 불가", "모스 부호에 없는 문자입니다", null, null, Symbol: "\uE783");
|
|
yield break;
|
|
}
|
|
|
|
yield return new LauncherItem(
|
|
morseStr.Length > 80 ? morseStr[..80] + "…" : morseStr,
|
|
$"'{text}' → 모스 부호 · Enter 복사",
|
|
null,
|
|
("copy", morseStr),
|
|
Symbol: "\uE8C4");
|
|
|
|
if (unknown.Count > 0)
|
|
yield return new LauncherItem("변환 불가 문자",
|
|
string.Join(" ", unknown.Distinct()), null, null, Symbol: "\uE946");
|
|
|
|
// 문자별 표 (최대 10자)
|
|
var displayText = upper.Replace(" ", "");
|
|
foreach (var ch in displayText.Take(10))
|
|
{
|
|
if (TextToMorse.TryGetValue(ch, out var code) && ch != ' ')
|
|
yield return new LauncherItem($"{ch} = {code}", "문자별 코드", null, ("copy", code), Symbol: "\uE8C4");
|
|
}
|
|
}
|
|
|
|
private static IEnumerable<LauncherItem> BuildMorseToText(string morse)
|
|
{
|
|
// "/" 는 단어 구분, 공백은 문자 구분
|
|
var sb = new StringBuilder();
|
|
var words = morse.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
|
var unknown = new List<string>();
|
|
|
|
foreach (var word in words)
|
|
{
|
|
var codes = word.Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (var code in codes)
|
|
{
|
|
if (MorseToText.TryGetValue(code, out var ch))
|
|
sb.Append(ch);
|
|
else
|
|
unknown.Add(code);
|
|
}
|
|
sb.Append(' ');
|
|
}
|
|
|
|
var result = sb.ToString().Trim();
|
|
if (string.IsNullOrEmpty(result))
|
|
{
|
|
yield return new LauncherItem("변환 실패", "인식할 수 없는 모스 부호입니다", null, null, Symbol: "\uE783");
|
|
yield break;
|
|
}
|
|
|
|
yield return new LauncherItem(
|
|
result,
|
|
$"모스 부호 → '{result}' · Enter 복사",
|
|
null,
|
|
("copy", result),
|
|
Symbol: "\uE8C4");
|
|
|
|
if (unknown.Count > 0)
|
|
yield return new LauncherItem("인식 불가 코드",
|
|
string.Join(" ", unknown.Distinct()), null, null, Symbol: "\uE946");
|
|
|
|
// 코드별 표 (최대 10개)
|
|
var codes_ = morse.Trim().Split(new[] { ' ', '/' }, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (var code in codes_.Take(10))
|
|
{
|
|
if (MorseToText.TryGetValue(code, out var ch))
|
|
yield return new LauncherItem($"{code} = {ch}", "코드별 문자", null, ("copy", ch.ToString()), Symbol: "\uE8C4");
|
|
}
|
|
}
|
|
|
|
// ── 헬퍼 ─────────────────────────────────────────────────────────────────
|
|
|
|
private static bool IsMorseCode(string s)
|
|
{
|
|
// .-/ 문자와 공백만으로 구성되어 있으면 모스 부호로 판단
|
|
return !string.IsNullOrWhiteSpace(s) &&
|
|
s.All(c => c is '.' or '-' or '/' or ' ') &&
|
|
(s.Contains('.') || s.Contains('-'));
|
|
}
|
|
|
|
private static string GetClipboard()
|
|
{
|
|
try
|
|
{
|
|
return System.Windows.Application.Current.Dispatcher.Invoke(
|
|
() => Clipboard.ContainsText() ? Clipboard.GetText() : "");
|
|
}
|
|
catch { return ""; }
|
|
}
|
|
}
|