diff --git a/lib/SetTimerUtil.ahk b/lib/SetTimerUtil.ahk deleted file mode 100644 index 8fceb22..0000000 --- a/lib/SetTimerUtil.ahk +++ /dev/null @@ -1,25 +0,0 @@ -#include Tippy.ahk - -; function which toggles a timer (using SetTimer) but also shows -; if it turned the timer on or off with a tooltip -StartTimerAndShowTooltip(functionName, interval) -{ - static functionNames := {} - - toggle := !functionNames[functionName] - functionNames[functionName] := toggle - - SetTimer, %functionName%, % toggle ? interval : "Off" - - if (toggle) - { - Tippy(functionName . " on") - Sleep 1000 - %functionName%() - } - else - { - Tippy(functionName . " off") - } -} - diff --git a/lib/ToggleTimerAndShowTooltip.ahk b/lib/ToggleTimerAndShowTooltip.ahk new file mode 100644 index 0000000..1864f50 --- /dev/null +++ b/lib/ToggleTimerAndShowTooltip.ahk @@ -0,0 +1,47 @@ +#include Tippy.ahk + +; Function which toggles a timer (using SetTimer) but also shows if it turned the timer on or off with a tooltip. +; +; How to use: +; call a function with: `ToggleTimerAndShowTooltip("functionName", 1000)` +; call a class method with: +; `ToggleTimerAndShowTooltip("ClassName.MethodName", 7000, ClassName.MethodName.Bind(ClassName))` +; eg. `ToggleTimerAndShowTooltip("SC2.aaa", 7000, SC2.aaa.Bind(SC2))` +; where +; SC2 = class +; aaa = method from class +; +; Note: the `functionIdentifier` and `functionReferences` thing is just a hack to be able to toggle class methods: `class.method.Bind(this)` +; +ToggleTimerAndShowTooltip(functionName, interval, functionIdentifier := 0) +{ + static functionNames := {} + static functionReferences := {} + + ; if there's no functionIdentifier, we're in a normal function call, not class method call + if (functionIdentifier = 0) + { + functionIdentifier := functionName + } + + if !(functionReferences[functionName]) + { + functionReferences[functionName] := functionIdentifier + } + + toggle := !functionNames[functionName] + functionNames[functionName] := toggle + + Fn := functionReferences[functionName] + SetTimer, % Fn, % toggle ? interval : "Off" + + if (toggle) + { + Tippy(functionName . " on") + %functionName%() + } + else + { + Tippy(functionName . " off") + } +}