(Source List) Fix drag-n-drop.

This commit is contained in:
Ben Loftis 2018-11-15 09:30:22 -06:00
parent be7ebbb7ba
commit b409c58ee6
4 changed files with 33 additions and 19 deletions

View File

@ -1979,7 +1979,8 @@ private:
gint y,
const Gtk::SelectionData& data,
guint info,
guint time);
guint time,
bool from_region_list);
void drop_routes (
const Glib::RefPtr<Gdk::DragContext>& context,

View File

@ -249,9 +249,15 @@ Editor::initialize_canvas ()
vector<TargetEntry> target_table;
<<<<<<< HEAD
// Drag-N-Drop from the region list can generate this target
target_table.push_back (TargetEntry ("regions"));
=======
target_table.push_back (TargetEntry ("regions")); // DnD from the region list will generate this target
target_table.push_back (TargetEntry ("sources")); // DnD from the source list will generate this target
target_table.push_back (TargetEntry ("text/plain"));
>>>>>>> Source list: Fix drag-n-drop.
target_table.push_back (TargetEntry ("text/uri-list"));
target_table.push_back (TargetEntry ("text/plain"));
target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
@ -376,8 +382,10 @@ Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context
if (!ARDOUR_UI_UTILS::engine_is_running ()) {
return;
}
if (data.get_target() == "regions") {
drop_regions (context, x, y, data, info, time);
if (data.get_target() == X_("regions")) {
drop_regions (context, x, y, data, info, time, true);
} else if (data.get_target() == X_("sources")) {
drop_regions (context, x, y, data, info, time, false);
} else {
drop_paths (context, x, y, data, info, time);
}

View File

@ -27,8 +27,8 @@
#include "ardour/audio_track.h"
#include "ardour/midi_track.h"
#include "ardour/midi_region.h"
#include "ardour/region_factory.h"
#include "ardour/profile.h"
#include "ardour/region_factory.h"
#include "canvas/canvas.h"
#include "canvas/text.h"
@ -1169,8 +1169,6 @@ Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context,
return false;
}
printf("Paul: DRAGGING: track_canvas_drag_motion\n");
event.type = GDK_MOTION_NOTIFY;
event.button.x = x;
event.button.y = y;
@ -1200,8 +1198,10 @@ printf("Paul: DRAGGING: track_canvas_drag_motion\n");
}
if (can_drop) {
region = _regions->get_dragged_region ();
if (!region) {
if (target == X_("regions")) {
region = _regions->get_dragged_region ();
} else if (target == X_("sources")) {
boost::shared_ptr<ARDOUR::Source> src = _sources->get_dragged_source ();
region = RegionFactory::get_whole_region_for_source (src);
}
@ -1261,7 +1261,8 @@ void
Editor::drop_regions (const Glib::RefPtr<Gdk::DragContext>& /*context*/,
int x, int y,
const SelectionData& /*data*/,
guint /*info*/, guint /*time*/)
guint /*info*/, guint /*time*/,
bool from_region_list)
{
GdkEvent event;
double px;
@ -1274,10 +1275,15 @@ Editor::drop_regions (const Glib::RefPtr<Gdk::DragContext>& /*context*/,
event.motion.state = Gdk::BUTTON1_MASK;
samplepos_t const pos = window_event_sample (&event, &px, &py);
boost::shared_ptr<Region> region = _regions->get_dragged_region ();
if (!region) {
boost::shared_ptr<Region> region;
if (from_region_list) {
region = _regions->get_dragged_region ();
} else {
boost::shared_ptr<ARDOUR::Source> src = _sources->get_dragged_source ();
region = RegionFactory::get_whole_region_for_source (src);
if (src) {
region = RegionFactory::get_whole_region_for_source (src);
}
}
if (!region) { return; }
@ -1367,4 +1373,3 @@ Editor::key_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType
return handled;
}

View File

@ -173,18 +173,18 @@ EditorSources::EditorSources (Editor* e)
tv_col->set_expand (true);
_display.get_selection()->set_mode (SELECTION_MULTIPLE);
_display.add_object_drag (_columns.source.index(), "regions");
_display.add_object_drag (_columns.source.index(), "sources");
_display.set_drag_column (_columns.name.index());
/* setup DnD handling */
list<TargetEntry> region_list_target_table;
list<TargetEntry> source_list_target_table;
region_list_target_table.push_back (TargetEntry ("text/plain"));
region_list_target_table.push_back (TargetEntry ("text/uri-list"));
region_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
source_list_target_table.push_back (TargetEntry ("text/plain"));
source_list_target_table.push_back (TargetEntry ("text/uri-list"));
source_list_target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
_display.add_drop_targets (region_list_target_table);
_display.add_drop_targets (source_list_target_table);
_display.signal_drag_data_received().connect (sigc::mem_fun(*this, &EditorSources::drag_data_received));
_scroller.add (_display);