undo/redo support
authorgc <gc>
Mon, 11 Apr 2005 20:47:36 +0000 (20:47 +0000)
committergc <gc>
Mon, 11 Apr 2005 20:47:36 +0000 (20:47 +0000)
bin/booh-gui
lib/booh/GtkAutoTable.rb
lib/booh/UndoHandler.rb [new file with mode: 0644]

index df93a7296f4a8353014083a2d88619862550eaf5..e0c0ace17f1275abb20ffb4ac6cfa38634732004 100755 (executable)
@@ -1075,10 +1075,14 @@ Click the <span foreground=\"darkblue\">None</span> icon when you're finished wi
             one_click_explain_try.call
             $r270.active = false
             $delete.active = false
+            nothing.sensitive = true
         else
             if !$r270.active? && !$delete.active?
                 set_mousecursor_normal($autotable)
                 set_mousecursor_normal($subalbums)
+                nothing.sensitive = false
+            else
+                nothing.sensitive = true
             end
         end
     }
@@ -1089,10 +1093,14 @@ Click the <span foreground=\"darkblue\">None</span> icon when you're finished wi
             one_click_explain_try.call
             $r90.active = false
             $delete.active = false
+            nothing.sensitive = true
         else
             if !$r90.active? && !$delete.active?
                 set_mousecursor_normal($autotable)
                 set_mousecursor_normal($subalbums)
+                nothing.sensitive = false
+            else
+                nothing.sensitive = true
             end
         end
     }
@@ -1102,10 +1110,14 @@ Click the <span foreground=\"darkblue\">None</span> icon when you're finished wi
             one_click_explain_try.call
             $r90.active = false
             $r270.active = false
+            nothing.sensitive = true
         else
             if !$r90.active? && !$r270.active?
                 set_mousecursor_normal($autotable)
                 set_mousecursor_normal($subalbums)
+                nothing.sensitive = false
+            else
+                nothing.sensitive = true
             end
         end
     }
index 962a224a77a4ecd1f5ffe30018e5bdfdd02f10a4..eee9aa1c2cbcaa214823a41bf8db8c0178a817c4 100644 (file)
@@ -77,20 +77,6 @@ class Gtk::AutoTable < Gtk::VBox
                 warn "Critical: child not found!"
             end
         }
-
-        #- handle reordering with drag and drop
-        Gtk::Drag.source_set(widget, Gdk::Window::BUTTON1_MASK, [['reorder-elements', Gtk::Drag::TARGET_SAME_APP, 1]], Gdk::DragContext::ACTION_MOVE)
-        Gtk::Drag.dest_set(widget, Gtk::Drag::DEST_DEFAULT_ALL, [['reorder-elements', Gtk::Drag::TARGET_SAME_APP, 1]], Gdk::DragContext::ACTION_MOVE)
-        widget.signal_connect('drag-data-get') { |w, ctxt, selection_data, info, time|
-            selection_data.set(Gdk::Selection::TYPE_STRING, get_current_number(widget).to_s)
-        }
-        widget.signal_connect('drag-data-received') { |w, ctxt, x, y, selection_data, info, time|
-            ctxt.targets.each { |target|
-                if target.name == 'reorder-elements'
-                    insert(selection_data.data.to_i, get_current_number(widget))
-                end
-            }
-        }
     end
 
     #- remove a widget from the list of automatically handled widgets
@@ -105,6 +91,13 @@ class Gtk::AutoTable < Gtk::VBox
         return false
     end
 
+    #- re-insert a widget at a given pos
+    def reinsert(pos, widget, name)
+        child = { :widget => widget, :name => name }
+        @children[pos, 0] = child
+        redistribute(true)
+    end
+
     #- remove all widgets
     def clear
         @children = []
@@ -136,8 +129,8 @@ class Gtk::AutoTable < Gtk::VBox
         return -1
     end
 
-    #- insert a widget before another by numbers
-    def insert(src, dst)
+    #- move widgets by numbers
+    def move(src, dst)
         if src != dst
             chld = @children.delete_at(src)
             @children[dst > src ? dst - 1 : dst, 0] = chld
diff --git a/lib/booh/UndoHandler.rb b/lib/booh/UndoHandler.rb
new file mode 100644 (file)
index 0000000..2a165b2
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/ruby
+#
+#                         *  BOOH  *
+#
+# A.k.a `Best web-album Of the world, Or your money back, Humerus'.
+#
+# The acronyn sucks, however this is a tribute to Dragon Ball by
+# Akira Toriyama, where the last enemy beaten by heroes of Dragon
+# Ball is named "Boo". But there was already a free software project
+# called Boo, so this one will be it "Booh". Or whatever.
+#
+#
+# Copyright (c) 2004 Guillaume Cottenceau <gc3 at bluewin.ch>
+#
+# This software may be freely redistributed under the terms of the GNU
+# public license version 2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+module UndoHandler
+
+    @undo_actions = []
+    @redo_actions = []
+
+    module_function
+
+    def save_undo(closure, params)
+        @undo_actions << { :closure => closure, :params => params }
+    end
+
+    def undo
+        todo = @undo_actions.pop
+        redo_closure = todo[:closure].call(*todo[:params])
+        @redo_actions << { :redo => redo_closure, :undo => todo }
+        return !@undo_actions.empty?
+    end
+
+    def redo
+        redo_item = @redo_actions.pop
+        redo_item[:redo].call
+        @undo_actions << redo_item[:undo]
+        return !@redo_actions.empty?
+    end
+
+    def cleanup
+        @undo_actions.clear
+        @redo_actions.clear
+    end
+
+end