381 lines
11 KiB
C#
381 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Animation;
|
|
using System.Windows.Media.Effects;
|
|
|
|
namespace AxCopilot.Views;
|
|
|
|
internal sealed class UserAskDialog : Window
|
|
{
|
|
private string _selectedResponse = "";
|
|
|
|
private readonly TextBox _customInput;
|
|
|
|
private readonly StackPanel _optionPanel;
|
|
|
|
public string SelectedResponse => _selectedResponse;
|
|
|
|
private UserAskDialog(string question, List<string> options, string defaultValue)
|
|
{
|
|
//IL_0c8c: Unknown result type (might be due to invalid IL or missing references)
|
|
UserAskDialog userAskDialog = this;
|
|
base.Width = 460.0;
|
|
base.MinWidth = 380.0;
|
|
base.MaxWidth = 560.0;
|
|
base.SizeToContent = SizeToContent.Height;
|
|
base.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
|
base.ResizeMode = ResizeMode.NoResize;
|
|
base.WindowStyle = WindowStyle.None;
|
|
base.AllowsTransparency = true;
|
|
base.Background = Brushes.Transparent;
|
|
base.Topmost = true;
|
|
Brush background = (Application.Current.TryFindResource("LauncherBackground") as Brush) ?? new SolidColorBrush(Color.FromRgb(26, 27, 46));
|
|
Brush brush = (Application.Current.TryFindResource("PrimaryText") as Brush) ?? Brushes.White;
|
|
Brush brush2 = (Application.Current.TryFindResource("SecondaryText") as Brush) ?? Brushes.Gray;
|
|
Brush accentBrush = (Application.Current.TryFindResource("AccentColor") as Brush) ?? new SolidColorBrush(Color.FromRgb(75, 94, 252));
|
|
Brush brush3 = (Application.Current.TryFindResource("BorderColor") as Brush) ?? Brushes.Gray;
|
|
Brush itemBg = (Application.Current.TryFindResource("ItemBackground") as Brush) ?? new SolidColorBrush(Color.FromRgb(42, 43, 64));
|
|
Brush hoverBg = (Application.Current.TryFindResource("ItemHoverBackground") as Brush) ?? new SolidColorBrush(Color.FromArgb(24, byte.MaxValue, byte.MaxValue, byte.MaxValue));
|
|
Border root = new Border
|
|
{
|
|
Background = background,
|
|
CornerRadius = new CornerRadius(16.0),
|
|
BorderBrush = brush3,
|
|
BorderThickness = new Thickness(1.0),
|
|
Padding = new Thickness(24.0, 20.0, 24.0, 18.0),
|
|
Effect = new DropShadowEffect
|
|
{
|
|
BlurRadius = 24.0,
|
|
ShadowDepth = 4.0,
|
|
Opacity = 0.3,
|
|
Color = Colors.Black
|
|
}
|
|
};
|
|
StackPanel stackPanel = new StackPanel();
|
|
Grid grid = new Grid
|
|
{
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 12.0)
|
|
};
|
|
grid.MouseLeftButtonDown += delegate
|
|
{
|
|
try
|
|
{
|
|
userAskDialog.DragMove();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
};
|
|
StackPanel stackPanel2 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal
|
|
};
|
|
stackPanel2.Children.Add(new TextBlock
|
|
{
|
|
Text = "\ue9ce",
|
|
FontFamily = new FontFamily("Segoe MDL2 Assets"),
|
|
FontSize = 16.0,
|
|
Foreground = accentBrush,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Margin = new Thickness(0.0, 0.0, 8.0, 0.0)
|
|
});
|
|
stackPanel2.Children.Add(new TextBlock
|
|
{
|
|
Text = "AX Agent — 질문",
|
|
FontSize = 14.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = brush,
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
});
|
|
grid.Children.Add(stackPanel2);
|
|
stackPanel.Children.Add(grid);
|
|
stackPanel.Children.Add(new Border
|
|
{
|
|
Height = 1.0,
|
|
Background = brush3,
|
|
Opacity = 0.3,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 14.0)
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = question,
|
|
FontSize = 13.5,
|
|
Foreground = brush,
|
|
TextWrapping = TextWrapping.Wrap,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 16.0),
|
|
LineHeight = 20.0
|
|
});
|
|
_optionPanel = new StackPanel
|
|
{
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 12.0)
|
|
};
|
|
Border selectedBorder = null;
|
|
foreach (string option in options)
|
|
{
|
|
string capturedOption = option;
|
|
Border border = new Border
|
|
{
|
|
Background = itemBg,
|
|
CornerRadius = new CornerRadius(10.0),
|
|
Padding = new Thickness(14.0, 10.0, 14.0, 10.0),
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 6.0),
|
|
Cursor = Cursors.Hand,
|
|
BorderBrush = Brushes.Transparent,
|
|
BorderThickness = new Thickness(1.5)
|
|
};
|
|
StackPanel stackPanel3 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal
|
|
};
|
|
Border element = new Border
|
|
{
|
|
Width = 18.0,
|
|
Height = 18.0,
|
|
CornerRadius = new CornerRadius(9.0),
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.5),
|
|
Margin = new Thickness(0.0, 0.0, 10.0, 0.0),
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Child = new Border
|
|
{
|
|
Width = 10.0,
|
|
Height = 10.0,
|
|
CornerRadius = new CornerRadius(5.0),
|
|
Background = Brushes.Transparent,
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
}
|
|
};
|
|
stackPanel3.Children.Add(element);
|
|
stackPanel3.Children.Add(new TextBlock
|
|
{
|
|
Text = capturedOption,
|
|
FontSize = 13.0,
|
|
Foreground = brush,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
TextWrapping = TextWrapping.Wrap
|
|
});
|
|
border.Child = stackPanel3;
|
|
border.MouseEnter += delegate(object s, MouseEventArgs _)
|
|
{
|
|
Border border4 = (Border)s;
|
|
if (border4.BorderBrush != accentBrush)
|
|
{
|
|
border4.Background = hoverBg;
|
|
}
|
|
};
|
|
border.MouseLeave += delegate(object s, MouseEventArgs _)
|
|
{
|
|
Border border4 = (Border)s;
|
|
if (border4.BorderBrush != accentBrush)
|
|
{
|
|
border4.Background = itemBg;
|
|
}
|
|
};
|
|
border.MouseLeftButtonUp += delegate(object s, MouseButtonEventArgs _)
|
|
{
|
|
if (selectedBorder != null)
|
|
{
|
|
selectedBorder.BorderBrush = Brushes.Transparent;
|
|
selectedBorder.Background = itemBg;
|
|
Border border4 = FindRadioCircle(selectedBorder);
|
|
if (border4 != null)
|
|
{
|
|
border4.Background = Brushes.Transparent;
|
|
}
|
|
}
|
|
Border border5 = (Border)s;
|
|
border5.BorderBrush = accentBrush;
|
|
border5.Background = new SolidColorBrush(Color.FromArgb(21, ((SolidColorBrush)accentBrush).Color.R, ((SolidColorBrush)accentBrush).Color.G, ((SolidColorBrush)accentBrush).Color.B));
|
|
Border border6 = FindRadioCircle(border5);
|
|
if (border6 != null)
|
|
{
|
|
border6.Background = accentBrush;
|
|
}
|
|
selectedBorder = border5;
|
|
userAskDialog._selectedResponse = capturedOption;
|
|
if (userAskDialog._customInput != null)
|
|
{
|
|
userAskDialog._customInput.Text = "";
|
|
}
|
|
};
|
|
_optionPanel.Children.Add(border);
|
|
}
|
|
stackPanel.Children.Add(_optionPanel);
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "또는 직접 입력:",
|
|
FontSize = 11.5,
|
|
Foreground = brush2,
|
|
Margin = new Thickness(2.0, 0.0, 0.0, 6.0)
|
|
});
|
|
_customInput = new TextBox
|
|
{
|
|
MinHeight = 40.0,
|
|
MaxHeight = 100.0,
|
|
AcceptsReturn = true,
|
|
TextWrapping = TextWrapping.Wrap,
|
|
FontSize = 13.0,
|
|
Background = itemBg,
|
|
Foreground = brush,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush3,
|
|
BorderThickness = new Thickness(1.0),
|
|
Padding = new Thickness(10.0, 8.0, 10.0, 8.0),
|
|
Text = defaultValue
|
|
};
|
|
_customInput.TextChanged += delegate
|
|
{
|
|
if (!string.IsNullOrEmpty(userAskDialog._customInput.Text))
|
|
{
|
|
if (selectedBorder != null)
|
|
{
|
|
selectedBorder.BorderBrush = Brushes.Transparent;
|
|
selectedBorder.Background = itemBg;
|
|
Border border4 = FindRadioCircle(selectedBorder);
|
|
if (border4 != null)
|
|
{
|
|
border4.Background = Brushes.Transparent;
|
|
}
|
|
selectedBorder = null;
|
|
}
|
|
userAskDialog._selectedResponse = userAskDialog._customInput.Text;
|
|
}
|
|
};
|
|
stackPanel.Children.Add(_customInput);
|
|
StackPanel stackPanel4 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
HorizontalAlignment = HorizontalAlignment.Right,
|
|
Margin = new Thickness(0.0, 16.0, 0.0, 0.0)
|
|
};
|
|
Border border2 = new Border
|
|
{
|
|
Background = accentBrush,
|
|
CornerRadius = new CornerRadius(10.0),
|
|
Padding = new Thickness(20.0, 9.0, 20.0, 9.0),
|
|
Cursor = Cursors.Hand,
|
|
Margin = new Thickness(8.0, 0.0, 0.0, 0.0)
|
|
};
|
|
border2.Child = new TextBlock
|
|
{
|
|
Text = "확인",
|
|
FontSize = 13.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = Brushes.White
|
|
};
|
|
border2.MouseEnter += delegate(object s, MouseEventArgs _)
|
|
{
|
|
((Border)s).Opacity = 0.85;
|
|
};
|
|
border2.MouseLeave += delegate(object s, MouseEventArgs _)
|
|
{
|
|
((Border)s).Opacity = 1.0;
|
|
};
|
|
border2.MouseLeftButtonUp += delegate
|
|
{
|
|
if (string.IsNullOrWhiteSpace(userAskDialog._selectedResponse) && !string.IsNullOrWhiteSpace(defaultValue))
|
|
{
|
|
userAskDialog._selectedResponse = defaultValue;
|
|
}
|
|
userAskDialog.DialogResult = true;
|
|
userAskDialog.Close();
|
|
};
|
|
stackPanel4.Children.Add(border2);
|
|
Border border3 = new Border
|
|
{
|
|
Background = Brushes.Transparent,
|
|
CornerRadius = new CornerRadius(10.0),
|
|
Padding = new Thickness(16.0, 9.0, 16.0, 9.0),
|
|
Cursor = Cursors.Hand,
|
|
BorderBrush = new SolidColorBrush(Color.FromArgb(64, 220, 38, 38)),
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
border3.Child = new TextBlock
|
|
{
|
|
Text = "취소",
|
|
FontSize = 13.0,
|
|
Foreground = new SolidColorBrush(Color.FromRgb(220, 38, 38))
|
|
};
|
|
border3.MouseEnter += delegate(object s, MouseEventArgs _)
|
|
{
|
|
((Border)s).Opacity = 0.85;
|
|
};
|
|
border3.MouseLeave += delegate(object s, MouseEventArgs _)
|
|
{
|
|
((Border)s).Opacity = 1.0;
|
|
};
|
|
border3.MouseLeftButtonUp += delegate
|
|
{
|
|
userAskDialog._selectedResponse = "";
|
|
userAskDialog.DialogResult = false;
|
|
userAskDialog.Close();
|
|
};
|
|
stackPanel4.Children.Insert(0, border3);
|
|
stackPanel.Children.Add(stackPanel4);
|
|
root.Child = stackPanel;
|
|
base.Content = root;
|
|
root.RenderTransformOrigin = new Point(0.5, 0.5);
|
|
root.RenderTransform = new ScaleTransform(0.95, 0.95);
|
|
root.Opacity = 0.0;
|
|
base.Loaded += delegate
|
|
{
|
|
DoubleAnimation animation = new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(150.0));
|
|
root.BeginAnimation(UIElement.OpacityProperty, animation);
|
|
DoubleAnimation animation2 = new DoubleAnimation(0.95, 1.0, TimeSpan.FromMilliseconds(200.0))
|
|
{
|
|
EasingFunction = new QuadraticEase
|
|
{
|
|
EasingMode = EasingMode.EaseOut
|
|
}
|
|
};
|
|
DoubleAnimation animation3 = new DoubleAnimation(0.95, 1.0, TimeSpan.FromMilliseconds(200.0))
|
|
{
|
|
EasingFunction = new QuadraticEase
|
|
{
|
|
EasingMode = EasingMode.EaseOut
|
|
}
|
|
};
|
|
((ScaleTransform)root.RenderTransform).BeginAnimation(ScaleTransform.ScaleXProperty, animation2);
|
|
((ScaleTransform)root.RenderTransform).BeginAnimation(ScaleTransform.ScaleYProperty, animation3);
|
|
};
|
|
base.KeyDown += delegate(object _, KeyEventArgs e)
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0046: Invalid comparison between Unknown and I4
|
|
if ((int)e.Key == 13)
|
|
{
|
|
userAskDialog._selectedResponse = "";
|
|
userAskDialog.DialogResult = false;
|
|
userAskDialog.Close();
|
|
}
|
|
if ((int)e.Key == 6 && !userAskDialog._customInput.IsFocused)
|
|
{
|
|
userAskDialog.DialogResult = true;
|
|
userAskDialog.Close();
|
|
}
|
|
};
|
|
}
|
|
|
|
private static Border? FindRadioCircle(Border optionBorder)
|
|
{
|
|
if (optionBorder.Child is StackPanel stackPanel && stackPanel.Children.Count > 0 && stackPanel.Children[0] is Border { Child: Border child })
|
|
{
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static string? Show(string question, List<string> options, string defaultValue = "")
|
|
{
|
|
UserAskDialog userAskDialog = new UserAskDialog(question, options, defaultValue);
|
|
return (userAskDialog.ShowDialog() == true) ? userAskDialog.SelectedResponse : null;
|
|
}
|
|
}
|