// Pop up Start Here and insert dropped links, in the form: // Wednesday, December 8, 6:45 AM // http://luna/kwiki/index.cgi?AdelaideUniThoughts // http://www.beatniksoftware.com/blog/ // And select the inserted text. // // FIXME: Make undoable, make sure our date-sizing tag never "bleeds". // void OnDragDataReceived(object sender, Gtk.DragDataReceivedArgs args) { UriList uri_list = new UriList(args.SelectionData); if (uri_list.Count == 0) { return; } StringBuilder insert_text = new StringBuilder(); bool more_than_one = false; foreach (Uri uri in uri_list) { if (more_than_one) { insert_text.Append("\n"); } if (uri.IsFile) { insert_text.Append(uri.LocalPath); } else { insert_text.Append(uri.ToString()); } more_than_one = true; } manager.GtkInvoke(() => { Note link_note = manager.FindByUri(NoteManager.StartNoteUri); if (link_note != null) { link_note.Window.Present(); PrependTimestampedText(link_note, DateTime.Now, insert_text.ToString()); } }); }
// // 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.Targets) { 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); } }