Added cancel button to icon selection view

This commit is contained in:
michael starke
2013-12-13 01:13:52 +01:00
parent 6b1aff9449
commit 21355101ed
5 changed files with 38 additions and 20 deletions

View File

@@ -125,11 +125,6 @@
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction

View File

@@ -55,6 +55,17 @@
<action selector="useDefault:" target="-2" id="129"/>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="His-4A-hcY">
<rect key="frame" x="199" y="18" width="56" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" title="Cancel" bezelStyle="texturedRounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="1kM-cI-P1o">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="cancel:" target="-2" id="cRO-8u-npC"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="57" firstAttribute="top" secondItem="1" secondAttribute="top" constant="10" id="88"/>

View File

@@ -16,12 +16,14 @@ extern NSInteger const kMPDefaultIcon;
* Is the selected Icon, kMPDefaultIcon if the default icons was selected
*/
@property (nonatomic, assign) NSInteger selectedIcon;
@property (nonatomic, assign) BOOL didCancel;
@property (weak) IBOutlet NSCollectionView *iconCollectionView;
@property (weak) IBOutlet NSButton *imageButton;
@property (weak) NSPopover *popover;
- (void)reset;
- (IBAction)cancel:(id)sender;
- (IBAction)useDefault:(id)sender;
@end

View File

@@ -26,6 +26,7 @@ NSInteger const kMPDefaultIcon = -1;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_didCancel = NO;
}
return self;
}
@@ -43,7 +44,13 @@ NSInteger const kMPDefaultIcon = -1;
[self.popover performClose:self];
}
- (IBAction)cancel:(id)sender {
self.didCancel = YES;
[self.popover performClose:self];
}
- (void)reset {
self.didCancel = NO;
self.selectedIcon = kMPDefaultIcon;
}

View File

@@ -175,19 +175,22 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
- (void)popoverDidClose:(NSNotification *)notification {
MPIconSelectViewController *viewController = (MPIconSelectViewController *)_popover.contentViewController;
MPDocument *document = [[self windowController] document];
BOOL useDefault = (viewController.selectedIcon == -1);
switch (self.activeTab) {
case MPGroupTab:
document.selectedGroup.iconId = useDefault ? [KPKGroup defaultIcon] : viewController.selectedIcon;
break;
case MPEntryTab:
document.selectedEntry.iconId = useDefault ? [KPKEntry defaultIcon]: viewController.selectedIcon;
break;
default:
break;
if(!viewController.didCancel) {
MPDocument *document = [[self windowController] document];
BOOL useDefault = (viewController.selectedIcon == -1);
switch (self.activeTab) {
case MPGroupTab:
document.selectedGroup.iconId = useDefault ? [KPKGroup defaultIcon] : viewController.selectedIcon;
break;
case MPEntryTab:
document.selectedEntry.iconId = useDefault ? [KPKEntry defaultIcon]: viewController.selectedIcon;
break;
default:
break;
}
}
_popover = nil;
}
@@ -207,10 +210,10 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
[self.itemNameTextField setHidden:YES];
[self.itemImageView unbind:NSValueBinding];
[self.itemImageView setHidden:YES];
return;
}
[self.itemImageView bind:NSValueBinding toObject:item withKeyPath:@"iconImage" options:nil];
if([item respondsToSelector:@selector(title)]) {