Changed templates and trash to simple property setter instead of custom functions

This commit is contained in:
michael starke
2013-12-03 00:39:51 +01:00
parent 1964adb439
commit 02a670ac7c
3 changed files with 40 additions and 42 deletions

View File

@@ -84,11 +84,11 @@
metaData.recycleBinEnabled = self.trashEnabled;
NSMenuItem *trashMenuItem = [self.selectRecycleBinGroupPopUpButton selectedItem];
KPKGroup *trashGroup = [trashMenuItem representedObject];
[_document useGroupAsTrash:trashGroup];
_document.trash = trashGroup;
NSMenuItem *templateMenuItem = [self.templateGroupPopUpButton selectedItem];
KPKGroup *templateGroup = [templateMenuItem representedObject];
[_document useGroupAsTemplate:templateGroup];
_document.templates = templateGroup;
BOOL protectNotes = [self.protectNotesCheckButton state] == NSOnState;
BOOL protectPassword = [self.protectPasswortCheckButton state] == NSOnState;

View File

@@ -46,9 +46,9 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@property (nonatomic, readonly, assign) BOOL encrypted;
@property (strong, readonly, nonatomic) KPKTree *tree;
@property (weak, readonly, nonatomic) KPKGroup *root;
@property (weak, readonly) KPKGroup *trash;
@property (weak, readonly) KPKGroup *templates;
@property (nonatomic, weak, readonly) KPKGroup *root;
@property (nonatomic, weak) KPKGroup *trash;
@property (nonatomic, weak) KPKGroup *templates;
@property (nonatomic, strong, readonly) KPKCompositeKey *compositeKey;
//@property (nonatomic, copy) NSString *password;
@@ -114,8 +114,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
- (NSArray *)allEntries;
- (NSArray *)allGroups;
- (void)useGroupAsTrash:(KPKGroup *)group;
- (void)useGroupAsTemplate:(KPKGroup *)group;
/**
* Determines, whether the given item is inside the trash.
* The trash group itself is not considered as trashed.

View File

@@ -308,6 +308,41 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
return self.tree.root;
}
- (KPKGroup *)trash {
static KPKGroup *_trash = nil;
if(self.useTrash) {
BOOL trashValid = [_trash.uuid isEqual:self.tree.metaData.recycleBinUuid];
if(!trashValid) {
_trash = [self findGroup:self.tree.metaData.recycleBinUuid];
}
return _trash;
}
return nil;
}
- (KPKGroup *)templates {
static KPKGroup *_templates = nil;
BOOL templateValid = [_templates.uuid isEqual:self.tree.metaData.entryTemplatesGroup];
if(!templateValid) {
_templates = [self findGroup:self.tree.metaData.entryTemplatesGroup];
}
return _templates;
}
- (void)setTrash:(KPKGroup *)trash {
if(self.useTrash) {
if(![self.tree.metaData.recycleBinUuid isEqual:trash.uuid]) {
self.tree.metaData.recycleBinUuid = trash.uuid;
}
}
}
- (void)setTemplates:(KPKGroup *)templates {
if(![self.tree.metaData.entryTemplatesGroup isEqual:templates.uuid]) {
self.tree.metaData.entryTemplatesGroup = templates.uuid;
}
}
- (void)setSelectedGroup:(KPKGroup *)selectedGroup {
if(_selectedGroup != selectedGroup) {
_selectedGroup = selectedGroup;
@@ -368,27 +403,6 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
return self.tree.metaData.recycleBinEnabled;
}
- (KPKGroup *)trash {
static KPKGroup *_trash = nil;
if(self.useTrash) {
BOOL trashValid = [_trash.uuid isEqual:self.tree.metaData.recycleBinUuid];
if(!trashValid) {
_trash = [self findGroup:self.tree.metaData.recycleBinUuid];
}
return _trash;
}
return nil;
}
- (KPKGroup *)templates {
static KPKGroup *_templates = nil;
BOOL templateValid = [_templates.uuid isEqual:self.tree.metaData.entryTemplatesGroup];
if(!templateValid) {
_templates = [self findGroup:self.tree.metaData.entryTemplatesGroup];
}
return _templates;
}
- (BOOL)isItemTrashed:(id)item {
BOOL validItem = [item isKindOfClass:[KPKEntry class]] || [item isKindOfClass:[KPKGroup class]];
if(!item) {
@@ -409,20 +423,6 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
return NO;
}
- (void)useGroupAsTrash:(KPKGroup *)group {
if(self.useTrash) {
if(![self.tree.metaData.recycleBinUuid isEqual:group.uuid]) {
self.tree.metaData.recycleBinUuid = group.uuid;
}
}
}
- (void)useGroupAsTemplate:(KPKGroup *)group {
if(![self.tree.metaData.entryTemplatesGroup isEqual:group.uuid]) {
self.tree.metaData.entryTemplatesGroup = group.uuid;
}
}
#pragma mark Data manipulation
- (KPKEntry *)createEntry:(KPKGroup *)parent {
if(!parent) {