262 lines
7.3 KiB
C#
262 lines
7.3 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Effects;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace AxCopilot.Views;
|
|
|
|
internal sealed class PromptTemplateDialog : Window
|
|
{
|
|
private readonly TextBox _nameBox;
|
|
|
|
private readonly TextBox _contentBox;
|
|
|
|
public string TemplateName => _nameBox.Text.Trim();
|
|
|
|
public string TemplateContent => _contentBox.Text.Trim();
|
|
|
|
public PromptTemplateDialog(string existingName = "", string existingContent = "")
|
|
{
|
|
bool flag = !string.IsNullOrEmpty(existingName);
|
|
base.Title = (flag ? "템플릿 편집" : "템플릿 추가");
|
|
base.Width = 480.0;
|
|
base.SizeToContent = SizeToContent.Height;
|
|
base.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
|
base.ResizeMode = ResizeMode.NoResize;
|
|
base.WindowStyle = WindowStyle.None;
|
|
base.AllowsTransparency = true;
|
|
base.Background = Brushes.Transparent;
|
|
Brush background = (Application.Current.TryFindResource("LauncherBackground") as Brush) ?? new SolidColorBrush(Color.FromRgb(26, 27, 46));
|
|
Brush foreground = (Application.Current.TryFindResource("PrimaryText") as Brush) ?? Brushes.White;
|
|
Brush foreground2 = (Application.Current.TryFindResource("SecondaryText") as Brush) ?? Brushes.Gray;
|
|
Brush brush = (Application.Current.TryFindResource("AccentColor") as Brush) ?? Brushes.Blue;
|
|
Brush background2 = (Application.Current.TryFindResource("ItemBackground") as Brush) ?? new SolidColorBrush(Color.FromRgb(42, 43, 64));
|
|
Brush brush2 = (Application.Current.TryFindResource("BorderColor") as Brush) ?? Brushes.Gray;
|
|
Border border = new Border
|
|
{
|
|
Background = background,
|
|
CornerRadius = new CornerRadius(16.0),
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0),
|
|
Padding = new Thickness(28.0, 24.0, 28.0, 24.0),
|
|
Effect = new DropShadowEffect
|
|
{
|
|
BlurRadius = 24.0,
|
|
ShadowDepth = 4.0,
|
|
Opacity = 0.3,
|
|
Color = Colors.Black
|
|
}
|
|
};
|
|
StackPanel stackPanel = new StackPanel();
|
|
StackPanel stackPanel2 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 20.0)
|
|
};
|
|
stackPanel2.Children.Add(new TextBlock
|
|
{
|
|
Text = "\ue8a5",
|
|
FontFamily = new FontFamily("Segoe MDL2 Assets"),
|
|
FontSize = 18.0,
|
|
Foreground = brush,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Margin = new Thickness(0.0, 0.0, 10.0, 0.0)
|
|
});
|
|
stackPanel2.Children.Add(new TextBlock
|
|
{
|
|
Text = (flag ? "템플릿 편집" : "새 프롬프트 템플릿"),
|
|
FontSize = 17.0,
|
|
FontWeight = FontWeights.Bold,
|
|
Foreground = foreground,
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
});
|
|
stackPanel.Children.Add(stackPanel2);
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "템플릿 이름",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "목록에 표시될 이름입니다. 예: 코드 리뷰 요청, 번역 요청",
|
|
FontSize = 11.0,
|
|
Foreground = foreground2,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
|
|
});
|
|
_nameBox = new TextBox
|
|
{
|
|
Text = existingName,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0)
|
|
};
|
|
Border element = new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _nameBox
|
|
};
|
|
stackPanel.Children.Add(element);
|
|
stackPanel.Children.Add(new Rectangle
|
|
{
|
|
Height = 1.0,
|
|
Fill = brush2,
|
|
Margin = new Thickness(0.0, 16.0, 0.0, 16.0),
|
|
Opacity = 0.5
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "프롬프트 내용",
|
|
FontSize = 12.0,
|
|
FontWeight = FontWeights.SemiBold,
|
|
Foreground = foreground,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 6.0)
|
|
});
|
|
stackPanel.Children.Add(new TextBlock
|
|
{
|
|
Text = "채팅 입력란에 자동으로 삽입될 텍스트입니다.",
|
|
FontSize = 11.0,
|
|
Foreground = foreground2,
|
|
Margin = new Thickness(0.0, 0.0, 0.0, 8.0)
|
|
});
|
|
_contentBox = new TextBox
|
|
{
|
|
Text = existingContent,
|
|
FontSize = 13.0,
|
|
Padding = new Thickness(12.0, 8.0, 12.0, 8.0),
|
|
Foreground = foreground,
|
|
Background = background2,
|
|
CaretBrush = brush,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0),
|
|
AcceptsReturn = true,
|
|
TextWrapping = TextWrapping.Wrap,
|
|
MinHeight = 100.0,
|
|
MaxHeight = 240.0,
|
|
VerticalScrollBarVisibility = ScrollBarVisibility.Auto
|
|
};
|
|
Border element2 = new Border
|
|
{
|
|
CornerRadius = new CornerRadius(8.0),
|
|
ClipToBounds = true,
|
|
Child = _contentBox
|
|
};
|
|
stackPanel.Children.Add(element2);
|
|
TextBlock charCount = new TextBlock
|
|
{
|
|
FontSize = 10.5,
|
|
Foreground = foreground2,
|
|
Margin = new Thickness(0.0, 6.0, 0.0, 0.0),
|
|
HorizontalAlignment = HorizontalAlignment.Right
|
|
};
|
|
UpdateCharCount(charCount);
|
|
_contentBox.TextChanged += delegate
|
|
{
|
|
UpdateCharCount(charCount);
|
|
};
|
|
stackPanel.Children.Add(charCount);
|
|
StackPanel stackPanel3 = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
HorizontalAlignment = HorizontalAlignment.Right,
|
|
Margin = new Thickness(0.0, 20.0, 0.0, 0.0)
|
|
};
|
|
Button button = new Button
|
|
{
|
|
Content = "취소",
|
|
Width = 80.0,
|
|
Padding = new Thickness(0.0, 8.0, 0.0, 8.0),
|
|
Margin = new Thickness(0.0, 0.0, 10.0, 0.0),
|
|
Background = Brushes.Transparent,
|
|
Foreground = foreground2,
|
|
BorderBrush = brush2,
|
|
BorderThickness = new Thickness(1.0),
|
|
Cursor = Cursors.Hand,
|
|
FontSize = 13.0
|
|
};
|
|
button.Click += delegate
|
|
{
|
|
base.DialogResult = false;
|
|
Close();
|
|
};
|
|
stackPanel3.Children.Add(button);
|
|
Button button2 = new Button
|
|
{
|
|
Content = (flag ? "저장" : "추가"),
|
|
Width = 80.0,
|
|
Padding = new Thickness(0.0, 8.0, 0.0, 8.0),
|
|
Background = brush,
|
|
Foreground = Brushes.White,
|
|
BorderThickness = new Thickness(0.0),
|
|
Cursor = Cursors.Hand,
|
|
FontSize = 13.0,
|
|
FontWeight = FontWeights.SemiBold
|
|
};
|
|
button2.Click += delegate
|
|
{
|
|
if (string.IsNullOrWhiteSpace(_nameBox.Text))
|
|
{
|
|
CustomMessageBox.Show("템플릿 이름을 입력하세요.", "입력 오류", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
_nameBox.Focus();
|
|
}
|
|
else if (string.IsNullOrWhiteSpace(_contentBox.Text))
|
|
{
|
|
CustomMessageBox.Show("프롬프트 내용을 입력하세요.", "입력 오류", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
_contentBox.Focus();
|
|
}
|
|
else
|
|
{
|
|
base.DialogResult = true;
|
|
Close();
|
|
}
|
|
};
|
|
stackPanel3.Children.Add(button2);
|
|
stackPanel.Children.Add(stackPanel3);
|
|
border.Child = stackPanel;
|
|
base.Content = border;
|
|
base.KeyDown += delegate(object _, KeyEventArgs ke)
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
if ((int)ke.Key == 13)
|
|
{
|
|
base.DialogResult = false;
|
|
Close();
|
|
}
|
|
};
|
|
base.Loaded += delegate
|
|
{
|
|
_nameBox.Focus();
|
|
_nameBox.SelectAll();
|
|
};
|
|
border.MouseLeftButtonDown += delegate(object _, MouseButtonEventArgs me)
|
|
{
|
|
if (me.LeftButton == MouseButtonState.Pressed)
|
|
{
|
|
try
|
|
{
|
|
DragMove();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
private void UpdateCharCount(TextBlock tb)
|
|
{
|
|
int length = _contentBox.Text.Length;
|
|
tb.Text = $"{length}자";
|
|
}
|
|
}
|