using System.Linq;
using System.Windows;
using System.Windows.Input;
using MergeHub.Services;
namespace MergeHub.Views
{
///
/// 단축키 목록 창.
///
/// 목록을 여기에 다시 적지 않는다 - 하나에서 읽어 온다.
/// 설명과 실제 키 처리가 갈라지면 설명이 곧 거짓말이 되기 때문이다.
///
public partial class ShortcutHelpWindow : Window
{
public ShortcutHelpWindow()
{
InitializeComponent();
GroupList.ItemsSource = ShortcutMap.ByGroup().ToList();
if (Application.Current?.MainWindow is { IsLoaded: true } main && !ReferenceEquals(main, this))
{
Owner = main;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
}
else
{
WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
}
private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) => DragMove();
private void Close_Click(object sender, RoutedEventArgs e) => Close();
/// 이미 떠 있으면 앞으로 가져온다. 누를 때마다 창이 쌓이면 성가시다.
private static ShortcutHelpWindow? open;
public static void ShowOrActivate(Window? owner = null)
{
if (open is { IsLoaded: true })
{
open.Activate();
return;
}
open = new ShortcutHelpWindow();
if (owner is not null) open.Owner = owner;
open.Closed += (_, _) => open = null;
((Window)open).Show();
}
}
}