0

I'm trying to create a NSTextField to allow batch renaming of some files. This field should allow to insert some tokens to customize each filename. The problem with NSTokenField is that 1) it trims whitespaces, which should be allowed, 2) it doesn't have enough features to mix tokens and plain text as I want, for example, it should recognize the start of a token even if the actual style is plain text.

Now I thought of subclassing NSTextField or NSTextView to draw my tokens manually, but how can I make each token act as if it was a single character? Can I somehow add a NSCell with some text?

Nickkk
  • 2,261
  • 1
  • 25
  • 34

1 Answers1

1

"1) it trims whitespaces, which should be allowed" - I thought this could be customized with delegate methods.

"2) ... it should recognize the start of a token even if the actual style is plain text" - A token is a token. It should be exact-match-or-not-a-token since your users may in fact conceivably have a substring of a token as an honest-to-god literal.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • I've tried quite everything but I couldn't get the whitespace trimming behavior to get disabled. Forget the plain text issue, in fact it's quite confusing. Now I could solve the problem by 1) either get the ability to add whitespaces or 2) add my custom tokens to a NSTextField (how?). – Nickkk Sep 01 '12 at 20:42
  • Finally I got it: I was mixing delegate methods of NSTokenField and NSTokenFieldCell (which look quite identical) and so didn't get the right behavior. Overwriting `- (NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject` and returning `representedObject` enables whitespaces. Still didn't get how to customize the tokens ... – Nickkk Sep 09 '12 at 21:38