Skip to content

Commit 54174f7

Browse files
committed
uses Panel in place of Page.Panel
1 parent f1bca8b commit 54174f7

File tree

3 files changed

+63
-55
lines changed

3 files changed

+63
-55
lines changed

Source/Menu/MainForm.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,6 @@ private void ToggleNotificationPages()
14621462
if (NotificationManager.ArePagesVisible == false)
14631463
{
14641464
NotificationManager.ArePagesVisible = true; // Set before calling ShowNotifcations()
1465-
//UpdateNotificationPageAlert();
14661465
ShowNotificationPages();
14671466
}
14681467
else
@@ -1500,10 +1499,9 @@ public void UpdateNotificationPageAlert()
15001499
// 3 should be enough, but is there a way to get unlimited buttons?
15011500
public void Button0_Click(object sender, EventArgs e)
15021501
{
1503-
if (NotificationManager.Notifications == null) // button0 is "Retry"
1502+
if (NotificationManager.Notifications == null) // button0 used for "Retry"
15041503
{
15051504
NotificationManager.CheckNotifications();
1506-
//UpdateNotificationPageAlert();
15071505
ShowNotificationPages();
15081506
}
15091507
else NotificationManager.Page.DoButton(UpdateManager, 0);

Source/Menu/Notifications/NotificationManager.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@
3535

3636
// Notifications are read only once as a background task at start into NotificationList.
3737
// Every time the notifications page is re-visited, the position is discarded and first page is shown.
38-
// Every time the notifications page is re-visited, the options may have changed, so
38+
// Every time the notifications page is re-visited, the Update Mode option may have changed, so
3939
// the visibility of each notification in NotificationList is re-assessed. Also its date.
4040
// Every time the notifications page is re-visited or the page is incremented up or down,
41-
// the current notification is re-assessed and the panel is re-loaded with items for the current page.
41+
// the panel is re-loaded with items for the current page.
4242

4343
namespace ORTS
4444
{
4545
public class NotificationManager
4646
{
47+
// The Page points to the MainForm.Panel which holds the items for the current notification.
48+
public NotificationPage Page { get; private set; }
49+
4750
public class PageTracking
4851
{
4952
// Notifications are listed in reverse date order, with the newest one at the front.
@@ -67,7 +70,6 @@ public class PageTracking
6770
private readonly UserSettings Settings;
6871
private readonly Panel Panel;
6972

70-
public NotificationPage Page { get; private set; }
7173
public Image PreviousImage { get; private set; }
7274
public Image NextImage { get; private set; }
7375
public Image FirstImage { get; private set; }
@@ -221,7 +223,7 @@ public void PopulatePage()
221223
var n = list[CurrentNotificationNo];
222224
LogNotification(n);
223225

224-
Page.NDetailList.Add(new NTitleControl(Page, CurrentNotificationNo + 1, list.Count, n.Date, n.Title));
226+
Page.NDetailList.Add(new NTitleControl(Panel, CurrentNotificationNo + 1, list.Count, n.Date, n.Title));
225227

226228
// Check constraints for each item
227229
foreach (var item in n.ItemList)
@@ -230,8 +232,8 @@ public void PopulatePage()
230232
}
231233
}
232234

233-
Page.NDetailList.Add(new NTextControl(Page, ""));
234-
Page.NDetailList.Add(new NTextControl(Page, "(Toggle icon to hide these notifications.)"));
235+
Page.NDetailList.Add(new NTextControl(Panel, ""));
236+
Page.NDetailList.Add(new NTextControl(Panel, "(Toggle icon to hide these notifications.)"));
235237
}
236238

237239
private void PopulateRetryPage()
@@ -241,16 +243,17 @@ private void PopulateRetryPage()
241243
// Reports notifications are not available.
242244
var channelName = UpdateManager.ChannelName == "" ? "None" : UpdateManager.ChannelName;
243245
var today = DateTime.Now.Date;
244-
Page.NDetailList.Add(new NTitleControl(Page, 1, 1, $"{today:dd-MMM-yy}", "Notifications are not available"));
245-
Page.NDetailList.Add(new NRecordControl(Page, "Update mode", 140, channelName));
246-
Page.NDetailList.Add(new NRecordControl(Page, "Installed version", 140, VersionInfo.VersionOrBuild));
246+
Page.NDetailList.Add(new NTitleControl(Panel, 1, 1, $"{today:dd-MMM-yy}", "Notifications are not available"));
247+
248+
Page.NDetailList.Add(new NRecordControl(Panel, "Update mode", 140, channelName));
249+
Page.NDetailList.Add(new NRecordControl(Panel, "Installed version", 140, VersionInfo.VersionOrBuild));
247250

248-
Page.NDetailList.Add(new NHeadingControl(Page, "Notifications are not available", "red"));
251+
Page.NDetailList.Add(new NHeadingControl(Panel, "Notifications are not available", "red"));
249252
var message = (UpdateManager.LastCheckError != null)
250253
? UpdateManager.LastCheckError.Message
251254
: Error.Message;
252-
Page.NDetailList.Add(new NTextControl(Page, $"Error: {message}"));
253-
Page.NDetailList.Add(new NTextControl(Page, "Is your Internet connected?"));
255+
Page.NDetailList.Add(new NTextControl(Panel, $"Error: {message}"));
256+
Page.NDetailList.Add(new NTextControl(Panel, "Is your Internet connected?"));
254257

255258
Page.NDetailList.Add(new NRetryControl(Page, "Retry", 140, "Try again to fetch notifications", MainForm));
256259
}
@@ -373,31 +376,31 @@ private void AddItemToPage(NotificationPage page, Item item)
373376
{
374377
if (item is Record record)
375378
{
376-
Page.NDetailList.Add(new NRecordControl(page, item.Label, item.Indent, record.Value));
379+
Page.NDetailList.Add(new NRecordControl(Panel, item.Label, item.Indent, record.Value));
377380
}
378381
else if (item is Link link)
379382
{
380383
var url = GetUrl(link);
381384
if (string.IsNullOrEmpty(url) == false)
382385
{
383-
Page.NDetailList.Add(new NLinkControl(page, item.Label, item.Indent, link.Value, MainForm, url));
386+
Page.NDetailList.Add(new NLinkControl(Page, item.Label, item.Indent, link.Value, MainForm, url));
384387
}
385388
}
386389
else if (item is Update update)
387390
{
388-
Page.NDetailList.Add(new NUpdateControl(page, item.Label, item.Indent, update.Value, MainForm));
391+
Page.NDetailList.Add(new NUpdateControl(Page, item.Label, item.Indent, update.Value, MainForm));
389392
}
390393
else if (item is Heading heading)
391394
{
392-
Page.NDetailList.Add(new NHeadingControl(page, item.Label, heading.Color));
395+
Page.NDetailList.Add(new NHeadingControl(Panel, item.Label, heading.Color));
393396
}
394397
else if (item is Text text)
395398
{
396-
Page.NDetailList.Add(new NTextControl(page, item.Label, text.Color));
399+
Page.NDetailList.Add(new NTextControl(Panel, item.Label, text.Color));
397400
}
398401
else
399402
{
400-
Page.NDetailList.Add(new NTextControl(page, item.Label));
403+
Page.NDetailList.Add(new NTextControl(Panel, item.Label));
401404
}
402405
}
403406

Source/Menu/Notifications/NotificationPage.cs

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@
2626

2727
namespace ORTS
2828
{
29+
/// <summary>
30+
/// Holds presentation details of the current notification displayed on the panel.
31+
/// </summary>
2932
public class NotificationPage
3033
{
34+
private Panel Panel; // Needed so that controls can be added
35+
private MainForm MainForm; // Needed so the Retry button can raise an event which the form can catch.
36+
37+
// Holds size of items, so they can be positioned on the panel
3138
public List<NDetail> NDetailList = new List<NDetail>();
39+
40+
// Holds the index of each button on the page and the button, so the correct action can be taken depending on the type of button and its index.
3241
public Dictionary<int, NButtonControl> ButtonDictionary = new Dictionary<int, NButtonControl>();
33-
public Panel Panel;
34-
private MainForm MainForm; // Needed so the Retry button can raise an event which the form can catch.
35-
public List<Control> ControlList = new List<Control>();
3642

3743
public NotificationPage(MainForm mainForm, Panel panel, NotificationManager manager)
3844
{
@@ -44,7 +50,7 @@ public NotificationPage(MainForm mainForm, Panel panel, NotificationManager mana
4450

4551
private void AddPageCountAndArrows(NotificationManager manager)
4652
{
47-
var pageCount = manager.Notifications?.NotificationList.Count ?? 0; // If not Internet, then Notifications == null
53+
var pageCount = manager.Notifications?.NotificationList.Count ?? 0; // If no Internet connection, then Notifications == null
4854
var pageLabel = $"{manager.CurrentNotificationNo + 1}/{pageCount}";
4955

5056
// Swap visibility for clickable arrows and disabled ones at each end of range.
@@ -92,6 +98,9 @@ public Arrow(Panel panel, Image image, bool visible, bool enabled, int indentRig
9298
}
9399
}
94100

101+
#region NDetails
102+
// An NDetail may create one or more controls and add them to the page's panel.
103+
95104
public class NDetail
96105
{
97106
public Label Control;
@@ -107,31 +116,28 @@ public class NDetail
107116
public const int ScrollBarWidth = 20;
108117
}
109118

110-
/// <summary>
111-
/// Title for the notification
112-
/// </summary>
113119
public class NTitleControl : NDetail
114120
{
115-
public NTitleControl(NotificationPage page, int current, int total, string date, string text)// : base(page)
121+
public NTitleControl(Panel panel, int current, int total, string date, string text)
116122
{
117123
var title = $"Notification {current}/{total}: {date} - {text}";
118124
var left = LeftPadding;
119125
Control = new Label
120126
{
121127
Text = title,
122128
UseMnemonic = false,
123-
Font = new Font(page.Panel.Font, FontStyle.Bold),
129+
Font = new Font(panel.Font, FontStyle.Bold),
124130
TextAlign = ContentAlignment.BottomLeft,
125131
Height = TitleHeight,
126-
Width = page.Panel.Width - ScrollBarWidth - left,
132+
Width = panel.Width - ScrollBarWidth - left,
127133
Left = LeftPadding
128134
};
129-
page.Panel.Controls.Add(Control);
135+
panel.Controls.Add(Control);
130136
}
131137
}
132138
public class NHeadingControl : NDetail
133139
{
134-
public NHeadingControl(NotificationPage page, string text, string colorName = "blue") //: base(page)
140+
public NHeadingControl(Panel panel, string text, string colorName = "blue")
135141
{
136142
var color = Color.FromName(colorName);
137143
var left = LeftPadding;
@@ -140,19 +146,19 @@ public NHeadingControl(NotificationPage page, string text, string colorName = "b
140146
ForeColor = color,
141147
Text = text,
142148
UseMnemonic = false,
143-
Font = new Font(page.Panel.Font, FontStyle.Bold),
149+
Font = new Font(panel.Font, FontStyle.Bold),
144150
TextAlign = ContentAlignment.BottomLeft,
145151
Height = HeadingHeight,
146-
Width = page.Panel.Width - ScrollBarWidth - left,
152+
Width = panel.Width - ScrollBarWidth - left,
147153
Left = left,
148154
Top = TopPadding,
149155
};
150-
page.Panel.Controls.Add(Control);
156+
panel.Controls.Add(Control);
151157
}
152158
}
153159
public class NTextControl : NDetail
154160
{
155-
public NTextControl(NotificationPage page, string text, string colorName = "black")// : base(page)
161+
public NTextControl(Panel panel, string text, string colorName = "black")
156162
{
157163
var color = Color.FromName(colorName);
158164
var left = LeftPaddingIndented;
@@ -161,36 +167,36 @@ public NTextControl(NotificationPage page, string text, string colorName = "blac
161167
ForeColor = color,
162168
Text = text,
163169
UseMnemonic = false,
164-
Font = new Font(page.Panel.Font, FontStyle.Regular),
170+
Font = new Font(panel.Font, FontStyle.Regular),
165171
TextAlign = ContentAlignment.BottomLeft,
166172
Height = TextHeight,
167-
Width = page.Panel.Width - ScrollBarWidth - left,
173+
Width = panel.Width - ScrollBarWidth - left,
168174
Left = left,
169175
};
170-
page.Panel.Controls.Add(Control);
176+
panel.Controls.Add(Control);
171177
}
172178
}
173179
public class NButtonControl : NDetail
174180
{
175181
public static int ButtonCount = 0;
176182
public Button Button;
177-
public NButtonControl(NotificationPage page, string legend, int width, string description, MainForm mainForm) //: base(page)
183+
public NButtonControl(Panel panel, string legend, int width, string description, MainForm mainForm)
178184
{
179185
var buttonLeft = LeftPaddingIndented;
180186
Button = new Button
181187
{
182188
Margin = new Padding(20),
183189
Text = legend,
184190
UseMnemonic = false,
185-
Font = new Font(page.Panel.Font, FontStyle.Regular),
191+
Font = new Font(panel.Font, FontStyle.Regular),
186192
TextAlign = ContentAlignment.MiddleCenter,
187193
Height = ButtonHeight,
188194
Width = width,
189195
Left = buttonLeft,
190196
Top = TopPadding,
191197
BackColor = SystemColors.ButtonFace
192198
};
193-
page.Panel.Controls.Add(Button);
199+
panel.Controls.Add(Button);
194200

195201
// 3 should be enough, but is there a way to get unlimited buttons?
196202
switch (ButtonCount)
@@ -215,21 +221,21 @@ public NButtonControl(NotificationPage page, string legend, int width, string de
215221
Margin = new Padding(20),
216222
Text = description,
217223
UseMnemonic = false,
218-
Font = new Font(page.Panel.Font, FontStyle.Regular),
224+
Font = new Font(panel.Font, FontStyle.Regular),
219225
TextAlign = ContentAlignment.MiddleLeft,
220226
Height = ButtonHeight,
221-
Width = page.Panel.Width - ScrollBarWidth - labelLeft,
227+
Width = panel.Width - ScrollBarWidth - labelLeft,
222228
Top = TopPadding,
223229
Left = labelLeft
224230
};
225-
page.Panel.Controls.Add(Control);
231+
panel.Controls.Add(Control);
226232
}
227233
}
228234
public class NLinkControl : NButtonControl
229235
{
230236
public string Url;
231237
public NLinkControl(NotificationPage page, string legend, int width, string description, MainForm mainForm, string url)
232-
: base(page, legend, width, description, mainForm)
238+
: base(page.Panel, legend, width, description, mainForm)
233239
{
234240
Url = url;
235241
page.ButtonDictionary.Add(ButtonCount, this);
@@ -239,7 +245,7 @@ public NLinkControl(NotificationPage page, string legend, int width, string desc
239245
public class NUpdateControl : NButtonControl
240246
{
241247
public NUpdateControl(NotificationPage page, string legend, int width, string description, MainForm mainForm)
242-
: base(page, legend, width, description, mainForm)
248+
: base(page.Panel, legend, width, description, mainForm)
243249
{
244250
page.ButtonDictionary.Add(ButtonCount, this);
245251
ButtonCount++;
@@ -248,7 +254,7 @@ public NUpdateControl(NotificationPage page, string legend, int width, string de
248254
public class NRetryControl : NButtonControl
249255
{
250256
public NRetryControl(NotificationPage page, string legend, int width, string description, MainForm mainForm)
251-
: base(page, legend, width, description, mainForm)
257+
: base(page.Panel, legend, width, description, mainForm)
252258
{
253259
page.ButtonDictionary.Add(ButtonCount, this);
254260
ButtonCount++;
@@ -271,34 +277,34 @@ public class NRecordControl : NDetail
271277
{
272278
public Label Field;
273279

274-
public NRecordControl(NotificationPage page, string label, int width, string field)//: base(page)
280+
public NRecordControl(Panel panel, string label, int width, string field)//: base(page)
275281
{
276282
Control = new Label
277283
{
278284
Text = label + ":",
279285
UseMnemonic = false,
280-
Font = new Font(page.Panel.Font, FontStyle.Bold),
286+
Font = new Font(panel.Font, FontStyle.Bold),
281287
TextAlign = ContentAlignment.BottomRight,
282288
Width = width,
283289
Height = RecordHeight,
284290
Left = LeftPadding,
285291
Top = TopPadding
286292
};
287-
page.Panel.Controls.Add(Control);
293+
panel.Controls.Add(Control);
288294

289295
var left = width + LeftPadding;
290296
Field = new Label
291297
{
292298
Text = field,
293299
UseMnemonic = false,
294-
Font = new Font(page.Panel.Font, FontStyle.Regular),
300+
Font = new Font(panel.Font, FontStyle.Regular),
295301
TextAlign = ContentAlignment.BottomLeft,
296-
Width = page.Panel.Width - ScrollBarWidth - left,
302+
Width = panel.Width - ScrollBarWidth - left,
297303
Height = RecordHeight,
298304
Left = left,
299305
Top = TopPadding
300306
};
301-
page.Panel.Controls.Add(Field);
307+
panel.Controls.Add(Field);
302308
}
303309
}
304310

@@ -323,5 +329,6 @@ public void FlowNDetails()
323329
top += nDetail.Control.Height + NDetail.VerticalSpacing;
324330
}
325331
}
332+
#endregion NDetails
326333
}
327334
}

0 commit comments

Comments
 (0)