Permalink
Browse files

save patterns on change

  • Loading branch information...
mattrajca committed Feb 24, 2013
1 parent 7f99c64 commit f6b37a888a0fdc3c1ef8ea20f045c1e2d66d852f
@@ -32,6 +32,8 @@ - (void)awakeFromNib
{
[self.collectionView addObserver:self forKeyPath:@"selectionIndexes" options:0 context:NULL];
+ [editorView setDelegate:self];
+
SBCenteringClipView *clip = [[SBCenteringClipView alloc] initWithFrame:[[scrollView contentView] frame]];
[clip setBackgroundColor:[NSColor lightGrayColor]];
[clip setCopiesOnScroll:NO];
@@ -97,6 +99,16 @@ - (id)init
return [super initWithWindowNibName:@"PXPatternEditor"];
}
+- (void)patternView:(PXPatternEditorView *)pv changedPattern:(PXPattern *)pattern
+{
+ [NSKeyedArchiver archiveRootObject:[patternsController arrangedObjects]
+ toFile:GetPixenPatternFile()];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:PXPatternsChangedNotificationName
+ object:self
+ userInfo:nil];
+}
+
- (void)reloadPatterns
{
BOOL isDirectory = NO;
@@ -16,4 +16,13 @@
@property (nonatomic, weak) PXPattern *pattern;
+@property (nonatomic, unsafe_unretained) id delegate;
+
+@end
+
+
+@interface NSObject (PXPatternEditorViewDelegate)
+
+- (void)patternView:(PXPatternEditorView *)pv changedPattern:(PXPattern *)pattern;
+
@end
@@ -13,6 +13,7 @@
@implementation PXPatternEditorView
@synthesize pattern = _pattern;
+@synthesize delegate = _delegate;
#define SCALE_FACTOR 32.0f
@@ -42,7 +43,12 @@ - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
NSPasteboard *pboard = [sender draggingPasteboard];
[self setPattern:[NSKeyedUnarchiver unarchiveObjectWithData:[pboard dataForType:PXPatternPboardType]]];
-#warning TODO: trigger update
+ [_pattern willChangeValueForKey:@"image"];
+
+ if ([_delegate respondsToSelector:@selector(patternView:changedPattern:)])
+ [_delegate patternView:self changedPattern:_pattern];
+
+ [_pattern didChangeValueForKey:@"image"];
return YES;
}
@@ -74,6 +80,10 @@ - (void)redrawPattern:(NSNotification *)notification
- (void)mouseUp:(NSEvent *)event
{
[_pattern willChangeValueForKey:@"image"];
+
+ if ([_delegate respondsToSelector:@selector(patternView:changedPattern:)])
+ [_delegate patternView:self changedPattern:_pattern];
+
[_pattern didChangeValueForKey:@"image"];
}

0 comments on commit f6b37a8

Please sign in to comment.