Hello ulis:
I am back again, I was busy for other things.
Last time, you said that the file name acturally is a path name, and you put a list a path of filename on the listbox.
Do you have any idea how to put the file name on the listbox, but we just can see the filename, not the path of the filename, and its fuctionality still same as now on the listbox, when people click on it, we still can save it to anther dirctory, or play it, like the MP3 player.
For example, I'd like the file name on the listbox like following;
.Butterfly
.test.cc
not like . ./home/bin/tcl/Butterfly
./home/bin/tcl/test.cc
I tried to search information from the website you gave me, but I still
couldn't solve this problem. Would you mind help me again for this question?
rgds
stewang
And the code from last time
I am back again, I was busy for other things.
Last time, you said that the file name acturally is a path name, and you put a list a path of filename on the listbox.
Do you have any idea how to put the file name on the listbox, but we just can see the filename, not the path of the filename, and its fuctionality still same as now on the listbox, when people click on it, we still can save it to anther dirctory, or play it, like the MP3 player.
For example, I'd like the file name on the listbox like following;
.Butterfly
.test.cc
not like . ./home/bin/tcl/Butterfly
./home/bin/tcl/test.cc
I tried to search information from the website you gave me, but I still
couldn't solve this problem. Would you mind help me again for this question?
rgds
stewang
And the code from last time
Code:
package require Tk
# the menu bar
menu .mbar
. configure -menu .mbar
menu .mbar.file -tearoff 0
.mbar add cascade -label "File" -underline 0 -menu .mbar.file
.mbar.file add command -label "Open" -underline 0 -command openFile
.mbar.file add command -label "Save" -underline 0 -command saveFile
.mbar.file add separator
.mbar.file add command -label "Quit" -underline 0 -command exitApp;
wm protocol . WM_DELETE_WINDOW exitApp
menu .mbar.list -tearoff 0
.mbar add cascade -label "List" -underline 0 -menu .mbar.list
.mbar.list add command -label "Remove" -underline 0 -command removeName
.mbar.list add command -label "Clear" -underline 0 -command clearList
# the list box
set ::names {}
listbox .l -listvar ::names -width 40
pack .l -expand 1 -fill both
# the actions
# get some file names
# add the new ones to the listbox
# do something with the content of each new file
proc openFile {} {
# get some file names
set filenames [tk_getOpenFile -multiple 1]
foreach fn $filenames {
# check if its a new one
if {[lsearch $::names $fn] == -1} {
# add the name to the listbox
lappend ::names $fn
# get the file content and do something with it
set thefile [open $fn r]
puts "the file : $thefile"
set filecontent [read $thefile]
close $thefile
}
}
# sort the listbox content
set ::names [lsort $::names]
}
# get the currently selected name
# copy the corresponding file somewhere
# remove the name from the listbox
proc saveFile {} {
# get the currently selected name
set n [.l curselection]
if {$n != ""} {
# get the old name
set source [lindex $::names $n]
# get the new name
set target [tk_getSaveFile]
if {$target != ""} {
# copy the file content to the new position
file copy $source $target
# remove the name from the listbox
removeName
}
}
}
# get the currently selected name
# remove the name from the listbox
proc removeName {} {
# get the currently selected name
set n [.l curselection]
set name [lindex $::names $n]
set n [lsearch $::names $name]
if {$n != -1} {
set ::names [lreplace $::names $n $n]
}
}
# clear the listbox
proc clearList {} { set ::names {} }
# exit
proc exitApp {} { exit }