Ejemplo n.º 1
0
 protected override void OnDragDataGet(Gdk.DragContext context, SelectionData selection_data, uint info, uint time)
 {
     if (info == Banshee.Gui.DragDrop.DragDropTarget.UriList.Info)
     {
         ITrackModelSource track_source = ServiceManager.SourceManager.ActiveSource as ITrackModelSource;
         if (track_source != null)
         {
             System.Text.StringBuilder sb = new System.Text.StringBuilder();
             foreach (TrackInfo track in track_source.TrackModel.SelectedItems)
             {
                 sb.Append(track.Uri);
                 sb.Append("\r\n");
             }
             byte [] data = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
             selection_data.Set(context.ListTargets()[0], 8, data, data.Length);
         }
     }
 }
Ejemplo n.º 2
0
        T GetSelectionData <T>(string type, Func <Gtk.SelectionData, T> getData)
        {
            if (_dragContext != null)
            {
#if GTK2
                var target = _dragContext.Targets.FirstOrDefault(r => r.Name == type);
#else
                var target = _dragContext.ListTargets().FirstOrDefault(r => r.Name == type);
#endif
                if (target != null)
                {
                    object data = null;
                    var    sem  = new ManualResetEventSlim(false);
                    _getData = selection =>
                    {
                        data = (object)getData(selection);
                        sem.Set();
                    };
                    Gtk.Drag.GetData(_sourceWidget, _dragContext, target, _dragTime);
                    if (!sem.IsSet)
                    {
                        // sometimes data gets passed back at the next run loop, so we pump the loop here
                        // is there a better way to wait for the data to arrive?
                        for (int i = 0; i < 2; i++)
                        {
                            Gtk.Application.RunIteration();
                            if (sem.Wait(100))
                            {
                                break;
                            }
                        }
                    }


                    _getData = null;
                    return((T)data);
                }
            }
            return(default(T));
        }
Ejemplo n.º 3
0
        internal bool DoDragDrop(Gdk.DragContext context, int x, int y, uint time)
        {
            DragDropInfo.LastDragPosition = new Point(x, y);
            var cda = ConvertDragAction(context.GetSelectedAction());

            DragDropResult res;

            if ((enabledEvents & WidgetEvent.DragDropCheck) == 0)
            {
                if ((enabledEvents & WidgetEvent.DragDrop) != 0)
                {
                    res = DragDropResult.None;
                }
                else
                {
                    res = DragDropResult.Canceled;
                }
            }
            else
            {
                DragCheckEventArgs da = new DragCheckEventArgs(new Point(x, y), Util.GetDragTypes(context.ListTargets()), cda);
                ApplicationContext.InvokeUserCode(delegate {
                    EventSink.OnDragDropCheck(da);
                });
                res = da.Result;
                if ((enabledEvents & WidgetEvent.DragDrop) == 0 && res == DragDropResult.None)
                {
                    res = DragDropResult.Canceled;
                }
            }
            if (res == DragDropResult.Canceled)
            {
                Gtk.Drag.Finish(context, false, false, time);
                return(true);
            }
            else if (res == DragDropResult.Success)
            {
                Gtk.Drag.Finish(context, true, cda == DragDropAction.Move, time);
                return(true);
            }
            else
            {
                // Undefined, we need more data
                QueryDragData(context, time, false);
                return(true);
            }
        }
Ejemplo n.º 4
0
 public bool Contains(string type)
 {
     return(_dragContext?.ListTargets().Any(r => r.Name == type)
            ?? Control.ContainsKey(type));
 }