Skip to content

Commit

Permalink
single-click to select patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrajca committed Feb 24, 2013
1 parent a4b6351 commit 5ca4e37
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
16 changes: 14 additions & 2 deletions English.lproj/PXPatternEditor.xib
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions Pixen Application/Tools/Patterns/PXPatternEditorController.h
Expand Up @@ -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;

Expand Down
18 changes: 13 additions & 5 deletions Pixen Application/Tools/Patterns/PXPatternEditorController.m
Expand Up @@ -14,7 +14,7 @@

@implementation PXPatternEditorController

@synthesize patternsController, scrollView, editorView;
@synthesize patternsController, collectionView, scrollView, editorView;

+ (id)sharedController
{
Expand All @@ -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];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5ca4e37

Please sign in to comment.