1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
|
# File 'lib/tk/variable.rb', line 1560
def trace_remove_for_element(elem,opts,cmd)
if @elem
fail(RuntimeError,
"invalid for a TkVariable which denotes an element of Tcl's array")
end
return self unless @trace_elem.kind_of? Hash
return self unless @trace_elem[elem].kind_of? Array
opts = _check_trace_opt(opts)
idx = -1
if USE_OLD_TRACE_OPTION_STYLE
@trace_elem[elem].each_with_index{|e, i|
if idx < 0 && e[1] == cmd
diff = false
['a', 'r', 'w', 'u'].each{|c|
break if (diff = e[0].index(c) ^ opts.index(c))
}
unless diff
idx = i
next
end
end
}
else
@trace_elem[elem].each_with_index{|e, i|
if idx < 0 && e[1] == cmd &&
e[0].size == opts.size && (e[0] - opts).empty?
idx = i
next
end
}
end
if idx >= 0
@trace_elem[elem].delete_at(idx)
else
return self
end
if USE_OLD_TRACE_OPTION_STYLE
newopts = ''
@trace_var.each{|e|
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
}
@trace_elem.each{|elem|
@trace_elem[elem].each{|e|
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
}
}
else
newopts = []
@trace_var.each{|e|
newopts |= e[0]
}
@trace_elem.each{|elem|
@trace_elem[elem].each{|e|
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
}
}
end
if USE_OLD_TRACE_OPTION_STYLE
diff = false
@trace_opts.each_byte{|c| break if (diff = ! newopts.index(c))}
if diff
Tk.tk_call_without_enc('trace', 'vdelete',
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
unless @trace_opts.empty?
Tk.tk_call_without_enc('trace', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
end
end
else
unless (@trace_opts - newopts).empty?
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
unless @trace_opts.empty?
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
end
end
end
self
end
|