>From 1fd41c30189db832abb54f1cda416d0aa624e028 Mon Sep 17 00:00:00 2001
From: Mike Stipicevic <[email protected]>
Date: Mon, 16 Feb 2009 00:11:28 -0500
Subject: [PATCH] Added undo for label edit
---
lib/sup/modes/thread-index-mode.rb | 27 +++++++++++++++++++++++++--
1 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/lib/sup/modes/thread-index-mode.rb
b/lib/sup/modes/thread-index-mode.rb
index 159839d..f28302b 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -509,6 +509,10 @@ EOS
def edit_labels
thread = cursor_thread or return
speciall = (@hidden_labels + LabelManager::RESERVED_LABELS).uniq
+
+ old_labels = thread.labels
+ pos = curpos
+
keepl, modifyl = thread.labels.partition { |t| speciall.member? t }
user_labels = BufferManager.ask_for_labels :label, "Labels for thread: ",
modifyl, @hidden_labels
@@ -517,6 +521,15 @@ EOS
thread.labels = keepl + user_labels
user_labels.each { |l| LabelManager << l }
update_text_for_line curpos
+
+ undo = lambda{
+ thread.labels = old_labels
+ update_text_for_line pos
+ UpdateManager.relay self, :labeled, thread.first
+ }
+
+ UndoManager.register("labeling thread #{thread.first.id}", undo)
+
UpdateManager.relay self, :labeled, thread.first
end
@@ -526,8 +539,18 @@ EOS
hl = user_labels.select { |l| @hidden_labels.member? l }
if hl.empty?
- threads.each { |t| user_labels.each { |l| t.apply_label l } }
- user_labels.each { |l| LabelManager << l }
+ undo = threads.map { |t| old_labels = t.labels
+ user_labels.each { |l| t.apply_label l }
+ ## UpdateManager or some other regresh mechanism?
+ UpdateManager.relay self, :labeled, t.first
+ lambda {
+ t.labels = old_labels
+ UpdateManager.relay self, :labeled, t.first
+ }
+ }
+ user_labels.each { |l| LabelManager << l }
+ UndoManager.register("labeling #{threads.size} #{threads.size.pluralize
'thread'}",
+ undo << lambda { regen_text})
else
BufferManager.flash "'#{hl}' is a reserved label!"
end
--
1.5.3
_______________________________________________
sup-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/sup-talk