internal string GetRtf(NSPasteboard pboard) { var data = pboard.GetDataForType(Pasteboard.NSPasteboardTypeRTF); if (data != null) { return(NSString.FromData(data, NSStringEncoding.ASCIIStringEncoding)?.ToString()); } return(null); }
public override bool AcceptDrop(NSTableView tableView, NSDraggingInfo info, nint row, NSTableViewDropOperation dropOperation) { if (row < 0) { return(false); } NSPasteboard pboard = info.DraggingPasteboard; NSData rowData = pboard.GetDataForType("NSStringPboardType"); var rowIndexes = NSKeyedUnarchiver.UnarchiveObject(rowData); int dragRow = (int)((NSIndexSet)rowIndexes).FirstIndex; if (dragRow == row) { return(false); } int index = Convert.ToInt32(row); if (dropOperation == NSTableViewDropOperation.Above) { // 插入 if (ViewController is EditTagsViewController) { var viewController = (EditTagsViewController)this.ViewController; viewController.DragItemFromIndexToIndex(tableView, dragRow, index); } tableView.ReloadData(); } else if (dropOperation == NSTableViewDropOperation.On) { // 替换 } else { //Console.WriteLine ("unexpected operation {0} in {1}", dropOperation, __FUNCTION__); } return(true); }
public static IDataObject GetDataObject() { var dataObject = new DataObject(); // Beside copying and pasting UnicodeText to/from pasteboard // editor inserts booleans like "VisualStudioEditorOperationsLineCutCopyClipboardTag" // which allows editor to know whole line was copied into pasteboard so on paste // it inserts line into new line, so we enumerate over all types and if length == 1 // we just assume it's boolean we set in method above foreach (var type in pasteboard.Types) { if (type == DataFormats.UnicodeText) { dataObject.SetText(pasteboard.GetStringForType(type)); continue; } var data = pasteboard.GetDataForType(type); if (data != null && data.Length == 1) { dataObject.SetData(type, data: data [0] != 0); } } return(dataObject); }