Permalink
Browse files

single-click to select patterns

  • Loading branch information...
mattrajca committed Feb 24, 2013
1 parent a4b6351 commit 5ca4e37eac4288368185cc28cafe9139a1e805d0
@@ -213,7 +213,6 @@
<string key="NSFrame">{{1, 144}, {233, 15}}</string>
<reference key="NSSuperview" ref="768350252"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:3883</string>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
<int key="NSsFlags">1</int>
@@ -353,6 +352,14 @@
</object>
<int key="connectionID">50</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">collectionView</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="866328524"/>
+ </object>
+ <int key="connectionID">64</int>
+ </object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">content: arrangedObjects</string>
@@ -587,7 +594,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">63</int>
+ <int key="maxID">64</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -635,11 +642,16 @@
</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">
+ <object class="IBToOneOutletInfo" key="collectionView">
+ <string key="name">collectionView</string>
+ <string key="candidateClassName">NSCollectionView</string>
+ </object>
<object class="IBToOneOutletInfo" key="editorView">
<string key="name">editorView</string>
<string key="candidateClassName">PXPatternEditorView</string>
@@ -12,6 +12,8 @@
}
@property (nonatomic, strong) IBOutlet NSArrayController *patternsController;
+
+@property (nonatomic, weak) IBOutlet NSCollectionView *collectionView;
@property (nonatomic, weak) IBOutlet NSScrollView *scrollView;
@property (nonatomic, weak) IBOutlet PXPatternEditorView *editorView;
@@ -14,7 +14,7 @@
@implementation PXPatternEditorController
-@synthesize patternsController, scrollView, editorView;
+@synthesize patternsController, collectionView, scrollView, editorView;
+ (id)sharedController
{
@@ -30,6 +30,8 @@ + (id)sharedController
- (void)awakeFromNib
{
+ [self.collectionView addObserver:self forKeyPath:@"selectionIndexes" options:0 context:NULL];
+
SBCenteringClipView *clip = [[SBCenteringClipView alloc] initWithFrame:[[scrollView contentView] frame]];
[clip setBackgroundColor:[NSColor lightGrayColor]];
[clip setCopiesOnScroll:NO];
@@ -133,11 +135,16 @@ - (void)deleteKeyPressedInCollectionView:(NSCollectionView *)view
contextInfo:nil];
}
-- (void)patternItemWasDoubleClicked:(PXPatternItem *)item
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
-#warning TODO: single click
- PXPattern *pattern = [item representedObject];
- [self setPattern:pattern];
+ if ([keyPath isEqualToString:@"selectionIndexes"]) {
+ NSUInteger index = [[self.collectionView selectionIndexes] firstIndex];
+
+ if (index != NSNotFound) {
+ PXPattern *pattern = [[patternsController arrangedObjects] objectAtIndex:index];
+ [self setPattern:pattern];
+ }
+ }
}
- (void)addPattern:(PXPattern *)pattern
@@ -167,6 +174,7 @@ - (void)removePattern:(PXPattern *)pattern
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ [collectionView removeObserver:self forKeyPath:@"selectionIndexes"];
}
- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard

0 comments on commit 5ca4e37

Please sign in to comment.