X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=bin%2Fembrace;h=bfd91c9187e631951842089f2910c4b569019d9a;hb=4a43ceec47783f0a66008d207a8479e324355d28;hp=8feccd3aff578921273392d1b24a95de89dbe492;hpb=e4a1763a49c6ad35ab3a93448e5aa1db8aaddead;p=embrace.git diff --git a/bin/embrace b/bin/embrace index 8feccd3..bfd91c9 100755 --- a/bin/embrace +++ b/bin/embrace @@ -110,6 +110,8 @@ module Embrace def initialize(evas, label) super(evas) + self.name = label + @slot = nil @alpha_anim = nil @@ -125,16 +127,12 @@ module Embrace @img.set_file(ICON_FILE) @img.set_fill(0, 0, *@img.get_size) - @label.text = label + @label.text = name @label.set_font("VeraBd", 10) resize(*@img.get_size) end - def label - @label.text - end - # smart callbacks def on_show @objects.each { |o| o.show } @@ -175,8 +173,6 @@ module Embrace class ContainerFullError < ContainerError; end class ContainerLockedError < ContainerError; end - include Enumerable - def initialize(evas) super @@ -192,8 +188,12 @@ module Embrace @add_lock_count = 0 end - def each - @icons.compact.each { |i| yield i } + def can_add? + !slots_left.zero? && @add_lock_count.zero? + end + + def can_delete? + @about_to_add.zero? && @add_lock_count.zero? end def <<(i) @@ -235,6 +235,7 @@ module Embrace def delete_at(i) Kernel.raise(ContainerLockedError) unless @about_to_add.zero? + Kernel.raise(ContainerLockedError) unless @add_lock_count.zero? # icons that are placed above the one that's deleted need # to be moved @@ -337,10 +338,6 @@ module Embrace end private - def add_icon(name) - @container << MailboxIcon.new(evas, name) - end - def on_timer return unless @server.nil? @@ -357,24 +354,12 @@ module Embrace lbl = md.captures.first end - found = @container.find { |i| i.label == lbl } - - begin - if ev.count.zero? - unless found.nil? - #puts "removing icon #{lbl}" - @container.delete(found) - else - #puts "count == 0, but icon not found (#{lbl})" - end - elsif found.nil? - #puts "adding icon #{lbl}" - add_icon(lbl) - else - #puts "count > 0, but already there (#{lbl})" - end - rescue Exception => e - puts e.message + found = evas.find_object(lbl) + + if ev.count.zero? && !found.nil? && @container.can_delete? + @container.delete(found) + elsif !ev.count.zero? && found.nil? && @container.can_add? + @container << MailboxIcon.new(evas, lbl) end false