mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 15:12:21 +00:00
Merged deleteGroup and deleteEntry call into delteNode
This commit is contained in:
@@ -150,8 +150,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
||||
- (KPKAttribute *)createCustomAttribute:(KPKEntry *)entry;
|
||||
|
||||
- (void)deleteNode:(KPKNode *)node;
|
||||
- (void)deleteGroup:(KPKGroup *)group;
|
||||
- (void)deleteEntry:(KPKEntry *)entry;
|
||||
|
||||
#pragma mark Actions
|
||||
/**
|
||||
|
||||
@@ -508,57 +508,41 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
||||
}
|
||||
|
||||
- (void)deleteNode:(KPKNode *)node {
|
||||
if(node.asGroup) {
|
||||
[self deleteGroup:node.asGroup];
|
||||
if(!node.asEntry && !node.asGroup) {
|
||||
return; // Nothing do
|
||||
}
|
||||
else if(node.asEntry) {
|
||||
[self deleteEntry:node.asEntry];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deleteEntry:(KPKEntry *)entry {
|
||||
if(!entry) {
|
||||
return; // Nothing to do;
|
||||
}
|
||||
if(entry.isTrashed) {
|
||||
[self _presentTrashAlertForItem:entry];
|
||||
if(node.isTrashed) {
|
||||
[self _presentTrashAlertForItem:node];
|
||||
return;
|
||||
}
|
||||
[entry trashOrRemove];
|
||||
[node trashOrRemove];
|
||||
BOOL permanent = (nil == self.trash);
|
||||
if(node.asGroup) {
|
||||
[self.undoManager setActionName:permanent ? NSLocalizedString(@"DELETE_GROUP", "Delete Group") : NSLocalizedString(@"TRASH_GROUP", "Move Group to Trash")];
|
||||
if(self.selectedGroup == node) {
|
||||
self.selectedGroup = nil;
|
||||
}
|
||||
}
|
||||
else if(node.asEntry) {
|
||||
[self.undoManager setActionName:permanent ? NSLocalizedString(@"DELETE_ENTRY", "") : NSLocalizedString(@"TRASH_ENTRY", "Move Entry to Trash")];
|
||||
|
||||
if(self.selectedEntry == entry) {
|
||||
if(self.selectedEntry == node) {
|
||||
self.selectedEntry = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deleteGroup:(KPKGroup *)group {
|
||||
if(!group) {
|
||||
return; // Nothing to do;
|
||||
}
|
||||
if(group.isTrashed) {
|
||||
[self _presentTrashAlertForItem:group];
|
||||
return;
|
||||
}
|
||||
[group trashOrRemove];
|
||||
BOOL permanent = (nil == self.trash);
|
||||
[self.undoManager setActionName:permanent ? NSLocalizedString(@"DELETE_GROUP", "Delete Group") : NSLocalizedString(@"TRASH_GROUP", "Move Group to Trash")];
|
||||
}
|
||||
|
||||
#pragma mark Actions
|
||||
- (void)emptyTrash:(id)sender {
|
||||
NSAlert *alert = [[NSAlert alloc] init];
|
||||
[alert setAlertStyle:NSWarningAlertStyle];
|
||||
[alert setMessageText:NSLocalizedString(@"WARNING_ON_EMPTY_TRASH_TITLE", "")];
|
||||
[alert setInformativeText:NSLocalizedString(@"WARNING_ON_EMPTY_TRASH_DESCRIPTION", "Informative Text displayed when clearing the Trash")];
|
||||
alert.alertStyle = NSWarningAlertStyle;
|
||||
alert.messageText = NSLocalizedString(@"WARNING_ON_EMPTY_TRASH_TITLE", "");
|
||||
alert.informativeText = NSLocalizedString(@"WARNING_ON_EMPTY_TRASH_DESCRIPTION", "Informative Text displayed when clearing the Trash");
|
||||
|
||||
[alert addButtonWithTitle:NSLocalizedString(@"EMPTY_TRASH", "Empty Trash")];
|
||||
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")];
|
||||
alert.buttons.lastObject.keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b];
|
||||
|
||||
[[alert buttons][1] setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x1b]];
|
||||
|
||||
NSWindow *window = [[self windowControllers][0] window];
|
||||
[alert beginSheetModalForWindow:window modalDelegate:self didEndSelector:@selector(_emptyTrashAlertDidEnd:returnCode:contextInfo:) contextInfo:NULL];
|
||||
[alert beginSheetModalForWindow:self.windowForSheet modalDelegate:self didEndSelector:@selector(_emptyTrashAlertDidEnd:returnCode:contextInfo:) contextInfo:NULL];
|
||||
}
|
||||
|
||||
- (void)_emptyTrashAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
|
||||
@@ -571,17 +555,16 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
||||
KPKEntry *entry = node.asEntry;
|
||||
|
||||
NSAlert *alert = [[NSAlert alloc] init];
|
||||
[alert setAlertStyle:NSWarningAlertStyle];
|
||||
[alert setMessageText:NSLocalizedString(@"WARNING_ON_DELETE_TRASHED_NODE_TITLE", "")];
|
||||
[alert setInformativeText:NSLocalizedString(@"WARNING_ON_DELETE_TRASHED_NODE_DESCRIPTION", "Informative Text displayed when clearing the Trash")];
|
||||
alert.alertStyle = NSWarningAlertStyle;
|
||||
alert.messageText = NSLocalizedString(@"WARNING_ON_DELETE_TRASHED_NODE_TITLE", "");
|
||||
alert.informativeText = NSLocalizedString(@"WARNING_ON_DELETE_TRASHED_NODE_DESCRIPTION", "Informative Text displayed when clearing the Trash");
|
||||
|
||||
NSString *okButtonText = entry ? NSLocalizedString(@"DELETE_TRASHED_ENTRY", "Empty Trash") : NSLocalizedString(@"DELETE_TRASHED_GROUP", "Empty Trash");
|
||||
[alert addButtonWithTitle:okButtonText];
|
||||
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")];
|
||||
alert.buttons.lastObject.keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b];
|
||||
|
||||
[[alert buttons][1] setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x1b]];
|
||||
|
||||
NSWindow *window = [[self windowControllers][0] window];
|
||||
[alert beginSheetModalForWindow:window modalDelegate:self didEndSelector:@selector(_deleteTrashedItemAlertDidEnd:returnCode:contextInfo:) contextInfo:(__bridge void *)(node)];
|
||||
[alert beginSheetModalForWindow:self.windowForSheet modalDelegate:self didEndSelector:@selector(_deleteTrashedItemAlertDidEnd:returnCode:contextInfo:) contextInfo:(__bridge void *)(node)];
|
||||
}
|
||||
|
||||
- (void)_deleteTrashedItemAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
|
||||
|
||||
@@ -382,7 +382,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
||||
if(entry) {
|
||||
return entry;
|
||||
}
|
||||
MPDocument *document = [[self windowController] document];
|
||||
MPDocument *document = self.windowController.document;
|
||||
return document.selectedItem;
|
||||
}
|
||||
|
||||
@@ -702,8 +702,9 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
||||
if(!entry) {
|
||||
return;
|
||||
}
|
||||
MPDocument *document = [[self windowController] document];
|
||||
[document deleteEntry:entry];
|
||||
|
||||
MPDocument *document = self.windowController.document;
|
||||
[document deleteNode:entry];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user