]> git.cworth.org Git - sup/commitdiff
labelmanager bugfix (deletion) and now only saves if modified
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 9 Jul 2007 00:20:14 +0000 (00:20 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 9 Jul 2007 00:20:14 +0000 (00:20 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@489 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/label.rb
lib/sup/modes/label-list-mode.rb

index 5d3dc4a6403de0d3f116fa92e8b99516eab038f9..755ed3ffb213da2e9522ec74de96530e76af5bb5 100644 (file)
@@ -22,6 +22,7 @@ class LabelManager
         []
       end
     @labels = {}
+    @modified = false
     labels.each { |t| @labels[t] = true }
 
     self.class.i_am_the_instance self
@@ -40,9 +41,21 @@ class LabelManager
     string.downcase.intern
   end
   
-  def << t; @labels[t] = true unless @labels.member?(t) || RESERVED_LABELS.member?(t); end
-  def delete t; @labels.delete t; end
+  def << t
+    unless @labels.member?(t) || RESERVED_LABELS.member?(t)
+      @labels[t] = true
+      @modified = true
+    end
+  end
+
+  def delete t
+    if @labels.delete t
+      @modified = true
+    end
+  end
+
   def save
+    return unless @modified
     File.open(@fn, "w") { |f| f.puts @labels.keys }
   end
 end
index cd7f9f5b69e6542433735e8d01df7e51159bc57d..22de97f7b2b0e1d00df87685f7dbaebc979694f8 100644 (file)
@@ -44,7 +44,7 @@ protected
     counts.map do |label, string, total, unread|
       if total == 0 && !LabelManager::RESERVED_LABELS.include?(label)
         Redwood::log "no hits for label #{label}, deleting"
-        LabelManager.delete t
+        LabelManager.delete label
         next
       end