-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgramPrompt.xaml.cs
80 lines (72 loc) · 1.92 KB
/
ProgramPrompt.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Microsoft.Win32;
using System.Windows;
using System.Windows.Input;
namespace App_Launcher
{
/// <summary>
/// Interaction logic for CategoryPrompt.xaml
/// </summary>
public partial class ProgramPrompt : Window
{
public ProgramPrompt()
{
InitializeComponent();
}
public bool ConfirmClicked { get; private set; } = false;
public (string, string) GetProgram()
{
return (ProgramName.Text, ProgramPath.Text);
}
public bool PromptSucceeded()
{
return !string.IsNullOrEmpty(ProgramName.Text) && !string.IsNullOrEmpty(ProgramPath.Text);
}
public void SetDefault(string Name, string Path)
{
ProgramName.Text = Name;
ProgramPath.Text = Path;
}
private void ConfirmProgram(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
if (string.IsNullOrEmpty(ProgramName.Text))
{
MessageBox.Show("New program requires a name to be added.", "Program Name Required",
MessageBoxButton.OK, MessageBoxImage.Error);
}
else if (string.IsNullOrEmpty(ProgramPath.Text))
{
MessageBox.Show("New program requires a path to be added.", "Program Path Required",
MessageBoxButton.OK, MessageBoxImage.Error);
}
else if (string.IsNullOrEmpty(ProgramName.Text) && string.IsNullOrEmpty(ProgramPath.Text))
{
MessageBox.Show("New program requires a name and path to be added.", "Program Name/Path Required",
MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
ConfirmClicked = true;
Close();
}
}
}
private void SelectProgram(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
OpenFileDialog ofd = new OpenFileDialog
{
Title = "Please select a program to add...",
Filter = "Program|*.exe",
};
if (ofd.ShowDialog() == true)
{
string programPath = ofd.FileName;
ProgramPath.Text = programPath;
}
}
}
}
}