AppKit.TextKit.Formatter.SourceTextView.PerformDragOperation C# (CSharp) Method

PerformDragOperation() public method

Process any drag operations initialized by the user to this AppKit.TextKit.Formatter.SourceTextView. If one or more files have dragged in, the contents of those files will be copied into the document at the current cursor location.
See Apple's drag and drop docs for more details (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DragandDrop/DragandDrop.html)
public PerformDragOperation ( NSDraggingInfo sender ) : bool
sender NSDraggingInfo The caller that initiated the drag operation.
return bool
		public override bool PerformDragOperation (NSDraggingInfo sender)
		{
			// Attempt to read filenames from pasteboard
			var plist = (NSArray) sender.DraggingPasteboard.GetPropertyListForType (NSPasteboard.NSFilenamesType);

			// Was a list of files returned from Finder?
			if (plist != null) {
				// Yes, process list
				for (nuint n = 0; n < plist.Count; ++n) {
					// Get the current file
					var path = plist.GetItem<NSString> (n);
					var url = NSUrl.FromString (path);
					var contents = File.ReadAllText (path);

					// Insert contents at cursor
					NSRange range = SelectedRange;
					TextStorage.BeginEditing ();
					Replace (range, contents);
					TextStorage.EndEditing ();

					// Expand range to fully encompass new content and 
					// reformat
					range = new NSRange (range.Location, contents.Length);
					range = Formatter.FindLineBoundries (TextStorage.Value, range);
					Formatter.HighlightSyntaxRegion (TextStorage.Value, range);
				}

				// Inform caller of success
				return true;
			} else {
				// No, allow base class to handle
				return base.PerformDragOperation (sender);
			}
		}