Skip to content

Commit 118aad2

Browse files
committed
Added apply options support to net graph form.
1 parent 75a142b commit 118aad2

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Source/Forms/NetGraphForm.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ private void ToggleWindowVisibility() {
134134
}
135135
}
136136

137-
private void Sampler_SampleAdded(NetworkInterfaceSampler sampler, Sample sample) {
138-
UpdateStats();
139-
UpdateTray();
140-
}
141-
142137
private bool CanSnap(int clientEdge, int containerEdge, int tension) {
143138
const int DOCK_DISTANCE = 10;
144139

@@ -181,6 +176,9 @@ private void reset_Click(object sender, EventArgs e) {
181176
private void settings_Click(object sender, EventArgs e) {
182177
using (var optionsForm = new OptionsForm(Options.Clone())) {
183178
optionsForm.Icon = Icon;
179+
optionsForm.ApplyOptions += (_, options) => {
180+
Options = options.Clone();
181+
};
184182

185183
if (optionsForm.ShowDialog(this) == DialogResult.OK) {
186184
Options = optionsForm.Options;
@@ -198,6 +196,11 @@ private void showMenuItem_Click(object sender, EventArgs e) {
198196
ToggleWindowVisibility();
199197
}
200198

199+
private void Sampler_SampleAdded(NetworkInterfaceSampler sampler, Sample sample) {
200+
UpdateStats();
201+
UpdateTray();
202+
}
203+
201204
private void NetGraphForm_Resize(object sender, EventArgs e) {
202205
ShowInTaskbar = WindowState != FormWindowState.Minimized;
203206
}

Source/Forms/OptionsForm.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ internal OptionsForm(Options options) {
2121
LoadNetworkInterfaces();
2222
}
2323

24+
internal delegate void ApplyOptionsDelegate(OptionsForm sender, Options options);
25+
26+
internal event ApplyOptionsDelegate ApplyOptions;
27+
2428
private void SaveSettings() {
2529
if (SelectedNic != null) {
2630
Options.NicSpeeds[SelectedNic.Id] = ulong.Parse(customSpeed.Text);
@@ -88,6 +92,8 @@ private void cancel_Click(object sender, EventArgs e) {
8892

8993
private void apply_Click(object sender, EventArgs e) {
9094
SaveSettings();
95+
96+
ApplyOptions?.Invoke(this, Options);
9197
}
9298

9399
private void nics_SelectedIndexChanged(object sender, EventArgs e) {

Source/Options.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public Options(Settings settings) {
1414

1515
NetworkInterface = NetworkInterfaces.Fetch(settings.LastNic);
1616
NicSpeeds = settings.NicSpeeds;
17+
Bounds = settings.Bounds;
1718
Topmost = settings.Topmost;
1819
Transparent = settings.Transparent;
19-
Bounds = settings.Bounds;
2020
}
2121

2222
public NetworkInterface NetworkInterface { get; set; }
@@ -39,9 +39,9 @@ public Options Clone() {
3939
public void Save() {
4040
settings.LastNic = NetworkInterface?.Id;
4141
settings.NicSpeeds = NicSpeeds;
42+
settings.Bounds = Bounds;
4243
settings.Topmost = Topmost;
4344
settings.Transparent = Transparent;
44-
settings.Bounds = Bounds;
4545

4646
settings.Save();
4747
}

0 commit comments

Comments
 (0)