##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r8109:f6dd3c548494
parent child
Show More
@@ -316,7 +316,6 module Redmine
316 316
317 317 def initialize(name, content = nil)
318 318 @name = name
319 @childrenHash ||= {}
320 319 @children = []
321 320 @last_items_count = 0
322 321 end
@@ -341,50 +340,34 module Redmine
341 340
342 341 # Adds a child at first position
343 342 def prepend(child)
344 raise "Child already added" if @childrenHash.has_key?(child.name)
345
346 @childrenHash[child.name] = child
347 @children = [child] + @children
348 child.parent = self
349 return child
343 add_at(child, 0)
350 344 end
351 345
352 346 # Adds a child at given position
353 347 def add_at(child, position)
354 raise "Child already added" if @childrenHash.has_key?(child.name)
348 raise "Child already added" if find {|node| node.name == child.name}
355 349
356 @childrenHash[child.name] = child
357 350 @children = @children.insert(position, child)
358 351 child.parent = self
359 return child
352 child
360 353 end
361 354
362 355 # Adds a child as last child
363 356 def add_last(child)
364 raise "Child already added" if @childrenHash.has_key?(child.name)
365
366 @childrenHash[child.name] = child
367 @children << child
357 add_at(child, -1)
368 358 @last_items_count += 1
369 child.parent = self
370 return child
359 child
371 360 end
372 361
373 362 # Adds a child
374 363 def add(child)
375 raise "Child already added" if @childrenHash.has_key?(child.name)
376
377 @childrenHash[child.name] = child
378 364 position = @children.size - @last_items_count
379 @children.insert(position, child)
380 child.parent = self
381 return child
365 add_at(child, position)
382 366 end
383 367 alias :<< :add
384 368
385 369 # Removes a child
386 370 def remove!(child)
387 @childrenHash.delete(child.name)
388 371 @children.delete(child)
389 372 @last_items_count -= +1 if child && child.last
390 373 child.parent = nil
General Comments 0
You need to be logged in to leave comments. Login now