
#-------------------------------------------------------------------------------
# Module:     browserOptions.tk
# Activation: Dynamically loadad on user request
# Scope:      Browser options dialog
#-------------------------------------------------------------------------------



proc SelectBrowserOptions {} {
    global WDBrowseOpt DialogFrame DefPadX DefPadY ActiveDialog ChangeOptions \
        AlignOptions InternalWindowing BalloonHelp BruteOverwrite BackupLevel \
        Fr2Options Fr1Options

    if {$ActiveDialog=="Browser Options"} {return}

    if {$InternalWindowing} {
        set WDBrowseOpt $DialogFrame.browseopt
        if {![winfo exists $WDBrowseOpt]} {
            eval frame $WDBrowseOpt $Fr1Options
        }
        
        RegisterDialog "Browser Options" $WDBrowseOpt SelectBrowserOptions {}
    } else {
        set WDBrowseOpt .browseopt
        if {![winfo exists $WDBrowseOpt]} {
            toplevel $WDBrowseOpt
            wm title $WDBrowseOpt "Browser Options"
            wm resizable $WDBrowseOpt 0 0
        } else {return}
    }
    
    eval frame $WDBrowseOpt.buttons $Fr1Options
    button $WDBrowseOpt.buttons.done -text "Done" -command {
        if {$InternalWindowing} {
            DestroyActiveDialog
        } else {
            destroy $WDBrowseOpt
        }
    }
    pack $WDBrowseOpt.buttons.done -side left -fill x -padx 3m
     
    pack $WDBrowseOpt.buttons -padx 5m -pady 5m -side bottom
    eval frame $WDBrowseOpt.f1 $Fr1Options
    eval frame $WDBrowseOpt.f1.saveopt $Fr2Options
#    eval frame $WDBrowseOpt.f1.align $Fr2Options
    eval frame $WDBrowseOpt.f1.check $Fr2Options
    eval frame $WDBrowseOpt.f1.backup $Fr2Options
    pack $WDBrowseOpt.f1.saveopt $WDBrowseOpt.f1.check $WDBrowseOpt.f1.backup \
        -side top -fill x -pady 3m
     
    pack $WDBrowseOpt.f1 -side top -fill x -padx $DefPadX -pady 3m

    label $WDBrowseOpt.f1.saveopt.label -text "Dismissed Objects:" -anchor w
    radiobutton $WDBrowseOpt.f1.saveopt.save -text "Automatically Save To File" \
        -variable ChangeOptions -value 0 -anchor w
    radiobutton $WDBrowseOpt.f1.saveopt.ask -text "Require Confirmations" \
        -variable ChangeOptions -value 1 -anchor w
    radiobutton $WDBrowseOpt.f1.saveopt.exit -text "Do Not Save To File" \
        -variable ChangeOptions -value 2 -anchor w
    pack $WDBrowseOpt.f1.saveopt.label $WDBrowseOpt.f1.saveopt.save \
        $WDBrowseOpt.f1.saveopt.ask $WDBrowseOpt.f1.saveopt.exit -side top -fill x
     
#    label $WDBrowseOpt.f1.align.label -text "Fit Graph Into Canvas:" -anchor w
#    radiobutton $WDBrowseOpt.f1.align.user -text "Only By User Demand" \
#        -variable AlignOptions -value 0 -anchor w
#    radiobutton $WDBrowseOpt.f1.align.trace -text "When Tracing Algorithms" \
#        -variable AlignOptions -value 1 -anchor w
#    radiobutton $WDBrowseOpt.f1.align.always -text "Every Time Object Is Drawn" \
#        -variable AlignOptions -value 2 -anchor w
#    pack $WDBrowseOpt.f1.align.label $WDBrowseOpt.f1.align.user \
#        $WDBrowseOpt.f1.align.trace $WDBrowseOpt.f1.align.always -side top -fill x
    
    checkbutton $WDBrowseOpt.f1.check.popup -text "Pop-Up Infos" \
        -variable BalloonHelp -anchor w
    checkbutton $WDBrowseOpt.f1.check.attach -text "Attach Slave Windows" \
        -variable InternalWindowing -anchor w -command {
            global RegisteredDialogs ActiveDialog 
            AdjustDialogPadding
            if {!$InternalWindowing} {
                set RegisteredDialogs [list]
                DestroyActiveDialog
                set ActiveDialog ""
                SplitWorkspace
                InitDialogRegion
            } else {
                destroy $WDBrowseOpt
                set RegisteredDialogs [list]
                set ActiveDialog ""
            }
            SelectBrowserOptions
        }
    checkbutton $WDBrowseOpt.f1.check.overwrite \
        -text "Overwrite Without Warning" -variable BruteOverwrite -anchor w
    pack $WDBrowseOpt.f1.check.popup $WDBrowseOpt.f1.check.attach \
        $WDBrowseOpt.f1.check.overwrite -side top -fill x

    label $WDBrowseOpt.f1.backup.label -text "Undo Stack Size:  " -anchor w
    entry $WDBrowseOpt.f1.backup.entry -textvariable BackupLevel \
        -bg white -width 3
    pack $WDBrowseOpt.f1.backup.label $WDBrowseOpt.f1.backup.entry -side left -fill x

    if {$InternalWindowing} {
        pack $WDBrowseOpt -anchor nw
        AlignActiveDialog
    }
}

if {![info exists WDBrowseOpt] || ![winfo exists $WDBrowseOpt]} {SelectBrowserOptions}
