Skip to content

Instantly share code, notes, and snippets.

@meelash
Created June 29, 2010 22:33
Show Gist options
  • Select an option

  • Save meelash/457927 to your computer and use it in GitHub Desktop.

Select an option

Save meelash/457927 to your computer and use it in GitHub Desktop.
var CPTextViewDataStorageKey = @"CPTextViewDataStorageKey",
CPTextViewTextContainerKey = @"CPTextViewTextContainerKey",
CPTextViewLayoutManagerKey = @"CPTextViewLayoutManagerKey",
CPTextViewDelegateKey = @"CPTextViewDelegateKey",
CPTextViewTextContainerInsetKey = @"CPTextViewTextContainerInsetKey",
CPTextViewTextContainerOriginKey = @"CPTextViewTextContainerOriginKey",
CPTextViewSelectionRangeKey = @"CPTextViewSelectionRangeKey",
CPTextViewSelectedTextAttributesKey = @"CPTextViewSelectedTextAttributesKey",
CPTextViewSelectionGranularityKey = @"CPTextViewSelectionGranularityKey",
CPTextViewInsertionPointColorKey = @"CPTextViewInsertionPointColorKey",
CPTextViewTypingAttributes = @"CPTextViewInsertionPointColorKey",
CPTextViewEditableKey = @"CPTextViewEditableKey",
CPTextViewSelectableKey = @"CPTextViewSelectableKey",
CPTextViewDrawCarretKey = @"CPTextViewDrawCarretKey",
CPTextViewCarretRectKey = @"CPTextViewCarretRectKey",
CPTextViewFontKey = @"CPTextViewFontKey",
CPTextViewTextColorKey = @"CPTextViewTextColorKey",
CPTextViewMinSizeKey = @"CPTextViewMinSizeKey",
CPTextViewMaxSizeKey = @"CPTextViewMaxSizeKey",
CPTextViewRichTextKey = @"CPTextViewRichTextKey",
CPTextViewUsesFontPanelKey = @"CPTextViewUsesFontPanelKey",
CPTextViewAllowsUndoKey = @"CPTextViewAllowsUndoKey",
CPTextViewHorizontallyResizableKey = @"CPTextViewHorizontallyResizableKey",
CPTextViewVerticallyResizableKey = @"CPTextViewVerticallyResizableKey";
@implementation CPTextView (CPCoding)
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
_textStorage = [aCoder decodeObjectForKey:CPTextViewTextStorageKey];
_textContainer = [aCoder decodeObjectForKey:CPTextViewTextContainerKey];
_layoutManager = [aCoder decodeObjectForKey:CPTextViewLayoutManagerKey];
[self setDelegate:[aCoder decodeObjectForKey:CPTextViewDelegateKey]];
_textContainerInset = [aCoder decodeObjectForKey:CPTextViewTextContainerInsetKey];
_textContainerOrigin = [aCoder decodeObjectForKey:CPTextViewTextContainerOriginKey];
_selectionGranularity = [aCoder decodeIntForKey:CPTextViewSelectionGranularityKey];
_insertionPointColor = [aCoder decodeObjectForKey:CPTextViewInsertionPointColorKey];
_typingAttributes = [aCoder decodeObjectForKey:CPTextViewTypingAttributesKey];
_isEditable = [aCoder decodeBoolForKey:CPTextViewEditableKey];
_isSelectable = [aCoder decodeBoolForKey:CPTextViewSelectableKey];
_drawCarret = [aCoder decodeBoolForKey:CPTextViewDrawCarretKey];
_carretRect = [aCoder decodeObjectForKey:CPTextViewCarretRectKey];
_font = [aCoder decodeObjectForKey:CPTextViewFontKey];
_textColor = [aCoder decodeObjectForKey:CPTextViewTextColorKey];
_minSize = [aCoder decodeObjectForKey:CPTextViewMinSizeKey];
_maxSize = [aCoder decodeObjectForKey:CPTextViewMaxSizeKey];
_isRichText = [aCoder decodeBoolForKey:CPTextViewRichTextKey];
_usesFontPanel = [aCoder decodeBoolForKey:CPTextViewUsesFontPanelKey];
_allowsUndo = [aCoder decodeBoolForKey:CPTextViewAllowsUndoKey];
_isHorizontallyResizable = [aCoder decodeBoolForKey:CPTextViewHorizontallyResizableKey];
_isVerticallyResizable = [aCoder decodeBoolForKey:CPTextViewVerticallyResizableKey];
//needed?
_selectionRange = [aCoder decodeObjectForKey:CPTextViewSelectionRangeKey];
_selectedTextAttributes = [aCoder decodeObjectForKey:CPTextViewSelectedTextAttributes];
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_textStorage forKey:CPTextViewTextStorageKey];
[aCoder encodeObject:_textContainer forKey:CPTextViewTextContainerKey];
[aCoder encodeObject:_layoutManager forKey:CPTextViewLayoutManagerKey];
[aCoder encodeObject:_delegate forKey:CPTextViewDelegateKey];
[aCoder encodeObject:_textContainerInset forKey:CPTextViewTextContainerInsetKey];
[aCoder encodeObject:_textContainerOrigin forKey:CPTextViewTextContainerOriginKey];
[aCoder encodeObject:_selectionGranularity forKey:CPTextViewSelectionGranularityKey];
[aCoder encodeObject:_insertionPointColor forKey:CPTextViewInsertionPointColorKey];
[aCoder encodeObject:_typingAttributes forKey:CPTextViewTypingAttributesKey];
[aCoder encodeObject:_isEditable forKey:CPTextViewEditableKey];
[aCoder encodeObject:_isSelectable forKey:CPTextViewSelectableKey];
[aCoder encodeObject:_drawCarret forKey:CPTextViewDrawCarretKey];
[aCoder encodeObject:_carretRect forKey:CPTextViewCarretRectKey];
[aCoder encodeObject:_font forKey:CPTextViewFontKey];
[aCoder encodeObject:_textColor forKey:CPTextViewTextColorKey];
[aCoder encodeObject:_minSize forKey:CPTextViewMinSizeKey];
[aCoder encodeObject:_maxSize forKey:CPTextViewMaxSizeKey];
[aCoder encodeObject:_isRichText forKey:CPTextViewRichTextKey];
[aCoder encodeObject:_usesFontPanel forKey:CPTextViewUsesFontPanelKey];
[aCoder encodeObject:_allowsUndo forKey:CPTextViewAllowsUndoKey];
[aCoder encodeObject:_isHorizontallyResizable forKey:CPTextViewHorizontallyResizableKey];
[aCoder encodeObject:_isVerticallyResizable forKey:CPTextViewVerticallyResizableKey];
//needed?
[aCoder encodeObject:_selectionRange forKey:CPTextViewSelectionRangeKey];
[aCoder encodeObject:_selectedTextAttributes forKey:CPTextViewSelectedTextAttributes];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment