Jump to content

Dynamic tab


Recommended Posts

I've got an issue when i add a tab. It adds it successfully. When you switch to the tab if you click one of the edit boxes it pulls information in from best i guess is the first tab. You switch tabs and switch back that information is gone. You can also bypass this by selecting the newly created tab and switching back to another then back to the new tab and it works as it is supposed to. Please help with this goofied issue.

#include <TabConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
#include <GuiTab.au3>

AutoItSetOption("MustDeclareVars",1)
AutoItSetOption("GUICoordMode",2)

Global CONST $BUTTON_VARIABLE_ARRAY_SIZE = 10
Global CONST $CTRL_TAB_TEMPLATE_ARRAY2_SIZE = 9
Global CONST $EMAIL_TEMPLATE_ARRAY2_SIZE = 3

Global $emailTemplateArray[1][$EMAIL_TEMPLATE_ARRAY2_SIZE]
$emailTemplateArray[0][0] = 0

Global $emailTemplateVariables[$BUTTON_VARIABLE_ARRAY_SIZE]
$emailTemplateVariables[0] = $BUTTON_VARIABLE_ARRAY_SIZE - 1
$emailTemplateVariables[1] = "test var"
$emailTemplateVariables[2] = "test var2"
$emailTemplateVariables[3] = "test var3"
$emailTemplateVariables[4] = "test var4"
$emailTemplateVariables[5] = "test var5"
$emailTemplateVariables[6] = "test var6"
$emailTemplateVariables[7] = "test var7"
$emailTemplateVariables[8] = "test var8"
$emailTemplateVariables[9] = "test var9"

_add_Email_Template_Array($emailTemplateArray,"test_button&1","test_subject1","test_body1")
_add_Email_Template_Array($emailTemplateArray,"test_button&2","test_subject2","test_body2")
_add_Email_Template_Array($emailTemplateArray,"test_button&2","test_subject2","test_body2")

EmailTemplateGui()

Func EmailTemplateGui()
    AutoItSetOption("GUICoordMode",1)
    Local $ctrlTabTemplate[$emailTemplateArray[0][0]+1][$CTRL_TAB_TEMPLATE_ARRAY2_SIZE]
    Local $x
    Local $msg
    Local $hData
    Local $loopControl
    Local $renameData
    Local $tempEmailTemplateArray[$emailTemplateArray[0][0]+1][$EMAIL_TEMPLATE_ARRAY2_SIZE]

    $tempEmailTemplateArray = $emailTemplateArray

    GUICreate("Email Templates",480,630)
    $ctrlTabTemplate[0][0] = $tempEmailTemplateArray[0][0]
    $ctrlTabTemplate[0][1] = GUICtrlCreateTab(5,5,470,595)

    For $x = 1 To $tempEmailTemplateArray[0][0]
        $ctrlTabTemplate[$x][0] = GUICtrlCreateTabItem($tempEmailTemplateArray[$x][0])
        $ctrlTabTemplate[$x][1] = GUICtrlCreateLabel("Subject",15,35,50,20)
        $ctrlTabTemplate[$x][2] = GUICtrlCreateEdit($tempEmailTemplateArray[$x][1],15,55,450,35,BitOR($__EDITCONSTANT_WS_HSCROLL,$ES_AUTOHSCROLL))
        $ctrlTabTemplate[$x][3] = GUICtrlCreateLabel("Body",15,100,50,20)
        $ctrlTabTemplate[$x][4] = GUICtrlCreateEdit($tempEmailTemplateArray[$x][2],15,120,450,450)
        $ctrlTabTemplate[$x][5] = GUICtrlCreateButton("Reset",415,35,50,20)
        $ctrlTabTemplate[$x][6] = GUICtrlCreateButton("Reset",415,100,50,20)
        $ctrlTabTemplate[$x][7] = GUICtrlCreateButton("Rename",15,570,50,20)
        $ctrlTabTemplate[$x][8] = GUICtrlCreateButton("Remove",70,570,50,20)
    Next
    GUICtrlCreateTabItem("")
    $ctrlTabTemplate[0][2] = GUICtrlCreateButton("Add",5,605,30,20)
    $ctrlTabTemplate[0][3] = GUICtrlCreateButton("Save and Exit",295,605,75,20)
    $ctrlTabTemplate[0][4] = GUICtrlCreateButton("Exit Do NOT Save",375,605,100,20)

    GUISetState()
    $loopControl = -99999
    While $loopControl = -99999
        $msg = GUIGetMsg()
        ;exit do not save button or x at top
        if $msg = $ctrlTabTemplate[0][4] Or $msg = $GUI_EVENT_CLOSE then
            for $x = 1 To $ctrlTabTemplate[0][0]
                if UBound($tempEmailTemplateArray) <> UBound($emailTemplateArray) or UBound($tempEmailTemplateArray,2) <> UBound($emailTemplateArray,2) or $tempEmailTemplateArray[$x][1] <> GUICtrlRead($ctrlTabTemplate[$x][2]) or $tempEmailTemplateArray[$x][2] <> GUICtrlRead($ctrlTabTemplate[$x][4]) Or $tempEmailTemplateArray[$x][0] <> _GUICtrlTab_GetItemText($ctrlTabTemplate[0][1], $x-1) Then
                    if MsgBox(36,"Are you sure?","Are you sure you wish to exit without saving changes?") = 6 Then
                        $loopControl +=1
                        ExitLoop
                    Else
                        ExitLoop
                    EndIf
                Else
                    $loopControl +=1
                    ExitLoop
                EndIf
            Next
        EndIf
        select
            case $msg = $ctrlTabTemplate[0][2]                      ;add button
                $renameData = InputBox("Add Email Template","Please enter the name you wish to name this email template." & @CRLF & "This name will also be used for the button on the email choices." & @CRLF & "If you wish to have an alt key option for the button use the && before the letter")
                If $renameData <> "" then
                    _email_tab_add($ctrlTabTemplate,$renameData)
                    _add_Email_Template_Array($tempEmailTemplateArray,$renameData & "_ADDED")
                    ;work around
                    $renameData = GUICtrlRead($ctrlTabTemplate[0][1])
                    ;_GUICtrlTab_SetCurFocus($ctrlTabTemplate[0][1],$ctrlTabTemplate[0][0])
                    ;_GUICtrlTab_SetCurFocus($ctrlTabTemplate[0][1],$renameData)
                    ;switch to the one just created
                    ;switch back to previous tab
                EndIf
            case $msg = $ctrlTabTemplate[0][3]                      ;Save and exit
        EndSelect
        For $x = 1 to $ctrlTabTemplate[0][0]
            $hData = GUICtrlRead($ctrlTabTemplate[$x][2])
            if StringInStr($hData,".var",2) > 0 Then
                GUICtrlSetData($ctrlTabTemplate[$x][2],StringReplace($hData,".var",insertVariable()))
            EndIf
            $hData = GUICtrlRead($ctrlTabTemplate[$x][4])
            if StringInStr($hData,".var",2) > 0 Then
                GUICtrlSetData($ctrlTabTemplate[$x][4],StringReplace($hData,".var",insertVariable()))
            EndIf
            Switch $msg
            case $ctrlTabTemplate[$x][5]                    ;subject reset
                GUICtrlSetData($ctrlTabTemplate[$x][2],$tempEmailTemplateArray[$x][1])
            Case $ctrlTabTemplate[$x][6]                    ;body reset
                GUICtrlSetData($ctrlTabTemplate[$x][4],$tempEmailTemplateArray[$x][2])
            Case $ctrlTabTemplate[$x][7]                    ;rename
                $renameData = InputBox("Rename Email Template","Please enter the name you wish to rename this email template to." & @CRLF & "This name will also be used for the button on the email choices." & @CRLF & "If you wish to have an alt key option for the button use the && before the letter")
                If $renameData <> "" then
                    GUICtrlSetData($ctrlTabTemplate[$x][0],$renameData)
                EndIf
            Case $ctrlTabTemplate[$x][8]                    ;remove
                _remove_Email_Template_Array($tempEmailTemplateArray,$x)
                _email_tab_remove($ctrlTabTemplate,$x)
                ExitLoop
            EndSwitch
        Next
        if $ctrlTabTemplate[0][0] = 1 Then
            if Not(GUICtrlGetState($ctrlTabTemplate[1][8]) - 128 >= 0) Then
                GUICtrlSetState($ctrlTabTemplate[1][8],$GUI_DISABLE)
            EndIf
        Else
            if GUICtrlGetState($ctrlTabTemplate[1][8]) - 128 >= 0 Then
                GUICtrlSetState($ctrlTabTemplate[1][8],$GUI_ENABLE)
            EndIf
        EndIf
    WEnd
    GUISetState(@SW_HIDE)
    AutoItSetOption("GUICoordMode",2)
EndFunc

Func _add_Email_Template_Array(ByRef $array,$name,$subject = "",$body = "")
    $array[0][0] += 1
    ReDim $array[$array[0][0]+1][3]
    $array[$array[0][0]][0] = $name
    $array[$array[0][0]][1] = $subject
    $array[$array[0][0]][2] = $body
EndFunc

Func insertVariable()
    local $varsCtrl[$BUTTON_VARIABLE_ARRAY_SIZE]
    Local $x
    Local $result
    Local $hResult
    $varsCtrl[0] = GUICreate("Variable Selection",100,20 * ($emailTemplateVariables[0] + 2))
    For $x =1 To $emailTemplateVariables[0]
        $varsCtrl[$x] = GUICtrlCreateButton($emailTemplateVariables[$x],10,20 * $x,80,20)
    Next
    GUISetState()
    $result = "-99999"
    While $result = "-99999"
        $hResult = GUIGetMsg()
        if $hResult = $GUI_EVENT_CLOSE Then
            $result = ""
            ExitLoop
        EndIf
        For $x = 1 to $emailTemplateVariables[0]
            if $hResult = $varsCtrl[$x] Then
                $result = "[" & $emailTemplateVariables[$x] & "]"
                ExitLoop
            EndIf
        Next
    WEnd
    GUISetState(@SW_HIDE)
    Return $result
EndFunc

Func _email_tab_add(ByRef $array, $tabName, $subjectText = "", $bodyText = "")
    $array[0][0] += 1
    ReDim $array[$array[0][0]+1][$CTRL_TAB_TEMPLATE_ARRAY2_SIZE]
    $array[$array[0][0]][0] = GUICtrlCreateTabItem($tabName)
    $array[$array[0][0]][1] = GUICtrlCreateLabel("Subject",15,35,50,20)
    $array[$array[0][0]][2] = GUICtrlCreateEdit($subjectText,15,55,450,35,BitOR($__EDITCONSTANT_WS_HSCROLL,$ES_AUTOHSCROLL))
    $array[$array[0][0]][3] = GUICtrlCreateLabel("Body",15,100,50,20)
    $array[$array[0][0]][4] = GUICtrlCreateEdit($bodyText,15,120,450,450)
    $array[$array[0][0]][5] = GUICtrlCreateButton("Reset",415,35,50,20)
    $array[$array[0][0]][6] = GUICtrlCreateButton("Reset",415,100,50,20)
    $array[$array[0][0]][7] = GUICtrlCreateButton("Rename",15,570,50,20)
    $array[$array[0][0]][8] = GUICtrlCreateButton("Remove",70,570,50,20)
EndFunc

Func _email_tab_remove(ByRef $array,$index)
    Local $x
    Local $xx
    for $x = $CTRL_TAB_TEMPLATE_ARRAY2_SIZE-1 to 0 Step -1
        GUICtrlDelete($array[$index][$x])
    Next
    if $array[0][0] <> $index Then
        for $x = $index to $array[0][0]-1
            for $xx =0 to $CTRL_TAB_TEMPLATE_ARRAY2_SIZE-1
                $array[$x][$xx] = $array[$x+1][$xx]
            Next
        Next
    EndIf
    ReDim $array[$array[0][0]][$CTRL_TAB_TEMPLATE_ARRAY2_SIZE]
    $array[0][0] -= 1

EndFunc

Func _remove_Email_Template_Array(ByRef $array, $index)
    Local $x
    Local $xx
    if $array[0][0] <> $index Then
        for $x = 1 to $array[0][0]-1
            For $xx = 0 to $EMAIL_TEMPLATE_ARRAY2_SIZE-1
                $array[$x][$xx] = $array[$x+1][$xx]
            Next
        Next
    EndIf
    ReDim $array[$array[0][0]][$EMAIL_TEMPLATE_ARRAY2_SIZE]
    $array[0][0] -= 1
EndFunc
Link to comment
Share on other sites

  • Moderators

ibigpapa,

You are not closing your tab creation code when you add a new tab.

If you add GUICtrlCreateTabItem("") after the tab creation code in Function _email_tab_add everything works as it should.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...