-
Notifications
You must be signed in to change notification settings - Fork 19
/
Reminders.ahk
executable file
·182 lines (158 loc) · 5.47 KB
/
Reminders.ahk
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
#NoEnv
TimeUnits := Object()
TimeUnits.Seconds := 1
TimeUnits.Minutes := 60
TimeUnits.Hours := 3600
TimeUnits.Days := 86400
TimeUnits.Weeks := 604800
TimeUnits.Months := 2629744
TimeUnits.Years := 31556926
Gui, Font, s18 Bold, Arial
Gui, Add, Text, x10 y10 w560 h30 Center, Reminders
Gui, Font, s10 Norm
Gui, Add, ListView, x10 y50 w380 h290 gSelectReminder AltSubmit, Message|Time Remaining
Gui, Font, s8 Bold
Gui, Add, Text, x400 y50 w180 h20, Message:
Gui, Font, s12
Gui, Add, Edit, x400 y70 w180 h60 vMessage gCheckReminder hwndhMessageControl, do something
Gui, Font, s8
Gui, Add, Text, x400 y140 w180 h20, Time Remaining:
Gui, Font, s16
Gui, Add, Edit, x400 y160 w180 h30 vDesiredTime gCheckReminder, next month
Gui, Font, s8
Gui, Add, Text, x400 y200 w180 h30 vTimeRemaining Center
Gui, Font, s10
Gui, Add, Button, x400 y240 w180 h30 vSubmitReminder gSubmitReminder Disabled Default, Add
GuiControl, Focus, Message
SendMessage, 0x00B1, 0, -1,, ahk_id %hMessageControl% ;EM_SETSEL
Gosub, CheckReminder
Gui, Show, w590 h350, Reminders
;wip: loading code here
LV_Add("","Test1","123ABC")
ResizeColumns()
Return
GuiEscape:
GuiClose:
ExitApp
SelectReminder:
If InStr(A_GuiEvent,"I")
SelectReminder()
Return
CheckReminder:
GuiControlGet, Message,, Message
GuiControlGet, DesiredTime,, DesiredTime
Remaining := ParseTime(DesiredTime)
GuiControl,, TimeRemaining, % FormatRemainingTime(Remaining)
If (Message != "" && Remaining)
GuiControl, Enable, SubmitReminder
Else
GuiControl, Disable, SubmitReminder
Return
SubmitReminder:
SubmitReminder()
Return
SelectReminder()
{
global Row, CurrentMessage, CurrentDesiredTime
static Row1 := 0
Row := LV_GetNext()
If Row
{
If !Row1
{
GuiControlGet, CurrentMessage,, Message
GuiControlGet, CurrentDesiredTime,, DesiredTime
}
LV_GetText(Message,Row,1)
LV_GetText(DesiredTime,Row,2)
GuiControl,, Message, %Message%
GuiControl,, DesiredTime, %DesiredTime%
GuiControl,, SubmitReminder, Update
}
Else
{
GuiControl,, Message, %CurrentMessage%
GuiControl,, DesiredTime, %CurrentDesiredTime%
GuiControl,, SubmitReminder, Add
}
Row1 := Row
}
SubmitReminder()
{
global Row
GuiControlGet, Message,, Message
GuiControlGet, DesiredTime,, DesiredTime
TimeRemaining := ParseTime(DesiredTime)
If Row ;update reminder
LV_Modify(Row,"",Message,FormatRemainingTime(TimeRemaining))
Else ;add reminder
LV_Add("Select Focus",Message,FormatRemainingTime(TimeRemaining))
ResizeColumns()
}
ResizeColumns()
{
LV_ModifyCol(1,"AutoHdr")
LV_ModifyCol(2,"AutoHdr")
}
ParseTime(TimeString)
{
global TimeUnits
Result := 0, FoundPos := 1
Loop, Parse, TimeString, %A_Space%%A_Tab%
{
FoundPos := RegExMatch(TimeString,"iS)(a|next|\d+)\s*(?:(s|secs?|seconds?|m|mins?|minutes?|h|hours?|d|days?|w|weeks?|mo|mons?|months?|y|yea|yrs?|years?)(?=[^a-z]|$))?",Output,FoundPos)
If (!FoundPos || Output = "")
Break
FoundPos += StrLen(Output)
If (Output1 = "")
Output1 := 1
If (Output1 = "a")
Output1 := 1
Else If (Output1 = "next")
Output1 := 1
Else If Output1 Is Not Digit
Output1 := 0
If RegExMatch(Output2,"iS)^(?:s|secs?|seconds?)$")
Output1 *= TimeUnits.Seconds
Else If RegExMatch(Output2,"iS)^(?:m|mins?|minutes?)$")
Output1 *= TimeUnits.Minutes
Else If RegExMatch(Output2,"iS)^(?:h|hours?)$")
Output1 *= TimeUnits.Hours
Else If RegExMatch(Output2,"iS)^(?:d|days?)$")
Output1 *= TimeUnits.Days
Else If RegExMatch(Output2,"iS)^(?:w|weeks?)$")
Output1 *= TimeUnits.Weeks
Else If RegExMatch(Output2,"iS)^(?:mo|mons?|months?)$")
Output1 *= TimeUnits.Months
Else If RegExMatch(Output2,"iS)y|yea|yrs?|years?")
Output1 *= TimeUnits.Years
Result += Output1
}
Return, Result
}
FormatRemainingTime(RemainingTime) ;time remaining in seconds
{
global TimeUnits
If (RemainingTime = 0)
Return, "Reminder expired"
Years := RemainingTime // TimeUnits.Years, RemainingTime := Mod(RemainingTime,TimeUnits.Years) ;extract years
Months := RemainingTime // TimeUnits.Months, RemainingTime := Mod(RemainingTime,TimeUnits.Months) ;extract months
Days := RemainingTime // TimeUnits.Days, RemainingTime := Mod(RemainingTime,TimeUnits.Days) ;extract days
Hours := RemainingTime // TimeUnits.Hours, RemainingTime := Mod(RemainingTime,TimeUnits.Hours) ;extract hours
Minutes := RemainingTime // TimeUnits.Minutes ;extract minutes
Seconds := Mod(RemainingTime,TimeUnits.Minutes) ;extract seconds
Result := ""
If (Years != 0)
Result .= Years . " year" . ((Years = 1) ? "" : "s") . ", "
If (Months != 0)
Result .= Months . " month" . ((Months = 1) ? "" : "s") . ", "
If (Days != 0)
Result .= Days . " day" . ((Days = 1) ? "" : "s") . ", "
If (Hours != 0)
Result .= Hours . " hour" . ((Hours = 1) ? "" : "s") . ", "
If (Minutes != 0)
Result .= Minutes . " minute" . ((Minutes = 1) ? "" : "s") . ", "
If (Seconds != 0)
Result .= Seconds . " second" . ((Seconds = 1) ? "" : "s") . ", "
Return, SubStr(Result,1,-2)
}