• 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: Changing font stuff in NSTextView + Undo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing font stuff in NSTextView + Undo


  • Subject: Re: Changing font stuff in NSTextView + Undo
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 29 Jan 2004 15:19:14 -0800

On Jan 29, 2004, at 11:25 AM, Bernie Zenis wrote:

I have a NSTextView. I want to make a change to the font of the current selection. So far, the only possibilities are changes to the font face or the font family. I know Cocoa is powerful, so is there an easy way to do this? I'm guessing that there might be a method somewhere (NSTextView, NSFontManager, etc.?) that I can call that will call a method in an object of a class that I wrote with my method taking a NSFont as input and returning a converted NSFont. I've been trying different things for a few days. I did come up with about 50 lines of code that makes the changes.

Call changeAttributes: on the text view. Pass as the sender an object that is to be called back. That object will receive a convertAttributes: call for each set of attributes in the selection; this method should take and return a dictionary, and should make whatever changes you wish to make to the attributes--in this case, NSFontAttributeName. Attributes you aren't interested in should be passed through unchanged. (See the AppKit release notes for 10.3.)

Also, Apple's docs say, "NSTextViews provide undo and redo behavior by default." The changes my code make are not automagically saved for undo.

If you manipulate the text storage directly, you need to call -[NSTextView shouldChangeTextInRange:replacementString:] before and -[NSTextView didChangeText] after making your changes for this to happen. If you use changeAttributes: that will all be done for you.

Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Changing font stuff in NSTextView + Undo
      • From: Bernie Zenis <email@hidden>
References: 
 >Changing font stuff in NSTextView + Undo (From: Bernie Zenis <email@hidden>)

  • Prev by Date: Re: Disabling_Expose_for_some_windows,_some_day?
  • Next by Date: Re: How to use a class, which may not be available
  • Previous by thread: Changing font stuff in NSTextView + Undo
  • Next by thread: Re: Changing font stuff in NSTextView + Undo
  • Index(es):
    • Date
    • Thread