Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a text editor using GTK3 in Vala. I need to drag a file and, when I drop it into the application window, the application opens that file. I'm using a Gtk.Notebook that contains the Gtk.SourceView's. It works when I drop a file into an empty Gtk.Notebook, but when there is at least one Gtk.SourceView appended on it, the SourceView grabs the URI of the file, shows it and the window can't handle the opening of the file.

In this case, what can I do to prevent a Gtk.SourceView from grabbing the URI of a file when I drop a file into a Gtk.SourceView.

PS: I tried to use the drag_dest_unset() inside the SourceView derived class. It worked, the SourceView didn't grab the URI and the window could open the file, but the application showed a message like this, in runtime:

Gtk-WARNING **: Can't set a target list on a widget until you've called gtk_drag_dest_set() to make the widget into a drag destination
share|improve this question
up vote 1 down vote accepted

To make the Gtk.SourceView stop grabbing the uri, I used the following code snippet:

public class MySourceView: Gtk.SourceView {
    public MySourceView() {
        Gtk.TargetEntry[] targets;
        targets = new Gtk.TargetEntry[1];
        targets[0].target = "text/uri-list";
        targets[0].flags = 0;
        targets[0].info = 0;

        Gtk.drag_dest_set(this, Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY);

    private void drag_data_received_cb(Gtk.Widget sender,
                    Gdk.DragContext drag_context,
                    int x, int y,
                    Gtk.SelectionData data,
                    uint info, uint time) {
        print("Drag data received!\n");
        // Do something

        Gtk.drag_finish (drag_context, true, false, time);

This way, the uri of the file that I drop in the source view is not pasted in it and I can open the file in another tab.

share|improve this answer

This sounds like you're trying to drag the file into the SourceView widget with the idea that it will open a new tab instead of opening that file in that source view widget.

What you need to do is not disable the drag event, you need to redirect it. The event will come into the sourceview widget and then you connect to it and pass it to your code (in your window?) which deals with opening a new tab.

Does this make sense? do you need code samples?

share|improve this answer
Yes, this makes sense. I'm gonna try to do this. But, if you have code samples, they'll be very useful. Thank you very much. – LuisABOL Mar 6 '12 at 14:28
No, sorry, but when you complete, please post back here with the code sample. – Martin Owens -doctormo- Mar 19 '12 at 11:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.