
#-------------------------------------------------------------------------------
# Module:     mainGoblet.tk
# Activation: Loaded during GOBLET startup
# Scope:      Main procedure
#             GOBLET initialization
#-------------------------------------------------------------------------------



# Configuration data: Change to your convenience

set Fr1Options ""
# set Fr1Options "-bg wheat"
    # Appearance of the outermost frame in various dialogs
set Fr2Options ""
# set Fr2Options "-bg wheat -relief groove -borderwidth 1m"
    # Appearance of the subframes in various dialogs



# Data initialization: Do not change

set StartCompleted 0
set BrowserDisabled 0

set goblinDisplayMode 3
set goblinLPDisplay 7

set ThisNColours ""
set ThisDegree 1
set goblinSource "*"
set goblinTarget "*"
set goblinRoot "*"

set TotalTime 0
set PrevTime "idle"
set SystemInfo "idle"
set SystemInfoType 1
set ActiveDialog ""

set Zoom 0.073

set RegisteredDialogs [list]

set Mode "insert nodes"



### ---------------------------- GOBLET Menus -------------------------- ###

frame .mbar -relief raised -borderwidth 1
pack .mbar -side top -fill x

menubutton .mbar.file -text File -underline 0 -menu .mbar.file.menu
menubutton .mbar.edit -text Edit -underline 0 -menu .mbar.edit.menu
menubutton .mbar.compose -text Compose -underline 0 -menu .mbar.compose.menu
menubutton .mbar.layout -text Layout -underline 0 -menu .mbar.layout.menu
menubutton .mbar.optimize -text Optimize -underline 0 -menu .mbar.optimize.menu
menubutton .mbar.browser -text Browser -underline 0 -menu .mbar.browser.menu
menubutton .mbar.info -text Info -underline 0 -menu .mbar.info.menu
pack .mbar.file .mbar.edit .mbar.compose .mbar.layout .mbar.optimize \
    .mbar.browser -side left
pack .mbar.info -side right


proc MakeMenus {} {
    MakeEditMenu
    MakeComposeMenu
    MakeLayoutMenu
    MakeOptimizeMenu
    MakeToolbar
}

image create photo msg_warn   -file [file join $GoblinTclPath msgWarn.gif]
image create photo msg_stop   -file [file join $GoblinTclPath msgStop.gif]
image create photo fold_open  -file [file join $GoblinTclPath foldOpen.gif]
image create photo fold_close -file [file join $GoblinTclPath foldClose.gif]
image create photo move_plus  -file [file join $GoblinTclPath foldOpen.gif]
image create photo move_minus -file [file join $GoblinTclPath foldClose.gif]
image create photo delbutton  -file [file join $GoblinTclPath delbutton.gif]


# File Menu

source [file join $GoblinTclPath menuFile.tk]


# Edit Menu

source [file join $GoblinTclPath menuEdit.tk]


# Compose Menu

source [file join $GoblinTclPath menuCompose.tk]


# Layout Menu

source [file join $GoblinTclPath menuLayout.tk]


# Optimize Menu

source [file join $GoblinTclPath menuOptimize.tk]


# Browser Menu

source [file join $GoblinTclPath menuBrowser.tk]


# Info Menu

source [file join $GoblinTclPath menuInfo.tk]




### ----------------------------- Workspace ---------------------------- ###


# Iconbars and Popup Infos

source [file join $GoblinTclPath mainIconbars.tk]


# Status line

source [file join $GoblinTclPath mainStatus.tk]


# Workspace, Canvas and Dialog Region

source [file join $GoblinTclPath mainWorkspace.tk]


# Messenger Region

source [file join $GoblinTclPath mainMessenger.tk]


# Graph Editor

source [file join $GoblinTclPath mainEditor.tk]




### ---------------------- Browser Initialization ---------------------- ###

# Directories

set WorkingDir [pwd]
set TraceDir [file join $env(HOME) .goblet]
file mkdir $TraceDir

set FileName [file join $TraceDir "unnamed"]
set OrigFileName "unnamed"

# Load Configuration File

source [file join $GoblinTclPath browserDefaults.tk]
set BrowserSettings [file join $TraceDir settings.tcl]
if {[file exists $BrowserSettings]} {
    catch {source $BrowserSettings}
}

# Configure Toplevel Window

wm geometry . [expr $InitialWidth]x[expr $InitialHeight]+[ \
    expr ([winfo screenwidth .]-$InitialWidth)/2]+[ \
    expr ([winfo screenheight .]-$InitialHeight)/2]
wm minsize  . 640 400
wm deiconify .

# Setup Default Graph Object

set ThisGraph GOB1
goblin mixed graph $ThisGraph

# Assemble Browser Window

AdjustDialogPadding
InitDialogRegion
InitCanvasRegion
InitFile

# Load Graph Object

if {$argc != 0} {
    if {[file extension [lindex $argv 0]]==".$goblinExtension"} {
        set OrigFileName [file rootname [lindex $argv 0]]
    } else {
        set OrigFileName [lindex $argv 0]
    }
    if {![file exists $OrigFileName.$goblinExtension]} {
        if {![file exists $OrigFileName.$goblinExtension$ZipExtension]} {
            toplevel .input
            wm title .input "GOBLET Prompt"
            wm resizable .input 0 0

            frame .input.buttons
            pack .input.buttons -padx 3m -pady 3m -side bottom

            button .input.buttons.start -text "Create" -command { \
                wm title . "GOBLET: [file tail $OrigFileName]"
                destroy .input
            }

            button .input.buttons.exit -text "Exit" -command { \
                destroy .input
                exit 0
            }    

            pack .input.buttons.start .input.buttons.exit \
                -side left -fill x -padx 3m

            label .input.warn -image msg_warn
            message .input.msg -width 10c -anchor w \
                -text "The file \"$OrigFileName\" does not exist!"
            pack .input.warn .input.msg -padx 2m -pady 3m -side left

            grab set .input
            raise .input .
        } else {
            eval exec $UnzipCommand $OrigFileName.$goblinExtension$ZipExtension
            set ZipEnabled 1
            cd [file dirname $OrigFileName]
            set WorkingDir [pwd]
            set OrigFileName [file join $WorkingDir [file tail $OrigFileName]]
            OpenFile
            eval exec $ZipCommand $OrigFileName.$goblinExtension
            DestroyLogFile
        }
    } else {
        set ZipEnabled 0
        cd [file dirname $OrigFileName]
        set WorkingDir [pwd]
        set OrigFileName [file join $WorkingDir [file tail $OrigFileName]]
        OpenFile
        DestroyLogFile
    }
}

set StartCompleted 1
