-
Notifications
You must be signed in to change notification settings - Fork 2
/
InputDialog.xaml.cs
62 lines (54 loc) · 1.73 KB
/
InputDialog.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Windows;
using System.Windows.Input;
namespace ChatGPTExtension
{
public partial class InputDialog : Window
{
public InputDialog(string title, string question, string defaultAnswer = "")
{
InitializeComponent();
this.Title = title;
lblQuestion.Content = question;
txtAnswer.Text = defaultAnswer;
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
// Attach KeyDown event handler to the TextBox
txtAnswer.KeyDown += TxtAnswer_KeyDown;
// Select txtAnswer until the "." in the string
int index = defaultAnswer.IndexOf('.');
if (index > 0)
{
txtAnswer.Select(0, index);
}
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
txtAnswer.Focus(); // Set focus to the TextBox when the window is activated
}
private void TxtAnswer_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
btnDialogOk_Click(this, new RoutedEventArgs());
}
else if (e.Key == Key.Escape)
{
btnDialogCancel_Click(this, new RoutedEventArgs());
}
}
private void btnDialogOk_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void btnDialogCancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
public string ResponseText
{
get { return txtAnswer.Text; }
}
}
}