There's two aspects to it for the most part. A hotkey that will grab the Window Title from the active window (if the first word is between 0 - 15 characters, and it's not already in the object).
It then makes a button with that that title. The button doesn't do anything, it's not relevant for this. But the hotkey will also add the text of the button to a DropDown (so you can delete the button - and "repopulate" the buttons using the object).
The label looks at what was selected from the dropdown list, deletes it from the object, clears the buttons list and recreates it.
That's it.
Code: Select all
WatchList_OBJ := {}
gosub, RepopulateButtons
Numpad1::
clipboard := ""
RegexActiveTitle1 := ""
WinGetTitle, ActiveWindowTitle, A
RegexMatch(ActiveWindowTitle, "(.+?)\s", RegexActiveTitle)
WatchList_Count := WatchList_OBJ.Count()
If (StrLen(RegexActiveTitle1) < 15) && (StrLen(RegexActiveTitle1) > 0) && (WatchList_Count < 14) && (WatchList_OBJ[RegexActiveTitle1] = "")
{
Proceed := 1
Try
{
Gui, WatchlistGUI:Add, Button, cBlack x+25 w85 gSendToTV v%RegexActiveTitle1% -Default +Hwnd%RegexActiveTitle1%, %RegexActiveTitle1% ; this has to be above adding it to an object so that if it errors on creating the button due to duplicate Hwnds, it skips adding it to the object.
}
catch
{
Proceed := 0
soundbeep, 100, 200
}
If Proceed = 1
{
WatchList_OBJ[RegexActiveTitle1] := RegexActiveTitle1
Msgbox % ButtonList
ButtonList .= RegexActiveTitle1 "|"
msgbox % ButtonList
GuiControl, WatchlistGUI:, DeleteButtonDropDownVar, %ButtonList%
msgbox % RegexActiveTitle1
}
}
Else
{
If (WatchList_OBJ[RegexActiveTitle1] != "")
{
soundbeep, 330, 200
soundbeep, 200, 200
}
Else
soundbeep, 100, 200
}
return
RepopulateButtons:
Gui, Submit
Gui, WatchlistGUI:New
Gui, +AlwaysOnTop
Gui, Margin, 10,10
Gui, Font, s11 q5 bold, Verdana
Gui, Add, DropDownList, x95 y7 w130 vDeleteButtonDropDownVar gRepopulateButtons
Gui, Add, Button, x225 y5 h0 w0
Gui, Font, s11 q5 , Verdana
Gui, Show, NoActivate x364 y500 w1000 h40, watchlistWinTitle
WatchList_OBJ.Delete(DeleteButtonDropDownVar)
ButtonList := ""
For k, v in WatchList_OBJ
{
Gui, WatchlistGUI:Add, Button, x+24 w85 gSendToTV v%v% -Default +Hwnd%v%, %v%
ButtonList .= v "|"
}
GuiControl, WatchlistGUI:, DeleteButtonDropDownVar, %ButtonList%
return
SendToTV:
return
ButtonList .= RegexActiveTitle1 "|"
You can see I've dropped some msgboxes around there to try and understand what is going on. The ButtonList var should be growing by the RegexActiveTitle1 (a match from the window title) each time the hotkey is pressed (up to a limit of 14 or so).
However, what actually happens using " ButtonList .= RegexActiveTitle1 "|" " is that it acts like it's adding the entire list to itself. Even though the messageboxes will show everything as expected (a single item for regexactivetitle1 (which gets reset at the start of the hotkey), a uniformly added ButtonList. But when you click the drop down, there's duplicates - no duplicate buttons, but duplicates in the list.
The WEIRD thing is, setting it as ButtonList := RegexActiveTitle1 "|" at line 29 completely fixes the problem. Not only that, in the label, when it recreates the buttons using the object, somehow now it remembers the position that the buttons were created. However, if you look at the msgbox variables.... it shouldn't be working! The msgboxes show what you'd expect each time, but the dropdown behaves much differently.
It's not the label being attached to the dropdown edit, disabling that and the problem is still there.
Using this at line 31:
Code: Select all
GuiControl, WatchlistGUI:, DeleteButtonDropDownVar,
GuiControl, WatchlistGUI:, DeleteButtonDropDownVar, %ButtonList%
If anyone experienced could spend a few minutes going over this I'd really love an explanation as to why it's behaving in this way (.= vs :=) and how the object is remembering the position. I'm not looking for a re-write or a fix, just an explanation as to the behavior. I already have it working with := but I don't like that it works unless I understand it.
Thank you.