Fixed memory leaks

Introduced Sorting
This commit is contained in:
michael starke
2013-05-11 23:56:49 +02:00
parent e33545a1de
commit ca4b8ee946
7 changed files with 71 additions and 5 deletions

View File

@@ -57,7 +57,7 @@
[[NSBundle mainBundle] loadNibNamed:@"PasswordCreatorWindow"owner:self topLevelObjects:nil];
}
if(!self.passwordCreatorController) {
self.passwordCreatorController = [[MPPasswordCreatorViewController alloc] init];
self.passwordCreatorController = [[[MPPasswordCreatorViewController alloc] init] autorelease];
}
[self.passwordCreatorWindow setContentView:[self.passwordCreatorController view]];
[self.passwordCreatorWindow makeKeyAndOrderFront:self.passwordCreatorWindow];

View File

@@ -9,6 +9,15 @@
#import <Cocoa/Cocoa.h>
#import "MPDatabaseVersion.h"
APPKIT_EXTERN NSString *const MPDocumentDidAddGroupNotification;
APPKIT_EXTERN NSString *const MPDocumentDidDelteGroupNotification;
APPKIT_EXTERN NSString *const MPDocumentDidAddEntryNotification;
APPKIT_EXTERN NSString *const MPDocumentDidDeleteEntryNotification;
APPKIT_EXTERN NSString *const MPDocumentEntryKey;
APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@class KdbGroup;
@class KdbEntry;
@@ -24,8 +33,12 @@
- (id)initWithVersion:(MPDatabaseVersion)version;
- (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL;
- (KdbGroup *)createGroup:(KdbGroup *)parent;
- (KdbEntry *)createEntry:(KdbGroup *)parent;
- (void)addGroup:(NSArray *)groupAndParent;
- (void)deleteEntry:(KdbEntry *)entry;
- (void)deleteGroup:(KdbGroup *)group;

View File

@@ -14,6 +14,15 @@
#import "KdbPassword.h"
#import "MPDatabaseVersion.h"
NSString *const MPDocumentDidAddGroupNotification = @"MPDocumentDidAddGroupNotification";
NSString *const MPDocumentDidDelteGroupNotification = @"MPDocumentDidDelteGroupNotification";
NSString *const MPDocumentDidAddEntryNotification = @"MPDocumentDidAddEntryNotification";
NSString *const MPDocumentDidDeleteEntryNotification = @"MPDocumentDidDeleteEntryNotification";
NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey";
NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
@interface MPDocument ()
@property (retain) KdbTree *tree;
@@ -58,6 +67,7 @@
- (void) makeWindowControllers {
MPDocumentWindowController *windowController = [[MPDocumentWindowController alloc] init];
[self addWindowController:windowController];
[windowController release];
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
@@ -128,7 +138,7 @@
- (KdbEntry *)createEntry:(KdbGroup *)parent {
KdbEntry *newEntry = [self.tree createEntry:parent];
newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry");
[[[self undoManager] prepareWithInvocationTarget:self] deleteEntry:newEntry];
[[self undoManager] registerUndoWithTarget:self selector:@selector(deleteEntry:) object:newEntry];
[[self undoManager] setActionName:NSLocalizedString(@"ADD_ENTRY_UNDO", @"Create Entry Undo")];
[parent addEntry:newEntry];
return newEntry;
@@ -138,13 +148,24 @@
KdbGroup *newGroup = [self.tree createGroup:parent];
newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
[[[self undoManager] prepareWithInvocationTarget:self] deleteGroup:newGroup];
[[self undoManager] registerUndoWithTarget:self selector:@selector(deleteGroup:) object:newGroup];
[[self undoManager] setActionName:NSLocalizedString(@"ADD_GROUP_UNDO", @"Create Group Undo")];
[parent addGroup:newGroup];
NSDictionary *userInfo = @{ MPDocumentGroupKey:newGroup };
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo];
self.isDirty = YES;
return newGroup;
}
- (void)addGroup:(NSArray *)groupAndParent{
KdbGroup *parent = groupAndParent[0];
KdbGroup *group = groupAndParent[1];
NSDictionary *userInfo = @{ MPDocumentGroupKey:group };
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo];
[parent addGroup:group];
}
- (void)deleteEntry:(KdbEntry *)entry {
if(entry.parent) {
[entry.parent removeEntry:entry];
@@ -154,7 +175,12 @@
- (void)deleteGroup:(KdbGroup *)group {
if(group.parent) {
[[self undoManager] registerUndoWithTarget:self selector:@selector(addGroup:) object:@[group.parent, group]];
[[self undoManager] setActionName:NSLocalizedString(@"DELETE_GROUP_UNDO", @"Create Group Undo")];
[group.parent removeGroup:group];
NSDictionary *userInfo = @{ MPDocumentEntryKey:group };
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidDelteGroupNotification object:self userInfo:userInfo];
self.isDirty = YES;
}
}

View File

@@ -151,6 +151,14 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
[passwordColumn setIdentifier:MPEntryTablePasswordColumnIdentifier];
[urlColumn setIdentifier:MPEntryTableURLColumnIdentifier];
NSSortDescriptor *titleColumSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES selector:@selector(compare:)];
NSSortDescriptor *userNameSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"username" ascending:YES selector:@selector(compare:)];
NSSortDescriptor *urlSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"url" ascending:YES selector:@selector(compare:)];
[titleColumn setSortDescriptorPrototype:titleColumSortDescriptor];
[userNameColumn setSortDescriptorPrototype:userNameSortDescriptor];
[urlColumn setSortDescriptorPrototype:urlSortDescriptor];
[[parentColumn headerCell] setStringValue:@"Group"];
[[titleColumn headerCell] setStringValue:@"Title"];
[[userNameColumn headerCell] setStringValue:@"Username"];
@@ -158,6 +166,8 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
[[urlColumn headerCell] setStringValue:@"URL"];
[self.entryTable bind:NSContentBinding toObject:self.entryArrayController withKeyPath:@"arrangedObjects" options:nil];
[self.entryTable bind:NSSortDescriptorsBinding toObject:self.entryArrayController withKeyPath:@"sortDescriptors" options:nil];
[parentColumn setHidden:YES];
}
#pragma mark NSTableViewDelgate

View File

@@ -22,6 +22,7 @@
@property (retain) NSMenu *menu;
- (void)_didUpdateData:(NSNotification *)notification;
- (NSMenu *)_contextMenu;
- (KdbGroup *)_clickedOrSelectedGroup;
@@ -38,6 +39,18 @@
if (self) {
self.outlineDelegate = [[[MPOutlineViewDelegate alloc] init] autorelease];
self.datasource = [[[MPOutlineDataSource alloc] init] autorelease];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didUpdateData:)
name:MPDocumentDidAddGroupNotification
object:[[self windowController] document]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didUpdateData:)
name:MPDocumentDidDelteGroupNotification
object:[[self windowController] document]];
}
return self;
@@ -116,5 +129,9 @@
return [self.outlineView itemAtRow:row];
}
- (void)_didUpdateData:(NSNotification *)notification {
[self.outlineView reloadData];
}
@end

View File

@@ -36,7 +36,7 @@
}
- (void)dealloc {
[self.pathControlDelegate release];
[_pathControlDelegate release];
[super dealloc];
}

View File

@@ -46,7 +46,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>67C</string>
<string>69B</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>