Repository navigation
Expand file tree
/
Copy pathOptionsWindow.cs
More file actions
294 lines (258 loc) · 11.6 KB
/
Copy pathOptionsWindow.cs
File metadata and controls
294 lines (258 loc) · 11.6 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using EasyConnect.Properties;
using System.Configuration;
namespace EasyConnect
{
/// <summary>
/// UI that allows the user to edit the global options associated with the application and the defaults for each connection protocol.
/// </summary>
public partial class OptionsWindow : Form
{
/// <summary>
/// Main application form instance associated with this window.
/// </summary>
protected MainForm _applicationForm = null;
/// <summary>
/// Lookup that associates each left navigation label with the child form that it belongs to.
/// </summary>
protected Dictionary<Label, Form> _optionsFormLabels = new Dictionary<Label, Form>();
/// <summary>
/// List of all of the child options forms; one for the global options and one for each connection protocol.
/// </summary>
protected List<Form> _optionsForms = new List<Form>();
protected HtmlPanel _urlPanel;
/// <summary>
/// Constructor; initializes <see cref="_applicationForm"/>.
/// </summary>
/// <param name="applicationForm">Main application form instance associated with this window.</param>
public OptionsWindow(MainForm applicationForm)
{
_applicationForm = applicationForm;
InitializeComponent();
_toolsMenu.Renderer = new EasyConnectToolStripRender();
_iconPictureBox.Image = new Icon(Icon, 16, 16).ToBitmap();
_urlPanel = new HtmlPanel
{
AutoScroll = false,
Width = _urlPanelContainer.Width,
Height = _urlPanelContainer.Height,
Left = 0,
Top = 1,
Font = urlTextBox.Font,
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top
};
_urlPanelContainer.Controls.Add(_urlPanel);
_urlPanel.Text = String.Format(
@"<span style=""background-color: #FFFFFF; font-family: {2}; font-size: {1}pt; height: {0}px; color: #9999BF"">easyconnect://<font color=""black"">options</font></span>",
_urlPanel.Height, urlTextBox.Font.SizeInPoints, urlTextBox.Font.FontFamily.GetName(0));
#if APPX
_updatesMenuItem.Visible = false;
_toolsMenuSeparator2.Visible = false;
#else
_updatesMenuItem.Visible = ConfigurationManager.AppSettings["checkForUpdates"] != "false";
_toolsMenuSeparator2.Visible = ConfigurationManager.AppSettings["checkForUpdates"] != "false";
#endif
}
/// <summary>
/// List of all of the child options forms; one for the global options and one for each connection protocol.
/// </summary>
public List<Form> OptionsForms
{
get
{
return _optionsForms;
}
set
{
_optionsForms = value;
}
}
/// <summary>
/// Handler method that's called when the form loads initially. Takes all of the entries in <see cref="OptionsForms"/> and creates left navigation
/// labels that, when clicked will display that option form.
/// </summary>
/// <param name="sender">Object from which this event originated.</param>
/// <param name="e">Arguments associated with this event.</param>
private void OptionsWindow_Load(object sender, EventArgs e)
{
if (OptionsForms.Count > 0)
{
foreach (Form form in OptionsForms)
{
Label formLabel = new Label
{
BackColor = Color.White,
TextAlign = ContentAlignment.MiddleLeft,
Padding = new Padding(0, 0, 0, 0),
Size = new Size(233, 29),
Text = " " + form.Text,
Font = new Font("Segoe UI", 10.0f),
Margin = new Padding(0),
Location = new Point(0, 0),
ForeColor = Color.FromArgb(0, 0, 0),
Cursor = Cursors.Hand
};
formLabel.Click += (o, args) => ShowOptionsForm(formLabel);
_optionsFormLabels[formLabel] = form;
_sidebarFlowLayoutPanel.Controls.Add(formLabel);
}
// Show the global options form
ShowOptionsForm((Label) _sidebarFlowLayoutPanel.Controls[1]);
}
}
/// <summary>
/// Called when a left navigation label is clicked and opens the option form associated with that label.
/// </summary>
/// <param name="navigationLabel"></param>
private void ShowOptionsForm(Label navigationLabel)
{
if (navigationLabel.Image != null)
return;
// Get and show the corresponding option form
Form optionsForm = _optionsFormLabels[navigationLabel];
optionsForm.FormBorderStyle = FormBorderStyle.None;
optionsForm.TopLevel = false;
optionsForm.Dock = DockStyle.Fill;
_containerPanel.Controls.Clear();
_containerPanel.Controls.Add(optionsForm);
_containerPanel.AutoScrollMinSize = optionsForm.Size;
optionsForm.Show();
// Set the background image for the label to the "focused" image
foreach (Label label in _sidebarFlowLayoutPanel.Controls.Cast<Label>().Where(c => c.Name != "_optionsLabel"))
{
label.Image = null;
label.ForeColor = Color.FromArgb(0, 0, 0);
label.Font = new Font("Segoe UI", 10.0f);
label.Cursor = Cursors.Hand;
}
navigationLabel.Image = Resources.SelectedOptionCategoryBackground;
navigationLabel.ImageAlign = ContentAlignment.MiddleCenter;
navigationLabel.ForeColor = Color.FromArgb(66, 139, 202);
navigationLabel.Font = new Font("Segoe UI", 10.0f, FontStyle.Bold);
navigationLabel.Cursor = Cursors.Default;
}
/// <summary>
/// Main application instance that this window is associated with, which is used to call back into application functionality.
/// </summary>
protected MainForm ParentTabs
{
get
{
return (MainForm)Parent;
}
}
/// <summary>
/// Handler method that's called when the window starts to close. Calls <see cref="Form.Close"/> on each item in <see cref="OptionsForms"/>, which
/// will cause each window to save its data.
/// </summary>
/// <param name="sender">Object from which this event originated.</param>
/// <param name="e">Arguments associated with this event.</param>
private void OptionsWindow_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (Form form in OptionsForms)
form.Close();
}
/// <summary>
/// Handler method that's called when the user's cursor goes over <see cref="_toolsButton"/>. Sets the button's background to the standard
/// "hover" image.
/// </summary>
/// <param name="sender">Object from which this event originated, <see cref="_toolsButton"/> in this case.</param>
/// <param name="e">Arguments associated with this event.</param>
private void _toolsButton_MouseEnter(object sender, EventArgs e)
{
_toolsButton.BackgroundImage = Resources.ButtonHoverBackground;
}
/// <summary>
/// Handler method that's called when the user's cursor leaves <see cref="_toolsButton"/>. Sets the button's background to nothing.
/// </summary>
/// <param name="sender">Object from which this event originated, <see cref="_toolsButton"/> in this case.</param>
/// <param name="e">Arguments associated with this event.</param>
private void _toolsButton_MouseLeave(object sender, EventArgs e)
{
if (!_toolsMenu.Visible)
_toolsButton.BackgroundImage = null;
}
/// <summary>
/// Handler method that's called when the user clicks the "Exit" menu item in the tools menu. Exits the entire application.
/// </summary>
/// <param name="sender">Object from which this event originated.</param>
/// <param name="e">Arguments associated with this event.</param>
private void _exitMenuItem_Click(object sender, EventArgs e)
{
((Form)Parent).Close();
}
/// <summary>
/// Handler method that's called when the user clicks the "Tools" icon in the toolbar. Opens up <see cref="_toolsMenu"/>.
/// </summary>
/// <param name="sender">Object from which this event originated.</param>
/// <param name="e">Arguments associated with this event.</param>
private void _toolsButton_Click(object sender, EventArgs e)
{
_toolsButton.BackgroundImage = Resources.ButtonPressedBackground;
_toolsMenu.DefaultDropDownDirection = ToolStripDropDownDirection.Left;
_toolsMenu.Show(_toolsButton, -1 * _toolsMenu.Width + _toolsButton.Width, _toolsButton.Height);
}
private void _aboutMenuItem_Click(object sender, EventArgs e)
{
AboutBox aboutBox = new AboutBox();
aboutBox.ShowDialog(ParentTabs);
}
/// <summary>
/// Handler method that's called when the user clicks on the "Check for updates" menu item under the tools menu. Starts the update check process by
/// calling <see cref="MainForm.CheckForUpdate"/> on <see cref="ParentTabs"/>.
/// </summary>
/// <param name="sender">Object from which this event originated.</param>
/// <param name="e">Arguments associated with this event.</param>
private void _updatesMenuItem_Click(object sender, EventArgs e)
{
ParentTabs.CheckForUpdate();
}
/// <summary>
/// Handler method that's called when the user clicks the "History" menu item under the tools menu. Creates the history tab if one doesn't exist
/// already and then switches to it.
/// </summary>
/// <param name="sender">Object from which this event originated.</param>
/// <param name="e">Arguments associated with this event.</param>
private void _historyToolStripMenuItem_Click(object sender, EventArgs e)
{
ParentTabs.OpenHistory();
}
/// <summary>
/// Handler method that's called when the user clicks the <see cref="_newWindowMenuItem"/> in the tools menu. Creates a new <see cref="MainForm"/>
/// instance and opens it.
/// </summary>
/// <param name="sender">Object from which this event originated, <see cref="_newWindowMenuItem"/> in this case.</param>
/// <param name="e">Arguments associated with this event.</param>
private void _newWindowMenuItem_Click(object sender, EventArgs e)
{
MainForm newWindow = new MainForm(new List<Guid>());
ParentTabs.ApplicationContext.OpenWindow(newWindow);
newWindow.Show();
}
/// <summary>
/// Handler method that's called when the user clicks the "New tab" menu item under the tools menu. Creates a new tab and then switches to it.
/// </summary>
/// <param name="sender">Object from which this event originated.</param>
/// <param name="e">Arguments associated with this event.</param>
private void _newTabMenuItem_Click(object sender, EventArgs e)
{
ParentTabs.AddNewTab();
}
private void _toolsMenu_VisibleChanged(object sender, EventArgs e)
{
if (!_toolsMenu.Visible)
_toolsButton.BackgroundImage = null;
}
private void urlBackground_Resize(object sender, EventArgs e)
{
if (_urlPanel != null)
{
_urlPanel.AutoScroll = false;
}
}
}
}