diff options
-rw-r--r-- | demos/explorer.tcl | 14 | ||||
-rw-r--r-- | demos/random.tcl | 99 | ||||
-rw-r--r-- | library/filelist-bindings.tcl | 120 |
3 files changed, 135 insertions, 98 deletions
diff --git a/demos/explorer.tcl b/demos/explorer.tcl index ab388f7..1b966e2 100644 --- a/demos/explorer.tcl +++ b/demos/explorer.tcl @@ -96,9 +96,11 @@ proc DemoExplorerDetails {} { $T style layout $S txtDate -padw 6 -pade 6 -squeeze x -expand ns set ::TreeCtrl::Priv(edit,$T) {e2} - set ::TreeCtrl::Priv(sensitive,$T) {e1 e2} + set ::TreeCtrl::Priv(sensitive,$T) { + {name styName e1 e2} + } set ::TreeCtrl::Priv(dragimage,$T) { - {0 styName e1 e2} + {name styName e1 e2} } $T notify bind $T <Edit-accept> { @@ -232,7 +234,9 @@ proc DemoExplorerLargeIcons {} { $T style layout $S elemSel -union [list elemTxt] set ::TreeCtrl::Priv(edit,$T) {elemTxt} - set ::TreeCtrl::Priv(sensitive,$T) {elemImg elemTxt} + set ::TreeCtrl::Priv(sensitive,$T) { + {0 STYLE elemImg elemTxt} + } set ::TreeCtrl::Priv(dragimage,$T) { {0 STYLE elemImg elemTxt} } @@ -321,7 +325,9 @@ proc DemoExplorerList {} { $T style layout $S elemSel -union [list elemTxt] -iexpand ns -ipadw 2 -ipade 2 set ::TreeCtrl::Priv(edit,$T) {elemTxt} - set ::TreeCtrl::Priv(sensitive,$T) {elemImg elemTxt} + set ::TreeCtrl::Priv(sensitive,$T) { + {0 STYLE elemImg elemTxt} + } set ::TreeCtrl::Priv(dragimage,$T) { {0 STYLE elemImg elemTxt} } diff --git a/demos/random.tcl b/demos/random.tcl index 3550fa9..2d817b0 100644 --- a/demos/random.tcl +++ b/demos/random.tcl @@ -17,9 +17,9 @@ proc DemoRandom {} { -showroot yes -showrootbutton yes -showbuttons yes -showlines yes \ -scrollmargin 16 -xscrolldelay "500 50" -yscrolldelay "500 50" - $T column configure 0 -expand yes -text Item -itembackground {#e0e8f0 {}} - $T column configure 1 -text Parent -justify center -itembackground {gray90 {}} - $T column configure 2 -text Depth -justify center -itembackground {linen {}} + $T column configure 0 -expand yes -text Item -itembackground {#e0e8f0 {}} -tag item + $T column configure 1 -text Parent -justify center -itembackground {gray90 {}} -tag parent + $T column configure 2 -text Depth -justify center -itembackground {linen {}} -tag depth $T element create e1 image -image {folder-open {open} folder-closed {}} $T element create e2 image -image small-file @@ -47,10 +47,13 @@ proc DemoRandom {} { $T style elements s3 {e6} $T style layout s3 e6 -padw 6 -pade 6 -expand ns - set ::TreeCtrl::Priv(sensitive,$T) {e5 e1 e2 e3} + set ::TreeCtrl::Priv(sensitive,$T) { + {item s1 e5 e1 e3} + {item s2 e5 e2 e3} + } set ::TreeCtrl::Priv(dragimage,$T) { - {0 s1 e1 e3} - {0 s2 e2 e3} + {item s1 e1 e3} + {item s2 e2 e3} } set clicks [clock clicks] @@ -156,9 +159,17 @@ proc TreeCtrl::RandomButton1 {T x y} { set ok 0 # Clicked an element if {[llength $id] == 6} { + set column [lindex $id 3] set E [lindex $id 5] - if {[lsearch -exact $Priv(sensitive,$T) $E] != -1} { + foreach list $Priv(sensitive,$T) { + set C [lindex $list 0] + set S [lindex $list 1] + set eList [lrange $list 2 end] + if {$column != [$T column index $C]} continue + if {[$T item style set $item $C] ne $S} continue + if {[lsearch -exact $eList $E] == -1} continue set ok 1 + break } } if {!$ok} { @@ -216,7 +227,7 @@ proc TreeCtrl::RandomMotion {T x y} { set Priv(drop) "" $T dragimage clear # For each selected item, add 2nd and 3rd elements of - # column zero to the dragimage + # column "item" to the dragimage foreach I $Priv(selection) { foreach list $Priv(dragimage,$T) { set C [lindex $list 0] @@ -235,38 +246,46 @@ proc TreeCtrl::RandomMotion {T x y} { set id [$T identify $x $y] set ok 0 if {($id ne "") && ([lindex $id 0] eq "item") && ([llength $id] == 6)} { + set item [lindex $id 1] + set column [lindex $id 3] set E [lindex $id 5] + foreach list $Priv(sensitive,$T) { + set C [lindex $list 0] + set S [lindex $list 1] + set eList [lrange $list 2 end] + if {$column != [$T column index $C]} continue + if {[$T item style set $item $C] ne $S} continue + if {[lsearch -exact $eList $E] == -1} continue + set ok 1 + break + } if {[lsearch -exact $Priv(sensitive,$T) $E] != -1} { set ok 1 } } if {$ok} { - set item [lindex $id 1] - set column [lindex $id 3] - if {$column == 0} { - # If the item is not in the pre-drag selection - # (i.e. not being dragged) see if we can drop on it - if {[lsearch -exact $Priv(selection) $item] == -1} { - set drop $item - # We can drop if dragged item isn't an ancestor - foreach item2 $Priv(selection) { - if {[$T item isancestor $item2 $item]} { - set drop "" - break - } + # If the item is not in the pre-drag selection + # (i.e. not being dragged) see if we can drop on it + if {[lsearch -exact $Priv(selection) $item] == -1} { + set drop $item + # We can drop if dragged item isn't an ancestor + foreach item2 $Priv(selection) { + if {[$T item isancestor $item2 $item]} { + set drop "" + break } - if {$drop ne ""} { - scan [$T item bbox $drop] "%d %d %d %d" x1 y1 x2 y2 - if {$y < $y1 + 3} { - set cursor top_side - set Priv(drop,pos) prevsibling - } elseif {$y >= $y2 - 3} { - set cursor bottom_side - set Priv(drop,pos) nextsibling - } else { - set cursor "" - set Priv(drop,pos) lastchild - } + } + if {$drop ne ""} { + scan [$T item bbox $drop] "%d %d %d %d" x1 y1 x2 y2 + if {$y < $y1 + 3} { + set cursor top_side + set Priv(drop,pos) prevsibling + } elseif {$y >= $y2 - 3} { + set cursor bottom_side + set Priv(drop,pos) nextsibling + } else { + set cursor "" + set Priv(drop,pos) lastchild } } } @@ -351,10 +370,10 @@ proc RandomDrop {T target source pos} { $T item $pos $target $item # Update text: parent - $T item element configure $item 1 e6 -text $parent + $T item element configure $item parent e6 -text $parent # Update text: depth - $T item element configure $item 2 e6 -text [$T depth $item] + $T item element configure $item depth e6 -text [$T depth $item] # Recursively update text: depth set itemList [$T item firstchild $item] @@ -363,7 +382,7 @@ proc RandomDrop {T target source pos} { set item [lindex $itemList end] set itemList [lrange $itemList 0 end-1] - $T item element configure $item 2 e6 -text [$T depth $item] + $T item element configure $item depth e6 -text [$T depth $item] set item2 [$T item nextsibling $item] if {$item2 ne ""} { @@ -383,19 +402,19 @@ proc RandomDrop {T target source pos} { set numChildren [$T item numchildren $item] if {$numChildren == 0} { $T item hasbutton $item no - $T item style map $item 0 s2 {e3 e3} + $T item style map $item item s2 {e3 e3} } else { - $T item element configure $item 0 e4 -text "($numChildren)" + $T item element configure $item item e4 -text "($numChildren)" } } # Update the target that gained some children if {[$T item style set $parent 0] ne "s1"} { $T item hasbutton $parent yes - $T item style map $parent 0 s1 {e3 e3} + $T item style map $parent item s1 {e3 e3} } set numChildren [$T item numchildren $parent] - $T item element configure $parent 0 e4 -text "($numChildren)" + $T item element configure $parent item e4 -text "($numChildren)" return } diff --git a/library/filelist-bindings.tcl b/library/filelist-bindings.tcl index c0523ea..2da8557 100644 --- a/library/filelist-bindings.tcl +++ b/library/filelist-bindings.tcl @@ -55,44 +55,44 @@ proc TreeCtrl::FileListButton1 {T x y} { ButtonPress1 $T $x $y } column { - # Clicked in column zero - if {$arg2 eq 0} { - set ok 0 - # Clicked an element - if {[llength $id] == 6} { - set E [lindex $id 5] - if {[lsearch -exact $Priv(sensitive,$T) $E] != -1} { - set ok 1 - } + set ok 0 + # Clicked an element + if {[llength $id] == 6} { + set E [lindex $id 5] + foreach list $Priv(sensitive,$T) { + set C [lindex $list 0] + set S [lindex $list 1] + set eList [lrange $list 2 end] + if {$arg2 != [$T column index $C]} continue + if {[$T item style set $item $C] ne $S} continue + if {[lsearch -exact $eList $E] == -1} continue + set ok 1 + break + } + } + if {$ok} { + set Priv(drag,motion) 0 + set Priv(drag,x) [$T canvasx $x] + set Priv(drag,y) [$T canvasy $y] + set Priv(drop) "" + set Priv(drag,wasSel) [$T selection includes $item] + set Priv(drag,E) $E + $T activate $item + if {$Priv(selectMode) eq "add"} { + BeginExtend $T $item + } elseif {$Priv(selectMode) eq "toggle"} { + BeginToggle $T $item + } elseif {![$T selection includes $item]} { + BeginSelect $T $item } - if {$ok} { - set Priv(drag,motion) 0 - set Priv(drag,x) [$T canvasx $x] - set Priv(drag,y) [$T canvasy $y] - set Priv(drop) "" - set Priv(drag,wasSel) [$T selection includes $item] - set Priv(drag,E) $E - $T activate $item - if {$Priv(selectMode) eq "add"} { - BeginExtend $T $item - } elseif {$Priv(selectMode) eq "toggle"} { - BeginToggle $T $item - } elseif {![$T selection includes $item]} { - BeginSelect $T $item - } - # Changing the selection might change the list - if {[$T index $item] eq ""} return + # Changing the selection might change the list + if {[$T index $item] eq ""} return - # Click selected item to drag - if {[$T selection includes $item]} { - set Priv(buttonMode) drag - } - # Clicked inside item, but outside elements - } else { - set marquee 1 + # Click selected item to drag + if {[$T selection includes $item]} { + set Priv(buttonMode) drag } - # Clicked column > 0 } else { set marquee 1 } @@ -145,14 +145,22 @@ proc TreeCtrl::FileListMotion {T x y} { foreach sublist [lrange $list 1 end] { set column [lindex $sublist 0] set ok 0 + + # Check covered elements in this column foreach E [lrange $sublist 1 end] { - if {[lsearch -exact $Priv(sensitive,$T) $E] != -1} { + foreach sList $Priv(sensitive,$T) { + set sC [lindex $sList 0] + set sS [lindex $sList 1] + set sEList [lrange $sList 2 end] + if {$column != [$T column index $sC]} continue + if {[$T item style set $item $sC] ne $sS} continue + if {[lsearch -exact $sEList $E] == -1} continue set ok 1 break } } - # Some elements in column zero are covered - if {($column == 0) && $ok} { + # Some sensitive elements in this column are covered + if {$ok} { # Toggle selected status if {$Priv(selectMode) eq "toggle"} { @@ -167,7 +175,6 @@ proc TreeCtrl::FileListMotion {T x y} { lappend select $item } } - break } } $T selection modify $select all @@ -197,27 +204,32 @@ proc TreeCtrl::FileListMotion {T x y} { set id [$T identify $x $y] set ok 0 if {($id ne "") && ([lindex $id 0] eq "item") && ([llength $id] == 6)} { + set item [lindex $id 1] + set column [lindex $id 3] set E [lindex $id 5] - if {[lsearch -exact $Priv(sensitive,$T) $E] != -1} { + foreach list $Priv(sensitive,$T) { + set C [lindex $list 0] + set S [lindex $list 1] + set eList [lrange $list 2 end] + if {$column != [$T column index $C]} continue + if {[$T item style set $item $C] ne $S} continue + if {[lsearch -exact $eList $E] == -1} continue set ok 1 + break } } if {$ok} { - set item [lindex $id 1] - set column [lindex $id 3] - if {$column == 0} { - # If the item is not in the pre-drag selection - # (i.e. not being dragged) and it is a directory, - # see if we can drop on it - if {[lsearch -exact $Priv(selection) $item] == -1} { - if {[lindex [$T item index $item] 1] < $Priv(DirCnt,$T)} { - set drop $item - # We can drop if dragged item isn't an ancestor - foreach item2 $Priv(selection) { - if {[$T item isancestor $item2 $item]} { - set drop "" - break - } + # If the item is not in the pre-drag selection + # (i.e. not being dragged) and it is a directory, + # see if we can drop on it + if {[lsearch -exact $Priv(selection) $item] == -1} { + if {[lindex [$T item index $item] 1] < $Priv(DirCnt,$T)} { + set drop $item + # We can drop if dragged item isn't an ancestor + foreach item2 $Priv(selection) { + if {[$T item isancestor $item2 $item]} { + set drop "" + break } } } |