Fix region content drag direction
[ardour.git] / gtk2_ardour / editor_drag.cc
index 56879fbaa09f7dbb3423eab50371fadfe38224f8..a3c07b86726fac58e0dcc15f38c480228fbc3fcb 100644 (file)
@@ -361,16 +361,16 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
 
                if (event->motion.state & Gdk::BUTTON1_MASK || event->motion.state & Gdk::BUTTON2_MASK) {
                        if (!from_autoscroll) {
-                               bool const moving_left = _drags->current_pointer_x() < _last_pointer_x;
-                               bool const moving_up = _drags->current_pointer_y() < _last_pointer_y;
-                               _editor->maybe_autoscroll (true, allow_vertical_autoscroll (), moving_left, moving_up);
+                               _editor->maybe_autoscroll (true, allow_vertical_autoscroll (), false);
                        }
 
-                       motion (event, _move_threshold_passed != old_move_threshold_passed);
-
-                       _last_pointer_x = _drags->current_pointer_x ();
-                       _last_pointer_y = _drags->current_pointer_y ();
-                       _last_pointer_frame = adjusted_current_frame (event);
+                       if (!_editor->autoscroll_active() || from_autoscroll) {
+                               motion (event, _move_threshold_passed != old_move_threshold_passed);
+                               
+                               _last_pointer_x = _drags->current_pointer_x ();
+                               _last_pointer_y = _drags->current_pointer_y ();
+                               _last_pointer_frame = adjusted_current_frame (event);
+                       }
 
                        return true;
                }
@@ -1077,6 +1077,17 @@ RegionMoveDrag::finished_no_copy (
 
                } else {
 
+                       boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
+
+                       /* this movement may result in a crossfade being modified, or a layering change,
+                          so we need to get undo data from the playlist as well as the region.
+                       */
+
+                       pair<PlaylistSet::iterator, bool> r = modified_playlists.insert (playlist);
+                       if (r.second) {
+                               playlist->clear_changes ();
+                       }
+
                        rv->region()->clear_changes ();
 
                        /*
@@ -1090,30 +1101,18 @@ RegionMoveDrag::finished_no_copy (
                        rv->drag_end ();
 
                        /* just change the model */
-
-                       boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
-
                        if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
                                playlist->set_layer (rv->region(), dest_layer);
                        }
 
                        /* freeze playlist to avoid lots of relayering in the case of a multi-region drag */
 
-                       pair<PlaylistSet::iterator, bool> r = frozen_playlists.insert (playlist);
+                       r = frozen_playlists.insert (playlist);
 
                        if (r.second) {
                                playlist->freeze ();
                        }
 
-                       /* this movement may result in a crossfade being modified, so we need to get undo
-                          data from the playlist as well as the region.
-                       */
-
-                       r = modified_playlists.insert (playlist);
-                       if (r.second) {
-                               playlist->clear_changes ();
-                       }
-
                        rv->region()->set_position (where);
 
                        _editor->session()->add_command (new StatefulDiffCommand (rv->region()));
@@ -1789,9 +1788,10 @@ VideoTimeLineDrag::aborted (bool)
 
 TrimDrag::TrimDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool preserve_fade_anchor)
        : RegionDrag (e, i, p, v)
+       , _preserve_fade_anchor (preserve_fade_anchor)
+       , _jump_position_when_done (false)
 {
        DEBUG_TRACE (DEBUG::Drags, "New TrimDrag\n");
-       _preserve_fade_anchor = preserve_fade_anchor;
 }
 
 void
@@ -1828,6 +1828,10 @@ TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
                }
        }
 
+       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
+               _jump_position_when_done = true;
+       }
+
        switch (_operation) {
        case StartTrim:
                show_verbose_cursor_time (region_start);
@@ -1954,8 +1958,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
 
        case ContentsTrim:
                {
-                       frame_delta = (adjusted_current_frame(event) - last_pointer_frame());
-                       // frame_delta = (last_pointer_frame() - adjusted_current_frame(event));
+                       frame_delta = (last_pointer_frame() - adjusted_current_frame(event));
 
                        for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
                                i->view->move_contents (frame_delta);
@@ -2007,6 +2010,9 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
                                                ar->set_fade_in_length(new_length);
                                        }
                                }
+                               if (_jump_position_when_done) {
+                                       i->view->region()->set_position (i->initial_position);
+                               }
                        }
                } else if (_operation == EndTrim) {
                        for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
@@ -2024,6 +2030,9 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
                                                ar->set_fade_out_length(new_length);
                                        }
                                }
+                               if (_jump_position_when_done) {
+                                       i->view->region()->set_position (i->initial_end - i->view->region()->length());
+                               }
                        }
                }
 
@@ -3912,9 +3921,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
                break;
        }
 
-       if (event->button.x >= _editor->horizontal_position() + _editor->_visible_canvas_width) {
-               _editor->start_canvas_autoscroll (1, 0);
-       }
+       _editor->maybe_autoscroll (true, false, false);
 
        if (start != end) {
                switch (_operation) {
@@ -4103,9 +4110,7 @@ RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move)
                }
        }
 
-       if (event->button.x >= _editor->horizontal_position() + _editor->_visible_canvas_width) {
-               _editor->start_canvas_autoscroll (1, 0);
-       }
+       _editor->maybe_autoscroll (true, false, false);
 
        if (start != end) {
                _editor->temp_location->set (start, end);