
#-------------------------------------------------------------------------------
# Module:     menuBrowser.tk
# Activation: Loaded during GOBLET startup
# Scope:      Browser menu item and bindings
#             Writing browser configuration to file
#-------------------------------------------------------------------------------



menu .mbar.browser.menu
.mbar.browser.menu add command -label "Toggle Editor/Navigator" \
    -accelerator Ctrl+D -command ToggleBrowser
.mbar.browser.menu add command -label "Snapshot Image" \
    -accelerator Ctrl+T -command DisplayNewLayout
.mbar.browser.menu add command -label "View/Update Messenger" \
    -accelerator Ctrl+L -command {ViewMessenger}
.mbar.browser.menu add separator
.mbar.browser.menu add command -label "Tracing Options..." \
    -accelerator Shift+Ctrl+T -command SourceTraceOpt
.mbar.browser.menu add command -label "Browser Options..." \
    -accelerator Shift+Ctrl+B -command SourceBrowseOpt
.mbar.browser.menu add command -label "Logging Options..." \
    -accelerator Shift+Ctrl+L -command SourceLogOpt
.mbar.browser.menu add command -label "Save Browser Settings" \
    -command SaveBrowserSettings
    
proc AdjustDialogPadding {} {
    global InternalWindowing DefPadX DefPadY
    if {$InternalWindowing} {
        set DefPadX "3m"
        set DefPadY "0m"
    } else {
        set DefPadX "10m"
        set DefPadY "5m"
    }
}

proc SourceTraceOpt {} {
    global GoblinTclPath
    source [file join $GoblinTclPath browserTraceOpt.tk]
}

proc SourceBrowseOpt {} {
    global GoblinTclPath
    source [file join $GoblinTclPath browserOptions.tk]
}

proc SourceLogOpt {} {
    global GoblinTclPath
    source [file join $GoblinTclPath browserLogOpt.tk]
}

proc SaveBrowserSettings {} {
    destroy .saveChanges
    toplevel .saveChanges
    wm title .saveChanges "GOBLET Prompt"
    wm resizable .saveChanges 0 0
    grab set .saveChanges

    global FileName
     
    frame .saveChanges.buttons
    button .saveChanges.buttons.cancel -text "Cancel" -command { \
        destroy .saveChanges
    }
    
    button .saveChanges.buttons.save -text "Yes" -command { \
        destroy .saveChanges

        global BrowserSettings PrintCommand BalloonHelp goblinCommLevel \
            SingleStep UpdateCycle InternalWindowing ChangeOptions \
            AlignOptions BruteOverwrite BrowserBalance DialogBalance \
            DialogBalance2 SepWidth Grid BackupLevel \
            InitialWidth InitialHeight BorderOptions Bg1Options

        set file [open "$BrowserSettings" w]

        puts $file "set PrintCommand \"$PrintCommand\""
        puts $file "set ZipCommand \"$ZipCommand\""
        puts $file "set UnzipCommand \"$UnzipCommand\""
        puts $file "set ZipExtension \"$ZipExtension\""
        puts $file "set ZipEnabled $ZipEnabled"
        puts $file "set BalloonHelp $BalloonHelp"
        puts $file "set goblinCommLevel $goblinCommLevel"
        puts $file "set goblinLPDisplay $goblinLPDisplay"
        puts $file "set SingleStep $SingleStep"
        puts $file "set UpdateCycle $UpdateCycle"
        puts $file "set BackupLevel $BackupLevel"
        puts $file "set InternalWindowing $InternalWindowing"
        puts $file "set ChangeOptions $ChangeOptions"
        puts $file "set AlignOptions $AlignOptions"
        puts $file "set BruteOverwrite $BruteOverwrite"
        puts $file "set Grid $Grid"
        puts $file "set BrowserBalance $BrowserBalance"
        puts $file "set DialogBalance $DialogBalance"
        puts $file "set DialogBalance2 $DialogBalance2"
        puts $file "set SepWidth $SepWidth"
        puts $file "set InitialWidth [winfo width .]"
        puts $file "set InitialHeight [winfo height .]"

        close $file
    }
    
    pack .saveChanges.buttons.save .saveChanges.buttons.cancel \
        -side left -fill x -padx 3m
     
    pack .saveChanges.buttons -padx 3m -pady 3m -side bottom
    
    global BrowserSettings
    label .saveChanges.warn -image msg_warn
    message .saveChanges.msg -width 10c \
        -text "Save current browser settings ?"
    pack .saveChanges.warn .saveChanges.msg -padx 2m -pady 3m -side left
}

proc ToggleBrowser {} {
    global goblinTraceCounter Mode

    if {[string equal $Mode "display object"] || [string equal $Mode "trace"]} {
        InitNavigator
    } else {
        DisplayObject
    }
}

bind . <Control-d> {ToggleBrowser}
bind . <Control-l> {ViewMessenger}
bind . <Control-T> {SourceTraceOpt}
bind . <Control-B> {SourceBrowseOpt}
bind . <Control-L> {SourceLogOpt}
