Added Undo/Redo for string field editing

Fixed #26 - Entries now can be added to the rout group
This commit is contained in:
michael starke
2013-06-28 18:39:24 +02:00
parent 6c8f0dcfa0
commit db30d641f2
11 changed files with 92 additions and 40 deletions

2
HNHUi

Submodule HNHUi updated: 87d76f4481...573b1d9409

View File

@@ -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 = "<group>"; };
4C3D4C0617594CA40038DAAC /* HNHSeparator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHSeparator.h; sourceTree = "<group>"; };
4C3D4C0717594CA40038DAAC /* HNHSeparator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHSeparator.m; sourceTree = "<group>"; };
4C3E1CBE177DEFB3003BD9BD /* StringField+Undo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "StringField+Undo.h"; sourceTree = "<group>"; };
4C3E1CBF177DEFB3003BD9BD /* StringField+Undo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "StringField+Undo.m"; sourceTree = "<group>"; };
4C3FFD9D16DAF60600DF9186 /* FilterBar.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FilterBar.xib; sourceTree = "<group>"; };
4C431BCB16E2A82700700A81 /* MPPasteBoardController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPasteBoardController.h; sourceTree = "<group>"; };
4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPasteBoardController.m; sourceTree = "<group>"; };
@@ -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;
};

View File

@@ -201,7 +201,6 @@
<string key="NSFrame">{{0, 31}, {293, 399}}</string>
<reference key="NSSuperview" ref="87082330"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="177600245"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<array class="NSMutableArray" key="NSTabViewItems">
<object class="NSTabViewItem" id="1002013291">
@@ -1030,7 +1029,7 @@
</array>
<double key="NSIntercellSpacingWidth">3</double>
<double key="NSIntercellSpacingHeight">2</double>
<reference key="NSBackgroundColor" ref="533509460"/>
<reference key="NSBackgroundColor" ref="566946319"/>
<reference key="NSGridColor" ref="771228525"/>
<double key="NSRowHeight">54</double>
<int key="NSTvFlags">-1774190592</int>

View File

@@ -58,7 +58,6 @@
<string key="NSFrame">{{7, 5}, {32, 19}}</string>
<reference key="NSSuperview" ref="163272962"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="160641004">
@@ -108,7 +107,7 @@
<string key="NSFrameSize">{684, 548}</string>
<reference key="NSSuperview" ref="262664416"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="788738248"/>
<reference key="NSNextKeyView" ref="736877784"/>
<string key="NSReuseIdentifierKey">_NS:13</string>
<bool key="NSEnabled">YES</bool>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
@@ -305,18 +304,8 @@
<double key="NSIntercellSpacingWidth">3</double>
<double key="NSIntercellSpacingHeight">2</double>
<object class="NSColor" key="NSBackgroundColor">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">_sourceListBackgroundColor</string>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">alternateSelectedControlColor</string>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MCAwIDEAA</bytes>
</object>
</object>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<object class="NSColor" key="NSGridColor">
<int key="NSColorSpace">6</int>
@@ -393,7 +382,7 @@
<string key="NSFrame">{{0, 30}, {684, 565}}</string>
<reference key="NSSuperview" ref="997686550"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="736877784"/>
<reference key="NSNextKeyView" ref="262664416"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<int key="NSsFlags">133680</int>
<reference key="NSVScroller" ref="1037276411"/>
@@ -1777,7 +1766,6 @@
<string key="filterTitleButton">NSButton</string>
<string key="filterURLButton">NSButton</string>
<string key="filterUsernameButton">NSButton</string>
<string key="readOnlyImageView">NSImageView</string>
<string key="tableToTop">NSLayoutConstraint</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
@@ -1821,10 +1809,6 @@
<string key="name">filterUsernameButton</string>
<string key="candidateClassName">NSButton</string>
</object>
<object class="IBToOneOutletInfo" key="readOnlyImageView">
<string key="name">readOnlyImageView</string>
<string key="candidateClassName">NSImageView</string>
</object>
<object class="IBToOneOutletInfo" key="tableToTop">
<string key="name">tableToTop</string>
<string key="candidateClassName">NSLayoutConstraint</string>

View File

@@ -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]];

View File

@@ -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];

View File

@@ -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];

View File

@@ -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];
}

View File

@@ -48,7 +48,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1508</string>
<string>1556</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>

View File

@@ -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

View File

@@ -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