@@ -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}
0 commit comments