Don't try to add to the container if it won't work anyway.
authorTilman Sauerbeck <tilman@code-monkey.de>
Wed, 12 Jul 2006 19:23:23 +0000 (21:23 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Wed, 12 Jul 2006 19:23:23 +0000 (21:23 +0200)
This means we no longer will create new MailboxIcon objects and losing
them immediately without calling the proper EvasObject#delete method.

bin/embrace

index 9772596e4280c26e21eeb6148f706d9049379765..bfd91c9187e631951842089f2910c4b569019d9a 100755 (executable)
@@ -188,6 +188,14 @@ module Embrace
                        @add_lock_count = 0
                end
 
+               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)
                        Kernel.raise(ContainerFullError) if slots_left.zero?
                        Kernel.raise(ContainerLockedError) unless @add_lock_count.zero?
@@ -330,10 +338,6 @@ module Embrace
                end
 
                private
-               def add_icon(name)
-                       @container << MailboxIcon.new(evas, name)
-               end
-
                def on_timer
                        return unless @server.nil?
 
@@ -352,22 +356,10 @@ module Embrace
 
                        found = evas.find_object(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
+                       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