Skip to content

Commit

Permalink
Timer Toggler V2 -- now supports methods from classes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed Apr 12, 2019
1 parent d77a110 commit 3c3e607
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 25 deletions.
25 changes: 0 additions & 25 deletions lib/SetTimerUtil.ahk

This file was deleted.

47 changes: 47 additions & 0 deletions lib/ToggleTimerAndShowTooltip.ahk
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 3c3e607

Please sign in to comment.