Implemented datePicking controller. Refactored popup handling in MPInspectorViewController

This commit is contained in:
michael starke
2014-03-17 00:07:25 +01:00
parent 6bbaccdb25
commit 51a59d73c6
12 changed files with 154 additions and 71 deletions

View File

@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13A603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment version="1070" defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPDatePickingViewController">
<connections>
<outlet property="datePicker" destination="3" id="YOw-gi-A02"/>
<outlet property="presetPopupButton" destination="15" id="VJh-of-PEU"/>
<outlet property="view" destination="1" id="2"/>
</connections>
</customObject>
@@ -16,7 +18,7 @@
<rect key="frame" x="0.0" y="0.0" width="179" height="259"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<datePicker verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3">
<datePicker horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3">
<rect key="frame" x="20" y="91" width="139" height="148"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<datePickerCell key="cell" borderStyle="bezel" alignment="left" datePickerStyle="clockAndCalendar" id="4">
@@ -24,7 +26,7 @@
<calendarDate key="date" timeIntervalSinceReferenceDate="-595929600" calendarFormat="%Y-%m-%d %H:%M:%S %z">
<!--1982-02-12 08:00:00 -0800-->
<timeZone key="timeZone" name="US/Pacific">
<mutableData key="data">
<data key="data">
VFppZgAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAC5AAAABAAAABCepkign7sVkKCGKqChmveQ
y4kaoNIj9HDSYSYQ1v50INiArZDa/tGg28CQENzes6DdqayQ3r6VoN+JjpDgnneg4WlwkOJ+WaDjSVKQ
5F47oOUpNJDmR1gg5xJREOgnOiDo8jMQ6gccIOrSFRDr5v4g7LH3EO3G4CDukdkQ76/8oPBxuxDxj96g
@@ -42,7 +44,7 @@ f5gqkAABAAECAwEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEA
AQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEA
AQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEA
AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA
</mutableData>
</data>
</timeZone>
</calendarDate>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -50,18 +52,12 @@ AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA
</datePickerCell>
</datePicker>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="15">
<rect key="frame" x="18" y="59" width="144" height="26"/>
<rect key="frame" x="18" y="47" width="144" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="1 Week" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="16">
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="16">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<menu key="menu" title="OtherViews" id="17">
<items>
<menuItem title="1 Week" state="on" id="18"/>
<menuItem title="1 Month" id="19"/>
<menuItem title="1 Year" id="20"/>
</items>
</menu>
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="17"/>
</popUpButtonCell>
</popUpButton>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="25">
@@ -71,6 +67,9 @@ AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="useDate:" target="-2" id="34n-E5-FQq"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="29">
<rect key="frame" x="20" y="18" width="56" height="25"/>
@@ -79,18 +78,23 @@ AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="cancel:" target="-2" id="eww-6g-58Z"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="3" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="13"/>
<constraint firstItem="3" firstAttribute="top" secondItem="1" secondAttribute="top" constant="20" symbolic="YES" id="14"/>
<constraint firstItem="15" firstAttribute="top" secondItem="3" secondAttribute="bottom" constant="8" id="21"/>
<constraint firstItem="15" firstAttribute="top" secondItem="3" secondAttribute="bottom" constant="20" symbolic="YES" id="21"/>
<constraint firstItem="15" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="22"/>
<constraint firstAttribute="trailing" secondItem="15" secondAttribute="trailing" constant="20" symbolic="YES" id="24"/>
<constraint firstAttribute="trailing" secondItem="25" secondAttribute="trailing" constant="20" symbolic="YES" id="27"/>
<constraint firstItem="29" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="35"/>
<constraint firstAttribute="bottom" secondItem="25" secondAttribute="bottom" constant="20" symbolic="YES" id="36"/>
<constraint firstAttribute="bottom" secondItem="29" secondAttribute="bottom" constant="20" symbolic="YES" id="37"/>
<constraint firstAttribute="trailing" secondItem="3" secondAttribute="trailing" constant="20" id="6Qs-OP-VRr"/>
<constraint firstItem="25" firstAttribute="centerY" secondItem="29" secondAttribute="centerY" id="M8N-5g-ClS"/>
<constraint firstItem="25" firstAttribute="top" secondItem="15" secondAttribute="bottom" constant="8" symbolic="YES" id="sxX-fk-xaJ"/>
</constraints>
</customView>
</objects>

View File

@@ -589,9 +589,12 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8">
<rect key="frame" x="169" y="128" width="63" height="19"/>
<rect key="frame" x="201" y="128" width="31" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="Set Date" bezelStyle="roundedRect" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="77">
<constraints>
<constraint firstAttribute="width" constant="31" id="Ped-nx-uti"/>
</constraints>
<buttonCell key="cell" type="roundRect" bezelStyle="roundedRect" image="NSActionTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="77">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="cellTitle"/>
</buttonCell>

View File

@@ -9,6 +9,7 @@
<connections>
<outlet property="autotypePopupButton" destination="240" id="285"/>
<outlet property="contentView" destination="38" id="Dv7-1B-VeH"/>
<outlet property="expireDateSelectButton" destination="4" id="KxN-kK-lan"/>
<outlet property="expiresCheckButton" destination="5" id="283"/>
<outlet property="searchPopupButton" destination="229" id="284"/>
<outlet property="titleTextField" destination="23" id="35"/>
@@ -55,9 +56,12 @@
</buttonCell>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4">
<rect key="frame" x="174" y="127" width="63" height="19"/>
<rect key="frame" x="206" y="127" width="31" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="Set Date" bezelStyle="roundedRect" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="33">
<constraints>
<constraint firstAttribute="width" constant="31" id="l5I-EF-dHs"/>
</constraints>
<buttonCell key="cell" type="roundRect" bezelStyle="roundedRect" image="NSActionTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="33">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="cellTitle"/>
</buttonCell>
@@ -153,5 +157,9 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<userDefaultsController representsSharedInstance="YES" id="ePk-k3-9qj"/>
</objects>
<resources>
<image name="NSActionTemplate" width="14" height="14"/>
</resources>
</document>

View File

@@ -54,18 +54,15 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didLoadView {
- (void)awakeFromNib {
[[self.filterLabelTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];
self.historyBar.activeGradient = [[NSGradient alloc] initWithStartingColor:[NSColor redColor] endingColor:[NSColor greenColor]];
/*
NSArray *activeColors = @[[NSColor colorWithCalibratedWhite:0.2 alpha:1],[NSColor colorWithCalibratedWhite:0.4 alpha:1]];
NSArray *inactiveColors = @[[NSColor colorWithCalibratedWhite:0.3 alpha:1],[NSColor colorWithCalibratedWhite:0.6 alpha:1]];
self.trashBar.activeGradient = [[NSGradient alloc] initWithColors:activeColors];
self.trashBar.inactiveGradient = [[NSGradient alloc] initWithColors:inactiveColors];
*/
[[self view] bind:NSSelectedIndexBinding toObject:self withKeyPath:@"activeTab" options:nil];

View File

@@ -10,4 +10,11 @@
@interface MPDatePickingViewController : MPViewController
@property (strong,readonly) NSDate *date;
@property (weak) IBOutlet NSDatePicker *datePicker;
@property (weak) IBOutlet NSPopUpButton *presetPopupButton;
- (IBAction)useDate:(id)sender;
- (IBAction)cancel:(id)sender;
@end

View File

@@ -8,8 +8,17 @@
#import "MPDatePickingViewController.h"
typedef NS_ENUM(NSUInteger, MPDatePresets) {
MPDatePresetTomorrow,
MPDatePresetOneWeek,
MPDatePresetOneMonth,
MPDatePresetOneYear,
};
@interface MPDatePickingViewController ()
@property (strong) NSDate *date;
@end
@implementation MPDatePickingViewController
@@ -19,11 +28,30 @@
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
- (void)awakeFromNib {
NSMenu *presetMenu = [[NSMenu alloc] init];
NSDictionary *dateItems = @{ @(MPDatePresetTomorrow): NSLocalizedString(@"TOMORROW", ""),
@(MPDatePresetOneWeek): NSLocalizedString(@"ONE_WEEK", ""),
@(MPDatePresetOneMonth): NSLocalizedString(@"ONE_MONTH", ""),
@(MPDatePresetOneYear): NSLocalizedString(@"ONE_YEAR", "") };
for(NSNumber *tagNumber in dateItems) {
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:dateItems[tagNumber] action:NULL keyEquivalent:@""];
[item setTag:[tagNumber integerValue]];
[presetMenu addItem:item];
}
return self;
[self.presetPopupButton setMenu:presetMenu];
}
- (IBAction)useDate:(id)sender {
self.date = [self.datePicker dateValue];
id target = [NSApp targetForAction:@selector(performClose:)];
[target performClose:sender];
}
- (IBAction)cancel:(id)sender {
self.date = [NSDate distantFuture];
id target = [NSApp targetForAction:@selector(performClose:)];
[target performClose:sender];
}
@end

View File

@@ -40,6 +40,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@class KPKBinary;
@class KPKAttribute;
@class KPKCompositeKey;
@class KPKNode;
typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
MPEntrySearchNone = 0,
@@ -79,7 +80,7 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
*/
@property (nonatomic, weak) KPKEntry *selectedEntry;
@property (nonatomic, weak) KPKGroup *selectedGroup;
@property (nonatomic, weak) id selectedItem;
@property (nonatomic, weak) KPKNode *selectedItem;
/*
Search - see MPDocument+Search for further details

View File

@@ -367,7 +367,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
self.selectedItem = selectedEntry;
}
- (void)setSelectedItem:(id)selectedItem {
- (void)setSelectedItem:(KPKNode *)selectedItem {
if(_selectedItem != selectedItem) {
_selectedItem = selectedItem;
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentCurrentItemChangedNotification object:self];

View File

@@ -16,6 +16,7 @@
@property (weak) IBOutlet HNHRoundedTextField *titleTextField;
@property (weak) IBOutlet NSButton *expiresCheckButton;
@property (weak) IBOutlet NSButton *expireDateSelectButton;
@property (weak) IBOutlet NSPopUpButton *searchPopupButton;
@property (weak) IBOutlet NSPopUpButton *autotypePopupButton;

View File

@@ -11,6 +11,7 @@
#import "MPPasteBoardController.h"
#import "KPKGroup.h"
#import "KPKTimeInfo.h"
#import "HNHScrollView.h"
#import "HNHRoundedTextField.h"
@@ -18,6 +19,7 @@
@interface MPGroupInspectorViewController ()
@property (nonatomic, weak) KPKGroup *group;
@property (strong) NSPopover *popover;
@end
@@ -34,7 +36,7 @@
return self;
}
- (void)didLoadView {
- (void)awakeFromNib {
HNHScrollView *scrollView = (HNHScrollView *)[self view];
scrollView.actAsFlipped = NO;
@@ -53,11 +55,13 @@
views:views]];
[[self view] layoutSubtreeIfNeeded];
/*
void(^copyBlock)(NSTextField *textField) = ^void(NSTextField *textField) {
[[MPPasteBoardController defaultController] copyObjects:@[ textField.stringValue ]];
};
self.titleTextField.copyActionBlock = copyBlock;
*/
}
- (void)setupBindings:(MPDocument *)document {
@@ -73,8 +77,12 @@
- (void)_updateBindings {
if(self.group) {
[self.titleTextField bind:NSValueBinding toObject:self.group withKeyPath:@"name" options:nil];
[self.expiresCheckButton bind:NSValueBinding toObject:self.group.timeInfo withKeyPath:@"expires" options:nil];
[self.titleTextField bind:NSValueBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(name)) options:nil];
[self.expiresCheckButton bind:NSValueBinding toObject:self.group.timeInfo withKeyPath:NSStringFromSelector(@selector(expires)) options:nil];
[self.expireDateSelectButton bind:NSHiddenBinding
toObject:self.group.timeInfo
withKeyPath:NSStringFromSelector(@selector(expires))
options:@{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName }];
[self.autotypePopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:@"isAutoTypeEnabled" options:nil];
[self.searchPopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:@"isSearchEnabled" options:nil];
}
@@ -82,6 +90,7 @@
[self.titleTextField unbind:NSValueBinding];
[self.expiresCheckButton unbind:NSValueBinding];
[self.expireDateSelectButton unbind:NSHiddenBinding];
[self.autotypePopupButton unbind:NSSelectedTagBinding];
[self.searchPopupButton unbind:NSSelectedTagBinding];
}

View File

@@ -23,6 +23,7 @@
@property (weak) IBOutlet NSButton *cancelEditButton;
- (IBAction)showImagePopup:(id)sender;
- (IBAction)pickExpiryDate:(id)sender;
- (IBAction)toggleEdit:(id)sender;
/* Seperate call to ensure alle registered objects are in place */

View File

@@ -13,6 +13,7 @@
#import "MPDocument.h"
#import "MPNotifications.h"
#import "MPIconSelectViewController.h"
#import "MPDatePickingViewController.h"
#import "NSDate+Humanized.h"
#import "KPKNode+IconImage.h"
@@ -21,6 +22,8 @@
#import "KPKMetaData.h"
#import "KPKGroup.h"
#import "KPKEntry.h"
#import "KPKNode.h"
#import "KPKTimeInfo.h"
#import "HNHGradientView.h"
#import "MPPopupImageView.h"
@@ -34,11 +37,11 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
@interface MPInspectorViewController () {
MPEntryInspectorViewController *_entryViewController;
MPGroupInspectorViewController *_groupViewController;
NSPopover *_popover;
BOOL _isEditing;
}
@property (strong) MPIconSelectViewController *iconSelectionViewController;
@property (strong) NSPopover *popover;
@property (nonatomic, strong) NSDate *modificationDate;
@property (nonatomic, strong) NSDate *creationDate;
@@ -203,25 +206,50 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
}
- (void)popoverDidClose:(NSNotification *)notification {
MPIconSelectViewController *viewController = (MPIconSelectViewController *)_popover.contentViewController;
NSPopover *popover = [notification object];
if([popover.contentViewController isKindOfClass:[MPIconSelectViewController class]]) {
MPIconSelectViewController *viewController = (MPIconSelectViewController *)popover.contentViewController;
if(!viewController.didCancel) {
[self _setIcon:viewController.selectedIcon];
}
}
if([popover.contentViewController isKindOfClass:[MPDatePickingViewController class]]) {
MPDatePickingViewController *viewController = (MPDatePickingViewController *)popover.contentViewController;
[self _setExpiryDate:viewController.date];
}
self.popover = nil;
}
- (IBAction)pickExpiryDate:(id)sender {
NSAssert(self.popover == nil, @"Popover hast to be niled out");
NSAssert([sender isKindOfClass:[NSView class]], @"");
self.popover = [[NSPopover alloc] init];
self.popover.delegate = self;
self.popover.behavior = NSPopoverBehaviorTransient;
self.popover.contentViewController = [[MPDatePickingViewController alloc] init];
[self.popover showRelativeToRect:NSZeroRect ofView:sender preferredEdge:NSMinYEdge];
}
- (void)_setIcon:(NSInteger)iconId {
MPDocument *document = [[self windowController] document];
BOOL useDefault = (viewController.selectedIcon == -1);
BOOL useDefault = (iconId == -1);
switch (self.activeTab) {
case MPGroupTab:
document.selectedGroup.iconId = useDefault ? [KPKGroup defaultIcon] : viewController.selectedIcon;
document.selectedGroup.iconId = useDefault ? [KPKGroup defaultIcon] : iconId;
break;
case MPEntryTab:
document.selectedEntry.iconId = useDefault ? [KPKEntry defaultIcon]: viewController.selectedIcon;
document.selectedEntry.iconId = useDefault ? [KPKEntry defaultIcon]: iconId;
break;
default:
break;
}
}
_popover = nil;
}
- (void)_setExpiryDate:(NSDate *)date {
MPDocument *document = [[self windowController] document];
document.selectedItem.timeInfo.expiryTime = date;
}
#pragma mark -
@@ -248,10 +276,6 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
}
[self.itemImageView setHidden:NO];
[self.itemNameTextField setHidden:NO];
if([item respondsToSelector:@selector(notes)]) {
}
}
#pragma mark -