#!/bin/sh # the next line restarts using wish \ exec wish "$0" "$@" global copyright set copyright "browse v0.7 Copyright (c) 1995-1997, Karl J. Runge" # script to provide directory/file browser. # Usage: browse [start_dir] # returns "" or selected file to stdout. # May return a User suggested filename # (i.e. one typed in entry that might not exist yet). # browse -fm will run as simple filemanager. See Edit, Viewer, Shell # procedures below. # Todo: # arrow key movement in Path entry box. # arrow key movement in listbox?? # geometry on command line. # cleanup code with rewrite # Procedure to create a simple resizable listbox or text widget. # MAKE LISTBOX OR TEXTAREA proc makeListBox { \ {frame_name} \ {insert ""} \ {width ""} \ {height ""} \ {type "listbox"} \ {hscroll "True"} \ {vscroll "True"} \ {font ""} \ } \ { # Todo: MUST fix height+width for text widget as well # default height is # of elements if { "$height" == "" } { if { $type == "listbox" } { set height [llength $insert]; } else { set height 0; foreach line [split $insert \n] { incr height; } } } # default width is max(5,max_width) if { "$width" == "" } { set width 5; # min width if { $type == "listbox" } { set split " "; } else { set split "\n"; } foreach line [split $insert $split] { set tmp_width [string length $line]; if { $tmp_width > $width } { set width $tmp_width; } } } if { ![winfo exists $frame_name] } { # create the frame to place widgets in frame $frame_name \ -bd 1; } # setup for resizing... # this is garbage so far... set relief "raised"; # set relief of list area # "sunken" and "" are other choices # Cases for "listbox" or "text" types... if { "$type" == "listbox" } { # now make listbox with scroll cmds global tk_version if { $tk_version < "4.0" } { listbox $frame_name.listbox \ -geom ${width}x${height} \ -setgrid 1 \ -yscrollcommand "$frame_name.scrolly set" \ -xscrollcommand "$frame_name.scrollx set" \ -relief $relief \ -bd 1 \ -font $font; } else { listbox $frame_name.listbox \ -width ${width} \ -height ${height} \ -setgrid 1 \ -yscrollcommand "$frame_name.scrolly set" \ -xscrollcommand "$frame_name.scrollx set" \ -relief $relief \ -bd 1 \ -font $font; } } elseif { "$type" == "text" } { # or make text widget with scroll cmd text $frame_name.text \ -width $width \ -height $height \ -setgrid 1 \ -yscrollcommand "$frame_name.scrolly set" \ -relief $relief \ -bd 1 \ -font $font; } # create the two scrollbars scrollbar $frame_name.scrolly \ -relief sunken \ -command "$frame_name.$type yview" if { "$type" != "text" } { # "text" doesn''t scroll horizontally # (or does it in tk4.0??) scrollbar $frame_name.scrollx \ -orient horizontal \ -relief sunken \ -command "$frame_name.$type xview" } else { set hscroll "False"; } # clear and insert list entries if { "$type" == "listbox" } { $frame_name.$type delete 0 end; eval $frame_name.$type insert 0 $insert; } elseif { "$type" == "text" } { $frame_name.$type insert 0.0 $insert; } # pack them together if { "$vscroll" == "True" } { # if doing vertical scrollbar pack $frame_name.scrolly \ -side right \ -fill y; } pack $frame_name.$type \ -side top \ -fill both \ -expand 1; if { "$hscroll" == "True" } { # if doing horizontal scrollbar pack $frame_name.scrollx \ -side top \ -fill x; } # A load of paging/motion bindings: # probably broke for Sun Keyboard... # comment out real characters so one can enter text # are some of these broken in tk_4.0? # (i.e. already there, and bound twice) bind $frame_name.$type "focus %W"; bind $frame_name.$type "pageDown $frame_name $type"; bind $frame_name.$type "pageDown $frame_name $type"; bind $frame_name.$type "pageDown $frame_name $type"; bind $frame_name.$type "pageDown $frame_name $type half"; bind $frame_name.$type "pageDown $frame_name $type line"; bind $frame_name.$type "pageDown $frame_name $type line"; bind $frame_name.$type "pageDown $frame_name $type line"; bind $frame_name.$type "pageUp $frame_name $type"; bind $frame_name.$type "pageUp $frame_name $type"; bind $frame_name.$type "pageUp $frame_name $type"; bind $frame_name.$type "pageUp $frame_name $type half"; bind $frame_name.$type "pageUp $frame_name $type line"; bind $frame_name.$type "pageUp $frame_name $type line"; bind $frame_name.$type "pageUp $frame_name $type line"; } # PAGING ACTION DOWN # paging Down procedure fullpage, halfpage, line proc pageDown {frame_name type {step full}} { # PAGEDOWN A TEXTAREA # get scrollbar position info global tk_version if { $tk_version < "4.0" } { set win_hgt [lindex [$frame_name.scrolly get] 1]; set win_p_min [lindex [$frame_name.scrolly get] 2]; if { $step == "half" } { set win_hgt [expr int($win_hgt/2)]; } elseif { $step == "line" } { set win_hgt 1; } # scroll the text/listbox window $frame_name.$type yview [expr $win_p_min+$win_hgt]; } else { if { $step == "half" } { set fList [$frame_name.scrolly get] set win_start [lindex $fList 0]; set win_stop [lindex $fList 1]; set win_hgt [expr "$win_stop - $win_start"] set win_half [expr $win_hgt/2]; $frame_name.$type yview moveto [expr $win_start+$win_half]; } elseif { $step == "line" } { $frame_name.$type yview scroll 1 unit } else { $frame_name.$type yview scroll 1 page } return -code break } } # PAGING ACTION UP # paging Up procedure fullpage, halfpage, line proc pageUp {frame_name type {step full}} { # PAGEUP A TEXTAREA # get scrollbar position info global tk_version if { $tk_version < "4.0" } { set win_hgt [lindex [$frame_name.scrolly get] 1]; set win_p_min [lindex [$frame_name.scrolly get] 2]; if { $step == "half" } { set win_hgt [expr int($win_hgt/2)]; } elseif { $step == "line" } { set win_hgt 1; } set diff [expr $win_p_min-$win_hgt]; if { "$diff" < 0 } { set diff 0 } # scroll the text/listbox window $frame_name.$type yview $diff; } else { if { $step == "half" } { set fList [$frame_name.scrolly get] set win_start [lindex $fList 0]; set win_stop [lindex $fList 1]; set win_hgt [expr "$win_stop - $win_start"] set win_half [expr $win_hgt/2]; $frame_name.$type yview moveto [expr $win_start-$win_half]; } elseif { $step == "line" } { $frame_name.$type yview scroll -1 unit } else { $frame_name.$type yview scroll -1 page } return -code break } } # FILENAME COMPLETION STUFF #-----File Complete Begin--------# # simple function to do file completion on string "partial_path" proc fileComplete {partial_path} { # FIND FILENAME COMPLETIONS set debug 0; # regsub {/[^/]*} "$partial_path" "/" dir_name; # get the glob list straight off: set list [glob -nocomplain ${partial_path}*]; if {$debug} {puts "list is: $list";} if { "$list" == "" } { # if no matches, send him back what he gave us return "$partial_path"; } set n_files [llength [split "$list"]]; # the number of matches if {"$n_files" == "1" } { # if only one return it set return_file [lindex $list 0]; if [file isdirectory $return_file] { # tack "/" on directory regsub {$} "$return_file" "/" return_file; } global env regsub "^$env(HOME)" $return_file {~} return_file; return $return_file; } # We have to loop set base_length [string length $partial_path]; set i [expr ${base_length}-1]; # definitely matches to this index set matching 1; while {$matching} { set igood $i; # maximum "good" index set matching 0; incr i; # try next index if {$debug} {puts "i is: $i";} set count 0; if [info exists tally] { unset tally; # tallies all characters at $i } foreach file $list { if {$debug} {puts "file is: $file";} set char [string index $file $i]; # get $i position if {$debug} {puts "char is: $char";} if {"$char" == ""} { # call no char "NULL" set index "NULL"; } else { # otherwise call it char set index "$char"; } if [info exists tally($index)] { # tally it incr tally($index); } else { set tally($index) 1; } } if {[array size tally] == "1" } { # if only one they all matched set matching 1; } } # return maximum match string set return_string [string range [lindex $list 0] 0 $igood]; if {$debug} {puts stdout $return_string;} global env regsub "^$env(HOME)" $return_string {~} return_string; return $return_string; } # simple function to make a selectable listbox of glob file matches # to "partial_path" proc filePossibilities {window entryInsert partial_path {font ""}} { # MAKE FILECOMPLETION POSSIBILITIES COMBO BOX global env Match set debug 0; set w .filePossibilitiesList; # toplevel widget name catch {destroy $w} toplevel $w; # glob it set list [glob -nocomplain ${partial_path}*]; set list_len [llength $list]; if { $list_len == "0" } { # one empty line if no matches set list_len 1; } if { $list_len < 7 } { # scroll > 7 set lheight $list_len } else { set lheight 7; } set list0 [lsort $list]; # sort them unset list; set list ""; foreach item $list0 { # trailing "/" for directories if { [file isfile $item] && $Match != "" && ![regexp $Match $item] } { # puts "OUT $Match $item" continue } if [file isdirectory $item] { set item "${item}/"; } regsub "^$env(HOME)" $item {~} item; lappend list "$item"; } if {"$window" == "ListOnly" } { # hook for list only return $list; } set p_x [winfo rootx $window]; # place it below $window set p_y [winfo rooty $window]; set p_h [winfo height $window]; # tweak for alignment... set p_x [expr ${p_x}-2]; set p_y [expr $p_y+$p_h+3]; # set the geometry position wm geometry $w +$p_x+$p_y; wm transient $w .; # no decorations makeListBox $w.listbox $list "" $lheight listbox True True $font; $w.listbox configure -bd 0; # trim excess border $w.listbox.listbox configure -bd 0; # we can insert selection into an # entry box.... if {"$entryInsert" == "True" } { #bind $w.listbox.listbox " # single click gets it bind $w.listbox.listbox " set sel \[selection get\]; $window delete 0 end; $window insert 0 \$sel; focus $window; after 200; destroy $w; " # keypress to kill listbox foreach key {Tab Meta-Tab} { foreach place "$w.listbox $w.listbox.listbox" { if {$debug} {puts "place is $place";} bind $place <$key> " focus $window; after 200; destroy $w; " } } } bind $w.listbox.listbox "focus $window; destroy $w"; global tk_version if { $tk_version >= 4.0 } { set wll $w.listbox.listbox eval bindtags $wll \{Listbox $wll . all\} } # dismiss button button $w.dismiss \ -text Dismiss \ -command "focus $window; destroy $w"; if { "$font" != "" } { $w.dismiss configure \ -font $font; } # pack together pack $w.listbox $w.dismiss \ -side top \ -fill x; # focus here for keypress exit focus $w.listbox.listbox if {$debug} {puts "list is: $list";} } #-----File Complete End----------# # PRIMARY BROWSE FUNCTION #----Browse.tcl-------# # This browses around in directories til you select a file # The logic gets rather contorted. Need to find the time to do a rewrite... # BROWSE DIRECTORIES FOR FILENAME proc browse { {width 32} \ {height 16} \ {delete FALSE} \ {recallOldDir TRUE} \ {needsToExist FALSE} \ {w .browse} \ } { global font fontSmall fontSmallerBold; global SelBrowse PwdBrowse KillBrowse RetBrowse DelBrowse DirBrowse global Match set SelBrowse ""; set RetBrowse ""; set DelBrowse "0"; set KillBrowse "False"; set text_var DirBrowse; global $text_var; global env; set cmd "selectBrowse; checkFileBrowse $w; refreshBrowse $w;"; if { $w != "." } { catch {destroy $w}; toplevel $w; } wm title $w "$PwdBrowse"; wm iconname $w "Browser"; wm minsize $w 1 1; set relief "groove"; frame $w.top \ -bd 1; global fontSmallerBold button $w.top.edit \ -text "Edit" \ -command {Edit [expand_tilde [selectBrowse]]} \ -font $fontSmallerBold; button $w.top.view \ -text "Viewer" \ -command {Viewer [expand_tilde [selectBrowse]]} \ -font $fontSmallerBold; button $w.top.shell \ -text "Shell" \ -command {Shell [expand_tilde [selectBrowse]]} \ -font $fontSmallerBold; global Viewer_Button Edit_Button Shell_Button if { $Viewer_Button || $Edit_Button || $Shell_Button } { if { $Edit_Button } { pack $w.top.edit -side left -expand 0; } if { $Viewer_Button } { pack $w.top.view -side left -expand 0; } if { $Shell_Button } { pack $w.top.shell -side left -expand 0; } } global Msg if { $Msg != "" } { label $w.msg \ -font $font \ -relief groove \ -text $Msg; } frame $w.frame \ -borderwidth 2; scrollbar $w.frame.scrolly \ -relief sunken \ -command "$w.frame.list yview"; scrollbar $w.frame.scrollx \ -relief sunken \ -orient horizontal \ -command "$w.frame.list xview"; global tk_version if { $tk_version < "4.0" } { listbox $w.frame.list \ -yscroll "$w.frame.scrolly set" \ -xscroll "$w.frame.scrollx set" \ -relief $relief \ -geom ${width}x${height} \ -setgrid 1 \ -font $fontSmall; } else { listbox $w.frame.list \ -yscroll "$w.frame.scrolly set" \ -xscroll "$w.frame.scrollx set" \ -relief $relief \ -width ${width} \ -height ${height} \ -setgrid 1 \ -font $fontSmall; } set width [expr ${width}+2]; frame $w.dir \ -bd 1; entry $w.dir.entry \ -relief sunken \ -width $width \ -font $fontSmall \ -textvariable $text_var; global tk_version if { $tk_version >= 4.0 } { set wde $w.dir.entry eval bindtags $wde \{Entry . all $wde\} } bind $w.dir.entry " $w.dir.entry delete 0 end; "; label $w.dir.label; bind $w.dir.entry " update; if \[file isdirectory \$DirBrowse\] \{ \ regsub \{/\$\} \$DirBrowse \{\} DirBrowse; \ set PwdBrowse \$DirBrowse; \ cd \$PwdBrowse; \ regsub \"^$env(HOME)\" \$PwdBrowse {~} PwdBrowse; \ refreshBrowse $w; \ wm title $w \"\$PwdBrowse\"; \ $w.dir.entry delete 0 end; \ $w.dir.entry insert 0 \$PwdBrowse; \ \} elseif \{ \[file isfile \$DirBrowse\] || \ \"$needsToExist\" == \"FALSE\"\} \{ \ set SelBrowse \$DirBrowse; \ regsub \"^$env(HOME)\" \$SelBrowse {~} SelBrowse; \ checkFileBrowse $w; \ refreshBrowse $w; \ \}" foreach key {Escape Tab Meta-Tab} { bind $w.dir.entry <$key> " set complete \[fileComplete \$$text_var\]; $w.dir.entry delete 0 end; $w.dir.entry insert 0 \$complete; focus $w.dir.entry; " } bind $w.dir.entry "focus %W" bind $w.dir.entry "filePossibilities $w.dir.entry True \$$text_var $fontSmall" bind $w.dir.entry <2> { %W insert insert [selection get] }; global fontSmallerBold $w.dir.label config -text "Path: " -font $fontSmallerBold; $w.dir.entry delete 0 end; $w.dir.entry insert 0 $PwdBrowse; pack $w.dir.label \ -side left; pack $w.dir.entry \ -side left \ -fill x \ -expand 1; frame $w.match \ -bd 1; entry $w.match.entry \ -relief sunken \ -width $width \ -font $fontSmall \ -textvariable Match; global tk_version if { $tk_version >= 4.0 } { set wde $w.match.entry eval bindtags $wde \{Entry . all $wde\} } bind $w.match.entry " $w.match.entry delete 0 end; "; label $w.match.label; bind $w.match.entry "set SelBrowse \".\"; refreshBrowse $w" bind $w.match.entry "focus %W" bind $w.match.entry <2> { %W insert insert [selection get] }; $w.match.label config -text "Match: " -font $fontSmallerBold; pack $w.match.label \ -side left; pack $w.match.entry \ -side left \ -fill x \ -expand 1; pack $w.frame.scrolly \ -side right \ -fill y; pack $w.frame.scrollx \ -side bottom \ -fill x; pack $w.frame.list \ -fill both \ -expand 1; refreshBrowse $w; bind $w.frame.list "$cmd"; #--Begin New bind $w.frame.list "focus %W"; bind $w.frame.list "pageDown $w.frame list"; bind $w.frame.list "pageDown $w.frame list"; bind $w.frame.list "pageDown $w.frame list"; bind $w.frame.list "pageDown $w.frame list half"; bind $w.frame.list "pageDown $w.frame list line"; bind $w.frame.list "pageDown $w.frame list line"; bind $w.frame.list "pageDown $w.frame list line"; bind $w.frame.list "pageUp $w.frame list"; bind $w.frame.list "pageUp $w.frame list"; bind $w.frame.list "pageUp $w.frame list"; bind $w.frame.list "pageUp $w.frame list half"; bind $w.frame.list "pageUp $w.frame list line"; bind $w.frame.list "pageUp $w.frame list line"; bind $w.frame.list "pageUp $w.frame list line"; #--End New global fontSmallerBold button $w.ok \ -text "OK" \ -command "$cmd" \ -font $fontSmallerBold; button $w.delete \ -text "Delete" \ -command "set DelBrowse 1; $cmd; set DelBrowse 0" \ -font $fontSmallerBold; button $w.cancel \ -text Dismiss \ -command "puts stdout \"\"; destroy $w; exit 0" \ -font $fontSmallerBold; bind $w.frame.list "destroy $w"; pack $w.top \ -side top \ -fill x; if { $Msg != "" } { pack $w.msg \ -side top \ -fill x; } pack $w.frame \ -side top \ -fill both \ -expand 1; pack $w.cancel \ -side bottom \ -fill x; if {$delete == "TRUE"} { pack $w.delete \ -side bottom \ -fill x; } pack $w.ok $w.match $w.dir \ -side bottom \ -fill x; global Geom if {$Geom == "+0+0"} { util_center_window $w } else { wm geometry $w $Geom } focus $w.dir.entry; tkwait window $w; catch {set RetBrowse [glob -nocomplain $RetBrowse]} return $RetBrowse; } # SELECT WHAT USER HAS HIGHLIGHTED proc selectBrowse {} { global SelBrowse DirBrowse PwdBrowse set SelBrowse "" catch {set SelBrowse [lindex [selection get] 0]} if { $SelBrowse == "" } { set SelBrowse $DirBrowse; } else { set SelBrowse $PwdBrowse/$SelBrowse } regsub {\*$} $SelBrowse "" SelBrowse; regsub {@$} $SelBrowse "" SelBrowse; regsub {/$} $SelBrowse "" SelBrowse; return $SelBrowse; } # EXAMINE WHAT USER HAS HIGHLIGHTED # (I.E. EITHER FILE OR DIRECTORY) proc checkFileBrowse {w} { global SelBrowse KillBrowse PwdBrowse RetBrowse global env; if ![file isdirectory $SelBrowse] { # Then it is a file depress $w.ok; set RetBrowse "$SelBrowse"; regsub {^~} $RetBrowse $env(HOME) RetBrowse set KillBrowse "True"; } else { # Then it is a directory $w.ok configure \ -state active; $w.ok configure \ -relief sunken; update; $w.ok configure \ -state normal; $w.ok configure \ -relief raised; update; cd $SelBrowse; set PwdBrowse [pwd]; regsub "^$env(HOME)" $PwdBrowse {~} PwdBrowse; wm title $w "$PwdBrowse"; $w.dir.entry delete 0 end; $w.dir.entry insert 0 $PwdBrowse; } } # REFRESH THE FILE LISTBOX AFTER SELECTION proc refreshBrowse {w} { global env global KillBrowse PwdBrowse SelBrowse RetBrowse DelBrowse global FileManager Match if {$DelBrowse} { if [file isfile $RetBrowse] { global deleteResponse; set deleteResponse "0"; set wait_del [getResponse "Delete File? $RetBrowse" deleteResponse YES]; tkwait window $wait_del; # puts stdout "deleteResponse: $deleteResponse"; if {$deleteResponse} { file delete $RetBrowse; } } set DelBrowse "0"; set KillBrowse ""; if { ! $FileManager } { puts stdout "DELETED: $RetBrowse"; destroy $w; exit 0; } } if {$KillBrowse == "True" } { if {$FileManager} { set KillBrowse "" Viewer $RetBrowse return } else { global Wait if { $Wait } { set KillBrowse "" if ![file isdirectory $SelBrowse] { puts stdout "$RetBrowse" } return; } else { puts stdout "$RetBrowse" destroy $w exit 0; } } } set listlist [glob -nocomplain *]; $w.frame.list delete 0 end $w.frame.list insert 0 "./" $w.frame.list insert 1 "../" set theList "" foreach item [lsort $listlist] { if { [file isfile $item] && $Match != "" && ![regexp $Match $item] } { # puts "OUT $Match $item" continue } if ![regexp {^~} $item] { if [file isdirectory $item] { lappend theList "$item/" } elseif [file executable $item] { # lappend theList "$item*" lappend theList "$item" } else { lappend theList "$item" } } else { lappend theList "$item" } } eval $w.frame.list insert 2 $theList } # MAKE A PUSH BUTTON ANIMATION proc depress {w} { $w configure -state active; $w configure -relief sunken; update; after 350; $w configure -relief raised; update; after 50; $w configure -state normal; } # USERS COMMAND TO EDIT A SELECTED FILE proc Edit {file} { global env Redir OS if {$file == ""} { return } if ![info exists env(X_EDITOR)] { if { $OS == "unix" } { set editor "xterm -e vi $file"; } elseif [regexp {^win} $OS] { # set editor "vi.exe $file"; set editor "write.exe $file"; } } else { set editor "$env(X_EDITOR) $file"; } eval exec $editor $Redir & } # USERS COMMAND TO VIEW A SELECTED FILE # (E.G. MIME LAUNCHER "av") proc Viewer {file} { global env Redir OS if {$file == ""} { return } if ![info exists env(X_VIEWER)] { if { $OS == "unix" } { set viewer "xterm -e vi $file"; } elseif [regexp {^win} $OS] { set viewer "write.exe $file"; } } else { set viewer "$env(X_VIEWER) $file"; } eval exec $viewer $Redir & } # USERS COMMAND TO START A SHELL IN A DIR proc Shell {file} { global env Redir OS if {$file == ""} { return } if ![info exists env(X_SHELL)] { if { $OS == "unix" } { if ![file isdirectory $file] { set shell "sh -c \"cd `dirname $file`; xterm\""; } else { set shell "sh -c \"cd $file; xterm\""; } } elseif [regexp {^win} $OS] { set shell command.com; # not working... grrr } } else { set shell "$env(X_SHELL) $file"; } eval exec $shell $Redir & } # TRANSLATE ~ TO HOME DIRECTORY. proc expand_tilde {file} { global env; regsub {^~} $file $env(HOME) file return $file; } # DETERMINE PLATFORM WE ARE RUNNING ON proc util_check_platform {} { global tcl_platform OS; set OS "unix" if { [info exists tcl_platform(platform)] } { if { $tcl_platform(platform) == "windows" \ && $tcl_platform(osVersion) < "4.0" } { set OS "windows" } elseif { $tcl_platform(platform) == "windows" \ && $tcl_platform(osVersion) >= "4.0" } { set OS "win95" } elseif { $tcl_platform(platform) == "unix" } { set OS "unix" } } } # CENTER A WINDOW IN MIDDLE OF SCREEN proc util_center_window {w} { wm withdraw $w update idletasks set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \ - [winfo vrootx [winfo parent $w]]] set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \ - [winfo vrooty [winfo parent $w]]] wm geom $w +$x+$y wm deiconify $w } # POST MESSAGE, GET REPLY proc getResponse { gr_message name {cancel YES} } { global $name; global fontSmallerBold; global getResponseCount; if ![info exists getResponseCount] { set getResponseCount "0"; } set nline [llength [split $gr_message \n] ]; if { $nline < 2 } { set aspect 550; } else { set aspect 220; } set FONT -adobe-helvetica-bold-r-*-*-*-180-*-*-*-*-*-*; set font -adobe-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*; set FONT $font set w .getResp$getResponseCount; incr getResponseCount; catch {destroy $w}; toplevel $w; wm title $w "Info/Response"; util_center_window $w # wm geometry $w +400+300; message $w.msg -text "$gr_message" -justify left \ -font $FONT -aspect $aspect; if { $cancel == "YES" } { set OKtext "OK"; } else { set OKtext "Dismiss"; } button $w.ok -text "$OKtext" -command "set $name 1; destroy $w" \ -font $fontSmallerBold; button $w.no -text Cancel -command "set $name 0; destroy $w" \ -font $fontSmallerBold; if { $cancel == "YES" } { pack $w.msg $w.ok $w.no -side top -fill x; } else { pack $w.msg $w.ok -side top -fill x; } return $w; } ############# main() MAIN starts here. ############################## global env tcl_platform Redir global Geom OS set Geom [wm geometry .] wm withdraw .; regsub {^[0-9]+x[0-9]+} $Geom {} Geom #puts stderr "Geom: $Geom"; #if {$Geom == "+0+0"} { # set Geom +175+175; #} global FileManager StartDir Match Wait Viewer_Button Edit_Button Shell_Button set FileManager 0 set StartDir "" set Match "" set Msg "" set Wait 0 set Viewer_Button 1 set Edit_Button 1 set Shell_Button 1 set arg_count 0 #foreach opt [split $argv] { foreach opt $argv { set args($arg_count) $opt incr arg_count; } for { set i 0} {$i < $arg_count} {incr i} { set o $args($i) if { "$o" == "-fm" || $o == "-filemanager" } { set FileManager "1"; } elseif { $o == "-m" || $o == "-match" } { incr i set Match $args($i) } elseif { $o == "-msg" || $o == "-message" } { incr i set Msg $args($i) } elseif { $o == "-w" || $o == "-wait" } { set Wait 1; } elseif { $o == "-ne" || $o == "-noedit" } { set Edit_Button 0; } elseif { $o == "-nv" || $o == "-noviewer" } { set Viewer_Button 0; } elseif { $o == "-ns" || $o == "-noshell" } { set Shell_Button 0; } elseif ![regexp {^-} $opt] { set StartDir $o; } } util_check_platform; if {![info exists env(HOME)] || $OS == "windows" || $OS == "win95"} { set env(HOME) "HOME_NOT_FOUND"; } if { ![info exists tcl_platform(osVersion)] || \ $tcl_platform(platform) == "unix" } { set Redir ">&/dev/null" } else { set Redir "" } global DebugMe; set DebugMe 0; global ResizeMin ResizeMax; global font fontb fontSmall; global dir_entry_var; # FONTS set font -adobe-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*; set fontb -adobe-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*; set fontSmallerBold -adobe-helvetica-bold-r-*-*-*-120-*-*-*-*-*-*; set fontSmall fixed; # COLOURS option add *selectBackground grey70 option add *background grey80 option add *activeBackground grey65 option add *frame*background grey80 option add *scrolly*foreground grey80 option add *scrolly*activeForeground grey65 option add *scrollx*foreground grey80 option add *scrollx*activeForeground grey65 global PwdBrowse if { $StartDir != "" } { if [file isdirectory $StartDir] { set PwdBrowse $StartDir } elseif [file isfile $StartDir] { set PwdBrowse [file dirname $StartDir] } cd $PwdBrowse } else { set PwdBrowse [pwd]; } regsub "^$env(HOME)" $PwdBrowse {~} PwdBrowse; if {$FileManager} { puts stdout [browse "32" "16" TRUE]; } elseif { $Wait } { while { 1 } { browse; } } else { puts stdout [browse]; } exit 0;