229 lines
7.1 KiB
C#
229 lines
7.1 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Effects;
|
|
|
|
namespace AxCopilot.Views;
|
|
|
|
internal sealed class InputDialog : Window
|
|
{
|
|
private readonly TextBox _textBox;
|
|
|
|
public string ResponseText => _textBox.Text;
|
|
|
|
public InputDialog(string title, string prompt, string defaultValue = "", string placeholder = "")
|
|
{
|
|
base.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
|
base.ResizeMode = ResizeMode.NoResize;
|
|
base.WindowStyle = WindowStyle.None;
|
|
base.AllowsTransparency = true;
|
|
base.Background = Brushes.Transparent;
|
|
base.Width = 400.0;
|
|
base.SizeToContent = SizeToContent.Height;
|
|
Brush background = (Application.Current.TryFindResource("LauncherBackground") as Brush) ?? new SolidColorBrush(Color.FromRgb(26, 27, 46));
|
|
Brush borderBrush = (Application.Current.TryFindResource("BorderColor") as Brush) ?? Brushes.Gray;
|
|
Brush foreground = (Application.Current.TryFindResource("PrimaryText") as Brush) ?? Brushes.White;
|
|
Brush foreground2 = (Application.Current.TryFindResource("SecondaryText") as Brush) ?? Brushes.Gray;
|
|
Brush accentBrush = (Application.Current.TryFindResource("AccentColor") as Brush) ?? Brushes.CornflowerBlue;
|
|
Brush background2 = (Application.Current.TryFindResource("ItemBackground") as Brush) ?? new SolidColorBrush(Color.FromRgb(42, 43, 62));
|
|
Border border = new Border
|
|
{
|
|
Background = background,
|
|
BorderBrush = borderBrush,
|
|
BorderThickness = new Thickness(1.0),
|
|
CornerRadius = new CornerRadius(14.0),
|
|
Margin = new Thickness(16.0),
|
|
Effect = new DropShadowEffect
|
|
{
|
|
BlurRadius = 24.0,
|
|
ShadowDepth = 6.0,
|
|
Opacity = 0.35,
|
|
Color = Colors.Black,
|
|
Direction = 270.0
|
|
}
|
|
};
|
|
StackPanel stackPanel = new StackPanel
|
|
{
|
|
Margin = new Thickness(24.0, 20.0, 24.0, 20.0)
|
|
};
|
|
StackPanel stackPanel2 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 16.0)
|
|
};
|
|
stackPanel2.Children.Add(new TextBlock
|
|
{
|
|
Text = "\ue8ac",
|
|
FontFamily = new FontFamily("Segoe MDL2 Assets"),
|
|
FontSize = 16.0,
|
|
Foreground = accentBrush,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Margin = new Thickness(0.0, 0.0, 10.0, 0.0)
|
|
});
|
|
stackPanel2.Children.Add(new TextBlock
|
|
{
|
|
Text = title,
|
|
FontSize = 15.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
});
|
|
stackPanel.Children.Add(stackPanel2);
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = prompt,
|
|
FontSize = 12.5,
|
|
Foreground = foreground2,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
|
|
});
|
|
_textBox = new TextBox
|
|
{
|
|
Text = defaultValue,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(14.0, 8.0, 14.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = Brushes.Transparent,
|
|
CaretBrush = accentBrush,
|
|
BorderThickness = new Thickness(0.0),
|
|
BorderBrush = Brushes.Transparent
|
|
};
|
|
_textBox.KeyDown += delegate(object _, KeyEventArgs e)
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002c: Invalid comparison between Unknown and I4
|
|
if ((int)e.Key == 6)
|
|
{
|
|
base.DialogResult = true;
|
|
Close();
|
|
}
|
|
if ((int)e.Key == 13)
|
|
{
|
|
base.DialogResult = false;
|
|
Close();
|
|
}
|
|
};
|
|
TextBlock placeholderBlock = new TextBlock
|
|
{
|
|
Text = placeholder,
|
|
FontSize = 13.0,
|
|
Foreground = foreground2,
|
|
Opacity = 0.5,
|
|
IsHitTestVisible = false,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Padding = new Thickness(14.0, 8.0, 14.0, 8.0),
|
|
Visibility = ((!string.IsNullOrEmpty(defaultValue) || string.IsNullOrEmpty(placeholder)) ? Visibility.Collapsed : Visibility.Visible)
|
|
};
|
|
_textBox.TextChanged += delegate
|
|
{
|
|
placeholderBlock.Visibility = ((!string.IsNullOrEmpty(_textBox.Text)) ? Visibility.Collapsed : Visibility.Visible);
|
|
};
|
|
Grid child = new Grid
|
|
{
|
|
Children =
|
|
{
|
|
(UIElement)_textBox,
|
|
(UIElement)placeholderBlock
|
|
}
|
|
};
|
|
Border inputBorder = new Border
|
|
{
|
|
CornerRadius = new CornerRadius(10.0),
|
|
BorderBrush = borderBrush,
|
|
BorderThickness = new Thickness(1.0),
|
|
Background = background2,
|
|
Child = child
|
|
};
|
|
_textBox.GotFocus += delegate
|
|
{
|
|
inputBorder.BorderBrush = accentBrush;
|
|
};
|
|
_textBox.LostFocus += delegate
|
|
{
|
|
inputBorder.BorderBrush = borderBrush;
|
|
};
|
|
stackPanel.Children.Add(inputBorder);
|
|
StackPanel stackPanel3 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
HorizontalAlignment = HorizontalAlignment.Right,
|
|
Margin = new Thickness(0.0, 18.0, 0.0, 0.0)
|
|
};
|
|
Button button = CreateButton("취소", Brushes.Transparent, foreground2, borderBrush);
|
|
button.Click += delegate
|
|
{
|
|
base.DialogResult = false;
|
|
Close();
|
|
};
|
|
stackPanel3.Children.Add(button);
|
|
Button button2 = CreateButton("확인", accentBrush, Brushes.White, null);
|
|
button2.Click += delegate
|
|
{
|
|
base.DialogResult = true;
|
|
Close();
|
|
};
|
|
stackPanel3.Children.Add(button2);
|
|
stackPanel.Children.Add(stackPanel3);
|
|
border.Child = stackPanel;
|
|
base.Content = border;
|
|
stackPanel2.MouseLeftButtonDown += delegate(object _, MouseButtonEventArgs e)
|
|
{
|
|
if (e.ClickCount == 1)
|
|
{
|
|
DragMove();
|
|
}
|
|
};
|
|
base.Loaded += delegate
|
|
{
|
|
_textBox.Focus();
|
|
_textBox.SelectAll();
|
|
};
|
|
}
|
|
|
|
private static Button CreateButton(string text, Brush background, Brush foreground, Brush? borderBrush)
|
|
{
|
|
Button button = new Button
|
|
{
|
|
Cursor = Cursors.Hand,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 0.0)
|
|
};
|
|
if (text == "취소")
|
|
{
|
|
button.Margin = new Thickness(0.0, 0.0, 8.0, 0.0);
|
|
}
|
|
ControlTemplate controlTemplate = new ControlTemplate(typeof(Button));
|
|
FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(Border));
|
|
frameworkElementFactory.SetValue(Border.BackgroundProperty, background);
|
|
frameworkElementFactory.SetValue(Border.CornerRadiusProperty, new CornerRadius(8.0));
|
|
frameworkElementFactory.SetValue(Border.PaddingProperty, new Thickness(20.0, 8.0, 20.0, 8.0));
|
|
frameworkElementFactory.Name = "Bd";
|
|
if (borderBrush != null)
|
|
{
|
|
frameworkElementFactory.SetValue(Border.BorderBrushProperty, borderBrush);
|
|
frameworkElementFactory.SetValue(Border.BorderThicknessProperty, new Thickness(1.0));
|
|
}
|
|
FrameworkElementFactory frameworkElementFactory2 = new FrameworkElementFactory(typeof(ContentPresenter));
|
|
frameworkElementFactory2.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
|
|
frameworkElementFactory2.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
|
|
frameworkElementFactory.AppendChild(frameworkElementFactory2);
|
|
controlTemplate.VisualTree = frameworkElementFactory;
|
|
Trigger trigger = new Trigger
|
|
{
|
|
Property = UIElement.IsMouseOverProperty,
|
|
Value = true
|
|
};
|
|
trigger.Setters.Add(new Setter(UIElement.OpacityProperty, 0.85));
|
|
controlTemplate.Triggers.Add(trigger);
|
|
button.Template = controlTemplate;
|
|
button.Content = new TextBlock
|
|
{
|
|
Text = text,
|
|
FontSize = 13.0,
|
|
Foreground = foreground
|
|
};
|
|
return button;
|
|
}
|
|
}
|