forked from sll552/DiscordBee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsWindow.cs
97 lines (85 loc) · 2.92 KB
/
SettingsWindow.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Windows.Forms;
namespace MusicBeePlugin
{
public partial class SettingsWindow : Form
{
private readonly Plugin _parent;
private PlaceholderTableWindow _placeholderTableWindow;
private readonly Settings _settings;
private bool _defaultsRestored;
public SettingsWindow(Plugin parent, Settings settings)
{
_parent = parent;
_settings = settings;
InitializeComponent();
UpdateValues(_settings);
Text += " (v" + parent.GetVersionString() + ")";
FormClosing += OnFormClosing;
Shown += OnShown;
VisibleChanged += OnVisibleChanged;
}
private void OnVisibleChanged(object sender, EventArgs eventArgs)
{
if (Visible)
{
UpdateValues(_settings);
}
}
private void OnShown(object sender, EventArgs eventArgs)
{
UpdateValues(_settings);
}
private void OnFormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason != CloseReason.UserClosing) return;
Hide();
e.Cancel = true;
}
private void UpdateValues(Settings settings)
{
textBoxTrackNo.Text = settings.PresenceTrackNo;
textBoxTrackCnt.Text = settings.PresenceTrackCnt;
textBoxDetails.Text = settings.PresenceDetails;
textBoxState.Text = settings.PresenceState;
textBoxLargeImage.Text = settings.LargeImageText;
textBoxSmallImage.Text = settings.SmallImageText;
textBoxSeperator.Text = settings.Seperator;
checkBoxPresenceUpdate.Checked = settings.UpdatePresenceWhenStopped;
checkBoxShowRemainingTime.Checked = settings.ShowRemainingTime;
checkBoxTextOnly.Checked = settings.TextOnly;
}
private void buttonPlaceholders_Click(object sender, EventArgs e)
{
_placeholderTableWindow = new PlaceholderTableWindow();
_placeholderTableWindow.UpdateTable(_parent.GenerateMetaDataDictionary());
_placeholderTableWindow.Show(this);
}
private void buttonRestoreDefaults_Click(object sender, EventArgs e)
{
_settings.Clear();
UpdateValues(_settings);
_defaultsRestored = true;
}
private void buttonSaveClose_Click(object sender, EventArgs e)
{
_settings.PresenceTrackNo = textBoxTrackNo.Text;
_settings.PresenceTrackCnt = textBoxTrackCnt.Text;
_settings.PresenceDetails = textBoxDetails.Text;
_settings.PresenceState = textBoxState.Text;
_settings.LargeImageText = textBoxLargeImage.Text;
_settings.SmallImageText = textBoxSmallImage.Text;
_settings.Seperator = textBoxSeperator.Text;
_settings.UpdatePresenceWhenStopped = checkBoxPresenceUpdate.Checked;
_settings.ShowRemainingTime = checkBoxShowRemainingTime.Checked;
_settings.TextOnly = checkBoxTextOnly.Checked;
if (_defaultsRestored && !_settings.IsDirty)
{
_settings.Delete();
_defaultsRestored = false;
}
_settings.Save();
Hide();
}
}
}