public override void CellClicked(NSTextView textView, NSTextAttachmentCell cell, CGRect cellFrame, nuint charIndex) { var textCell = cell as ImageCell; if (textCell == null) { return; } // 存在就直接打开 var localFileName = textCell.GetData("localName"); if (localFileName != null) { OpenPreview(localFileName); return; } // 开始创建 var url = textCell.GetData("picUrl"); if (url == null) { return; } var randomPicName = Config.PICSAVEDIRECTORY + Guid.NewGuid().ToString(); // get pic from network File.WriteAllBytes(randomPicName, BaseService.SendGetRequest(url)); var fullPathName = Path.GetFullPath(randomPicName); textCell.SetData("localName", fullPathName); OpenPreview(fullPathName); }
public static NSAttributedString GetAttributedStringWithImage(string imageName, int imageSize, string text) { var attrString = new NSMutableAttributedString(""); if (!string.IsNullOrEmpty(imageName)) { var image = GetImageForSize(imageName, imageSize); if (image != null) { image.AlignmentRect = new CGRect { X = 0, Y = 5, Width = imageSize - 2, Height = imageSize - 2 }; var cell = new NSTextAttachmentCell(image); cell.Alignment = NSTextAlignment.Left; attrString.Append(NSAttributedString.FromAttachment(new NSTextAttachment { AttachmentCell = cell })); attrString.Append(new NSAttributedString(" ")); } } attrString.Append(new NSAttributedString(text)); var style = new NSMutableParagraphStyle { LineBreakMode = NSLineBreakMode.TruncatingMiddle }; attrString.AddAttribute(NSStringAttributeKey.ParagraphStyle, style, new NSRange(0, attrString.Length)); return(attrString); }
void InsertCat (NSTextAttachmentCell cell) { textView.TextStorage.Append ( NSAttributedString.FromAttachment ( new NSTextAttachment { AttachmentCell = cell } ) ); }
void InsertCat(NSTextAttachmentCell cell) { textView.TextStorage.Append( NSAttributedString.FromAttachment( new NSTextAttachment { AttachmentCell = cell } ) ); }
public static NSAttributedString GetMultiLineAttributedStringWithImage(NSImage image, string title, string description, nfloat fontSize, NSColor titleColor, NSColor descriptionColor) { var attrString = new NSMutableAttributedString(""); if (image != null) { var cell = new NSTextAttachmentCell(image); image.AlignmentRect = new CoreGraphics.CGRect(0, 5, image.Size.Width, image.Size.Height); cell.Alignment = NSTextAlignment.Natural; attrString.Append(NSAttributedString.FromAttachment(new NSTextAttachment { AttachmentCell = cell })); attrString.Append(new NSAttributedString(" ")); } var pstyle = new NSMutableParagraphStyle(); pstyle.HeadIndent = pstyle.FirstLineHeadIndent = 24; attrString.Append(GetMultiLineAttributedString(title, description, fontSize, titleColor, descriptionColor, pstyle)); return(attrString); }
/// <summary> /// Called when the cell is clicked. /// </summary> /// <param name="textView">The <see cref="AppKit.TextKit.Formatter.SourceTextView"/>.</param> /// <param name="cell">The cell being acted upon.</param> /// <param name="cellFrame">The onscreen frame of the cell.</param> /// <param name="charIndex">The index of the character clicked.</param> /// <remarks> /// Because a custom <c>Delegate</c> has been attached to the <c>NSTextView</c>, the normal events /// will not work so we are using this method to call custom <see cref="AppKit.TextKit.Formatter.SourceTextView"/> /// events instead. /// </remarks> public override void CellClicked (NSTextView textView, NSTextAttachmentCell cell, CGRect cellFrame, nuint charIndex) { // Pass through to Text Editor event TextEditor.RaiseSourceCellClicked(TextEditor, new NSTextViewClickedEventArgs(cell, cellFrame, charIndex)); }
/// <summary> /// Called when the cell is dragged. /// </summary> /// <param name="textView">The <see cref="AppKit.TextKit.Formatter.SourceTextView"/>.</param> /// <param name="cell">The cell being acted upon.</param> /// <param name="cellFrame">The onscreen frame of the cell.</param> /// <param name="theevent">An event defining the drag operation.</param> /// <remarks> /// Because a custom <c>Delegate</c> has been attached to the <c>NSTextView</c>, the normal events /// will not work so we are using this method to call custom <see cref="AppKit.TextKit.Formatter.SourceTextView"/> /// events instead. /// </remarks> public override void DraggedCell (NSTextView view, NSTextAttachmentCell cell, CGRect rect, NSEvent theevent) { // Pass through to Text Editor event TextEditor.RaiseSourceCellDragged(TextEditor, new NSTextViewDraggedCellEventArgs(cell, rect, theevent)); }
/// <summary> /// Called when the cell is dragged. /// </summary> /// <param name="textView">The <see cref="AppKit.TextKit.Formatter.SourceTextView"/>.</param> /// <param name="cell">The cell being acted upon.</param> /// <param name="cellFrame">The onscreen frame of the cell.</param> /// <param name="theevent">An event defining the drag operation.</param> /// <remarks> /// Because a custom <c>Delegate</c> has been attached to the <c>NSTextView</c>, the normal events /// will not work so we are using this method to call custom <see cref="AppKit.TextKit.Formatter.SourceTextView"/> /// events instead. /// </remarks> public override void DraggedCell(NSTextView view, NSTextAttachmentCell cell, CGRect rect, NSEvent theevent) { // Pass through to Text Editor event TextEditor.RaiseSourceCellDragged(TextEditor, new NSTextViewDraggedCellEventArgs(cell, rect, theevent)); }
/// <summary> /// Called when the cell is double-clicked. /// </summary> /// <param name="textView">The <see cref="AppKit.TextKit.Formatter.SourceTextView"/>.</param> /// <param name="cell">The cell being acted upon.</param> /// <param name="cellFrame">The onscreen frame of the cell.</param> /// <param name="charIndex">The index of the character clicked.</param> /// <remarks> /// Because a custom <c>Delegate</c> has been attached to the <c>NSTextView</c>, the normal events /// will not work so we are using this method to call custom <see cref="AppKit.TextKit.Formatter.SourceTextView"/> /// events instead. /// </remarks> public override void CellDoubleClicked(NSTextView textView, NSTextAttachmentCell cell, CGRect cellFrame, nuint charIndex) { // Pass through to Text Editor event TextEditor.RaiseSourceCellDoubleClicked(TextEditor, new NSTextViewDoubleClickEventArgs(cell, cellFrame, charIndex)); }