Permalink
Browse files

handle refreshes

  • Loading branch information...
mattrajca committed Feb 25, 2013
1 parent 33b979d commit 7652286b4196122de102ec4a1c5af90a872d8fb4
@@ -11,7 +11,6 @@
<string key="NS.object.0">3084</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
- <string>NSArrayController</string>
<string>NSButton</string>
<string>NSButtonCell</string>
<string>NSCollectionView</string>
@@ -213,6 +212,7 @@
<string key="NSFrame">{{1, 144}, {233, 15}}</string>
<reference key="NSSuperview" ref="768350252"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="356238979"/>
<string key="NSReuseIdentifierKey">_NS:3883</string>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
<int key="NSsFlags">1</int>
@@ -299,16 +299,6 @@
<object class="NSCollectionViewItem" id="1062859766">
<string key="NSNibName">PXPatternItem</string>
</object>
- <object class="NSArrayController" id="256417791">
- <string key="NSObjectClassName">PXPattern</string>
- <bool key="NSEditable">YES</bool>
- <object class="_NSManagedProxy" key="_NSManagedProxy"/>
- <bool key="NSAvoidsEmptySelection">YES</bool>
- <bool key="NSPreservesSelection">YES</bool>
- <bool key="NSSelectsInsertedObjects">YES</bool>
- <bool key="NSFilterRestrictsInsertion">YES</bool>
- <bool key="NSClearsFilterPredicateOnInsertion">YES</bool>
- </object>
</array>
<object class="IBObjectContainer" key="IBDocument.Objects">
<array class="NSMutableArray" key="connectionRecords">
@@ -328,14 +318,6 @@
</object>
<int key="connectionID">34</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">patternsController</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="256417791"/>
- </object>
- <int key="connectionID">35</int>
- </object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">editorView</string>
@@ -360,22 +342,6 @@
</object>
<int key="connectionID">64</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">content: arrangedObjects</string>
- <reference key="source" ref="866328524"/>
- <reference key="destination" ref="256417791"/>
- <object class="NSNibBindingConnector" key="connector" id="740425699">
- <reference key="NSSource" ref="866328524"/>
- <reference key="NSDestination" ref="256417791"/>
- <string key="NSLabel">content: arrangedObjects</string>
- <string key="NSBinding">content</string>
- <string key="NSKeyPath">arrangedObjects</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">29</int>
- </object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
@@ -384,23 +350,6 @@
</object>
<int key="connectionID">51</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">selectionIndexes: selectionIndexes</string>
- <reference key="source" ref="866328524"/>
- <reference key="destination" ref="256417791"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="866328524"/>
- <reference key="NSDestination" ref="256417791"/>
- <string key="NSLabel">selectionIndexes: selectionIndexes</string>
- <string key="NSBinding">selectionIndexes</string>
- <string key="NSKeyPath">selectionIndexes</string>
- <reference key="NSPreviousConnector" ref="740425699"/>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">56</int>
- </object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">itemPrototype</string>
@@ -508,11 +457,6 @@
<reference key="object" ref="1062859766"/>
<reference key="parent" ref="0"/>
</object>
- <object class="IBObjectRecord">
- <int key="objectID">25</int>
- <reference key="object" ref="256417791"/>
- <reference key="parent" ref="0"/>
- </object>
<object class="IBObjectRecord">
<int key="objectID">32</int>
<reference key="object" ref="356238979"/>
@@ -570,7 +514,6 @@
<string key="20.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="21.CustomClassName">PXPatternItem</string>
<string key="21.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string key="25.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<object class="NSMutableDictionary" key="32.IBAttributePlaceholdersKey">
<string key="NS.key.0">ToolTip</string>
<object class="IBToolTipAttribute" key="NS.object.0">
@@ -630,21 +573,9 @@
<object class="IBPartialClassDescription">
<string key="className">PXPatternEditorController</string>
<string key="superclassName">NSWindowController</string>
- <object class="NSMutableDictionary" key="actions">
- <string key="NS.key.0">newPattern:</string>
- <string key="NS.object.0">id</string>
- </object>
- <object class="NSMutableDictionary" key="actionInfosByName">
- <string key="NS.key.0">newPattern:</string>
- <object class="IBActionInfo" key="NS.object.0">
- <string key="name">newPattern:</string>
- <string key="candidateClassName">id</string>
- </object>
- </object>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="collectionView">NSCollectionView</string>
<string key="editorView">PXPatternEditorView</string>
- <string key="patternsController">NSArrayController</string>
<string key="scrollView">NSScrollView</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
@@ -656,10 +587,6 @@
<string key="name">editorView</string>
<string key="candidateClassName">PXPatternEditorView</string>
</object>
- <object class="IBToOneOutletInfo" key="patternsController">
- <string key="name">patternsController</string>
- <string key="candidateClassName">NSArrayController</string>
- </object>
<object class="IBToOneOutletInfo" key="scrollView">
<string key="name">scrollView</string>
<string key="candidateClassName">NSScrollView</string>
@@ -11,7 +11,6 @@
<string key="NS.object.0">3084</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
- <string>NSArrayController</string>
<string>NSButton</string>
<string>NSButtonCell</string>
<string>NSCollectionView</string>
@@ -195,16 +194,6 @@
<object class="NSCollectionViewItem" id="97160644">
<string key="NSNibName">PXPatternItem</string>
</object>
- <object class="NSArrayController" id="763176197">
- <string key="NSObjectClassName">PXPattern</string>
- <bool key="NSEditable">YES</bool>
- <object class="_NSManagedProxy" key="_NSManagedProxy"/>
- <bool key="NSAvoidsEmptySelection">YES</bool>
- <bool key="NSPreservesSelection">YES</bool>
- <bool key="NSSelectsInsertedObjects">YES</bool>
- <bool key="NSFilterRestrictsInsertion">YES</bool>
- <bool key="NSClearsFilterPredicateOnInsertion">YES</bool>
- </object>
</array>
<object class="IBObjectContainer" key="IBDocument.Objects">
<array class="NSMutableArray" key="connectionRecords">
@@ -216,14 +205,6 @@
</object>
<int key="connectionID">4</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">patternsController</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="763176197"/>
- </object>
- <int key="connectionID">14</int>
- </object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">closePopover:</string>
@@ -256,22 +237,6 @@
</object>
<int key="connectionID">11</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">content: arrangedObjects</string>
- <reference key="source" ref="15732746"/>
- <reference key="destination" ref="763176197"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="15732746"/>
- <reference key="NSDestination" ref="763176197"/>
- <string key="NSLabel">content: arrangedObjects</string>
- <string key="NSBinding">content</string>
- <string key="NSKeyPath">arrangedObjects</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">16</int>
- </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -352,11 +317,6 @@
<reference key="object" ref="97160644"/>
<reference key="parent" ref="0"/>
</object>
- <object class="IBObjectRecord">
- <int key="objectID">13</int>
- <reference key="object" ref="763176197"/>
- <reference key="parent" ref="0"/>
- </object>
<object class="IBObjectRecord">
<int key="objectID">17</int>
<reference key="object" ref="584266188"/>
@@ -377,7 +337,6 @@
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string key="13.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="17.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="18.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -444,20 +403,17 @@
<string key="candidateClassName">id</string>
</object>
</dictionary>
- <dictionary class="NSMutableDictionary" key="outlets">
- <string key="collectionView">NSCollectionView</string>
- <string key="patternsController">NSArrayController</string>
- </dictionary>
- <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
- <object class="IBToOneOutletInfo" key="collectionView">
+ <object class="NSMutableDictionary" key="outlets">
+ <string key="NS.key.0">collectionView</string>
+ <string key="NS.object.0">NSCollectionView</string>
+ </object>
+ <object class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <string key="NS.key.0">collectionView</string>
+ <object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">collectionView</string>
<string key="candidateClassName">NSCollectionView</string>
</object>
- <object class="IBToOneOutletInfo" key="patternsController">
- <string key="name">patternsController</string>
- <string key="candidateClassName">NSArrayController</string>
- </object>
- </dictionary>
+ </object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/PXSelectPatternController.h</string>
@@ -11,12 +11,12 @@
PXPattern *_pattern;
}
-@property (nonatomic, strong) IBOutlet NSArrayController *patternsController;
-
@property (nonatomic, weak) IBOutlet NSCollectionView *collectionView;
@property (nonatomic, weak) IBOutlet NSScrollView *scrollView;
@property (nonatomic, weak) IBOutlet PXPatternEditorView *editorView;
+ (id)sharedController;
+- (NSArrayController *)patternsController;
+
@end
@@ -12,9 +12,12 @@
#import "PXPatternItem.h"
#import "SBCenteringClipView.h"
-@implementation PXPatternEditorController
+@implementation PXPatternEditorController {
+ NSArrayController *_patternsController;
+ BOOL _loadedPatterns;
+}
-@synthesize patternsController, collectionView, scrollView, editorView;
+@synthesize collectionView, scrollView, editorView;
+ (id)sharedController
{
@@ -44,7 +47,15 @@ - (void)awakeFromNib
[scrollView setDocumentView:editorView];
- [self reloadPatterns];
+ [self.collectionView bind:@"content" toObject:[self patternsController] withKeyPath:@"arrangedObjects" options:nil];
+}
+
+- (NSArrayController *)patternsController {
+ if (!_loadedPatterns) {
+ [self performSelector:@selector(reloadPatterns) withObject:nil afterDelay:0.0];
+ }
+
+ return _patternsController;
}
- (void)setPattern:(PXPattern *)pattern
@@ -91,19 +102,23 @@ - (void)deleteSheetDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInf
{
if (returnCode == NSAlertFirstButtonReturn)
{
- PXPattern *selectedPattern = [[patternsController selectedObjects] objectAtIndex:0];
+ PXPattern *selectedPattern = [[_patternsController selectedObjects] objectAtIndex:0];
[self removePattern:selectedPattern];
}
}
- (id)init
{
- return [super initWithWindowNibName:@"PXPatternEditor"];
+ self = [super initWithWindowNibName:@"PXPatternEditor"];
+ if (self) {
+ _patternsController = [[NSArrayController alloc] init];
+ }
+ return self;
}
- (void)patternView:(PXPatternEditorView *)pv changedPattern:(PXPattern *)pattern
{
- [NSKeyedArchiver archiveRootObject:[patternsController arrangedObjects]
+ [NSKeyedArchiver archiveRootObject:[_patternsController arrangedObjects]
toFile:GetPixenPatternFile()];
[[NSNotificationCenter defaultCenter] postNotificationName:PXPatternsChangedNotificationName
@@ -121,17 +136,19 @@ - (void)reloadPatterns
if (![fileManager fileExistsAtPath:patternFileName isDirectory:&isDirectory] || isDirectory)
return;
- [patternsController removeObjects:[patternsController arrangedObjects]];
+ [_patternsController removeObjects:[_patternsController arrangedObjects]];
NSArray *p = [NSKeyedUnarchiver unarchiveObjectWithFile:patternFileName];
if (p)
- [patternsController addObjects:p];
+ [_patternsController addObjects:p];
+
+ _loadedPatterns = YES;
}
- (void)deleteKeyPressedInCollectionView:(NSCollectionView *)view
{
- if ([patternsController selectionIndex] == NSNotFound)
+ if ([_patternsController selectionIndex] == NSNotFound)
return;
NSAlert *alert = [[NSAlert alloc] init];
@@ -155,17 +172,17 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
NSUInteger index = [[self.collectionView selectionIndexes] firstIndex];
if (index != NSNotFound) {
- PXPattern *pattern = [[patternsController arrangedObjects] objectAtIndex:index];
+ PXPattern *pattern = [[_patternsController arrangedObjects] objectAtIndex:index];
[self setPattern:pattern];
}
}
}
- (void)addPattern:(PXPattern *)pattern
{
- [patternsController addObject:pattern];
+ [_patternsController addObject:pattern];
- [NSKeyedArchiver archiveRootObject:[patternsController arrangedObjects]
+ [NSKeyedArchiver archiveRootObject:[_patternsController arrangedObjects]
toFile:GetPixenPatternFile()];
[[NSNotificationCenter defaultCenter] postNotificationName:PXPatternsChangedNotificationName
@@ -175,9 +192,9 @@ - (void)addPattern:(PXPattern *)pattern
- (void)removePattern:(PXPattern *)pattern
{
- [patternsController removeObject:pattern];
+ [_patternsController removeObject:pattern];
- [NSKeyedArchiver archiveRootObject:[patternsController arrangedObjects]
+ [NSKeyedArchiver archiveRootObject:[_patternsController arrangedObjects]
toFile:GetPixenPatternFile()];
[[NSNotificationCenter defaultCenter] postNotificationName:PXPatternsChangedNotificationName
@@ -194,7 +211,7 @@ - (void)dealloc
- (NSArray *)collectionView:(NSCollectionView *)collectionView namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropURL forDraggedItemsAtIndexes:(NSIndexSet *)indexes
{
NSUInteger index = [indexes firstIndex];
- PXPattern *pattern = [[patternsController arrangedObjects] objectAtIndex:index];
+ PXPattern *pattern = [[_patternsController arrangedObjects] objectAtIndex:index];
NSString *dir = [dropURL path];
NSString *name = @"Pattern.pxpattern";
Oops, something went wrong.

0 comments on commit 7652286

Please sign in to comment.