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
;=======================================================================================
;BDD Test Naming Mode AHK Script
;
;Description:
; Replaces spaces with underscores while typing, to help with writing BDD test names.
; Toggle on and off with Ctrl + Shift + U.
;=======================================================================================


;==========================
;Initialise
;==========================
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode 2

enabledIcon := "testnamingmode_16.ico"
disabledIcon := "testnamingmode_disabled_16.ico"
IsInTestNamingMode := false
SetTestNamingMode(false)

;==========================
;Functions
;==========================
SetTestNamingMode(toActive) {
local iconFile := toActive ? enabledIcon : disabledIcon
local state := toActive ? "ON" : "OFF"

IsInTestNamingMode := toActive
Menu, Tray, Icon, %iconFile%,
Menu, Tray, Tip, Test naming mode is %state%

Send {Shift Up}
}

;==========================
;Test Mode toggle
;==========================
#IfWinActive Microsoft Visual Studio
^+u::
SetTestNamingMode(!IsInTestNamingMode)
return

$Escape::
if (IsInTestNamingMode) {
SetTestNamingMode(!IsInTestNamingMode)
}
Send, {Escape}
return

^[::
if (IsInTestNamingMode) {
SetTestNamingMode(!IsInTestNamingMode)
}
Send, ^[
return

$Enter::
if (IsInTestNamingMode) {
SetTestNamingMode(!IsInTestNamingMode)
} else {
Send, {Enter}
}
return

"::
if (IsInTestNamingMode) {
Send, _
} else {
Send, "
}
return


;==========================
;Handle SPACE press
;==========================
$Space::
if (IsInTestNamingMode) {
Send, _
} else {
Send, {Space}
}
#IfWinActive