[Gtk-sharp-list] Draging text/uri from external app to widget
ub
boo@youfuckingbitch.com
Mon, 20 Sep 2004 09:23:16 +0200
ok, i got it now :-)
i translated the tutorial from http://scentric.net/tutorial/sec-dnd.htm
, which seems to do exactly what i want, and it even works ;)
here is my test-source, just in case anyone got the same problem:
using System;
using Gtk;
public class MyWindow : Window {
enum bla{
TARGET_STRING,
TARGET_URL
};
static Gtk.TargetEntry[] targetentries =
{
new TargetEntry ("STRING", 0, (uint) bla.TARGET_STRING ),
new TargetEntry ("text/plain", 0, (uint) bla.TARGET_STRING ),
new TargetEntry ("text/uri-list", 0, (uint) bla.TARGET_URL
),
};
public MyWindow () : base ("MyWindow")
{
this.SetDefaultSize (400, 300);
this.DeleteEvent += new DeleteEventHandler (OnMyWindowDelete);
this.ShowAll ();
Gtk.Drag.DestSet(this, Gtk.DestDefaults.All, targetentries,
Gdk.DragAction.Copy|Gdk.DragAction.Move|Gdk.DragAction.Link);
this.DragDataReceived += new DragDataReceivedHandler(on_drop);
}
void on_drop (object o, DragDataReceivedArgs args)
{
Console.WriteLine(System.Text.Encoding.UTF8.GetString
(args.SelectionData.Data));
}
void OnMyWindowDelete (object o, DeleteEventArgs args)
{
Application.Quit ();
}
}
ub wrote:
> hi list!
> i am trying to drag some link from firefox/konq into my gui, but i
> dont seem to get it to work.i am messing around with this stuff all
> day; ok so here's what i've tried:
>
> textview1.DragDataReceived += new DragDataReceivedHandler (on_drop);
>
> void on_drop(object o, DragDataReceivedArgs args){
> Console.WriteLine("stuff got dropped");
> }
>
> also tried that with DragDataDrop, DragEnd, kinda every Drag* handler,
> on almost every widget in the gui, but on_drop() never fired. i
> figured i'd need to add Drag.DestSet method. i downloaded f-spot
> source (http://www.gnome.org/projects/f-spot/) where it seems to work
> (kinda), so i added
>
> private static TargetEntry [] icon_source_target_table = new
> TargetEntry [] {
> new TargetEntry ("application/x-fspot-photos", 0, (uint)
> TargetType.PhotoList), new TargetEntry ("text/uri-list", 0,
> (uint) TargetType.UriList), //i really have no clue what this does
> };
> // TargetTypeis an enum containing some lists, they dont get used
> before a handler is called, still tried to add/modify them - didnt help.
> Gtk.Drag.DestSet (textview, DestDefaults.All, icon_dest_target_table,
> DragAction.Copy | DragAction.Move); //copy/paste from
> MainWindow.cs - f-spot-0.0.2
>
> again i tried almost every possible constelation of widget - drag*,
> but no luck. now im kinda fed up with bruteforcing (this is very
> frustrating by now) ;(
> btw, yes - i read the tutorial at gtk.org and the mono documentation,
> but i still have no clue how to do a simple drop operation. would be
> nice if someone could explain how i get a widget to except drops from
> an external app (any help is appreciated).
>
> Thanks,
> Ulrich
>
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>