0

I made this function that has in input one block of test with one structure of menus and submenus and create it. It works good for the pattern 1 and 2 (text1,text2). Can someone makes the function general so that it can be applied on any structure of menus and submenus?

    #SingleInstance,Force ;make sure it only runs once

        text1 =

(
1 Search|
2 File|
3 Edit|
4 Vuoto|
5 Tabs|
6 Help|
7 Tip|
8 Trick|
)

        text2 =
(
1 Search>1 Tool-
         2 Option-
         3 Language|
2 File|
3 Edit|
4 Vuoto>1 A perdere-
        2 A rendere|
5 Tabs|
6 Help|
7 Tip>1 interior-
      2 Exwife|
8 Trick|
)


    text3 =
(
1 Prova|
2 Search>1 Tool-
         2 Option-
         3 Language>1 Italiano-
                    2 Francese>1 Angela Merchel-
                               2 Berlusconi-
                               3 Conte-
                    3 Tedesco-
                    4 Inglese-
         4 Sito>1 Vlc-
                2 Windows-
         5 Personaggi|
3 File|
4 Edit|
5 Vuoto|
6 Tabs|
7 Help|
8 Tip>1 interior-
      2 Exwife|
9 Trick|
)

    text4 =
(
1 Prova|
2 Search>1 Tool-
         2 Option-
         3 Language>1 Italiano-
                    2 Francese>1 Angela Merchel-
                               2 Berlusconi-
                               3 Conte-
                    3 Tedesco-
                    4 Inglese-
         4 Sito>1 Vlc-
                2 Windows-
         5 Personaggi|
3 File|
4 Edit|
5 Vuoto>1 A perdere
        2 A rendere
        3 Non Reso
        4 Bottiglia|
6 Tabs|
7 Help|
8 Tip>1 interior-
      2 Exwife|
9 Trick|

)



TextMenu(text2)




return ; End AutoExecute



Esc::
    ExitApp
return






TextMenu(TextOptions)
{
;TextOptions:=Trim(TextOptions)
TextOptions:= RegExReplace(TextOptions," {2,}\W","")
;MsgBox,% TextOptions

        Opzioni:=StrSplit(TextOptions,"|")
        b:=0
        Loop
        {
                b:=b+1
                Opzione:=Opzioni[b]

                MsgBox,
                (
                Opzione n. %b% is
                %Opzione%
                )

                If InStr(Opzione,">"){

                        Submenus:=StrSplit(Opzione,">")
                        Primo:=Submenus[1]

                        a:=1
                        Loop {
                                a:=a+1
                                Submenu:=Submenus[a]

                                MsgBox,
                                (
                                Split Maggiore n %a% is
                                %Submenu%
                                )

                                If InStr(submenu,"-"){

                                                Submenus2:=StrSplit(Submenu,"-")
                                                Primo2:=Submenus2[1]


                                                c:=0
                                                Loop {
                                                        c:=c+1
                                                        Primo3:=Submenus2[c]



                                                        data:=""
                                                        data.="Split - n. " . c . " su " .  Submenus2.MaxIndex() . " is " . "`n"
                                                        data.=primo3
                                                        MsgBox,% data

                                                        Menu, % primo, Add,% primo3, Action

                                                }until (c = Submenus2.MaxIndex() )


                                                Menu, MyMenu, Add, % primo, :%primo%

                                }else{
                                }

                                ;Menu, % primo, Add,% Submenu,Action

                        }until (a = Submenus.MaxIndex() )


                        Menu, MyMenu, Add, % primo, :%primo%
                }else{

                       Menu, MyMenu,Add,% Opzione,Action ;Add each item to the Menu
                }


        }until ( b=Opzioni.MaxIndex()-1 )




    Menu, MyMenu, Show ;Display the GUI and wait for action
    Menu, MyMenu, DeleteAll ;Delete all the menu items

}




Action:
/*
    ClipboardBackup:=ClipboardAll ;backup clipboard
    Clipboard:=A_ThisMenuItem ;Shove what was selected into the clipboard
    Send, ^v ;paste the text
    sleep, 50 ;Remember to sleep before restoring clipboard or it will fail
    Clipboard:=ClipboardBackup ;Restore clipboard
*/
    MsgBox,
(
You selected A_ThisMenuItem = [%A_ThisMenuItem%]
con posizione A_ThisMenuItemPos = [%A_ThisMenuItemPos%]
from the Menu A_ThisMenu = [%A_ThisMenu%]
)


return

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.