-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileNameDialog.xaml.cs
More file actions
70 lines (61 loc) · 1.6 KB
/
FileNameDialog.xaml.cs
File metadata and controls
70 lines (61 loc) · 1.6 KB
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
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace StageCoder
{
public partial class FileNameDialog : Window
{
private const string DEFAULT_TEXT = "Enter a name for the snippet";
private static readonly List<string> _tips = new List<string> {
"Tip: The name you choose is the same name you can use to trigger the snippet",
"Tip: The snippets gets saved into a folder caller snippets in the solution folder"
};
public FileNameDialog()
{
InitializeComponent();
Loaded += (s, e) =>
{
//Icon = BitmapFrame.Create(new Uri("pack://application:,,,/AddAnyFile;component/Resources/icon.png", UriKind.RelativeOrAbsolute));
Title = "Save selection as snippet";
SetRandomTip();
Name.Focus();
Name.CaretIndex = 0;
Name.Text = DEFAULT_TEXT;
Name.Select(0, Name.Text.Length);
Name.PreviewKeyDown += (a, b) =>
{
if (b.Key == Key.Escape)
{
if (string.IsNullOrWhiteSpace(Name.Text) || Name.Text == DEFAULT_TEXT)
{
Close();
}
else
{
Name.Text = string.Empty;
}
}
else if (Name.Text == DEFAULT_TEXT)
{
Name.Text = string.Empty;
btnCreate.IsEnabled = true;
}
};
};
}
public string Input => Name.Text.Trim();
private void SetRandomTip()
{
Random rnd = new Random(DateTime.Now.GetHashCode());
int index = rnd.Next(_tips.Count);
lblTips.Content = _tips[index];
}
private void Button_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
}
}