From 81c3bdcb5aa282907e910b51f105aa0777c8e5dc Mon Sep 17 00:00:00 2001 From: michael starke Date: Thu, 27 Jun 2013 04:35:09 +0200 Subject: [PATCH] Added test for custom field ui. Field can be added/removed. But no data is displayes/stored --- MacPass.xcodeproj/project.pbxproj | 10 + MacPass/Base.lproj/InspectorView.xib | 78 +-- MacPass/CustomFieldView.xib | 708 +++++++++++++++++++++++++++ MacPass/MPCustomFieldView.h | 17 + MacPass/MPCustomFieldView.m | 14 + MacPass/MPInspectorViewController.h | 1 + MacPass/MPInspectorViewController.m | 78 ++- MacPass/MacPass-Info.plist | 2 +- 8 files changed, 871 insertions(+), 37 deletions(-) create mode 100644 MacPass/CustomFieldView.xib create mode 100644 MacPass/MPCustomFieldView.h create mode 100644 MacPass/MPCustomFieldView.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 4b868f15..606faaaf 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -110,6 +110,8 @@ 4C669BA016760ED100DD0774 /* Salsa20RandomStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C669B7716760ED100DD0774 /* Salsa20RandomStream.m */; }; 4C669BA216760ED100DD0774 /* UUID.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C669B7B16760ED100DD0774 /* UUID.m */; }; 4C69A73A16D589DF00EC1B1A /* HNHGradientView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C69A73916D589DF00EC1B1A /* HNHGradientView.m */; }; + 4C74DD04177BD00E0034A9DB /* CustomFieldView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C74DD03177BD00E0034A9DB /* CustomFieldView.xib */; }; + 4C74DD07177BD1640034A9DB /* MPCustomFieldView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C74DD06177BD1640034A9DB /* MPCustomFieldView.m */; }; 4C76155C1764C04C0015A1A6 /* GeneralSettings.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C76155E1764C04C0015A1A6 /* GeneralSettings.xib */; }; 4C7615631764C08C0015A1A6 /* PasswordEditView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C7615651764C08C0015A1A6 /* PasswordEditView.xib */; }; 4C7615681764C0C40015A1A6 /* PasswordInputView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C76156A1764C0C40015A1A6 /* PasswordInputView.xib */; }; @@ -380,6 +382,9 @@ 4C669B7B16760ED100DD0774 /* UUID.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UUID.m; sourceTree = ""; }; 4C69A73816D589DF00EC1B1A /* HNHGradientView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHGradientView.h; sourceTree = ""; }; 4C69A73916D589DF00EC1B1A /* HNHGradientView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHGradientView.m; sourceTree = ""; }; + 4C74DD03177BD00E0034A9DB /* CustomFieldView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CustomFieldView.xib; sourceTree = ""; }; + 4C74DD05177BD1640034A9DB /* MPCustomFieldView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPCustomFieldView.h; sourceTree = ""; }; + 4C74DD06177BD1640034A9DB /* MPCustomFieldView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPCustomFieldView.m; sourceTree = ""; }; 4C76155F1764C0590015A1A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/GeneralSettings.xib; sourceTree = ""; }; 4C7615601764C05A0015A1A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 4C7615661764C08F0015A1A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PasswordEditView.xib; sourceTree = ""; }; @@ -545,6 +550,9 @@ 4C3FFD9D16DAF60600DF9186 /* FilterBar.xib */, 4C76156F1764C0E20015A1A6 /* InspectorView.xib */, 4CE39AC016ECE359000FE29D /* IconSelection.xib */, + 4C74DD03177BD00E0034A9DB /* CustomFieldView.xib */, + 4C74DD05177BD1640034A9DB /* MPCustomFieldView.h */, + 4C74DD06177BD1640034A9DB /* MPCustomFieldView.m */, 4CE8247316E2F2B900573141 /* MPOverlayView.h */, 4CE8247416E2F2B900573141 /* MPOverlayView.m */, 4CFC53BD16E94729007396BE /* MPShadowBox.h */, @@ -1272,6 +1280,7 @@ 4CF7805F176E75110032EE71 /* ServerSettings.xib in Resources */, 4C7F35681779DFFB00C57890 /* Errors.strings in Resources */, 4CD5D702177A5EE400100649 /* DocumentSettingsWindow.xib in Resources */, + 4C74DD04177BD00E0034A9DB /* CustomFieldView.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1432,6 +1441,7 @@ 4C2A6134177A1D5F00C9826C /* KPLErrorCodes.m in Sources */, 4CD5D705177A5F3300100649 /* MPDocumentSettingsWindowController.m in Sources */, 4C5EC302177B700D00DA955B /* MPRootAdapter.m in Sources */, + 4C74DD07177BD1640034A9DB /* MPCustomFieldView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacPass/Base.lproj/InspectorView.xib b/MacPass/Base.lproj/InspectorView.xib index 1bbf4847..0ad4da1a 100644 --- a/MacPass/Base.lproj/InspectorView.xib +++ b/MacPass/Base.lproj/InspectorView.xib @@ -137,7 +137,6 @@ {299, 30} - _NS:9 HNHGradientView @@ -202,13 +201,13 @@ {{0, 31}, {299, 399}} - + _NS:9 1 - + 256 @@ -216,7 +215,6 @@ 268 {{17, 365}, {35, 14}} - _NS:1535 YES @@ -249,7 +247,6 @@ 268 {{20, 335}, {259, 22}} - _NS:9 YES @@ -284,7 +281,6 @@ 268 {{17, 313}, {58, 14}} - _NS:1535 YES @@ -305,7 +301,6 @@ 268 {{20, 283}, {259, 22}} - _NS:9 YES @@ -327,7 +322,6 @@ 268 {{20, 231}, {259, 22}} - _NS:9 YES @@ -349,7 +343,6 @@ 268 {{17, 261}, {25, 14}} - _NS:1535 YES @@ -370,7 +363,6 @@ 268 {{17, 209}, {58, 14}} - _NS:1535 YES @@ -391,7 +383,6 @@ 268 {{20, 179}, {259, 22}} - _NS:9 YES @@ -413,7 +404,6 @@ 268 {{20, 152}, {259, 19}} - _NS:9 {250, 750} @@ -443,7 +433,6 @@ 268 {{17, 131}, {42, 14}} - _NS:1535 YES @@ -464,7 +453,6 @@ 268 {{20, 105}, {259, 18}} - _NS:9 YES @@ -486,7 +474,6 @@ 268 {{17, 35}, {46, 11}} - _NS:1535 YES @@ -511,7 +498,6 @@ 268 {{17, 16}, {43, 11}} - _NS:1535 YES @@ -529,8 +515,6 @@ {299, 399} - - _NS:11 @@ -557,7 +541,7 @@ 2322 {257, 332} - + _NS:13 @@ -674,7 +658,7 @@ {{20, 20}, {259, 334}} - + _NS:9 133138 @@ -934,7 +918,7 @@ - + 256 @@ -942,7 +926,8 @@ 268 {{247, 362}, {32, 19}} - + + _NS:9 YES @@ -970,6 +955,7 @@ 268 {{17, 365}, {80, 14}} + _NS:1535 YES @@ -987,6 +973,8 @@ {299, 399} + + Fields @@ -994,13 +982,13 @@ - + 6 YES YES - + @@ -1149,6 +1137,22 @@ 1554 + + + customFieldsTextField + + + + 2005 + + + + addCustomField: + + + + 2006 + imageView @@ -3836,7 +3840,7 @@ - 2004 + 2008 @@ -3883,22 +3887,26 @@ MPInspectorViewController MPViewController - - _popUpPasswordGenerator: - id - - - _popUpPasswordGenerator: - + + id + id + + + _popUpPasswordGenerator: id - + + addCustomField: + id + + NSTextField NSTableView HNHGradientView NSTextField + NSTextField NSButton NSSegmentedControl MPPopupImageView @@ -3928,6 +3936,10 @@ createdTextField NSTextField + + customFieldsTextField + NSTextField + generatePasswordButton NSButton diff --git a/MacPass/CustomFieldView.xib b/MacPass/CustomFieldView.xib new file mode 100644 index 00000000..997d1ad1 --- /dev/null +++ b/MacPass/CustomFieldView.xib @@ -0,0 +1,708 @@ + + + + 1080 + 12E55 + 3084 + 1187.39 + 626.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 3084 + + + IBNSLayoutConstraint + NSButton + NSButtonCell + NSCustomObject + NSCustomView + NSTextField + NSTextFieldCell + + + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + + NSObject + + + FirstResponder + + + NSApplication + + + + 268 + + + + 268 + {{130, 1}, {32, 19}} + + + _NS:9 + YES + + -2080374784 + 134217728 + + + LucidaGrande + 12 + 16 + + _NS:9 + + -2033958912 + 164 + + NSImage + NSRemoveTemplate + + + + 400 + 75 + + NO + + + + 268 + {{-3, 28}, {168, 14}} + + + + _NS:9 + YES + + -1808793535 + 272761856 + + + LucidaGrande + 11 + 3100 + + New Field + _NS:9 + + + 6 + System + textBackgroundColor + + 3 + MQA + + + + 6 + System + disabledControlTextColor + + 3 + MC4zMzMzMzMzMzMzAA + + + + NO + + + + 268 + {122, 22} + + + + _NS:9 + YES + + -1804599231 + 272630784 + + + LucidaGrande + 13 + 1044 + + Field Value + _NS:9 + + YES + + + 6 + System + textColor + + 3 + MAA + + + + NO + + + {162, 42} + + + + MPCustomFieldView + + + + + + + removeCustomField: + + + + 44 + + + + valueTextField + + + + 20 + + + + deleteButton + + + + 45 + + + + labelTextField + + + + 46 + + + + + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 3 + 0 + + 3 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 3 + 0 + + 3 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 8 + 0 + + 0 + 1 + + 42 + + 1000 + + 9 + 40 + 1 + + + + + + + + + 2 + + + + + + + + 3 + + + + + 15 + + + + + 16 + + + + + 18 + + + + + 21 + + + + + + + + 22 + + + + + 30 + + + + + 32 + + + + + 34 + + + + + + 7 + 0 + + 0 + 1 + + 32 + + 1000 + + 3 + 9 + 1 + + + + + + 35 + + + + + 36 + + + + + 39 + + + + + 40 + + + + + 42 + + + + + 43 + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + 46 + + + + + HNHGradientView + NSView + + IBProjectSource + ./Classes/HNHGradientView.h + + + + MPCustomFieldView + NSView + + NSButton + NSTextField + NSTextField + + + + deleteButton + NSButton + + + labelTextField + NSTextField + + + valueTextField + NSTextField + + + + IBProjectSource + ./Classes/MPCustomFieldView.h + + + + MPInspectorViewController + MPViewController + + id + id + + + + addCustomField: + id + + + removeCustomField: + id + + + + NSTextField + NSTableView + HNHGradientView + NSTextField + NSTextField + NSButton + NSSegmentedControl + MPPopupImageView + NSTextField + NSTextField + NSTextView + NSTextField + NSTabView + NSTextField + NSTextField + NSTextField + + + + URLTextField + NSTextField + + + attachmentTableView + NSTableView + + + bottomBar + HNHGradientView + + + createdTextField + NSTextField + + + customFieldsTextField + NSTextField + + + generatePasswordButton + NSButton + + + infoTabControl + NSSegmentedControl + + + itemImageView + MPPopupImageView + + + itemNameTextfield + NSTextField + + + modifiedTextField + NSTextField + + + notesTextView + NSTextView + + + passwordTextField + NSTextField + + + tabView + NSTabView + + + titleOrNameLabel + NSTextField + + + titleTextField + NSTextField + + + usernameTextField + NSTextField + + + + IBProjectSource + ./Classes/MPInspectorViewController.h + + + + MPPopupImageView + NSImageView + + IBProjectSource + ./Classes/MPPopupImageView.h + + + + MPViewController + NSViewController + + IBProjectSource + ./Classes/MPViewController.h + + + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + + + + 0 + IBCocoaFramework + YES + 3 + + NSRemoveTemplate + {8, 8} + + YES + + diff --git a/MacPass/MPCustomFieldView.h b/MacPass/MPCustomFieldView.h new file mode 100644 index 00000000..10889570 --- /dev/null +++ b/MacPass/MPCustomFieldView.h @@ -0,0 +1,17 @@ +// +// MPCustomFieldView.h +// MacPass +// +// Created by Michael Starke on 27.06.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + +@interface MPCustomFieldView : NSView + +@property (assign) IBOutlet NSTextField *labelTextField; +@property (assign) IBOutlet NSTextField *valueTextField; +@property (assign) IBOutlet NSButton *deleteButton; + +@end diff --git a/MacPass/MPCustomFieldView.m b/MacPass/MPCustomFieldView.m new file mode 100644 index 00000000..b1152da2 --- /dev/null +++ b/MacPass/MPCustomFieldView.m @@ -0,0 +1,14 @@ +// +// MPCustomFieldView.m +// MacPass +// +// Created by Michael Starke on 27.06.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "MPCustomFieldView.h" + +@implementation MPCustomFieldView + + +@end diff --git a/MacPass/MPInspectorViewController.h b/MacPass/MPInspectorViewController.h index e2eb0814..8f19b4c7 100644 --- a/MacPass/MPInspectorViewController.h +++ b/MacPass/MPInspectorViewController.h @@ -30,6 +30,7 @@ @property (assign) IBOutlet NSSegmentedControl *infoTabControl; @property (assign) IBOutlet NSTableView *attachmentTableView; @property (assign) IBOutlet NSTextView *notesTextView; +@property (assign) IBOutlet NSTextField *customFieldsTextField; /* Seperate call to ensure alle registered objects are in place */ diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index 302848b1..63f61313 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -16,6 +16,7 @@ #import "MPDocumentWindowController.h" #import "MPOutlineViewController.h" #import "MPDocument.h" +#import "MPCustomFieldView.h" #import "KdbLib.h" #import "Kdb4Node.h" @@ -49,6 +50,10 @@ enum { @property (nonatomic, assign) NSUInteger activeTab; @property (assign) IBOutlet NSTabView *tabView; @property (retain) NSArrayController *attachmentsController; +@property (retain) NSMutableArray *customFieldViews; + +- (IBAction)addCustomField:(id)sender; +- (IBAction)removeCustomField:(id)sender; @end @@ -65,6 +70,7 @@ enum { _selectedGroup = nil; _attachmentsController = [[NSArrayController alloc] init]; _activeTab = MPGeneralTab; + _customFieldViews = [[NSMutableArray alloc] initWithCapacity:5]; } return self; } @@ -73,6 +79,7 @@ enum { [[NSNotificationCenter defaultCenter] removeObserver:self]; [_activePopover release]; [_attachmentsController release]; + [_customFieldViews release]; [super dealloc]; } @@ -186,7 +193,7 @@ enum { [self.URLTextField setStringValue:@""]; // Reste toggle. Do not call setter on control or the bindings wont update - self.activeTab = MPGeneralTab; + self.activeTab = MPGeneralTab; [self _setInputEnabled:YES]; } @@ -231,7 +238,7 @@ enum { [self.usernameTextField setEnabled:enabled]; [self.URLTextField setEnabled:enabled]; [self.generatePasswordButton setEnabled:enabled]; - + [self.infoTabControl setEnabled:enabled forSegment:MPAttachmentsTab]; [self.infoTabControl setEnabled:enabled forSegment:MPNotesTab]; [self.infoTabControl setEnabled:enabled forSegment:MPCustomFieldsTab]; @@ -278,6 +285,72 @@ enum { _activePopover = nil; } +#pragma mark Actions +- (IBAction)addCustomField:(id)sender { + NSArray *topLevelObjects; + BOOL success = [[NSBundle mainBundle] loadNibNamed:@"CustomFieldView" owner:self topLevelObjects:&topLevelObjects]; + if(success) { + id object = [topLevelObjects lastObject]; + MPCustomFieldView *fieldView; + if(![object isKindOfClass:[MPCustomFieldView class]]) { + fieldView = topLevelObjects[0]; + } + else { + fieldView = object; + } + [fieldView.deleteButton setTarget:self]; + NSTabViewItem *tabViewItem = [self.tabView tabViewItemAtIndex:MPCustomFieldsTab]; + + NSView *predecessorView = [self.customFieldViews lastObject]; + if(!predecessorView) { + predecessorView = _customFieldsTextField; + } + + [[tabViewItem view] addSubview:fieldView]; + [self.customFieldViews addObject:fieldView]; + + NSDictionary *views = NSDictionaryOfVariableBindings(fieldView, predecessorView); + [[tabViewItem view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[fieldView]-20-|" + options:0 + metrics:nil + views:views]]; + [[tabViewItem view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[predecessorView]-10-[fieldView]" + options:0 + metrics:nil + views:views]]; + [[tabViewItem view] layoutSubtreeIfNeeded]; + } +} +- (IBAction)removeCustomField:(id)sender { + NSControl *button = sender; + NSView *fieldView = [button superview]; + + if([self.customFieldViews containsObject:fieldView]) { + [fieldView removeFromSuperview]; + NSUInteger index = [self.customFieldViews indexOfObject:fieldView]; + NSView *newPredecessorView = nil; + NSView *newSuccesorView = nil; + if(index == 0) { + newPredecessorView = _customFieldsTextField; + } + else { + NSAssert(index > 0, @""); + newPredecessorView = [self.customFieldViews objectAtIndex:index - 1]; + } + NSTabViewItem *tabViewItem = [self.tabView tabViewItemAtIndex:MPCustomFieldsTab]; + if(index < [self.customFieldViews count] - 1) { + newSuccesorView = [self.customFieldViews objectAtIndex:index + 1]; + NSDictionary *views = NSDictionaryOfVariableBindings(newPredecessorView, newSuccesorView); + [[tabViewItem view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[newPredecessorView]-10-[newSuccesorView]" + options:0 + metrics:nil + views:views]]; + } + [self.customFieldViews removeObject:fieldView]; + [[tabViewItem view] layoutSubtreeIfNeeded]; + } +} + #pragma mark Notificiations - (void)_didChangeCurrentItem:(NSNotification *)notification { MPDocumentWindowController *sender = [notification object]; @@ -311,5 +384,4 @@ enum { } return view; } - @end diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 37a508b6..e68024ce 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -48,7 +48,7 @@ CFBundleSignature ???? CFBundleVersion - 1324 + 1354 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright