Skip to content

Commit a151ff4

Browse files
committed
add context menu to tray icon, for #20
1 parent 6ed17d7 commit a151ff4

File tree

3 files changed

+86
-20
lines changed

3 files changed

+86
-20
lines changed

KeyboardChatterBlocker/MainBlockerForm.Designer.cs

Lines changed: 56 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

KeyboardChatterBlocker/MainBlockerForm.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,27 @@ public void MainBlockerForm_Load(object sender, EventArgs e)
265265
/// </summary>
266266
public void StatsUpdateTimer_Tick(object sender, EventArgs e)
267267
{
268-
if (Program.Blocker.AnyKeyChange && !IsHidden && tabControl1.SelectedTab == StatsTabPage)
268+
if (Program.Blocker.AnyKeyChange && !IsHidden && TabControl1.SelectedTab == StatsTabPage)
269269
{
270270
Program.Blocker.AnyKeyChange = false;
271271
PushStatsToGrid();
272272
}
273273
}
274274

275+
/// <summary>
276+
/// If enabled, any close should fully close the form and exit the program.
277+
/// </summary>
278+
public bool ShouldForceClose = false;
279+
275280
/// <summary>
276281
/// Event method auto-called when the form close button is pressed.
277282
/// </summary>
278283
public void MainBlockerForm_FormClosing(object sender, FormClosingEventArgs e)
279284
{
285+
if (ShouldForceClose)
286+
{
287+
return;
288+
}
280289
if (e.CloseReason != CloseReason.UserClosing) // Don't block windows shutdown, etc.
281290
{
282291
return;
@@ -431,7 +440,7 @@ private void ChatterLogGrid_CellContentDoubleClick(object sender, DataGridViewCe
431440
ConfigureKeysGrid.Rows.Add(key.Stringify(), Program.Blocker.GlobalChatterTimeLimit.ToString(), "[X]");
432441
}
433442
string keyText = key.Stringify();
434-
tabControl1.SelectedTab = KeysTabPage;
443+
TabControl1.SelectedTab = KeysTabPage;
435444
foreach (DataGridViewRow row in ConfigureKeysGrid.Rows)
436445
{
437446
if (row.Cells[0].Value.ToString() == keyText)
@@ -563,5 +572,21 @@ private void AutoDisableProgramsList_Click(object sender, EventArgs e)
563572
AddProgramTextBox.Text = selected.Text;
564573
}
565574
}
575+
576+
/// <summary>
577+
/// Event method to handle clicks of the tray icon.
578+
/// </summary>
579+
private void TrayIconContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
580+
{
581+
if (e.ClickedItem == ContextMenuShowButton)
582+
{
583+
ShowForm();
584+
}
585+
else if (e.ClickedItem == ContextMenuExitButton)
586+
{
587+
ShouldForceClose = true;
588+
Close();
589+
}
590+
}
566591
}
567592
}

KeyboardChatterBlocker/MainBlockerForm.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
<metadata name="TrayIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
133133
<value>17, 17</value>
134134
</metadata>
135+
<metadata name="trayIconContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
136+
<value>115, 17</value>
137+
</metadata>
135138
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
136139
<data name="TrayIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
137140
<value>

0 commit comments

Comments
 (0)