From db30d641f2cc5c38cca56295b33e3c8a8ba8068b Mon Sep 17 00:00:00 2001 From: michael starke Date: Fri, 28 Jun 2013 18:39:24 +0200 Subject: [PATCH] Added Undo/Redo for string field editing Fixed #26 - Entries now can be added to the rout group --- HNHUi | 2 +- MacPass.xcodeproj/project.pbxproj | 6 ++++ MacPass/Base.lproj/InspectorView.xib | 3 +- MacPass/EntryView.xib | 24 +++------------ MacPass/MPDocument.m | 6 ++++ MacPass/MPInspectorViewController.m | 7 +++-- MacPass/MPOutlineViewController.m | 13 -------- MacPass/MPTableView.m | 2 +- MacPass/MacPass-Info.plist | 2 +- MacPass/StringField+Undo.h | 23 +++++++++++++++ MacPass/StringField+Undo.m | 44 ++++++++++++++++++++++++++++ 11 files changed, 92 insertions(+), 40 deletions(-) create mode 100644 MacPass/StringField+Undo.h create mode 100644 MacPass/StringField+Undo.m diff --git a/HNHUi b/HNHUi index 87d76f44..573b1d94 160000 --- a/HNHUi +++ b/HNHUi @@ -1 +1 @@ -Subproject commit 87d76f4481e971e7f75f7e7072c77f06461d9c48 +Subproject commit 573b1d94098457dd01a78bf03e2a2d6489bf570a diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index b2424e0b..a85a7da9 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -56,6 +56,7 @@ 4C37A84015B8B474005EF8EE /* MPOutlineDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C37A83F15B8B474005EF8EE /* MPOutlineDataSource.m */; }; 4C3BD51516D276F800389F1F /* MPToolbarDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C3BD51416D276F800389F1F /* MPToolbarDelegate.m */; }; 4C3D4C0817594CA40038DAAC /* HNHSeparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C3D4C0717594CA40038DAAC /* HNHSeparator.m */; }; + 4C3E1CC0177DEFB3003BD9BD /* StringField+Undo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C3E1CBF177DEFB3003BD9BD /* StringField+Undo.m */; }; 4C3FFD9E16DAF60600DF9186 /* FilterBar.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C3FFD9D16DAF60600DF9186 /* FilterBar.xib */; }; 4C431BCD16E2A82800700A81 /* MPPasteBoardController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */; }; 4C431BCF16E2BAB000700A81 /* OverlayWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C431BCE16E2BAB000700A81 /* OverlayWindow.xib */; }; @@ -281,6 +282,8 @@ 4C3BD51416D276F800389F1F /* MPToolbarDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPToolbarDelegate.m; sourceTree = ""; }; 4C3D4C0617594CA40038DAAC /* HNHSeparator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHSeparator.h; sourceTree = ""; }; 4C3D4C0717594CA40038DAAC /* HNHSeparator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHSeparator.m; sourceTree = ""; }; + 4C3E1CBE177DEFB3003BD9BD /* StringField+Undo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "StringField+Undo.h"; sourceTree = ""; }; + 4C3E1CBF177DEFB3003BD9BD /* StringField+Undo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "StringField+Undo.m"; sourceTree = ""; }; 4C3FFD9D16DAF60600DF9186 /* FilterBar.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FilterBar.xib; sourceTree = ""; }; 4C431BCB16E2A82700700A81 /* MPPasteBoardController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPasteBoardController.h; sourceTree = ""; }; 4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPasteBoardController.m; sourceTree = ""; }; @@ -752,6 +755,8 @@ 4C22040C1746ED160054C916 /* KdbGroup+Undo.m */, 4C36E5AF177CD38C00152132 /* Kdb4Tree+Undo.h */, 4C36E5B0177CD38C00152132 /* Kdb4Tree+Undo.m */, + 4C3E1CBE177DEFB3003BD9BD /* StringField+Undo.h */, + 4C3E1CBF177DEFB3003BD9BD /* StringField+Undo.m */, 4C4A101017629DA900BBF2CA /* KdbGroup+KVOAdditions.h */, 4C4A101117629DA900BBF2CA /* KdbGroup+KVOAdditions.m */, 4C36E5B2177CD4FB00152132 /* Kdb4Tree+KVOAdditions.h */, @@ -1462,6 +1467,7 @@ 4C4FCE15177CFE6B00BBF7AE /* MPCustomFieldTableCellView.m in Sources */, 4C4FCE18177D03D700BBF7AE /* Kdb4Entry+KVOAdditions.m in Sources */, 4C52A244177D7B9F0000D88F /* HNHScrollView.m in Sources */, + 4C3E1CC0177DEFB3003BD9BD /* StringField+Undo.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacPass/Base.lproj/InspectorView.xib b/MacPass/Base.lproj/InspectorView.xib index 1aab6564..2641ec93 100644 --- a/MacPass/Base.lproj/InspectorView.xib +++ b/MacPass/Base.lproj/InspectorView.xib @@ -201,7 +201,6 @@ {{0, 31}, {293, 399}} - _NS:9 @@ -1030,7 +1029,7 @@ 3 2 - + 54 -1774190592 diff --git a/MacPass/EntryView.xib b/MacPass/EntryView.xib index 664096b8..40085bd9 100644 --- a/MacPass/EntryView.xib +++ b/MacPass/EntryView.xib @@ -58,7 +58,6 @@ {{7, 5}, {32, 19}} - _NS:9 YES @@ -108,7 +107,7 @@ {684, 548} - + _NS:13 YES NO @@ -305,18 +304,8 @@ 3 2 - 6 - System - _sourceListBackgroundColor - - 6 - System - alternateSelectedControlColor - - 1 - MCAwIDEAA - - + 1 + MSAxIDEAA 6 @@ -393,7 +382,7 @@ {{0, 30}, {684, 565}} - + _NS:9 133680 @@ -1777,7 +1766,6 @@ NSButton NSButton NSButton - NSImageView NSLayoutConstraint @@ -1821,10 +1809,6 @@ filterUsernameButton NSButton - - readOnlyImageView - NSImageView - tableToTop NSLayoutConstraint diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 80aa327a..fb4e17e2 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -252,6 +252,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; #pragma mark Data manipulation - (KdbEntry *)createEntry:(KdbGroup *)parent { + if(!parent) { + return nil; // No parent + } KdbEntry *newEntry = [self.tree createEntry:parent]; newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry"); if(self.treeV4 && ([self.treeV4.defaultUserName length] > 0)) { @@ -264,6 +267,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; } - (KdbGroup *)createGroup:(KdbGroup *)parent { + if(!parent) { + return nil; // no parent! + } KdbGroup *newGroup = [self.tree createGroup:parent]; newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group"); [self group:parent addGroup:newGroup atIndex:[parent.groups count]]; diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index 8e82f4f2..82e8e107 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -25,6 +25,7 @@ #import "Kdb3Node.h" #import "KdbGroup+Undo.h" #import "KdbEntry+Undo.h" +#import "StringField+Undo.h" #import "Kdb4Entry+KVOAdditions.h" #import "NSMutableData+Base64.h" @@ -97,6 +98,8 @@ enum { [_attachmentTableView bind:NSContentBinding toObject:self.attachmentsController withKeyPath:@"arrangedObjects" options:nil]; [_attachmentTableView setDelegate:self]; + /* Set background to clearcolor so we can draw in the scrollview */ + [_customFieldsTableView setBackgroundColor:[NSColor clearColor]]; [_customFieldsTableView bind:NSContentBinding toObject:self.customFieldsController withKeyPath:@"arrangedObjects" options:nil]; [_customFieldsTableView setDelegate:self]; @@ -358,8 +361,8 @@ enum { if([self.selectedEntry isKindOfClass:[Kdb4Entry class]]) { Kdb4Entry *entry = (Kdb4Entry *)self.selectedEntry; StringField *stringField = entry.stringFields[row]; - [view.labelTextField bind:NSValueBinding toObject:stringField withKeyPath:@"key" options:nil]; - [view.valueTextField bind:NSValueBinding toObject:stringField withKeyPath:@"value" options:nil]; + [view.labelTextField bind:NSValueBinding toObject:stringField withKeyPath:MPStringFieldKeyUndoableKey options:nil]; + [view.valueTextField bind:NSValueBinding toObject:stringField withKeyPath:MPStringFieldValueUndoableKey options:nil]; [view.removeButton setTarget:self]; [view.removeButton setAction:@selector(removeCustomField:)]; [view.removeButton setTag:row]; diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 009292b5..32b04517 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -111,7 +111,6 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; [_outlineView expandItem:item]; indexSet = [NSIndexSet indexSetWithIndex:selectedRow + 1]; } - [_outlineView selectRowIndexes:indexSet byExtendingSelection:NO]; } #pragma mark - @@ -123,23 +122,11 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; if(!group) { group = document.root; } - BOOL isFistGroup = [document.root.groups count] == 0; [document createGroup:group]; - /* - TODO: Find out if a lower hierachy node was the first child - and auto-expand that item too - */ - if(isFistGroup) { - NSTreeNode *node = [_outlineView itemAtRow:0]; - [_outlineView expandItem:node expandChildren:NO]; - } } - (void)createEntry:(id)sender { KdbGroup *group = [self _clickedOrSelectedGroup]; - if(!group.parent) { - return; // Entries are not allowed in root group - } if(group) { MPDocument *document = [[self windowController] document]; [document createEntry:group]; diff --git a/MacPass/MPTableView.m b/MacPass/MPTableView.m index bf3d0cfa..8403cbdf 100644 --- a/MacPass/MPTableView.m +++ b/MacPass/MPTableView.m @@ -15,7 +15,7 @@ We need to clear the outer areas as calling super will not do that for us */ - [[NSColor whiteColor] set]; + [[self backgroundColor] set]; NSRectFill(clipRect); [super drawBackgroundInClipRect:clipRect]; } diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 0dcfd243..fc75ed49 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -48,7 +48,7 @@ CFBundleSignature ???? CFBundleVersion - 1508 + 1556 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright diff --git a/MacPass/StringField+Undo.h b/MacPass/StringField+Undo.h new file mode 100644 index 00000000..734650fb --- /dev/null +++ b/MacPass/StringField+Undo.h @@ -0,0 +1,23 @@ +// +// StringField+Undo.h +// MacPass +// +// Created by Michael Starke on 28.06.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "Kdb4Node.h" + +APPKIT_EXTERN NSString *const MPStringFieldKeyUndoableKey; +APPKIT_EXTERN NSString *const MPStringFieldValueUndoableKey; + +@interface StringField (Undo) + + +- (NSString *)keyUndoable; +- (NSString *)valueUndoable; + +- (void)setKeyUndoable:(NSString *)key; +- (void)setValueUndoable:(NSString *)value; + +@end diff --git a/MacPass/StringField+Undo.m b/MacPass/StringField+Undo.m new file mode 100644 index 00000000..57c3e391 --- /dev/null +++ b/MacPass/StringField+Undo.m @@ -0,0 +1,44 @@ +// +// StringField+Undo.m +// MacPass +// +// Created by Michael Starke on 28.06.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "StringField+Undo.h" + +NSString *const MPStringFieldKeyUndoableKey = @"keyUndoable"; +NSString *const MPStringFieldValueUndoableKey = @"valueUndoable"; + +@implementation StringField (Undo) + +- (NSUndoManager *)undoManager { + return [[[NSDocumentController sharedDocumentController] currentDocument] undoManager]; +} + +- (NSString *)keyUndoable { + return self.key; +} + +- (NSString *)valueUndoable { + return self.value; +} + +- (void)setKeyUndoable:(NSString *)key { + if(![self.key isEqualToString:key]) { + [[self undoManager] registerUndoWithTarget:self selector:@selector(setKeyUndoable:) object:self.key]; + [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_STRINGFILED_KEY", @"Set StringField key")]; + self.key = key; + } +} + +- (void)setValueUndoable:(NSString *)value { + if(![self.value isEqualToString:value]) { + [[self undoManager] registerUndoWithTarget:self selector:@selector(setValueUndoable:) object:self.value]; + [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_STRINGFIELD_VALUE", @"Set StringField value")]; + self.value = value; + } +} + +@end