-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsWindow.cs
123 lines (100 loc) · 4.05 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace MusicBeePlugin
{
public partial class SettingsWindow : Form
{
private readonly Plugin plugin;
private readonly Settings settings;
public SettingsWindow(Plugin plugin, Settings settings)
{
this.plugin = plugin;
this.settings = settings;
InitializeComponent();
}
private void OnShown(object sender, EventArgs eventArgs)
{
requestMethodComboBox.Text = settings.RequestMethod;
requestUriTextBox.Text = settings.RequestUri;
mediaTypeComboBox.Text = settings.MediaType;
contentTextBox.Text = settings.Content;
var fields = new Dictionary<string, string>{
{ "property:Bitrate", "Bitrate" },
{ "property:Channels", "Channels" },
{ "property:Duration", "Duration" },
{ "property:Format", "Format" },
{ "property:Kind", "Kind" },
{ "property:SampleRate", "Sample Rate" },
{ "property:Size", "Size" },
{ "property:Status", "Status" },
{ "property:Url", "Url" },
{ "tag:Album", "Album" },
{ "tag:AlbumArtist", "Album Artist" },
{ "tag:Artist", "Artist" },
{ "tag:Artwork", "Artwork" },
{ "tag:BeatsPerMin", "Beats Per Minute" },
{ "tag:Composer", "Composer" },
{ "tag:Comment", "Comment" },
{ "tag:DiscNo", "Disc Number" },
{ "tag:DiscCount", "Disc Count" },
{ "tag:Encoder", "Encoder" },
{ "tag:Genre", "Genre" },
{ "tag:TrackCount", "Track Count" },
{ "tag:TrackNo", "Track Number" },
{ "tag:TrackTitle", "Track Title" },
{ "tag:Year", "Year" },
};
foreach (var field in fields)
{
var button = new Button
{
Dock = DockStyle.Top,
Tag = field.Key,
Text = field.Value,
};
button.Click += OnFieldClick;
fieldsPanel.Controls.Add(button);
}
foreach (var pair in settings.Headers)
headersDataGridView.Rows.Add(new string[] { pair.Key, pair.Value });
}
private void OnSave(object sender, EventArgs e)
{
var headers = new Dictionary<string, string>();
foreach (DataGridViewRow row in headersDataGridView.Rows)
{
var name = $"{row.Cells[0].Value}";
var value = $"{row.Cells[1].Value}";
if (string.IsNullOrEmpty(name))
continue;
headers.Add(name, value);
}
settings.RequestMethod = requestMethodComboBox.Text;
settings.RequestUri = requestUriTextBox.Text;
settings.MediaType = mediaTypeComboBox.Text;
settings.Content = contentTextBox.Text;
settings.Headers = headers;
settings.Save();
Close();
}
private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
headersDataGridView.Rows[e.RowIndex].Tag = e.Value;
if (e.ColumnIndex == 1 && e.Value != null)
e.Value = new string('\u25CF', e.Value.ToString().Length);
}
private void OnEditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
var tag = headersDataGridView.CurrentRow.Tag;
if (tag != null)
e.Control.Text = tag.ToString();
}
private void OnFieldClick(object sender, EventArgs e)
{
var button = sender as Button;
var fieldName = $"{{{button.Tag}}}";
contentTextBox.Text = contentTextBox.Text.Insert(contentTextBox.SelectionStart, fieldName);
}
}
}