@@ -36,8 +36,7 @@ public partial class Form1 : Form
3636 #endregion
3737
3838 #region ToolBar
39- private ContextMenuStrip trayMenu = new ContextMenuStrip ( ) ;
40- private bool CloseOnTry = false ;
39+ private ContextMenuStrip trayMenu ;
4140
4241 private void ShowMainForm ( )
4342 {
@@ -48,7 +47,6 @@ private void ShowMainForm()
4847 private void CloseHCM ( )
4948 {
5049 notifyIconToolBar . Visible = false ;
51- CloseOnTry = true ;
5250 Application . Exit ( ) ;
5351 }
5452
@@ -109,66 +107,54 @@ private void Form1_Load(object sender, EventArgs e)
109107 #endregion
110108
111109 #region ToolBar
112- trayMenu . Items . Add ( "Open HCM" , null , ( s , e ) => ShowMainForm ( ) ) ;
113-
114- // Timer
115- var timerMenu = new ToolStripMenuItem ( "Timer" ) ;
116- timerMenu . DropDownItems . Add ( "StartTimer" , null , ( s , e ) => StartStopTimer ( true ) ) ;
117- timerMenu . DropDownItems . Add ( "StopTimer" , null , ( s , e ) => StartStopTimer ( false ) ) ;
118- trayMenu . Items . Add ( timerMenu ) ;
119-
120- // Hit
121- var hitMenu = new ToolStripMenuItem ( "Hit" ) ;
122-
123- var wayMenu = new ToolStripMenuItem ( "Way" ) ;
124- wayMenu . DropDownItems . Add ( "Increase" , null , ( s , e ) => btnWayHit_Click ( null , null ) ) ;
125- wayMenu . DropDownItems . Add ( "Decrease" , null , ( s , e ) => btnWayHitUndo_Click ( null , null ) ) ;
126- hitMenu . DropDownItems . Add ( wayMenu ) ;
127-
128- var bossMenu = new ToolStripMenuItem ( "Boss" ) ;
129- bossMenu . DropDownItems . Add ( "Increase" , null , ( s , e ) => btnHit_Click ( null , null ) ) ;
130- bossMenu . DropDownItems . Add ( "Decrease" , null , ( s , e ) => btnHitUndo_Click ( null , null ) ) ;
131- hitMenu . DropDownItems . Add ( bossMenu ) ;
132-
133- trayMenu . Items . Add ( hitMenu ) ;
134-
135- // Split
136- var splitMenu = new ToolStripMenuItem ( "Split" ) ;
137- splitMenu . DropDownItems . Add ( "Reset Run" , null , ( s , e ) => btnReset_Click ( null , null ) ) ;
138- splitMenu . DropDownItems . Add ( "Next Split" , null , ( s , e ) => btnSplit_Click ( null , null ) ) ;
139- splitMenu . DropDownItems . Add ( "Previous Split" , null , ( s , e ) => btnSplitPrev_Click ( null , null ) ) ;
140- trayMenu . Items . Add ( splitMenu ) ;
141-
142- // Close HCM
143- trayMenu . Items . Add ( "Close HCM" , null , ( s , e ) => CloseHCM ( ) ) ;
144-
145- // NotifyIcon
146- notifyIconToolBar . ContextMenuStrip = trayMenu ;
147- notifyIconToolBar . DoubleClick += ( s , e ) => ShowMainForm ( ) ;
148- notifyIconToolBar . Visible = true ;
110+ if ( _settings . TrayIconEnable )
111+ {
112+ trayMenu = new ContextMenuStrip ( ) ;
113+
114+ // Split
115+ trayMenu . Items . Add ( "Next split" , null , ( s , e ) => btnSplit_Click ( null , null ) ) ;
116+ trayMenu . Items . Add ( "Previous split" , null , ( s , e ) => btnSplitPrev_Click ( null , null ) ) ;
117+
118+ // Hit
119+ trayMenu . Items . Add ( new ToolStripSeparator ( ) ) ;
120+ trayMenu . Items . Add ( "Hit increase (way)" , null , ( s , e ) => btnWayHit_Click ( null , null ) ) ;
121+ trayMenu . Items . Add ( "Hit decrease (way)" , null , ( s , e ) => btnWayHitUndo_Click ( null , null ) ) ;
122+ trayMenu . Items . Add ( "Hit increase (boss)" , null , ( s , e ) => btnHit_Click ( null , null ) ) ;
123+ trayMenu . Items . Add ( "Hit decrease (boss)" , null , ( s , e ) => btnHitUndo_Click ( null , null ) ) ;
124+
125+ // Timer / Run Reset
126+ trayMenu . Items . Add ( new ToolStripSeparator ( ) ) ;
127+ var runMenu = new ToolStripMenuItem ( "Run" ) ;
128+ runMenu . DropDownItems . Add ( "Timer start" , null , ( s , e ) => StartStopTimer ( true ) ) ;
129+ runMenu . DropDownItems . Add ( "Timer stop" , null , ( s , e ) => StartStopTimer ( false ) ) ;
130+ runMenu . DropDownItems . Add ( "Reset run" , null , ( s , e ) => btnReset_Click ( null , null ) ) ;
131+ trayMenu . Items . Add ( runMenu ) ;
132+
133+ // Open / Close
134+ trayMenu . Items . Add ( "Open" , null , ( s , e ) => ShowMainForm ( ) ) ;
135+ trayMenu . Items . Add ( new ToolStripSeparator ( ) ) ; // Spacing to not close the application by accident
136+ trayMenu . Items . Add ( "Close" , null , ( s , e ) => CloseHCM ( ) ) ;
137+
138+ // NotifyIcon
139+ notifyIconToolBar . ContextMenuStrip = trayMenu ;
140+ notifyIconToolBar . DoubleClick += ( s , e ) => ShowMainForm ( ) ;
141+ notifyIconToolBar . Visible = true ;
142+ }
149143 #endregion
150144
151145 this . UpdateDarkMode ( ) ;
152146 }
153147
154- private void Form1_FormClosing ( object sender , FormClosingEventArgs e )
148+ private void Form1_Resize ( object sender , EventArgs e )
155149 {
156- if ( ! CloseOnTry )
150+ if ( _settings . TrayIconEnable && _settings . TrayIconMinimize && ( WindowState == FormWindowState . Minimized ) )
157151 {
158- var resultMinimize = MessageBox . Show (
159- "Do you want to minimize to the taskbar or close the program?\n Yes = Minimize - No = Close" ,
160- "Exit" ,
161- MessageBoxButtons . YesNo ,
162- MessageBoxIcon . Question ) ;
163-
164- if ( resultMinimize == DialogResult . Yes )
165- {
166- Hide ( ) ;
167- e . Cancel = true ;
168- return ;
169- }
170- }
152+ Hide ( ) ;
153+ }
154+ }
171155
156+ private void Form1_FormClosing ( object sender , FormClosingEventArgs e )
157+ {
172158 DialogResult result = MessageBox . Show ( "Do you want to save this session?" , this . Text , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question ) ;
173159 if ( result == DialogResult . Yes )
174160 {
0 commit comments