Method: Tk::BLT::Treeview::Node#initialize

Defined in:
lib/tkextlib/blt/treeview.rb

#initialize(tree, pos, parent, keys) ⇒ Node

Returns a new instance of Node.



1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
# File 'lib/tkextlib/blt/treeview.rb', line 1116

def initialize(tree, pos, parent, keys)
  @parent = @tree = tree
  @tpath = @parent.path

  if (id = keys['node'])
    # if tk_call(@tpath, 'get', id).empty?
    #   fail RuntimeError, "not exist the node '#{id}'"
    # end
    @path = @id = id
    tk_call(@tpath, 'move', @id, pos, tagid(parent)) if parent
    configure(keys) if keys && ! keys.empty?
  else
    name = nil
    TreeNode_ID.mutex.synchronize{
      name = TreeNode_ID.join(TkCore::INTERP._ip_id_).freeze
      TreeNode_ID[1].succ!
    }

    at = keys.delete['at']

    if parent
      if parent.kind_of?(Tk::BLT::Treeview::Node) ||
          parent.kind_of?(Tk::BLT::Treeview::Tag)
        path = [get_full(parent.id)[0], name]
        at = nil # ignore 'at' option
      else
        path = [parent.to_s, name]
      end
    else
      path = name
    end

    if at
      @id = tk_call(@tpath, 'insert', '-at', tagid(at), pos, path, keys)
    else
      @id = tk_call(@tpath, 'insert', pos, path, keys)
    end
    @path = @id
  end
end