Update tk to version 8.5.11
[git/jnareb-git.git] / mingw / lib / tk8.5 / demos / filebox.tcl
blob032e3d86d3b9cbda4a97e322bd69be471b89b2dc
1 # filebox.tcl --
3 # This demonstration script prompts the user to select a file.
5 if {![info exists widgetDemo]} {
6 error "This script should be run from the \"widget\" demo."
9 package require Tk
11 set w .filebox
12 catch {destroy $w}
13 toplevel $w
14 wm title $w "File Selection Dialogs"
15 wm iconname $w "filebox"
16 positionWindow $w
18 label $w.msg -font $font -wraplength 4i -justify left -text "Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog."
19 pack $w.msg -side top
21 ## See Code / Dismiss buttons
22 set btns [addSeeDismiss $w.buttons $w]
23 pack $btns -side bottom -fill x
25 foreach i {open save} {
26 set f [frame $w.$i]
27 label $f.lab -text "Select a file to $i: " -anchor e
28 entry $f.ent -width 20
29 button $f.but -text "Browse ..." -command "fileDialog $w $f.ent $i"
30 pack $f.lab -side left
31 pack $f.ent -side left -expand yes -fill x
32 pack $f.but -side left
33 pack $f -fill x -padx 1c -pady 3
36 if {[tk windowingsystem] eq "x11"} {
37 checkbutton $w.strict -text "Use Motif Style Dialog" \
38 -variable tk_strictMotif -onvalue 1 -offvalue 0
39 pack $w.strict -anchor c
41 # This binding ensures that we don't run the rest of the demos
42 # with motif style interactions
43 bind $w.strict <Destroy> {set tk_strictMotif 0}
46 proc fileDialog {w ent operation} {
47 # Type names Extension(s) Mac File Type(s)
49 #---------------------------------------------------------
50 set types {
51 {"Text files" {.txt .doc} }
52 {"Text files" {} TEXT}
53 {"Tcl Scripts" {.tcl} TEXT}
54 {"C Source Files" {.c .h} }
55 {"All Source Files" {.tcl .c .h} }
56 {"Image Files" {.gif} }
57 {"Image Files" {.jpeg .jpg} }
58 {"Image Files" "" {GIFF JPEG}}
59 {"All files" *}
61 if {$operation == "open"} {
62 global selected_type
63 if {![info exists selected_type]} {
64 set selected_type "Tcl Scripts"
66 set file [tk_getOpenFile -filetypes $types -parent $w \
67 -typevariable selected_type]
68 puts "You selected filetype \"$selected_type\""
69 } else {
70 set file [tk_getSaveFile -filetypes $types -parent $w \
71 -initialfile Untitled -defaultextension .txt]
73 if {[string compare $file ""]} {
74 $ent delete 0 end
75 $ent insert 0 $file
76 $ent xview end