Cleaned up code

Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
michael starke
2015-12-07 19:30:10 +01:00
parent 204f413560
commit 54b11f9b7b

View File

@@ -67,6 +67,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
@property (nonatomic, strong) KPKCompositeKey *compositeKey; @property (nonatomic, strong) KPKCompositeKey *compositeKey;
@property (nonatomic, strong) NSData *encryptedData; @property (nonatomic, strong) NSData *encryptedData;
@property (nonatomic, strong) MPTreeDelegate *treeDelgate; @property (nonatomic, strong) MPTreeDelegate *treeDelgate;
@property (copy) NSDate *lastLoadedModificationDate;
@property (assign) BOOL readOnly; @property (assign) BOOL readOnly;
@property (strong) NSURL *lockFileURL; @property (strong) NSURL *lockFileURL;
@@ -176,18 +177,18 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
} }
return NO; return NO;
} }
[self _watchForFileChanges:NO];
NSData *treeData = [self.tree encryptWithPassword:self.compositeKey forVersion:version error:outError]; NSData *treeData = [self.tree encryptWithPassword:self.compositeKey forVersion:version error:outError];
BOOL sucess = [treeData writeToURL:url options:0 error:outError]; BOOL sucess = [treeData writeToURL:url options:0 error:outError];
if(!sucess) { if(!sucess) {
NSLog(@"%@", [*outError localizedDescription]); NSLog(@"%@", [*outError localizedDescription]);
} }
[self _watchForFileChanges:YES]; else {
self.lastLoadedModificationDate = [NSDate date];
}
return sucess; return sucess;
} }
- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError { - (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
[self _watchForFileChanges:YES];
/* FIXME: Lockfile handling /* FIXME: Lockfile handling
self.lockFileURL = [url URLByAppendingPathExtension:@"lock"]; self.lockFileURL = [url URLByAppendingPathExtension:@"lock"];
if([[NSFileManager defaultManager] fileExistsAtPath:[_lockFileURL path]]) { if([[NSFileManager defaultManager] fileExistsAtPath:[_lockFileURL path]]) {
@@ -204,6 +205,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
*/ */
self.tree = nil; self.tree = nil;
self.encryptedData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:outError]; self.encryptedData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:outError];
self.lastLoadedModificationDate = self.fileModificationDate;
return YES; return YES;
} }
@@ -226,8 +228,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
We store the last url. Restored windows are automatically handled. We store the last url. Restored windows are automatically handled.
If closeAllDocuments is set, all docs get this message If closeAllDocuments is set, all docs get this message
*/ */
if([[self fileURL] isFileURL]) { if(self.fileURL.isFileURL) {
[[NSUserDefaults standardUserDefaults] setObject:[self.fileURL absoluteString] forKey:kMPSettingsKeyLastDatabasePath]; [[NSUserDefaults standardUserDefaults] setObject:self.fileURL.absoluteString forKey:kMPSettingsKeyLastDatabasePath];
} }
self.tree = nil; self.tree = nil;
[super close]; [super close];
@@ -720,21 +722,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
} }
} }
/*
- (KPKGroup *)_createTrashGroup {
KPKGroup *trash = [self.tree createGroup:self.tree.root];
BOOL wasEnabled = [self.undoManager isUndoRegistrationEnabled];
[self.undoManager disableUndoRegistration];
trash.title = NSLocalizedString(@"TRASH", @"Name for the trash group");
trash.iconId = MPIconTrash;
[self.tree.root addGroup:trash];
if(wasEnabled) {
[self.undoManager enableUndoRegistration];
}
self.tree.metaData.trashUuid = trash.uuid;
return trash;
}
*/
- (void)_emptyTrash { - (void)_emptyTrash {
for(KPKEntry *entry in [self.trash childEntries]) { for(KPKEntry *entry in [self.trash childEntries]) {
[[self undoManager] removeAllActionsWithTarget:entry]; [[self undoManager] removeAllActionsWithTarget:entry];
@@ -756,10 +743,4 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
return self.selectedGroup; return self.selectedGroup;
} }
# pragma mark File Watching
- (void) _watchForFileChanges:(BOOL)watch {
}
@end @end