From 1737d1242570171d33aff7602a32770559e10143 Mon Sep 17 00:00:00 2001 From: michael starke Date: Fri, 16 Oct 2015 19:08:02 +0200 Subject: [PATCH] More drafting for editing (broken!) Signed-off-by: michael starke --- KeePassKit | 2 +- MacPass.xcodeproj/project.pbxproj | 8 ----- MacPass/MPDocument+EditingSession.m | 19 +++++------- MacPass/MPDocument.h | 4 +-- MacPass/MPEntryInspectorViewController.m | 7 ----- MacPass/MPInspectorViewController.m | 37 +++++++----------------- MacPassTests/KPKTestNSCopying.m | 2 +- MacPassTests/KPKTestUndo.m | 5 ++-- 8 files changed, 23 insertions(+), 61 deletions(-) diff --git a/KeePassKit b/KeePassKit index 65f46c47..88936f50 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit 65f46c47e414d3d50ee199c35152ecf748ef8fe1 +Subproject commit 88936f50254b9ee06a60348b1e1186415018c9c7 diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index e5205df2..be52ff93 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -244,7 +244,6 @@ 4C8A173D1790AA41008B5C17 /* NSData+Keyfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8A173C1790AA41008B5C17 /* NSData+Keyfile.m */; }; 4C8B36AB17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */; }; 4C8EB8C118D399FD00438B08 /* KPKTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8EB8C018D399FD00438B08 /* KPKTag.m */; }; - 4C94A06F1938DC8C0040ABAB /* KPKEditingSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C94A06E1938DC8C0040ABAB /* KPKEditingSession.m */; }; 4C94A0721938DDC20040ABAB /* MPDocument+EditingSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C94A0711938DDC20040ABAB /* MPDocument+EditingSession.m */; }; 4C978E0619AE53FE003067DF /* HNHCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C978E0519AE53FE003067DF /* HNHCommon.m */; }; 4C978E0D19AE54AB003067DF /* MPFlagsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C978E0C19AE54AB003067DF /* MPFlagsHelper.m */; }; @@ -798,8 +797,6 @@ 4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineContextMenuDelegate.m; sourceTree = ""; }; 4C8EB8BF18D399FD00438B08 /* KPKTag.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKTag.h; sourceTree = ""; }; 4C8EB8C018D399FD00438B08 /* KPKTag.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKTag.m; sourceTree = ""; }; - 4C94A06D1938DC8C0040ABAB /* KPKEditingSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKEditingSession.h; sourceTree = ""; }; - 4C94A06E1938DC8C0040ABAB /* KPKEditingSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKEditingSession.m; sourceTree = ""; }; 4C94A0711938DDC20040ABAB /* MPDocument+EditingSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+EditingSession.m"; sourceTree = ""; }; 4C978E0519AE53FE003067DF /* HNHCommon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHCommon.m; sourceTree = ""; }; 4C978E0C19AE54AB003067DF /* MPFlagsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPFlagsHelper.m; sourceTree = ""; }; @@ -899,7 +896,6 @@ 4CD78ABB16D155FF00768A1D /* 11_CameraTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 11_CameraTemplate.pdf; sourceTree = ""; }; 4CD820221A32173100399DBB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ReferenceBuilderView.xib; sourceTree = ""; }; 4CD884B615BD47080042BBF8 /* DocumentWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DocumentWindow.xib; sourceTree = ""; }; - 4CD9D6CB1BCE6539008C1960 /* KPKEditingSession+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKEditingSession+Private.h"; sourceTree = ""; }; 4CDB5C401794AA4F0017667E /* KPKTree+Serializing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKTree+Serializing.h"; sourceTree = ""; }; 4CDB5C411794AA4F0017667E /* KPKTree+Serializing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "KPKTree+Serializing.m"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = ""; }; @@ -1842,9 +1838,6 @@ 4CD3ABB1178F71B50073F5C5 /* Core */ = { isa = PBXGroup; children = ( - 4C94A06D1938DC8C0040ABAB /* KPKEditingSession.h */, - 4CD9D6CB1BCE6539008C1960 /* KPKEditingSession+Private.h */, - 4C94A06E1938DC8C0040ABAB /* KPKEditingSession.m */, 4C70D0FE179092F200652EE9 /* KPKCompositeKey.h */, 4C70D0FF179092F200652EE9 /* KPKCompositeKey.m */, 4CD3ABB3178F71B50073F5C5 /* KPKTree.h */, @@ -2371,7 +2364,6 @@ 4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */, 4C89F524182FB4740069C73C /* MPAutotypeCommand.m in Sources */, 4C8EB8C118D399FD00438B08 /* KPKTag.m in Sources */, - 4C94A06F1938DC8C0040ABAB /* KPKEditingSession.m in Sources */, 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */, 4C0AF62F195C1F2B009E658D /* MPEntrySearchContext.m in Sources */, 4C888C9316EB6F5E003D34A1 /* MPToolbarItem.m in Sources */, diff --git a/MacPass/MPDocument+EditingSession.m b/MacPass/MPDocument+EditingSession.m index 02a3f0ea..f557b1de 100644 --- a/MacPass/MPDocument+EditingSession.m +++ b/MacPass/MPDocument+EditingSession.m @@ -7,8 +7,8 @@ // #import "MPDocument.h" -#import "KPKEditingSession.h" +#import "KPKTree.h" #import "KPKNode.h" NSString *const MPDocumentDidBeginEditingSelectedItem = @"com.hicknhack.macpass.MPDocumentDidBeginEditingSelectedItem"; @@ -17,14 +17,12 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac @implementation MPDocument (EditingSession) -- (BOOL)isEditing { - return (self.editingSession != nil); +- (BOOL)hasActiveEditingSession { +// return (self.tree.activeEditingSession != nil); +// return (self.editingSession != nil); } - (void)commitChangesToSelectedItem:(id)sender { - if(nil == self.editingSession) { - return; // No session to commit - } /* Force any lingering updates to be written */ /* FIXME explore potential usage of: * NSObject(NSEditorRegistration) @@ -33,20 +31,17 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac [((NSWindowController *)self.windowControllers.firstObject).window makeFirstResponder:nil]; /* update the data */ - [self.editingSession.source commitEditing]; - if(self.editingSession.source.asEntry) { + [self.selectedItem commitEditing]; + if(self.selectedItem.asEntry) { [self.undoManager setActionName:NSLocalizedString(@"UPDATE_ENTRY", "")]; } - else if(self.editingSession.source.asGroup) { + else if(self.selectedItem.asGroup) { [self.undoManager setActionName:NSLocalizedString(@"UPDATE_GROUP", "")]; } [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidCommitChangesToSelectedItem object:self]; } - (void)cancelChangesToSelectedItem:(id)sender { - if(nil == self.editingSession) { - return; // No session to cancel - } [self.selectedItem cancelEditing]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidCancelChangesToSelectedItem object:self]; } diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 4ef3fece..6d6508fc 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -86,7 +86,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; */ @property (nonatomic, readonly) BOOL hasSearch; @property (nonatomic, copy) MPEntrySearchContext *searchContext; -@property (nonatomic, strong) NSArray *searchResult; +@property (nonatomic, strong, readonly) NSArray *searchResult; + (KPKVersion)versionForFileType:(NSString *)fileType; + (NSString *)fileTypeForVersion:(KPKVersion)version; @@ -222,8 +222,6 @@ APPKIT_EXTERN NSString *const MPDocumentDidCommitChangesToSelectedItem; @interface MPDocument (EditingSession) -- (BOOL)isEditing; - #pragma mark Edit Actions - (IBAction)beginEditingSelectedItem:(id)sender; - (IBAction)cancelChangesToSelectedItem:(id)sender; diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index 81afcf4a..f99ef70e 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -487,11 +487,4 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { [[[self view] window] makeFirstResponder:nil]; } -- (void)_didBeginEditingSelectedItem:(NSNotification *)notification { - [self _toggleEditing:YES]; -} - -- (void)_didCancelOrCommitChangesToSelectedItem:(NSNotification *)notification { - [self _toggleEditing:NO]; -} @end diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index 957f4088..13cf1bb6 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -9,7 +9,6 @@ #import "MPInspectorViewController.h" #import "MPDatePickingViewController.h" #import "MPDocument.h" -#import "KPKEditingSession.h" #import "MPEntryInspectorViewController.h" #import "MPGroupInspectorViewController.h" #import "MPIconHelper.h" @@ -108,8 +107,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { [[self view] layout]; /* Init edit and cancel buttons */ - self.editButton.action = @selector(beginEditingSelectedItem:); - self.cancelEditButton.action = @selector(cancelChangesToSelectedItem:); + self.editButton.action = @selector(beginEditing:); + self.cancelEditButton.action = @selector(cancelEditing:); self.cancelEditButton.hidden = YES; [self _updateBindings:nil]; @@ -121,22 +120,6 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { selector:@selector(_didChangeCurrentItem:) name:MPDocumentCurrentItemChangedNotification object:document]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_didBeginEditingSelectedItem:) - name:MPDocumentDidBeginEditingSelectedItem - object:document]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_didCancelOrCommitChangesToSelectedItem:) - name:MPDocumentDidCommitChangesToSelectedItem - object:document]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_didCancelOrCommitChangesToSelectedItem:) - name:MPDocumentDidCancelChangesToSelectedItem - object:document]; - [self.entryViewController regsiterNotificationsForDocument:document]; [self.entryViewController setupBindings:document]; @@ -315,21 +298,21 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { [self _updateBindings:document.selectedItem]; } -- (void)_didBeginEditingSelectedItem:(NSNotification *)notification { - MPDocument *document = notification.object; - self.editButton.action = @selector(commitChangesToSelectedItem:); +- (IBAction)beginEditing:(id)sender { + self.editButton.action = @selector(commitEditing:); self.editButton.title = NSLocalizedString(@"SAVE", ""); self.cancelEditButton.hidden = NO; - [self _updateBindings:document.editingSession.node]; [self _toggleEditors:YES]; } -- (void)_didCancelOrCommitChangesToSelectedItem:(NSNotification *)notification { - MPDocument *document = notification.object; +- (IBAction)cancelEditing:(id)sender { self.editButton.title = NSLocalizedString(@"EDIT", ""); self.cancelEditButton.hidden = YES; - self.editButton.action = @selector(beginEditingSelectedItem:); - [self _updateBindings:document.selectedItem]; + self.editButton.action = @selector(beginEditing:); [self _toggleEditors:NO]; } + +- (IBAction)commitEditing:(id)sender { + [self cancelEditing:sender]; +} @end diff --git a/MacPassTests/KPKTestNSCopying.m b/MacPassTests/KPKTestNSCopying.m index f2e27a97..7b8adb3f 100644 --- a/MacPassTests/KPKTestNSCopying.m +++ b/MacPassTests/KPKTestNSCopying.m @@ -63,7 +63,7 @@ XCTAssertEqualObjects(copyEntry.url, @"URL", @"URLS should match"); XCTAssertEqual(copyEntry.binaries.count, 1, @"Binareis should be copied"); - KPKBinary *copiedBinary = [copyEntry.binaries lastObject]; + KPKBinary *copiedBinary = copyEntry.binaries.lastObject; XCTAssertTrue([copiedBinary.data isEqualToData:binary.data], @"Binary data should match"); XCTAssertTrue([copiedBinary.name isEqualToString:binary.name], @"Binary names should macht"); } diff --git a/MacPassTests/KPKTestUndo.m b/MacPassTests/KPKTestUndo.m index a7b0e842..db5366cf 100644 --- a/MacPassTests/KPKTestUndo.m +++ b/MacPassTests/KPKTestUndo.m @@ -10,6 +10,7 @@ #import #import "KPKTree.h" +#import "KPKNode+Private.h" #import "KPKGroup.h" #import "KPKEntry.h" @@ -340,8 +341,8 @@ XCTAssertFalse(_undoManager.canUndo, @"Undo stack is empty"); XCTAssertFalse(_undoManager.canRedo, @"Redo stack is empty"); - XCTAssertThrows([_entryA updateToNode:_groupA], @"Updating Entry to Group is not possible"); - XCTAssertThrows([_groupA updateToNode:_entryA], @"Updating Group to Entry is not possible"); + XCTAssertThrows([_entryA _updateToNode:_groupA], @"Updating Entry to Group is not possible"); + XCTAssertThrows([_groupA _updateToNode:_entryA], @"Updating Group to Entry is not possible"); XCTAssertFalse(_undoManager.canUndo, @"Undo stack is empty after failed update"); XCTAssertFalse(_undoManager.canRedo, @"Redo stack is empty after failed update");