Files
AX-Copilot/src/AxCopilot/Handlers/FontHandler.cs
lacvet f9c4bc0122 [Phase L14] 네트워크·계산·시스템 도구 핸들러 4종 추가
WolHandler.cs (신규, ~200줄, prefix=wol):
- MAC 파싱: :/- 구분자 제거 후 12자리 hex → byte[6]
- 매직 패킷: 0xFF×6 + MAC×16 = 102바이트 UDP 브로드캐스트
- 포트 9 + 7 동시 전송, UdpClient.EnableBroadcast=true
- wol_hosts.json 영속 스토리지: save/delete 서브커맨드
- 저장된 호스트 목록 Enter → 즉시 전송

RegHandler.cs (신규, ~185줄, prefix=reg):
- HKCU/HKLM/HKCR/HKU/HKCC 5개 하이브 지원
- RegistryKey.OpenSubKey 오류를 변수로 분리 (CS1631 회피)
- 값 타입별 포맷: string/int/long/byte[]/string[] 각각 처리
- 9개 즐겨찾기(Run/Uninstall/Environment/Explorer) 빠른 접근
- 조회 전용 — OpenSubKey(writable: false)

TipHandler.cs (신규, ~200줄, prefix=tip):
- decimal 타입으로 금액 계산 (부동소수점 오차 없음)
- 기본 모드: 10/15/18/20/25% 5종 팁 동시 표시
- off: 할인가 + 5~50% 비교, vat: 포함/역산 동시 계산
- 100원 단위 올림: Math.Ceiling(perPerson / 100) * 100
- 쉼표/원 제거 파싱으로 "50,000원" 형식 지원

FontHandler.cs (신규, ~100줄, prefix=font):
- Fonts.SystemFontFamilies WPF API (PresentationCore)
- static List<string>? _fontCache + lock 객체로 스레드 안전 캐시
- 전체 폰트 알파벳 정렬 후 최초 1회 로드
- 그룹 힌트: 한글/나눔/mono/Arial/Times/Consolas

App.xaml.cs: 4개 핸들러 Phase L14 블록 등록
docs/LAUNCHER_ROADMAP.md: Phase L14 완료 섹션 추가
빌드: 경고 0, 오류 0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 14:55:42 +09:00

137 lines
4.3 KiB
C#

using System.Windows;
using System.Windows.Media;
using AxCopilot.SDK;
using AxCopilot.Services;
using AxCopilot.Themes;
namespace AxCopilot.Handlers;
/// <summary>
/// L14-4: 시스템 폰트 목록·검색 핸들러. "font" 프리픽스로 사용합니다.
///
/// 예: font → 설치된 폰트 전체 목록
/// font 맑은 → "맑은" 포함 폰트 검색
/// font malgun → 영문 이름으로 검색
/// font mono → "mono" 포함 폰트 목록
/// font nanum → 나눔 폰트 목록
/// Enter → 폰트 이름을 클립보드에 복사.
/// </summary>
public class FontHandler : IActionHandler
{
public string? Prefix => "font";
public PluginMetadata Metadata => new(
"Font",
"시스템 폰트 목록 — 검색 · 이름 복사",
"1.0",
"AX");
// 폰트 목록 캐시 (최초 1회 로드)
private static List<string>? _fontCache;
private static readonly object _lock = new();
private static List<string> GetFonts()
{
if (_fontCache != null) return _fontCache;
lock (_lock)
{
if (_fontCache != null) return _fontCache;
try
{
_fontCache = Fonts.SystemFontFamilies
.Select(f => f.Source)
.OrderBy(n => n, StringComparer.OrdinalIgnoreCase)
.ToList();
}
catch
{
_fontCache = new List<string>();
}
return _fontCache;
}
}
// 주목할 만한 폰트 그룹 키워드
private static readonly (string Label, string Keyword)[] FontGroups =
[
("한글 폰트", "malgun"),
("나눔 폰트", "nanum"),
("코딩용 폰트", "mono"),
("Arial 계열", "arial"),
("Times 계열", "times"),
("Consolas", "consolas"),
];
public Task<IEnumerable<LauncherItem>> GetItemsAsync(string query, CancellationToken ct)
{
var q = query.Trim();
var items = new List<LauncherItem>();
var fonts = GetFonts();
if (string.IsNullOrWhiteSpace(q))
{
items.Add(new LauncherItem(
$"설치된 폰트 {fonts.Count}개",
"font <검색어> 로 필터링",
null, null, Symbol: "\uE8D2"));
// 그룹 힌트
foreach (var (label, kw) in FontGroups)
{
var cnt = fonts.Count(f => f.Contains(kw, StringComparison.OrdinalIgnoreCase));
if (cnt > 0)
items.Add(new LauncherItem(label, $"{cnt}개 · font {kw}", null, null, Symbol: "\uE8D2"));
}
// 첫 15개 표시
foreach (var f in fonts.Take(15))
items.Add(MakeFontItem(f));
return Task.FromResult<IEnumerable<LauncherItem>>(items);
}
// 검색
var filtered = fonts
.Where(f => f.Contains(q, StringComparison.OrdinalIgnoreCase))
.ToList();
if (filtered.Count == 0)
{
items.Add(new LauncherItem("결과 없음",
$"'{q}' 포함 폰트가 없습니다", null, null, Symbol: "\uE946"));
}
else
{
items.Add(new LauncherItem(
$"'{q}' 검색 결과 {filtered.Count}개",
"전체 복사: 첫 항목 Enter",
null,
("copy", string.Join("\n", filtered)),
Symbol: "\uE8D2"));
foreach (var f in filtered.Take(30))
items.Add(MakeFontItem(f));
}
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("Font", "클립보드에 복사했습니다.");
}
catch { /* 비핵심 */ }
}
return Task.CompletedTask;
}
private static LauncherItem MakeFontItem(string fontName) =>
new(fontName, "폰트 이름 · Enter 복사", null, ("copy", fontName), Symbol: "\uE8D2");
}