• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Tokenizing" NSTextView content [solved]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Tokenizing" NSTextView content [solved]


  • Subject: Re: "Tokenizing" NSTextView content [solved]
  • From: Rob Keniger <email@hidden>
  • Date: Fri, 19 Jun 2009 17:40:55 +1000


On 19/06/2009, at 12:32 PM, Rob Keniger wrote:
I need to display a text view which will contain HTML-like syntax and allow the user to drag "objects" into the view.

I have been able to use NSTextAttachment to handle the display of the dragged objects just fine, but what I want to do is restrict the user from dragging the object anywhere except between the "tags" in the document.

It turns out this was easier than I thought.

I subclassed NSTextView and in -dragOperationForDraggingInfo:type: I check to see if the current location is inside a tag and return NSDragOperationNone if so.

- (NSDragOperation)dragOperationForDraggingInfo:(id < NSDraggingInfo >)dragInfo type:(NSString *)type
{
if([type isEqualToString:@"MyType"])
{
//get the current character index that the mouse is over
NSPoint location = [self convertPoint:[dragInfo draggingLocation] fromView:nil];
NSUInteger currentDragLocation = [self characterIndexForInsertionAtPoint:location];

//scan forward from the current point to find the location of the next tag close character
NSString* string = [[self string] substringFromIndex:currentDragLocation];
NSScanner* scanner = [NSScanner scannerWithString:string];
[scanner scanUpToString:@">" intoString:NULL];
NSUInteger closingTagLocation = [scanner scanLocation];

//rescan to find the next tag open character
[scanner setScanLocation:0];
[scanner scanUpToString:@"<" intoString:NULL];

//if we're inside a tag the closing character will come first
NSUInteger openingTagLocation = [scanner scanLocation];
if(openingTagLocation > closingTagLocation)
return NSDragOperationNone;
}

//otherwise just do the normal thing
return [super dragOperationForDraggingInfo:dragInfo type:type];
}


--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >"Tokenizing" NSTextView content (From: Rob Keniger <email@hidden>)

  • Prev by Date: Re: What is the best way to store some kind of identifying string in an interface builder object?
  • Next by Date: Filling View With Pattern Image
  • Previous by thread: "Tokenizing" NSTextView content
  • Next by thread: Filling View With Pattern Image
  • Index(es):
    • Date
    • Thread