mmikeww / AHK-v2-script-converter

AHK v1 -> v2 script converter
https://autohotkey.com/boards/viewtopic.php?f=6&t=25100
The Unlicense
489 stars 38 forks source link

`Gui, new` not name case miss #202

Open CoffeeChaton opened 2 weeks ago

CoffeeChaton commented 2 weeks ago

V1:

#Requires AutoHotkey v1.1.33.11
#SingleInstance Force
#Warn All, MsgBox

Gui, guiName:new
Gui, Add, text,, % "text              text                text       text"
Gui, Add, Button, Default, AAAA
Gui, Show

Gui, new ; not name
Gui, Add, text,, % "text2              text2                text2       text2"
Gui, Add, Button, Default, BBBB
Gui, Show

return

guiNameButtonAAAA() {
    ; Gui, Add, Button, Default, AAAA
    ; guiName + Button + AAAA
    ; guiNameButtonAAAA
    MsgBox, % "Button AAAA is call"
}

ButtonBBBB() {
    MsgBox, % "Button BBBB is call"
}

GuiClose:
GuiEscape:
ExitApp

V2 (Converted):

#Requires Autohotkey v2.0
#SingleInstance Force
#Warn All, MsgBox

guiName := Gui()
guiName.Add("text", , "text              text                text       text")
ogcButtonAAAA := guiName.Add("Button", "Default", "AAAA")
ogcButtonAAAA.OnEvent("Click", guiNameButtonAAAA.Bind("Normal"))
guiName.Show()

 ; not name
guiName.Add("text", , "text2              text2                text2       text2")
ogcButtonBBBB := guiName.Add("Button", "Default", "BBBB")
ogcButtonBBBB.OnEvent("Click", guiNameButtonBBBB.Bind("Normal"))
guiName.Show()

return

guiNameButtonAAAA() {
    ; Gui, Add, Button, Default, AAAA
    ; guiName + Button + AAAA
    ; guiNameButtonAAAA
    MsgBox("Button AAAA is call")
}

ButtonBBBB() {
    MsgBox("Button BBBB is call")
}

GuiClose:
GuiEscape:
ExitApp()

V2 (Expected):

#Requires Autohotkey v2.0
#SingleInstance Force
#Warn All, MsgBox

guiName := Gui()
guiName.Add("text", , "text              text                text       text")
ogcButtonAAAA := guiName.Add("Button", "Default", "AAAA")
ogcButtonAAAA.OnEvent("Click", guiNameButtonAAAA.Bind("Normal"))
guiName.Show()

myGui := Gui()
myGui.OnEvent("Close", GuiClose)
myGui.OnEvent("Escape", GuiClose)
; not name
myGui.Add("text", , "text2              text2                text2       text2")
ogcButtonBBBB := myGui.Add("Button", "Default", "BBBB")
ogcButtonBBBB.OnEvent("Click", ButtonBBBB.Bind("Normal"))
myGui.Show()

return

guiNameButtonAAAA() {
    ; Gui, Add, Button, Default, AAAA
    ; guiName + Button + AAAA
    ; guiNameButtonAAAA
    MsgBox("Button AAAA is call")
}

ButtonBBBB() {
    MsgBox("Button BBBB is call")
}

GuiClose(*)
{ ; V1toV2: Added bracket
    global ; V1toV2: Made function global
    GuiEscape:
    ExitApp()
} ; Added bracket in the end

Expected is use Gui, 1:new ; not name to converted

andymbody commented 1 week ago

FYI... I added this as a failed test to my most recent local repo. So the failed test might be part of my next PR. I don't plan to fix it just yet, just added the failed test.

Banaanae commented 4 days ago

I have a basic fix done (fixes below)

Gui, Add, Text, w250, Gui 1
Gui, Show

Gui, New
Gui, Add, Text, w200, Gui 2
Gui, Show
myGui := Gui()
myGui.Add("Text", "w250", "Gui 1")
myGui.Show()

myGui1 := Gui()
myGui1.Add("Text", "w200", "Gui 2")
myGui1.Show()

But it also somehow broke your script worse? How fun Nevermind, but this script breaks the convertor in serveral ways

Banaanae commented 4 days ago

not quite fixed yet :) The gui, new part is fixed, but the following isn't: