forked from hummypkg/webif
7c038a1776
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@588 2a923420-c742-0410-a762-8d5b09965624
88 lines
1.4 KiB
Plaintext
88 lines
1.4 KiB
Plaintext
|
|
if {![exists -proc class ]} { package require oo }
|
|
|
|
class clipboard {
|
|
path "/tmp/webif.cb"
|
|
items {}
|
|
}
|
|
|
|
class clipboarditem {
|
|
action ""
|
|
path ""
|
|
}
|
|
|
|
clipboarditem method _parse {line} {
|
|
lassign [split $line "|"] action path
|
|
}
|
|
|
|
proc {clipboarditem load} {line} {
|
|
set c [clipboarditem new]
|
|
$c _parse $line
|
|
return $c
|
|
}
|
|
|
|
clipboard method save {} {
|
|
set fd [open $path w]
|
|
foreach item $items {
|
|
puts $fd "[$item get action]|[$item get path]"
|
|
}
|
|
$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]]} {
|
|
lappend items $ci
|
|
} else {
|
|
set changed 1
|
|
}
|
|
}
|
|
}
|
|
if {$changed} { $self save }
|
|
return $self
|
|
}
|
|
|
|
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 {}
|
|
}
|
|
|
|
clipboard method size {} {
|
|
return [llength $items]
|
|
}
|
|
|
|
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]
|
|
}
|
|
|