Skip to content

Commit

Permalink
add context menu to tray icon, for #20
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 15, 2021
1 parent 6ed17d7 commit a151ff4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 20 deletions.
74 changes: 56 additions & 18 deletions KeyboardChatterBlocker/MainBlockerForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions KeyboardChatterBlocker/MainBlockerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,27 @@ public void MainBlockerForm_Load(object sender, EventArgs e)
/// </summary>
public void StatsUpdateTimer_Tick(object sender, EventArgs e)
{
if (Program.Blocker.AnyKeyChange && !IsHidden && tabControl1.SelectedTab == StatsTabPage)
if (Program.Blocker.AnyKeyChange && !IsHidden && TabControl1.SelectedTab == StatsTabPage)
{
Program.Blocker.AnyKeyChange = false;
PushStatsToGrid();
}
}

/// <summary>
/// If enabled, any close should fully close the form and exit the program.
/// </summary>
public bool ShouldForceClose = false;

/// <summary>
/// Event method auto-called when the form close button is pressed.
/// </summary>
public void MainBlockerForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (ShouldForceClose)
{
return;
}
if (e.CloseReason != CloseReason.UserClosing) // Don't block windows shutdown, etc.
{
return;
Expand Down Expand Up @@ -431,7 +440,7 @@ private void ChatterLogGrid_CellContentDoubleClick(object sender, DataGridViewCe
ConfigureKeysGrid.Rows.Add(key.Stringify(), Program.Blocker.GlobalChatterTimeLimit.ToString(), "[X]");
}
string keyText = key.Stringify();
tabControl1.SelectedTab = KeysTabPage;
TabControl1.SelectedTab = KeysTabPage;
foreach (DataGridViewRow row in ConfigureKeysGrid.Rows)
{
if (row.Cells[0].Value.ToString() == keyText)
Expand Down Expand Up @@ -563,5 +572,21 @@ private void AutoDisableProgramsList_Click(object sender, EventArgs e)
AddProgramTextBox.Text = selected.Text;
}
}

/// <summary>
/// Event method to handle clicks of the tray icon.
/// </summary>
private void TrayIconContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem == ContextMenuShowButton)
{
ShowForm();
}
else if (e.ClickedItem == ContextMenuExitButton)
{
ShouldForceClose = true;
Close();
}
}
}
}
3 changes: 3 additions & 0 deletions KeyboardChatterBlocker/MainBlockerForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<metadata name="TrayIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="trayIconContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>115, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="TrayIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down

0 comments on commit a151ff4

Please sign in to comment.