Method: Tk::Text#dump

Defined in:
lib/tk/text.rb

#dump(type_info, *index, &block) ⇒ Object



1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
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
# File 'lib/tk/text.rb', line 1432

def dump(type_info, *index, &block)
  if type_info.kind_of?(Symbol)
    type_info = [ type_info.to_s ]
  elsif type_info.kind_of?(String)
    type_info = [ type_info ]
  end
  args = type_info.collect{|inf| '-' + inf}
  args << '-command' << block if block
  str = tk_send('dump', *(args + index))
  result = []
  sel = nil
  i = 0
  while i < str.size
    # retrieve key
    idx = str.index(/ /, i)
    result.push str[i..(idx-1)]
    i = idx + 1

    # retrieve value
    case result[-1]
    when 'text'
      if str[i] == ?{
        # text formed as {...}
        val, i = _retrieve_braced_text(str, i)
        result.push val
      else
        # text which may contain backslashes
        val, i = _retrieve_backslashed_text(str, i)
        result.push val
      end
    else
      idx = str.index(/ /, i)
      val = str[i..(idx-1)]
      case result[-1]
      when 'mark'
        case val
        when 'insert'
          result.push TkTextMarkInsert.new(self)
        when 'current'
          result.push TkTextMarkCurrent.new(self)
        when 'anchor'
          result.push TkTextMarkAnchor.new(self)
        else
          result.push tk_tcl2ruby(val)
        end
      when 'tagon'
        if val == 'sel'
          if sel
            result.push sel
          else
            result.push TkTextTagSel.new(self)
          end
        else
          result.push tk_tcl2ruby(val)
        end
      when 'tagoff'
          result.push tk_tcl2ruby(val)
      when 'window'
        result.push tk_tcl2ruby(val)
      when 'image'
        result.push tk_tcl2ruby(val)
      end
      i = idx + 1
    end

    # retrieve index
    idx = str.index(/ /, i)
    if idx
      result.push(Tk::Text::IndexString.new(str[i..(idx-1)]))
      i = idx + 1
    else
      result.push(Tk::Text::IndexString.new(str[i..-1]))
      break
    end
  end

  kvis = []
  until result.empty?
    kvis.push [result.shift, result.shift, result.shift]
  end
  kvis  # result is [[key1, value1, index1], [key2, value2, index2], ...]
end