2011-12-28 14:11:10 +00:00
|
|
|
|
2012-01-13 21:23:03 +00:00
|
|
|
if {![exists -proc class]} { package require oo }
|
2011-12-28 14:11:10 +00:00
|
|
|
|
|
|
|
class clipboard {
|
|
|
|
path "/tmp/webif.cb"
|
|
|
|
items {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class clipboarditem {
|
|
|
|
action ""
|
|
|
|
path ""
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboarditem method _parse {line} {
|
2011-12-28 21:36:35 +00:00
|
|
|
lassign [split $line "|"] action path
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proc {clipboarditem load} {line} {
|
|
|
|
set c [clipboarditem new]
|
|
|
|
$c _parse $line
|
|
|
|
return $c
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard method save {} {
|
|
|
|
set fd [open $path w]
|
|
|
|
foreach item $items {
|
2011-12-28 21:36:35 +00:00
|
|
|
puts $fd "[$item get action]|[$item get path]"
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
|
|
|
$fd close
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard method load {} {
|
|
|
|
set items {}
|
|
|
|
set changed 0
|
|
|
|
if {[file exists $path]} {
|
|
|
|
set fd [open $path r]
|
|
|
|
foreach line [split [$fd read] "\n"] {
|
|
|
|
set ci [clipboarditem load $line]
|
|
|
|
if {[file exists [$ci get path]]} {
|
2011-12-28 21:36:35 +00:00
|
|
|
lappend items $ci
|
2011-12-28 14:11:10 +00:00
|
|
|
} else {
|
|
|
|
set changed 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if {$changed} { $self save }
|
|
|
|
return $self
|
|
|
|
}
|
|
|
|
|
2011-12-28 21:36:35 +00:00
|
|
|
clipboard method present {xfile} {
|
|
|
|
foreach item $items {
|
|
|
|
if {[$item get path] eq $xfile} {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard method index {xfile} {
|
|
|
|
set index -1
|
|
|
|
foreach item $items {
|
|
|
|
incr index
|
|
|
|
if {[$item get path] eq $xfile} {
|
|
|
|
return $index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard method clear {} {
|
|
|
|
set items {}
|
|
|
|
}
|
|
|
|
|
2011-12-28 14:11:10 +00:00
|
|
|
clipboard method size {} {
|
|
|
|
return [llength $items]
|
|
|
|
}
|
|
|
|
|
2011-12-28 21:36:35 +00:00
|
|
|
clipboard method add {xaction xpath} {
|
|
|
|
lappend items [clipboarditem load "$xaction|$xpath"]
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard method remove {xpath} {
|
|
|
|
set index [$self index $xpath]
|
|
|
|
if {$index < 0} { return }
|
|
|
|
set items [lreplace $items $index $index]
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
|
|
|
|