mouse gestures: left->right button does undo, right->left button does redo
authorgc <gc>
Sun, 12 Jun 2005 15:27:32 +0000 (15:27 +0000)
committergc <gc>
Sun, 12 Jun 2005 15:27:32 +0000 (15:27 +0000)
bin/booh

index 79bb17e9bd39ceea1ac308e502c5d2166e658825..5843fa0b1480372a20147ca669ee94d50b147e9d 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -881,54 +881,56 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
         !propagate  #- propagate if needed
     }
 
+    $ignore_next_release = false
     evtbox.signal_connect('button-press-event') { |w, event|
-        retval = true
         if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 1
-            shift_or_control = event.state & Gdk::Window::SHIFT_MASK != 0 || event.state & Gdk::Window::CONTROL_MASK != 0
-            if $r90.active?
-                rotate_and_cleanup.call(shift_or_control ? -90 : 90)
-            elsif $r270.active?
-                rotate_and_cleanup.call(shift_or_control ? 90 : -90)
-            elsif $enhance.active?
-                enhance_and_cleanup.call
-            elsif $delete.active?
-                delete.call
+            if event.state & Gdk::Window::BUTTON3_MASK != 0
+                #- gesture redo: hold right mouse button then click left mouse button
+                perform_redo
+                $ignore_next_release = true
             else
-                textview.grab_focus
+                shift_or_control = event.state & Gdk::Window::SHIFT_MASK != 0 || event.state & Gdk::Window::CONTROL_MASK != 0
+                if $r90.active?
+                    rotate_and_cleanup.call(shift_or_control ? -90 : 90)
+                elsif $r270.active?
+                    rotate_and_cleanup.call(shift_or_control ? 90 : -90)
+                elsif $enhance.active?
+                    enhance_and_cleanup.call
+                elsif $delete.active?
+                    delete.call
+                else
+                    textview.grab_focus
+                    $gesture_press = { :filename => filename, :x => event.x, :y => event.y }
+                end
             end
-        end
-        if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 3
-            x, y = autotable.get_current_pos(vbox)
-            next_ = autotable.get_next_widget(vbox)
-            popup_thumbnail_menu(event, ['delete'], type, $xmldir.elements["[@filename='#{filename}']"], '',
-                                 { :can_left => x > 0, :can_right => next_ && autotable.get_current_pos(next_)[0] > x,
-                                   :can_up => y > 0, :can_down => y < autotable.get_max_y },
-                                 { :rotate => rotate_and_cleanup, :move => move, :color_swap => color_swap_and_cleanup, :enhance => enhance_and_cleanup,
-                                   :frame_offset => change_frame_offset_and_cleanup, :delete => delete, :whitebalance => whitebalance_and_cleanup })
-        end
-        if event.event_type == Gdk::Event::BUTTON2_PRESS && event.button == 1
+        elsif event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 3
+            if event.state & Gdk::Window::BUTTON1_MASK != 0
+                #- gesture undo: hold left mouse button then click right mouse button
+                perform_undo
+                $ignore_next_release = true
+            end
+        elsif event.event_type == Gdk::Event::BUTTON2_PRESS && event.button == 1
             view_element(filename, { :delete => delete })
-        else
-            retval = false  #- propagate
+        elsif event.event_type == Gdk::Event::BUTTON2_PRESS && event.button == 3
         end
-        retval
+        false  #- propagate
     }
 
-    vbox.signal_connect('button-press-event') { |w, event|
-        if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 1
-            $gesture_press = { :filename => filename, :x => event.x, :y => event.y }
-        end
-        false
-    }
-    vbox.signal_connect('drag-data-received') { |w, ctxt, x, y, selection_data, info, time|
-        if $gesture_press && $gesture_press[:filename] == filename
-            if (($gesture_press[:x]-x)/($gesture_press[:y]-y)).abs > 2 && ($gesture_press[:x]-x).abs > 5
-                angle = x-$gesture_press[:x] > 0 ? 90 : -90
-                msg 3, "gesture rotate: #{angle}"
-                rotate_and_cleanup.call(angle)
+    evtbox.signal_connect('button-release-event') { |w, event|
+        if event.event_type == Gdk::Event::BUTTON_RELEASE && event.button == 3
+            if !$ignore_next_release
+                x, y = autotable.get_current_pos(vbox)
+                next_ = autotable.get_next_widget(vbox)
+                popup_thumbnail_menu(event, ['delete'], type, $xmldir.elements["[@filename='#{filename}']"], '',
+                                     { :can_left => x > 0, :can_right => next_ && autotable.get_current_pos(next_)[0] > x,
+                                         :can_up => y > 0, :can_down => y < autotable.get_max_y },
+                                     { :rotate => rotate_and_cleanup, :move => move, :color_swap => color_swap_and_cleanup, :enhance => enhance_and_cleanup,
+                                         :frame_offset => change_frame_offset_and_cleanup, :delete => delete, :whitebalance => whitebalance_and_cleanup })
             end
+            $ignore_next_release = false
+            $gesture_press = nil
         end
-        $gesture_press = nil
+        false   #- propagate
     }
 
     #- handle reordering with drag and drop
@@ -937,29 +939,48 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
     vbox.signal_connect('drag-data-get') { |w, ctxt, selection_data, info, time|
         selection_data.set(Gdk::Selection::TYPE_STRING, autotable.get_current_number(vbox).to_s)
     }
+
     vbox.signal_connect('drag-data-received') { |w, ctxt, x, y, selection_data, info, time|
-        ctxt.targets.each { |target|
-            if target.name == 'reorder-elements'
-                from, to = selection_data.data.to_i, autotable.get_current_number(vbox)
-                if from != to
-                    $modified = true
-                    autotable.move(from, to)
-                    save_undo(_("reorder"),
-                              Proc.new { |from, to|
-                                  if to > from
-                                      autotable.move(to - 1, from)
-                                  else
-                                      autotable.move(to, from + 1)
-                                  end
-                                  $notebook.set_page(1)
-                                  Proc.new {
-                                      autotable.move(from, to)
+        done = false
+        #- mouse gesture first (dnd disables button-release-event)
+        if $gesture_press && $gesture_press[:filename] == filename
+            if (($gesture_press[:x]-x)/($gesture_press[:y]-y)).abs > 2 && ($gesture_press[:x]-x).abs > 5
+                angle = x-$gesture_press[:x] > 0 ? 90 : -90
+                msg 3, "gesture rotate: #{angle}: click-drag right button to the left/right"
+                rotate_and_cleanup.call(angle)
+                $statusbar.push(0, utf8(_("Mouse gesture: rotate.")))
+                done = true
+            elsif (($gesture_press[:y]-y)/($gesture_press[:x]-x)).abs > 2 && y-$gesture_press[:y] > 5
+                msg 3, "gesture delete: click-drag right button to the bottom"
+                delete.call
+                $statusbar.push(0, utf8(_("Mouse gesture: delete.")))
+                done = true
+            end
+        end
+        if !done
+            ctxt.targets.each { |target|
+                if target.name == 'reorder-elements'
+                    from, to = selection_data.data.to_i, autotable.get_current_number(vbox)
+                    if from != to
+                        $modified = true
+                        autotable.move(from, to)
+                        save_undo(_("reorder"),
+                                  Proc.new { |from, to|
+                                      if to > from
+                                          autotable.move(to - 1, from)
+                                      else
+                                          autotable.move(to, from + 1)
+                                      end
                                       $notebook.set_page(1)
-                                  }
-                              }, from, to)
+                                      Proc.new {
+                                          autotable.move(from, to)
+                                          $notebook.set_page(1)
+                                      }
+                                  }, from, to)
+                    end
                 end
-            end
-        }
+            }
+        end
     }
 
     vbox.show_all
@@ -2205,6 +2226,24 @@ def preferences
     dialog.destroy
 end
 
+def perform_undo
+    if $undo_tb.sensitive?
+        $redo_tb.sensitive = $redo_mb.sensitive = true
+        if not more_undoes = UndoHandler.undo($statusbar)
+            $undo_tb.sensitive = $undo_mb.sensitive = false
+        end
+    end
+end
+
+def perform_redo
+    if $redo_tb.sensitive?
+        $undo_tb.sensitive = $undo_mb.sensitive = true
+        if not more_redoes = UndoHandler.redo($statusbar)
+            $redo_tb.sensitive = $redo_mb.sensitive = false
+        end
+    end
+end
+
 def create_menu_and_toolbar
 
     #- menu
@@ -2350,23 +2389,11 @@ Copyright (c) 2005 Guillaume Cottenceau") % $VERSION), { :centered => true, :pos
     tb.insert(-1, $undo_tb = Gtk::ToolButton.new(Gtk::Stock::UNDO).set_sensitive(false))
     tb.insert(-1, $redo_tb = Gtk::ToolButton.new(Gtk::Stock::REDO).set_sensitive(false))
 
-    perform_undo = Proc.new {
-        $redo_tb.sensitive = $redo_mb.sensitive = true
-        if not more_undoes = UndoHandler.undo($statusbar)
-            $undo_tb.sensitive = $undo_mb.sensitive = false
-        end
-    }
-    perform_redo = Proc.new {
-        $undo_tb.sensitive = $undo_mb.sensitive = true
-        if not more_redoes = UndoHandler.redo($statusbar)
-            $redo_tb.sensitive = $redo_mb.sensitive = false
-        end
-    }
 
-    $undo_tb.signal_connect('clicked')  { perform_undo.call }
-    $undo_mb.signal_connect('activate') { perform_undo.call }
-    $redo_tb.signal_connect('clicked')  { perform_redo.call }
-    $redo_mb.signal_connect('activate') { perform_redo.call }
+    $undo_tb.signal_connect('clicked')  { perform_undo }
+    $undo_mb.signal_connect('activate') { perform_undo }
+    $redo_tb.signal_connect('clicked')  { perform_redo }
+    $redo_mb.signal_connect('activate') { perform_redo }
 
     one_click_explain_try = Proc.new {
         if !$config['one-click-explained']