diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-15 10:57:59 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-15 10:57:59 +0000 |
commit | f6dd3c54849430f0976704465ec51f7c20b0a50e (patch) | |
tree | e0bf1a61d1803d2a95c25202e4c4b37b0b7f6038 /lib | |
parent | 77e8a76af342557f99dc4160f7527f599b3c31da (diff) | |
download | redmine-f6dd3c54849430f0976704465ec51f7c20b0a50e.tar.gz redmine-f6dd3c54849430f0976704465ec51f7c20b0a50e.zip |
Code cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8229 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/menu_manager.rb | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index d3693d9ac..b88e6fa2f 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -316,7 +316,6 @@ module Redmine def initialize(name, content = nil) @name = name - @childrenHash ||= {} @children = [] @last_items_count = 0 end @@ -341,50 +340,34 @@ module Redmine # Adds a child at first position def prepend(child) - raise "Child already added" if @childrenHash.has_key?(child.name) - - @childrenHash[child.name] = child - @children = [child] + @children - child.parent = self - return child + add_at(child, 0) end # Adds a child at given position def add_at(child, position) - raise "Child already added" if @childrenHash.has_key?(child.name) - - @childrenHash[child.name] = child + raise "Child already added" if find {|node| node.name == child.name} + @children = @children.insert(position, child) child.parent = self - return child + child end # Adds a child as last child def add_last(child) - raise "Child already added" if @childrenHash.has_key?(child.name) - - @childrenHash[child.name] = child - @children << child + add_at(child, -1) @last_items_count += 1 - child.parent = self - return child + child end # Adds a child def add(child) - raise "Child already added" if @childrenHash.has_key?(child.name) - - @childrenHash[child.name] = child position = @children.size - @last_items_count - @children.insert(position, child) - child.parent = self - return child + add_at(child, position) end alias :<< :add # Removes a child def remove!(child) - @childrenHash.delete(child.name) @children.delete(child) @last_items_count -= +1 if child && child.last child.parent = nil |