-
Notifications
You must be signed in to change notification settings - Fork 6
/
HotString.ahk
95 lines (91 loc) · 2.31 KB
/
HotString.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
class HotStringMaps{
static List := []
;------------------------------
HotStringCheck(){
for i,v in HotStringMaps.List {
result := v.when()
if(result){
return v
}
}
return false
}
;------------------------------
Extract(theHotStringMap){
local String := ""
for k,v in theHotStringMap {
result := HotString.isHotString(v)
if(result){
String .= v.Trigger "`t" v.Remarks "`r`n"
}
}
return String
}
;------------------------------
ExtractAndMerge(){
for k,v in HotStringMaps.List{
theHotStringMap := v
String := HotStringMaps.Extract(theHotStringMap)
HotStringMaps.List[k] := Object("String",String,"Name",v.__class,"When",v.when)
}
return
}
} ;HotStringMaps End
;------------------------------
class HotString{
ContextMatch(){
return this.PremiseBindFunc.call()
}
isHotString(HotStringObj){
try{
result := Instanof(HotStringObj,HotString)
}
catch Ex{
return false
}
return result
}
;------------------------------
Trigger := behavior := Remarks := ""
static On := "On",Toggle := "Toggle",Off := "Off"
Premise := PremiseBindFunc := Object("Null","Null")
;------------------------------
IFOn(){
theFunc := this.PremiseBindFunc
Hotkey, If, % theFunc
return ErrorLevel
}
;------------------------------
IFOff(){
Hotkey, If
return ErrorLevel
}
;------------------------------
__New(Trigger,behavior,Remarks,Premise){
type.assertStr(Trigger),type.assertStr(Remarks),type.assertObj(Premise)
this.PremiseBindFunc := this.Premise.bind(this)
this.Premise := Premise,this.Trigger := Trigger,this.behavior := behavior,this.Remarks := Remarks
return this
}
;----------------------------------------------------------------------
clone(Remarks){
return HotString.__New(this.Trigger,this.behavior,Remarks)
}
;----------------------------------------------------------------------
equal(OtherHotString){
result := ((Trigger = this.Trigger) AND (behavior = this.behavior))
return result
}
;------------------------------
register(){
this.IFOn(),Hotstring(this.Trigger,this.behavior),this.IFOff()
return
}
;------------------------------
create(Trigger,behavior,Remarks,Premise){
theObj := new HotString(Trigger,behavior,Remarks,Premise)
theObj.register()
return theObj
}
;------------------------------
} ;---------class HotString End