-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFormMain.cs
910 lines (784 loc) · 23.6 KB
/
FormMain.cs
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BrightIdeasSoftware;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Threading;
using System.Timers;
using System.Linq;
using IniParser;
using IniParser.Model;
using System.IO;
namespace CCTime
{
public partial class FormMain : Form
{
private DateTime currentlyViewingDate;
private System.Timers.Timer minuteTimer;
private int minuteTimerSeconds = 0;
private int pausedTimerMinutesLeft = 0;
private bool okToHide = true;
//private enum TimerState
//{
// Off,
// On,
// Paused
//}
public FormMain()
{
InitializeComponent();
this.Opacity = 0; // if hide at startup, this prevents flashing by
}
private void Form1_Load( object sender, EventArgs e )
{
Settings.InitSettings();
this.Width = Settings.WindowWidth;
this.Height = Settings.WindowHeight;
TaskManager.InitData();
currentlyViewingDate = DateTime.Now;
InitTimers();
ShowDate();
InitObjectListView();
PositionForm();
InitSystemTrayIconMenu();
this.ShowInTaskbar = false;
SetTimerState( Settings.ClockOnAtStartup );
RefreshCurrentView();
if( Settings.StartMinimized )
HideForm();
else
this.Opacity = 1;
}
private void Form1_Deactivate( object sender, EventArgs e ) // lost focus
{
if( okToHide )
{
HideForm();
}
}
private void Form1_FormClosing( object sender, FormClosingEventArgs e )
{
if( Settings.CloseButtonMinimizes )
{
HideForm();
e.Cancel = true;
}
else
{
QuitApp();
}
}
private void FormMain_KeyDown( object sender, KeyEventArgs e )
{
if( objectListView.IsCellEditing )
{
return;
}
RefreshCurrentView();
}
private void FormMain_KeyUp( object sender, KeyEventArgs e )
{
if( objectListView.IsCellEditing )
{
return;
}
if( e.KeyCode == Keys.Left )
{
buttonPrevDate_Click( null, null );
}
else if( e.KeyCode == Keys.Right )
{
buttonNextDate_Click( null, null );
}
RefreshCurrentView();
}
// --- Form Utilities -----------------------------------------------------------
private void ShowForm()
{
this.Opacity = 1;
this.Visible = true;
if( Settings.ReturnToTodayWhenRestoring )
{
currentlyViewingDate = DateTime.Now;
ShowDate();
}
PositionForm();
this.Activate();
this.BringToFront();
}
private void HideForm()
{
this.Opacity = 0;
this.Visible = false;
TaskManager.PersistData();
}
private void PositionForm()
{
switch( Settings.WindowPosition.ToLower() )
{
case "topleft":
this.Top = Screen.PrimaryScreen.WorkingArea.Top;
this.Left = Screen.PrimaryScreen.WorkingArea.Left;
break;
case "topright":
this.Top = Screen.PrimaryScreen.WorkingArea.Top;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
break;
case "bottomleft":
this.Top = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
this.Left = Screen.PrimaryScreen.WorkingArea.Left;
break;
case "bottomright":
default:
this.Top = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
break;
}
}
private void QuitApp()
{
if( minuteTimer != null) // Null means application did not initialize. Could be an error, so we should not persist data
{
minuteTimer.Enabled = false;
okToHide = false;
notifyIcon.Visible = false;
TaskManager.PersistData();
Application.Exit();
}
}
private void ShowDate()
{
// ReDraws UI
TextInfo textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;
labelDate.Text = textInfo.ToTitleCase( currentlyViewingDate.ToString( "dddd d MMMM" ) );
var currentTasks = TaskManager.GetDay( currentlyViewingDate );
objectListView.SetObjects( currentTasks );
RefreshCurrentView();
buttonNextDate.Enabled = TaskManager.GetNextDate( currentlyViewingDate ) != null;
buttonPrevDate.Enabled = TaskManager.GetPreviousDate( currentlyViewingDate ) != null;
}
private void RefreshCurrentView()
{
// update unaccounted minutes
var currentTasks = TaskManager.GetDay( currentlyViewingDate );
var totalMinutes = currentTasks[0].Minutes;
var totalAccountedFor = 0;
for( int i = 2; i < currentTasks.Count; i++ )
{
totalAccountedFor += currentTasks[i].Minutes;
}
currentTasks[1].Minutes = totalMinutes - totalAccountedFor;
// force view to refresh
for( int i = 0; i < currentTasks.Count; i++ )
{
objectListView.RefreshObject( currentTasks[i] );
}
}
// --- Timers --------------------------------------------------------------------
private void InitTimers()
{
// setup main timer
minuteTimer = new System.Timers.Timer();
minuteTimer.Interval = 1000;
minuteTimer.Elapsed += delegate( object source, ElapsedEventArgs ev )
{
// This runs once a second
minuteTimerSeconds++;
var todayTasks = TaskManager.GetToday();
if( minuteTimerSeconds >= 60 )
{ // one minute has passed
minuteTimerSeconds = 0;
if( pausedTimerMinutesLeft > 0 )
{
// paused
pausedTimerMinutesLeft--;
}
else
{
// normal
foreach( var t in todayTasks )
{
if( t.Type == TaskType.Total )
{
t.Minutes++;
}
else if( t.Type == TaskType.Normal && t.AutoTick )
{
t.Minutes++;
}
}
}
RefreshCurrentView();
}
try
{
if( !this.IsDisposed && !this.Disposing )
{
this.Invoke( new Action( () =>
{
if( pausedTimerMinutesLeft > 0 )
{
this.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " [PAUSED FOR " + pausedTimerMinutesLeft + " MIN]";
}
else
{
if( buttonTimerOnOff.Image != CCTime.Properties.Resources.clock )
{
buttonTimerOnOff.Image = CCTime.Properties.Resources.clock;
}
int hours = ( todayTasks[0].Minutes - todayTasks[0].Minutes % 60 ) / 60;
this.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " [" + hours.ToString( "D2" ) + ":" + ( todayTasks[0].Minutes - hours * 60 ).ToString( "D2" ) + ":" + minuteTimerSeconds.ToString( "D2" ) + "]";
}
} ) );
}
}
catch( Exception ex )
{
}
};
// save data every 10 minutes to be safe
var persisTimer = new System.Timers.Timer();
persisTimer.Interval = 600000;
persisTimer.Elapsed += delegate( object source, ElapsedEventArgs ev )
{
TaskManager.PersistData();
};
persisTimer.Enabled = true;
}
private void SetTimerState( bool enabled )
{
if( enabled )
{
minuteTimer.Enabled = true;
buttonTimerOnOff.Image = CCTime.Properties.Resources.clock;
this.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
RefreshCurrentView();
}
else
{
minuteTimer.Enabled = false;
buttonTimerOnOff.Image = CCTime.Properties.Resources.clock_gray;
this.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " [STOPPED]";
}
}
// --- ObjectListView -----------------------------------------------------------
private void InitObjectListView()
{
objectListView.ButtonClick += ClickListviewButton;
this.olvColumn6.AspectGetter = delegate( object x )
{
var task = x as Task;
var tick = "";
if(task.Type == TaskType.Normal && task.AutoTick )
{
tick = "●";
}
return tick;
};
// show task title without comment (if any)
this.olvColumn1.AspectToStringConverter = delegate( object x )
{
string[] tmp = ( x as string ).Split( ';' );
if( tmp.Length > 1 )
return tmp[0] + "*";
else if( tmp.Length == 1 )
return tmp[0];
else
return "";
};
// show minutes as hours:minutes
this.olvColumn2.AspectToStringConverter = delegate( object x )
{
int minutes = (int)x;
var neg = "";
if( minutes < 0 )
{
neg = "-";
minutes = Math.Abs( minutes );
}
int hours = ( minutes - minutes % 60 ) / 60;
return neg + hours.ToString( "D2" ) + ":" + ( minutes - hours * 60 ).ToString( "D2" );
};
// button labels
this.olvColumn3.AspectToStringConverter = delegate( object x )
{
return GetButtonLabel( (string)x, 3 );
};
this.olvColumn4.AspectToStringConverter = delegate( object x )
{
return GetButtonLabel( (string)x, 4 );
};
this.olvColumn5.AspectToStringConverter = delegate( object x )
{
return GetButtonLabel( (string)x, 5 );
};
}
private string GetButtonLabel(string source, int column)
{
// Converts original button label depending on modifier keys
if( objectListView.IsCellEditing )
{
return source;
}
if( source == "" ) return "";
var label = source;
if( column == 3 ) // 15 min
{
if( ModifierKeys.HasFlag( Keys.Shift ) )
{
label = label.Replace( "+", "- " );
label = label.Replace( "< ", "- " );
}
if( ModifierKeys.HasFlag( Keys.Control ) )
{
label = label = "< " + Settings.MinutesOnClockButtons;
}
}
if( column == 4 ) // 30 min
{
if( ModifierKeys.HasFlag( Keys.Shift ) )
{
label = label.Replace( "+", "- " );
}
if( ModifierKeys.HasFlag( Keys.Control ) )
{
label = "";
}
}
if( column == 5 ) // 60 min
{
if( ModifierKeys.HasFlag( Keys.Shift ) )
{
label = label.Replace( "+", "- " );
if( label.Contains( " >" ) )
{
label = "+" + label.Replace( " >", "" );
}
}
if( ModifierKeys.HasFlag( Keys.Control ) )
{
label = label = Settings.MinutesOnClockButtons + " >";
}
}
return label;
}
private void ClickListviewButton( object senderObject, CellClickEventArgs ev )
{
// Processes time based on buttons labels
var label = GetButtonLabel( ev.SubItem.ModelValue.ToString(), ev.ColumnIndex );
var timerState = minuteTimer.Enabled;
minuteTimer.Enabled = false;
var m = ev.Model as Task;
var modifier = Regex.Replace( label, "[0-9 -]", "" );
var minutes = Convert.ToInt32( Regex.Replace( label, "[^0-9-]", "" ) );
if( modifier == "<" )
{
if( minutes == 15 )
{
// round down to nearest 15 min
if( m.Minutes == 0 || m.Minutes % 15 == 0 || m.Minutes % 30 == 0 || m.Minutes % 45 == 0 || m.Minutes % 60 == 0 ) m.Minutes--; // if already at nearest 15 min, allow skipping past
while( m.Minutes != 0 && m.Minutes % 15 != 0 && m.Minutes % 30 != 0 && m.Minutes % 45 != 0 && m.Minutes % 60 != 0 ) m.Minutes--;
}
else if( minutes == 30 )
{
// round down to nearest 30 min
if( m.Minutes == 0 || m.Minutes % 30 == 0 || m.Minutes % 60 == 0 ) m.Minutes--; // if already at nearest 30 min, allow skipping past
while( m.Minutes != 0 && m.Minutes % 30 != 0 && m.Minutes % 60 != 0 ) m.Minutes--;
}
else if( minutes == 60 )
{
// round down to nearest 60 min
if( m.Minutes == 0 || m.Minutes % 60 == 0 ) m.Minutes--; // if already at nearest 60 min, allow skipping past
while( m.Minutes != 0 && m.Minutes % 60 != 0 ) m.Minutes--;
}
else
{
// skip rounding, just subtract
m.Minutes -= minutes;
}
}
else if( modifier == ">" )
{
if( minutes == 15 )
{
// round up to nearest 15 min
if( m.Minutes == 0 || m.Minutes % 15 == 0 || m.Minutes % 30 == 0 || m.Minutes % 45 == 0 || m.Minutes % 60 == 0 ) m.Minutes++; // if already at nearest 15 min, allow skipping past
while( m.Minutes != 0 && m.Minutes % 15 != 0 && m.Minutes % 30 != 0 && m.Minutes % 45 != 0 && m.Minutes % 60 != 0 ) m.Minutes++;
}
else if( minutes == 30 )
{
// round up to nearest 30 min
if( m.Minutes == 0 || m.Minutes % 30 == 0 || m.Minutes % 60 == 0 ) m.Minutes++; // if already at nearest 30 min, allow skipping past
while( m.Minutes != 0 && m.Minutes % 30 != 0 && m.Minutes % 60 != 0 ) m.Minutes++;
}
else if( minutes == 60 )
{
// round up to nearest 6+ min
if( m.Minutes == 0 || m.Minutes % 60 == 0 ) m.Minutes++; // if already at nearest 60 min, allow skipping past
while( m.Minutes != 0 && m.Minutes % 60 != 0 ) m.Minutes++;
}
else
{
// skip rounding, just add
m.Minutes += minutes;
}
}
else
{
// normal
m.Minutes += minutes;
}
minuteTimer.Enabled = timerState;
RefreshCurrentView();
}
private void objectListView1_CellEditStarting( object sender, CellEditEventArgs e )
{
// prevent editing totals & unaccounted
var task = e.RowObject as Task;
if( task.Type != TaskType.Normal )
{
if( e.Column.Index == 0 ) // name column
{
e.Cancel = true;
}
if( e.Column.Index == 2 ) // time column
{
// unaccounted time is calculated, so don't allow editing it either
if( task.Type != TaskType.Total )
{
e.Cancel = true;
}
}
}
}
private void objectListView1_CellEditFinished( object sender, CellEditEventArgs e )
{
RefreshCurrentView();
}
private void objectListView1_KeyUp( object sender, KeyEventArgs e )
{
if(e.KeyCode == Keys.Delete)
{
buttonTaskDel_Click( new object(), new EventArgs() );
}
}
private void objectListView1_CellRightClick( object sender, CellRightClickEventArgs e )
{
if( e.Item != null )
{
var task = e.Item.RowObject as Task;
task.AutoTick = !task.AutoTick;
//e.Item.Selected = false;
RefreshCurrentView();
}
}
// --- GUI Buttons --------------------------------------------------------------
private void buttonPrevDate_Click( object sender, EventArgs e )
{
var prevDay = TaskManager.GetPreviousDate( currentlyViewingDate );
if( prevDay != null )
{
currentlyViewingDate = DateTime.Parse( prevDay );
ShowDate();
}
}
private void buttonNextDate_Click( object sender, EventArgs e )
{
var nextDay = TaskManager.GetNextDate( currentlyViewingDate );
if ( nextDay != null )
{
currentlyViewingDate = DateTime.Parse(nextDay);
ShowDate();
}
}
private void labelDate_Click( object sender, EventArgs e )
{
// go to date when clicking the date label
var hideState = okToHide;
okToHide = false;
var dateSelectForm = new FormDateSelect( currentlyViewingDate, true, "Select a Date to View" );
dateSelectForm.ShowDialog();
if( dateSelectForm.SelectedDate != DateTime.MinValue )
{
currentlyViewingDate = dateSelectForm.SelectedDate;
ShowDate();
}
okToHide = hideState;
}
private void buttonTaskAdd_Click( object sender, EventArgs e )
{
var hideState = okToHide;
var timerState = minuteTimer.Enabled;
okToHide = false;
minuteTimer.Enabled = false;
if( Control.ModifierKeys == Keys.Control || Control.ModifierKeys == Keys.Shift )
{
// Add day
var dateSelectForm = new FormDateSelect( currentlyViewingDate, false, "Select a Date to Add" );
dateSelectForm.ShowDialog();
if( dateSelectForm.SelectedDate != DateTime.MinValue )
{
var copyTasks = MessageBox.Show( "Copy tasks from currently viewing day?", "Copy Tasks?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question );
if( copyTasks != System.Windows.Forms.DialogResult.Cancel )
{
if( copyTasks == System.Windows.Forms.DialogResult.Yes )
{
TaskManager.AddDay( dateSelectForm.SelectedDate, currentlyViewingDate.ToShortDateString() );
}
else
{
TaskManager.AddDay( dateSelectForm.SelectedDate );
}
currentlyViewingDate = dateSelectForm.SelectedDate;
}
}
}
else
{
// Add task
var title = Microsoft.VisualBasic.Interaction.InputBox( "Add Task", "Name the task:", "New Task" );
if( title.Trim() != "" )
{
TaskManager.AddTaskToDay( currentlyViewingDate, title );
}
}
ShowDate();
minuteTimer.Enabled = timerState;
okToHide = hideState;
}
private void buttonTaskDel_Click( object sender, EventArgs e )
{
var hideState = okToHide;
okToHide = false;
if( Control.ModifierKeys == Keys.Control || Control.ModifierKeys == Keys.Shift )
{
// Delete day
if( currentlyViewingDate.ToShortDateString() == DateTime.Now.ToShortDateString() )
{
MessageBox.Show( "Can't remove todays date...", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, MessageBoxButtons.OK, MessageBoxIcon.Information );
}
else
{
var confirm = MessageBox.Show( "Remove " + currentlyViewingDate.ToString( "dddd d MMMM" ) + "?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
if( confirm == System.Windows.Forms.DialogResult.Yes )
{
var nextDay = TaskManager.GetNextDate( currentlyViewingDate );
var prevDay = TaskManager.GetPreviousDate( currentlyViewingDate );
if( nextDay != null || prevDay != null ) // prevent removing all dates...
{
TaskManager.DeleteDay( currentlyViewingDate );
if( nextDay != null )
currentlyViewingDate = DateTime.Parse( nextDay );
else
currentlyViewingDate = DateTime.Parse( prevDay );
ShowDate();
}
}
}
}
else if( Control.ModifierKeys == Keys.Alt )
{
// Delete all tasks with 0 hours
var confirm = MessageBox.Show( "Remove all task with 0 time?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
if( confirm == System.Windows.Forms.DialogResult.Yes )
{
var timerState = minuteTimer.Enabled;
minuteTimer.Enabled = false;
TaskManager.RemoveTasksWithZeroTime( currentlyViewingDate );
ShowDate();
minuteTimer.Enabled = timerState;
}
}
else
{
// Delete task
if( objectListView.SelectedIndex > 1 )
{
var confirm = System.Windows.Forms.DialogResult.Yes;
if( ( objectListView.SelectedObject as Task ).Minutes > 0 )
{
confirm = MessageBox.Show( "Remove task, are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
}
if( confirm == System.Windows.Forms.DialogResult.Yes )
{
var timerState = minuteTimer.Enabled;
minuteTimer.Enabled = false;
var previouslySelected = objectListView.SelectedIndex;
TaskManager.RemoveTask( currentlyViewingDate, objectListView.SelectedIndex );
ShowDate();
// restore selection to "next" item
if( previouslySelected > objectListView.Items.Count - 1) previouslySelected = objectListView.Items.Count - 1;
objectListView.SelectedIndex = previouslySelected;
objectListView.FocusedItem = objectListView.SelectedItems[0];
objectListView.Focus();
minuteTimer.Enabled = timerState;
}
}
}
okToHide = hideState;
}
private void buttonTaskUp_Click( object sender, EventArgs e )
{
var index = objectListView.SelectedIndex;
if( index <= 2 ) return;
var timerState = minuteTimer.Enabled;
minuteTimer.Enabled = false;
if( Control.ModifierKeys == Keys.Control || Control.ModifierKeys == Keys.Shift )
{
// move to top
while( index > 2 )
{
TaskManager.MoveTask( currentlyViewingDate, index, index - 1 );
index--;
}
}
else
{
// move one step up
TaskManager.MoveTask( currentlyViewingDate, index, index - 1 );
index--;
}
ShowDate();
objectListView.SelectedIndex = index;
objectListView.FocusedItem = objectListView.SelectedItems[0];
objectListView.Focus();
minuteTimer.Enabled = timerState;
}
private void buttonTaskDown_Click( object sender, EventArgs e )
{
var index = objectListView.SelectedIndex;
if( index >= objectListView.GetItemCount() ) return;
if( index <= 1 ) return;
var timerState = minuteTimer.Enabled;
minuteTimer.Enabled = false;
if( Control.ModifierKeys == Keys.Control || Control.ModifierKeys == Keys.Shift )
{
// move to bottom
while( index < objectListView.GetItemCount() )
{
TaskManager.MoveTask( currentlyViewingDate, index, index + 1 );
index++;
}
index--;
}
else
{
// move one step down
TaskManager.MoveTask( currentlyViewingDate, index, index + 1 );
index++;
}
ShowDate();
objectListView.SelectedIndex = index;
objectListView.FocusedItem = objectListView.SelectedItems[0];
objectListView.Focus();
minuteTimer.Enabled = timerState;
}
private void buttonWeeklyReport_Click( object sender, EventArgs e )
{
new Report( currentlyViewingDate );
}
private void buttonTimerOnOff_MouseUp( object sender, MouseEventArgs e )
{
if( e.Button == System.Windows.Forms.MouseButtons.Right )
{
if( minuteTimer.Enabled )
{
var hideState = okToHide;
okToHide = false;
var response = Microsoft.VisualBasic.Interaction.InputBox( "For how long do you want to pause the timer?", "Pause Timer", Settings.DefaultMinutesToPause.ToString() );
int pauseTime;
Int32.TryParse(response, out pauseTime);
if( pauseTime != 0 )
{
pausedTimerMinutesLeft = pauseTime;
buttonTimerOnOff.Image = CCTime.Properties.Resources.clock_gray;
}
okToHide = hideState;
}
}
else
{
if( pausedTimerMinutesLeft > 0 )
{
// turn off pause
pausedTimerMinutesLeft = 0;
}
else
{
// normal toggle on/off
SetTimerState( !minuteTimer.Enabled );
}
}
}
private void buttonAlwaysOnTop_Click( object sender, EventArgs e )
{
var b = sender as Button;
if( this.TopMost )
{
this.TopMost = false;
okToHide = true;
b.Image = CCTime.Properties.Resources.pin_gray;
}
else
{
this.TopMost = true;
okToHide = false;
b.Image = CCTime.Properties.Resources.pin;
}
}
// --- System Tray Icon ---------------------------------------------------------
private void InitSystemTrayIconMenu()
{
this.notifyIcon.Text = this.Text;
this.notifyIcon.ContextMenu = new ContextMenu();
this.notifyIcon.ContextMenu.MenuItems.Add( new MenuItem( "Show Window", new EventHandler( notifyIconHandler_Show ) ) );
this.notifyIcon.ContextMenu.MenuItems.Add( new MenuItem( "-" ) );
var help = new MenuItem( "Help" );
this.notifyIcon.ContextMenu.MenuItems.Add( help );
help.MenuItems.Add( new MenuItem( "About", new EventHandler( notifyIconHandler_About ) ) );
help.MenuItems.Add( new MenuItem( "Open ReadMe file", new EventHandler( notifyIconHandler_ReadMe ) ) );
help.MenuItems.Add( new MenuItem( "Go to Homepage", new EventHandler( notifyIconHandler_Homepage ) ) );
this.notifyIcon.ContextMenu.MenuItems.Add( new MenuItem( "Settings", new EventHandler( notifyIconHandler_Settings ) ) );
this.notifyIcon.ContextMenu.MenuItems.Add( new MenuItem( "-" ) );
this.notifyIcon.ContextMenu.MenuItems.Add( new MenuItem( "Exit", new EventHandler( notifyIconHandler_Exit ) ) );
this.notifyIcon.Visible = true; // Shows the notify icon in the system tray
}
private void notifyIcon_Click( object sender, EventArgs e )
{
ShowForm();
}
private void notifyIconHandler_Show( object sender, EventArgs e )
{
ShowForm();
}
private void notifyIconHandler_About( object sender, EventArgs e )
{
okToHide = false;
new FormAbout().ShowDialog();
okToHide = true;
}
private void notifyIconHandler_ReadMe( object sender, EventArgs e )
{
var appFolder = Path.GetDirectoryName( Application.ExecutablePath );
System.Diagnostics.Process.Start( appFolder + @"\ReadMe.txt" );
}
private void notifyIconHandler_Homepage( object sender, EventArgs e )
{
System.Diagnostics.Process.Start( "https://www.rlvision.com" );
}
private void notifyIconHandler_Settings( object sender, EventArgs e )
{
var appFolder = Path.GetDirectoryName( Application.ExecutablePath );
System.Diagnostics.Process.Start( "notepad.exe", appFolder + @"\Settings.ini" );
}
private void notifyIconHandler_Exit( object sender, EventArgs e )
{
QuitApp();
}
}
}