Exemple #1
0
		//
		// DND Drop handling
		//
		protected override void OnDragDataReceived (Gdk.DragContext context,
		                int x,
		                int y,
		                Gtk.SelectionData selection_data,
		                uint info,
		                uint time)
		{
			bool has_url = false;

			foreach (Gdk.Atom target in context.ListTargets()) {
				if (target.Name == "text/uri-list" ||
				                target.Name == "_NETSCAPE_URL") {
					has_url = true;
					break;
				}
			}

			if (has_url) {
				UriList uri_list = new UriList (selection_data);
				bool more_than_one = false;

				// Place the cursor in the position where the uri was
				// dropped, adjusting x,y by the TextView's VisibleRect.
				Gdk.Rectangle rect = VisibleRect;
				int adjustedX = x + rect.X;
				int adjustedY = y + rect.Y;
				Gtk.TextIter cursor = GetIterAtLocation (adjustedX, adjustedY);
				Buffer.PlaceCursor (cursor);

				Gtk.TextTag link_tag = Buffer.TagTable.Lookup ("link:url");

				foreach (Uri uri in uri_list) {
					Logger.Debug ("Got Dropped URI: {0}", uri);
					string insert;
					if (uri.IsFile) {
						// URL-escape the path in case
						// there are spaces (bug #303902)
						insert = System.Uri.EscapeUriString (uri.LocalPath);
					} else {
						insert = uri.ToString ();
					}

					if (insert == null || insert.Trim () == String.Empty)
						continue;

					if (more_than_one) {
						cursor = Buffer.GetIterAtMark (Buffer.InsertMark);

						// FIXME: The space here is a hack
						// around a bug in the URL Regex which
						// matches across newlines.
						if (cursor.LineOffset == 0)
							Buffer.Insert (ref cursor, " \n");
						else
							Buffer.Insert (ref cursor, ", ");
					}

					Buffer.InsertWithTags (ref cursor, insert, link_tag);
					more_than_one = true;
				}

				Gtk.Drag.Finish (context, more_than_one, false, time);
			} else {
				base.OnDragDataReceived (context, x, y, selection_data, info, time);
			}
		}
Exemple #2
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;
            }
        }
        protected override void OnDragDataGet(Gdk.DragContext context, SelectionData selectionData,
            uint info, uint time)
        {
            switch ((DragDropTargetType)info) {
                case DragDropTargetType.Source:
                    new DragDropList<Source> (ServiceManager.SourceManager.ActiveSource,
                        selectionData, context.ListTargets ()[0]);
                    break;
                default:
                    return;
            }

            base.OnDragDataGet (context, selectionData, info, time);
        }