Method: TkVariable#trace_remove

Defined in:
lib/tk/variable.rb

#trace_remove(opts, cmd) ⇒ Object Also known as: trace_delete, trace_vdelete



1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
# File 'lib/tk/variable.rb', line 1480

def trace_remove(opts,cmd)
  return self unless @trace_var.kind_of? Array

  opts = _check_trace_opt(opts)

  idx = -1
  if USE_OLD_TRACE_OPTION_STYLE
    newopts = ''
    @trace_var.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
          #find
          idx = i
          next
        end
      end
      e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
    }
  else
    newopts = []
    @trace_var.each_with_index{|e, i|
      if idx < 0 && e[1] == cmd &&
          e[0].size == opts.size && (e[0] - opts).empty?
        # find
        idx = i
        next
      end
      newopts |= e[0]
    }
  end

  if idx >= 0
    @trace_var.delete_at(idx)
  else
    return self
  end

  (@trace_elem ||= {}).each{|elem|
    @trace_elem[elem].each{|e|
      if USE_OLD_TRACE_OPTION_STYLE
        e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
      else
        newopts |= e[0]
      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