Using modern Objective-C syntac

This commit is contained in:
michael starke
2015-07-15 14:40:53 +02:00
parent cc68a57914
commit a75e5c7e2f
2 changed files with 68 additions and 69 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPEntryViewController">
@@ -26,10 +26,11 @@
<rect key="frame" x="0.0" y="17" width="694" height="548"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnSelection="YES" multipleSelection="NO" rowSizeStyle="automatic" headerView="676" viewBased="YES" id="55" customClass="MPTableView">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" rowSizeStyle="automatic" headerView="676" viewBased="YES" id="55" customClass="MPTableView">
<rect key="frame" x="0.0" y="0.0" width="693" height="0.0"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="Group Column" width="104.609375" minWidth="40" maxWidth="3.4028234663852886e+38" id="117">
@@ -50,7 +51,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="270">
<rect key="frame" x="1" y="0.0" width="102.5" height="17"/>
<rect key="frame" x="1" y="0.0" width="102" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="271">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -136,7 +137,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="429" customClass="NSSecureTextField">
<rect key="frame" x="1" y="0.0" width="116.5" height="17"/>
<rect key="frame" x="1" y="0.0" width="116" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="430">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -260,7 +261,7 @@
<font key="font" metaFont="cellTitle"/>
</buttonCell>
</button>
<textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="uCV-75-BFs">
<textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uCV-75-BFs">
<rect key="frame" x="324" y="8" width="46" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="infotext" id="GLC-co-PAD">
<font key="font" metaFont="smallSystem"/>
@@ -291,6 +292,6 @@
</objects>
<resources>
<image name="NSActionTemplate" width="14" height="14"/>
<image name="NSAddTemplate" width="8" height="8"/>
<image name="NSAddTemplate" width="11" height="11"/>
</resources>
</document>

View File

@@ -134,10 +134,10 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
[_bottomBar setBorderType:HNHBorderTop|HNHBorderHighlight];
[self.addEntryButton setAction:[MPActionHelper actionOfType:MPActionAddEntry]];
[self.entryTable setDelegate:self];
[self.entryTable setDoubleAction:@selector(_columnDoubleClick:)];
[self.entryTable setTarget:self];
[self.entryTable setFloatsGroupRows:NO];
self.entryTable.delegate = self;
self.entryTable.doubleAction = @selector(_columnDoubleClick:);
self.entryTable.target = self;
self.entryTable.floatsGroupRows = NO;
[self.entryTable registerForDraggedTypes:@[KPKEntryUTI]];
/* First responder notifications */
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -146,55 +146,51 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
object:_entryTable];
[self _setupEntryMenu];
NSTableColumn *parentColumn = [self.entryTable tableColumns][0];
NSTableColumn *titleColumn = [self.entryTable tableColumns][1];
NSTableColumn *userNameColumn = [self.entryTable tableColumns][2];
NSTableColumn *passwordColumn = [self.entryTable tableColumns][3];
NSTableColumn *urlColumn = [self.entryTable tableColumns][4];
NSTableColumn *parentColumn = self.entryTable.tableColumns[0];
NSTableColumn *titleColumn = self.entryTable.tableColumns[1];
NSTableColumn *userNameColumn = self.entryTable.tableColumns[2];
NSTableColumn *passwordColumn = self.entryTable.tableColumns[3];
NSTableColumn *urlColumn = self.entryTable.tableColumns[4];
NSTableColumn *attachmentsColumn = [[NSTableColumn alloc] initWithIdentifier:MPEntryTableAttachmentColumnIdentifier];
NSTableColumn *notesColumn = [[NSTableColumn alloc] initWithIdentifier:MPEntryTableNotesColumnIdentifier];
NSTableColumn *modifiedColumn = [[NSTableColumn alloc] initWithIdentifier:MPEntryTableModfiedColumnIdentifier];
[notesColumn setMinWidth:40.0];
[attachmentsColumn setMinWidth:40.0];
[modifiedColumn setMinWidth:40.0];
notesColumn.minWidth = 40.0;
attachmentsColumn.minWidth = 40.0;
modifiedColumn.minWidth = 40.0;
[self.entryTable addTableColumn:notesColumn];
[self.entryTable addTableColumn:attachmentsColumn];
[self.entryTable addTableColumn:modifiedColumn];
[parentColumn setIdentifier:MPEntryTableParentColumnIdentifier];
[titleColumn setIdentifier:MPEntryTableTitleColumnIdentifier];
[userNameColumn setIdentifier:MPEntryTableUserNameColumnIdentifier];
[passwordColumn setIdentifier:MPEntryTablePasswordColumnIdentifier];
[urlColumn setIdentifier:MPEntryTableURLColumnIdentifier];
parentColumn.identifier = MPEntryTableParentColumnIdentifier;
titleColumn.identifier = MPEntryTableTitleColumnIdentifier;
userNameColumn.identifier = MPEntryTableUserNameColumnIdentifier;
passwordColumn.identifier = MPEntryTablePasswordColumnIdentifier;
urlColumn.identifier = MPEntryTableURLColumnIdentifier;
self.entryTable.autosaveName = @"EntryTable";
self.entryTable.autosaveTableColumns = YES;
[self.entryTable setAutosaveName:@"EntryTable"];
[self.entryTable setAutosaveTableColumns:YES];
NSString *parentNameKeyPath = [[NSString alloc] initWithFormat:@"%@.%@", NSStringFromSelector(@selector(parent)), NSStringFromSelector(@selector(name))];
NSSortDescriptor *titleColumSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(title))ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSSortDescriptor *userNameSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(username)) ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSSortDescriptor *urlSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(url)) ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSSortDescriptor *groupnameSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:parentNameKeyPath ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSSortDescriptor *dateSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:[MPEntryViewController timeInfoModificationTimeKeyPath] ascending:YES selector:@selector(compare:)];
[titleColumn setSortDescriptorPrototype:titleColumSortDescriptor];
[userNameColumn setSortDescriptorPrototype:userNameSortDescriptor];
[urlColumn setSortDescriptorPrototype:urlSortDescriptor];
[parentColumn setSortDescriptorPrototype:groupnameSortDescriptor];
[modifiedColumn setSortDescriptorPrototype:dateSortDescriptor];
titleColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(title))ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
userNameColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(username)) ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
urlColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(url)) ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
parentColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:parentNameKeyPath ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
modifiedColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:[MPEntryViewController timeInfoModificationTimeKeyPath] ascending:YES selector:@selector(compare:)];
[[parentColumn headerCell] setStringValue:NSLocalizedString(@"GROUP", "")];
[[titleColumn headerCell] setStringValue:NSLocalizedString(@"TITLE", "")];
[[userNameColumn headerCell] setStringValue:NSLocalizedString(@"USERNAME", "")];
[[passwordColumn headerCell] setStringValue:NSLocalizedString(@"PASSWORD", "")];
[[urlColumn headerCell] setStringValue:NSLocalizedString(@"URL", "")];
[[notesColumn headerCell] setStringValue:NSLocalizedString(@"NOTES", "")];
[[attachmentsColumn headerCell] setStringValue:NSLocalizedString(@"ATTACHMENTS", "")];
[[modifiedColumn headerCell] setStringValue:NSLocalizedString(@"MODIFIED", "")];
[parentColumn.headerCell setStringValue:NSLocalizedString(@"GROUP", "")];
[titleColumn.headerCell setStringValue:NSLocalizedString(@"TITLE", "")];
[userNameColumn.headerCell setStringValue:NSLocalizedString(@"USERNAME", "")];
[passwordColumn.headerCell setStringValue:NSLocalizedString(@"PASSWORD", "")];
[urlColumn.headerCell setStringValue:NSLocalizedString(@"URL", "")];
[notesColumn.headerCell setStringValue:NSLocalizedString(@"NOTES", "")];
[attachmentsColumn.headerCell setStringValue:NSLocalizedString(@"ATTACHMENTS", "")];
[modifiedColumn.headerCell setStringValue:NSLocalizedString(@"MODIFIED", "")];
[self.entryTable bind:NSContentBinding toObject:self.entryArrayController withKeyPath:NSStringFromSelector(@selector(arrangedObjects)) options:nil];
[self.entryTable bind:NSSortDescriptorsBinding toObject:self.entryArrayController withKeyPath:NSStringFromSelector(@selector(sortDescriptors)) options:nil];
[self.entryTable setDataSource:_dataSource];
self.entryTable.dataSource = self.dataSource;
// bind NSArrayController sorting so that sort order gets auto-saved
// see: http://simx.me/technonova/software_development/sort_descriptors_nstableview_bindings_a.html
@@ -204,7 +200,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
options:@{ NSValueTransformerNameBindingOption: NSUnarchiveFromDataTransformerName }];
[self _setupHeaderMenu];
[parentColumn setHidden:YES];
parentColumn.hidden = YES;
}
- (NSResponder *)reconmendedFirstResponder {
@@ -256,14 +252,14 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
BOOL isTitleColumn = [[tableColumn identifier] isEqualToString:MPEntryTableTitleColumnIdentifier];
BOOL isGroupColumn = [[tableColumn identifier] isEqualToString:MPEntryTableParentColumnIdentifier];
BOOL isPasswordColum = [[tableColumn identifier] isEqualToString:MPEntryTablePasswordColumnIdentifier];
BOOL isUsernameColumn = [[tableColumn identifier] isEqualToString:MPEntryTableUserNameColumnIdentifier];
BOOL isURLColumn = [[tableColumn identifier] isEqualToString:MPEntryTableURLColumnIdentifier];
BOOL isAttachmentColumn = [[tableColumn identifier] isEqualToString:MPEntryTableAttachmentColumnIdentifier];
BOOL isNotesColumn = [[tableColumn identifier] isEqualToString:MPEntryTableNotesColumnIdentifier];
BOOL isModifedColumn = [[tableColumn identifier] isEqualToString:MPEntryTableModfiedColumnIdentifier];
BOOL isTitleColumn = [tableColumn.identifier isEqualToString:MPEntryTableTitleColumnIdentifier];
BOOL isGroupColumn = [tableColumn.identifier isEqualToString:MPEntryTableParentColumnIdentifier];
BOOL isPasswordColum = [tableColumn.identifier isEqualToString:MPEntryTablePasswordColumnIdentifier];
BOOL isUsernameColumn = [tableColumn.identifier isEqualToString:MPEntryTableUserNameColumnIdentifier];
BOOL isURLColumn = [tableColumn.identifier isEqualToString:MPEntryTableURLColumnIdentifier];
BOOL isAttachmentColumn = [tableColumn.identifier isEqualToString:MPEntryTableAttachmentColumnIdentifier];
BOOL isNotesColumn = [tableColumn.identifier isEqualToString:MPEntryTableNotesColumnIdentifier];
BOOL isModifedColumn = [tableColumn.identifier isEqualToString:MPEntryTableModfiedColumnIdentifier];
NSTableCellView *view = nil;
if(isTitleColumn || isGroupColumn) {
@@ -275,8 +271,8 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
NSString *iconImageKeyPath = [NSString stringWithFormat:@"%@.%@",
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(iconImage))];
[[view textField] bind:NSValueBinding toObject:view withKeyPath:titleKeyPath options:nil];
[[view imageView] bind:NSValueBinding toObject:view withKeyPath:iconImageKeyPath options:nil];
[view.textField bind:NSValueBinding toObject:view withKeyPath:titleKeyPath options:nil];
[view.imageView bind:NSValueBinding toObject:view withKeyPath:iconImageKeyPath options:nil];
}
else {
KPKEntry *entry = [self.entryArrayController arrangedObjects][row];
@@ -290,8 +286,8 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(parent)),
NSStringFromSelector(@selector(iconImage))];
[[view textField] bind:NSValueBinding toObject:view withKeyPath:parentNameKeyPath options:nil];
[[view imageView] bind:NSValueBinding toObject:view withKeyPath:parentIconImageKeyPath options:nil];
[view.textField bind:NSValueBinding toObject:view withKeyPath:parentNameKeyPath options:nil];
[view.imageView bind:NSValueBinding toObject:view withKeyPath:parentIconImageKeyPath options:nil];
}
}
else if(isPasswordColum) {
@@ -300,17 +296,16 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(password))];
NSDictionary *options = @{ NSValueTransformerBindingOption : [NSValueTransformer valueTransformerForName:MPStringLengthValueTransformerName] };
[[view textField] bind:NSValueBinding toObject:view withKeyPath:passwordKeyPath options:options];
[view.textField bind:NSValueBinding toObject:view withKeyPath:passwordKeyPath options:options];
}
else {
view = [tableView makeViewWithIdentifier:_MPTableStringCellView owner:self];
NSTextField *textField = [view textField];
if(!isModifedColumn) {
/* clean up old formatter that might be left */
[textField setFormatter:nil];
view.textField.formatter = nil;
}
if(isModifedColumn) {
if(![[view textField] formatter]) {
if(!view.textField.formatter) {
/* Just use one formatter instance since it's expensive to create */
static NSDateFormatter *formatter = nil;
static dispatch_once_t onceToken;
@@ -319,38 +314,41 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
});
[textField setFormatter:formatter];
view.textField.formatter = formatter;
}
NSString *modificatoinTimeKeyPath = [NSString stringWithFormat:@"%@.%@.%@",
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(timeInfo)),
NSStringFromSelector(@selector(lastModificationTime))];
[textField bind:NSValueBinding toObject:view withKeyPath:modificatoinTimeKeyPath options:nil];
[view.textField bind:NSValueBinding toObject:view withKeyPath:modificatoinTimeKeyPath options:nil];
return view;
}
else if(isURLColumn) {
NSString *urlKeyPath = [NSString stringWithFormat:@"%@.%@",
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(url))];
[textField bind:NSValueBinding toObject:view withKeyPath:urlKeyPath options:nil];
[view.textField bind:NSValueBinding toObject:view withKeyPath:urlKeyPath options:nil];
}
else if(isUsernameColumn) {
NSString *usernameKeyPath = [NSString stringWithFormat:@"%@.%@",
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(username))];
[textField bind:NSValueBinding toObject:view withKeyPath:usernameKeyPath options:nil];
[view.textField bind:NSValueBinding toObject:view withKeyPath:usernameKeyPath options:nil];
}
else if(isNotesColumn) {
NSDictionary *options = @{ NSValueTransformerNameBindingOption : MPStripLineBreaksTransformerName };
NSString *notesKeyPath = [NSString stringWithFormat:@"%@.%@",
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(notes))];
[textField bind:NSValueBinding toObject:view withKeyPath:notesKeyPath options:options];
[view.textField bind:NSValueBinding toObject:view withKeyPath:notesKeyPath options:options];
}
else if(isAttachmentColumn) {
[textField bind:NSValueBinding toObject:view withKeyPath:@"objectValue.binaries.@count" options:nil];
NSString *binariesCoundKeyPath = [NSString stringWithFormat:@"%@.%@.@count",
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(binaries))];
[view.textField bind:NSValueBinding toObject:view withKeyPath:binariesCoundKeyPath options:nil];
}
}
return view;