순정 MessageBox 를 앱 테마 대화상자로 교체 (53곳 중 49곳)
다크 테마에서 흰 시스템 창이 튀어나오던 알림을 자체 창(MessageDialogView)으로 바꿨다. 앱 셸과 같은 커스텀 타이틀바(36px) + B.Surface 본문 + 성격 아이콘 + 우측 버튼 줄. 폭 440 고정, 내용에 따라 높이 자동, 긴 예외는 스크롤로 흡수한다. 진입점은 DialogService 정적 메서드 4개로 모았다 — Notify / Confirm / ConfirmWithCancel / ShowError. MessageBox 는 Win32 호출이라 아무 데서나 되지만 WPF 창은 아니다. 교체로 새로 생기는 제약 셋을 DialogService 한곳에서 막는다. - 진단 모드에서는 창을 만들지 않고 기각 기본값을 즉시 돌려준다. 스모크는 무인 실행이라 모달이 하나라도 뜨면 타임아웃 없이 영원히 멈춘다 — 실제로 편집 스모크가 지나는 경로에 붙여넣기·개명 가드가 있다. 규약을 스모크 검사 3건으로 고정했다. - UI 스레드가 아니면 Dispatcher 로 넘긴다. - 소유 창은 '살아 있는 것'만 건다. 아직 안 보였거나 이미 닫힌 창을 Owner 로 주면 예외이고, 진단 렌더러가 도는 동안 MainWindow 가 닫힌 창을 가리킬 수 있다. App.xaml.cs 4곳은 다르게 처리했다. - 기동 실패(:49)·예외 폭주(:82)·복구 안내(:89) 3곳은 순정 유지. 창이 없는 시점이라 자체 창을 띄우면 종료코드가 유실되고, 이미 예외가 터진 자리에서 WPF 창을 새로 만들면 같은 핸들러로 재진입한다. 이유를 각 자리에 주석으로 남겼다. 덤으로 :89 는 e.Handled 를 알림보다 먼저 세우도록 순서를 바로잡았다 — 알림이 던지면 '복구 가능한 예외'가 하드 크래시로 바뀐다. - 알 수 없는 진단 옵션(:179)은 알림을 없앴다. 옵션 오타 하나로 무인 실행이 멈추던 자리다. 함께 고친 것 — Primary 버튼 스타일. 공유 버튼 템플릿의 호버 트리거가 TargetName 으로 채움을 회색으로 덮는데(TargetName 트리거는 TemplateBinding 을 이긴다) 글자는 흰색 그대로라, 라이트에서 마우스를 올리면 #F3F3F3 위 흰 글자 1.08:1 로 사라진다. 지금까지 Primary 사용처가 0건이라 드러난 적이 없었고 이 창이 첫 사용이다. 전용 템플릿 + 채움 호버·누름 토큰 2종 신설. 신설 토큰: B.Warning / B.Danger(라이트는 다크값을 못 쓴다 — 앰버 #E0A33A 는 흰 면 위 2.22:1 로 아이콘 기준 3:1 도 미달), B.AccentFillHover / B.AccentFillPressed. 전부 양 테마에 동시 추가. Lucide 아이콘 4종(info·circle-alert·triangle-alert·circle-help) 추가. 바꾸지 않은 것: 예외 원문. 18곳을 ShowError 로 수렴시키면 화면에서 ex.Message 가 오류코드+로그로 대체되는 동작 변경이 된다 — 요청은 시각 변경이라 문구·정보량을 그대로 뒀다. 남는 시스템 대화상자: 인쇄(PrintDialog)와 파일 열기/저장 — OS 셸 대화상자라 대상이 아니다. 진단 렌더러에 알림 5종(오류·경고·확인·저장확인·정보)을 등록해 라이트/다크 10장이 자동으로 남는다. 회귀: 테스트 124/124, 편집 스모크 실패 0, DB 왕복 1,271건 diff 0/예외 0, 종이 렌더 P062 바이트 동일. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
bd0d055e0d
commit
604f8f7d1b
@@ -0,0 +1,161 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using SheetMe.Designer.Controls;
|
||||
using SheetMe.Designer.Services;
|
||||
|
||||
namespace SheetMe.Designer.Views;
|
||||
|
||||
/// <summary>
|
||||
/// 알림·확인 대화상자 — 순정 Win32 MessageBox 대체.
|
||||
///
|
||||
/// 기각 의미론은 MessageBox 를 그대로 따른다: 닫기(X)·Alt+F4·Esc 는
|
||||
/// 확인 1개면 '확인', 예/아니오면 '아니오', 예/아니오/취소면 '취소'로 돌아간다.
|
||||
///
|
||||
/// <b><see cref="Window.DialogResult"/> 를 쓰지 않는다.</b> Show() 로 띄운 창에 대입하면
|
||||
/// InvalidOperationException 이고, 진단 렌더러(DialogShots)가 정확히 그 경로로 이 창을 찍는다.
|
||||
/// 같은 이유로 <c>Closing</c> 에서 <c>e.Cancel</c> 로 닫기를 막지도 않는다 —
|
||||
/// 렌더러가 <c>Close()</c> 로만 창을 정리하므로 취소되면 화면 밖 창이 살아남는다.
|
||||
/// </summary>
|
||||
public partial class MessageDialogView : Window
|
||||
{
|
||||
#region Member Fields
|
||||
private readonly string caption;
|
||||
private readonly string head;
|
||||
private readonly string? detail;
|
||||
private bool? answer;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>사용자 응답 — 예=true / 아니오=false / 취소=null</summary>
|
||||
public bool? Answer => answer;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// 공개 생성자 — 정적 헬퍼로 감싸지 말고 이 형태를 유지할 것.
|
||||
/// 진단 렌더러가 팩토리로 <c>new</c> 해서 라이트·다크 스냅샷을 찍는다(private 생성자면 편입 불가).
|
||||
/// </summary>
|
||||
public MessageDialogView(DialogKind kind, string caption, string head, string? detail,
|
||||
DialogButtons buttons, string yes = "예", string no = "아니오", bool destructive = false)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.caption = caption;
|
||||
this.head = head;
|
||||
this.detail = detail;
|
||||
|
||||
// 노트북 해상도에서 창이 화면을 덮지 않도록 한 번 더 조인다
|
||||
MaxHeight = Math.Min(620, SystemParameters.WorkArea.Height * 0.85);
|
||||
|
||||
CaptionText.Text = caption;
|
||||
HeadText.Text = head;
|
||||
DetailText.Text = detail ?? string.Empty;
|
||||
DetailText.Visibility = string.IsNullOrEmpty(detail) ? Visibility.Collapsed : Visibility.Visible;
|
||||
|
||||
var (icon, brushKey) = Visual(kind);
|
||||
// 색은 반드시 '키'로 넘긴다 — Brush 인스턴스를 대입하면 그 시점 값으로 굳어 테마 전환을 못 따라간다
|
||||
SeverityIcon.Content = LucideIcons.Icon(icon, 22, brushKey);
|
||||
// 오류만 복사 버튼을 노출한다 — 오류 코드를 전화로 불러 주던 실사용 경로
|
||||
CopyButton.Visibility = kind == DialogKind.Error ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
Configure(buttons, yes, no, destructive);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
/// <summary>성격 → (아이콘, 색 토큰)</summary>
|
||||
private static (string Icon, string BrushKey) Visual(DialogKind kind) => kind switch
|
||||
{
|
||||
DialogKind.Error => ("circle-alert", "B.Danger"),
|
||||
DialogKind.Warning => ("triangle-alert", "B.Warning"),
|
||||
DialogKind.Question => ("circle-help", "B.AccentText"),
|
||||
_ => ("info", "B.AccentText"),
|
||||
};
|
||||
|
||||
/// <summary>버튼 구성·기본 응답·초기 포커스</summary>
|
||||
private void Configure(DialogButtons buttons, string yes, string no, bool destructive)
|
||||
{
|
||||
switch (buttons)
|
||||
{
|
||||
case DialogButtons.YesNo:
|
||||
answer = false;
|
||||
AffirmButton.Content = yes;
|
||||
DenyButton.Content = no;
|
||||
DenyButton.Visibility = Visibility.Visible;
|
||||
DenyButton.IsCancel = true;
|
||||
break;
|
||||
|
||||
case DialogButtons.YesNoCancel:
|
||||
answer = null;
|
||||
AffirmButton.Content = yes;
|
||||
DenyButton.Content = no;
|
||||
DenyButton.Visibility = Visibility.Visible;
|
||||
CancelButton.Visibility = Visibility.Visible;
|
||||
CancelButton.IsCancel = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
answer = true;
|
||||
AffirmButton.Content = "확인";
|
||||
AffirmButton.IsCancel = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// 되돌리기 어려운 확인에서는 기본 버튼을 부정 쪽에 둔다 — Enter 한 번에 페이지가 지워지면 안 된다
|
||||
var defaultButton = destructive && DenyButton.Visibility == Visibility.Visible
|
||||
? DenyButton
|
||||
: AffirmButton;
|
||||
defaultButton.IsDefault = true;
|
||||
Loaded += (_, _) => defaultButton.Focus();
|
||||
}
|
||||
|
||||
private void OnAffirmClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
answer = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnDenyClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
answer = false;
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>닫기(X)·취소 — 생성자에서 정한 기각 기본값을 그대로 두고 닫는다</summary>
|
||||
private void OnDismissClick(object sender, RoutedEventArgs e) => Close();
|
||||
|
||||
/// <summary>본문이 넘칠 때만 버튼 줄 위에 구분선 — 창이 최대 높이에 걸렸다는 유일한 신호</summary>
|
||||
private void OnBodyScrollChanged(object sender, System.Windows.Controls.ScrollChangedEventArgs e)
|
||||
=> Footer.BorderThickness = new Thickness(0, BodyScroll.ScrollableHeight > 0.5 ? 1 : 0, 0, 0);
|
||||
|
||||
/// <summary>내용 복사 — MessageBox 의 Ctrl+C 동작 보존(오류 코드를 옮겨 적던 경로)</summary>
|
||||
private void OnCopyClick(object sender, RoutedEventArgs e) => CopyToClipboard();
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
|
||||
{
|
||||
CopyToClipboard();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
private void CopyToClipboard()
|
||||
{
|
||||
var text = string.IsNullOrEmpty(detail)
|
||||
? $"{caption}\n---\n{head}"
|
||||
: $"{caption}\n---\n{head}\n\n{detail}";
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 클립보드는 다른 프로세스가 잠글 수 있다 — 복사 실패가 알림 자체를 막으면 안 된다
|
||||
AppLog.Warn($"알림 내용 복사 실패: {ex.Message}");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user