Added duplicate group as context menu action

This commit is contained in:
Michael Starke
2019-08-16 17:24:54 +02:00
parent 245a58d81b
commit 7d8bb85d9b
16 changed files with 55 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ typedef NS_ENUM(NSUInteger, MPActionType) {
MPActionAddGroup, // Add a new group MPActionAddGroup, // Add a new group
MPActionDuplicateEntry, // Simply duplicate an entry (including history) MPActionDuplicateEntry, // Simply duplicate an entry (including history)
MPActionDuplicateEntryWithOptions, // Request user input on what to duplicate MPActionDuplicateEntryWithOptions, // Request user input on what to duplicate
MPActionDuplicateGroup, // Duplicate the group and all it's children
MPActionReverToHistoryEntry, // Restore an entry to an older state in history MPActionReverToHistoryEntry, // Restore an entry to an older state in history
MPActionDelete, // Delete entry or group MPActionDelete, // Delete entry or group
MPActionCopyUsername, // copy username to pasteboard MPActionCopyUsername, // copy username to pasteboard

View File

@@ -38,6 +38,7 @@
@(MPActionAddGroup): NSStringFromSelector(@selector(createGroup:)), @(MPActionAddGroup): NSStringFromSelector(@selector(createGroup:)),
@(MPActionDuplicateEntry): NSStringFromSelector(@selector(duplicateEntry:)), @(MPActionDuplicateEntry): NSStringFromSelector(@selector(duplicateEntry:)),
@(MPActionDuplicateEntryWithOptions): NSStringFromSelector(@selector(duplicateEntryWithOptions:)), @(MPActionDuplicateEntryWithOptions): NSStringFromSelector(@selector(duplicateEntryWithOptions:)),
@(MPActionDuplicateGroup): NSStringFromSelector(@selector(duplicateGroup:)),
@(MPActionReverToHistoryEntry): NSStringFromSelector(@selector(revertToHistoryEntry:)), @(MPActionReverToHistoryEntry): NSStringFromSelector(@selector(revertToHistoryEntry:)),
@(MPActionCopyPassword): NSStringFromSelector(@selector(copyPassword:)), @(MPActionCopyPassword): NSStringFromSelector(@selector(copyPassword:)),
@(MPActionCopyURL): NSStringFromSelector(@selector(copyURL:)), @(MPActionCopyURL): NSStringFromSelector(@selector(copyURL:)),

View File

@@ -31,7 +31,7 @@ typedef NS_OPTIONS(NSUInteger, MPContextMenuItemsFlags) {
MPContextMenuAutotype = 1 << 5, MPContextMenuAutotype = 1 << 5,
MPContextMenuHistory = 1 << 6, MPContextMenuHistory = 1 << 6,
MPContextMenuShowGroupInOutline = 1 << 7, MPContextMenuShowGroupInOutline = 1 << 7,
MPContextMenuMinimal = MPContextMenuCreate | MPContextMenuDelete, MPContextMenuMinimal = MPContextMenuCreate | MPContextMenuDelete | MPContextMenuDuplicate,
MPContextMenuFull = MPContextMenuMinimal | MPContextMenuCopy | MPContextMenuDuplicate | MPContextMenuAutotype | MPContextMenuHistory, MPContextMenuFull = MPContextMenuMinimal | MPContextMenuCopy | MPContextMenuDuplicate | MPContextMenuAutotype | MPContextMenuHistory,
MPContextMenuExtended = MPContextMenuFull | MPContextMenuTrash MPContextMenuExtended = MPContextMenuFull | MPContextMenuTrash
}; };

View File

@@ -64,8 +64,11 @@ static void MPContextmenuHelperBeginSection(NSMutableArray *items) {
NSMenuItem *duplicateEntyWithOptions = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DUPLICATE_ENTRY_WITH_OPTIONS", @"Menu item to duplicate an entry with options how to duplicate. Will present a dialog.") NSMenuItem *duplicateEntyWithOptions = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DUPLICATE_ENTRY_WITH_OPTIONS", @"Menu item to duplicate an entry with options how to duplicate. Will present a dialog.")
action:[MPActionHelper actionOfType:MPActionDuplicateEntryWithOptions] action:[MPActionHelper actionOfType:MPActionDuplicateEntryWithOptions]
keyEquivalent:@""]; keyEquivalent:@""];
NSMenuItem *duplicateGroup = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DUPLICATE_GROUP", @"Menu item to directly diplicate a group")
[items addObjectsFromArray:@[ duplicateEntry, duplicateEntyWithOptions ]]; action:[MPActionHelper actionOfType:MPActionDuplicateGroup]
keyEquivalent:@""];
[items addObjectsFromArray:@[ duplicateEntry, duplicateEntyWithOptions, duplicateGroup ]];
} }
if(insertDelete || insertTrash) { if(insertDelete || insertTrash) {

View File

@@ -165,7 +165,6 @@ FOUNDATION_EXPORT NSString *const MPDocumentGroupKey;
- (void)deleteNode:(KPKNode *)node; - (void)deleteNode:(KPKNode *)node;
- (void)duplicateEntryWithOptions:(KPKCopyOptions)options; - (void)duplicateEntryWithOptions:(KPKCopyOptions)options;
#pragma mark Actions #pragma mark Actions
/** /**
* Empties the Trash group. Removing all Groups and Entries inside. This action is not undo-able * Empties the Trash group. Removing all Groups and Entries inside. This action is not undo-able
@@ -179,6 +178,7 @@ FOUNDATION_EXPORT NSString *const MPDocumentGroupKey;
*/ */
- (IBAction)createEntryFromTemplate:(id)sender; - (IBAction)createEntryFromTemplate:(id)sender;
- (IBAction)duplicateEntry:(id)sender; - (IBAction)duplicateEntry:(id)sender;
- (IBAction)duplicateGroup:(id)sender;
@end @end

View File

@@ -828,7 +828,16 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
KPKEntry *duplicate = [entry copyWithTitle:nil options:options]; KPKEntry *duplicate = [entry copyWithTitle:nil options:options];
[duplicate addToGroup:entry.parent]; [duplicate addToGroup:entry.parent];
} }
[self.undoManager setActionName:[NSString stringWithFormat:NSLocalizedString(@"DUPLICATE_ENTRIES_%ld", @"Action name for duplicating entries"), self.selectedEntries.count]]; [self.undoManager setActionName:[NSString stringWithFormat:NSLocalizedString(@"DUPLICATE_ENTRIES_ACTION_NAME", @"Action name for duplicating entries"), self.selectedEntries.count]];
}
- (void)duplicateGroup:(id)sender {
for(KPKGroup *group in self.selectedGroups) {
KPKGroup *duplicate = [group copyWithTitle:nil options:kKPKCopyOptionNone];
/* if group is root group, add the duplicate below */
[duplicate addToGroup:(group.parent ? group.parent : group)];
}
[self.undoManager setActionName:[NSString stringWithFormat:NSLocalizedString(@"DUPLICATE_GROUPS_ACTION_NAME", @"Action name for duplicating groups"), self.selectedGroups.count]];
} }
#pragma mark Validation #pragma mark Validation
@@ -886,6 +895,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
valid &= targetEntries.count > 0; valid &= targetEntries.count > 0;
valid &= !self.historyEntry; valid &= !self.historyEntry;
break; break;
case MPActionDuplicateGroup:
valid &= targetGroups.count > 0;
break;
case MPActionEmptyTrash: case MPActionEmptyTrash:
valid &= (self.trash.groups.count + self.trash.entries.count) > 0; valid &= (self.trash.groups.count + self.trash.entries.count) > 0;
break; break;

View File

@@ -57,7 +57,7 @@ NSString *const _MPOutlineMenuTemplate = @"Template";
if( [item isKindOfClass:KPKGroup.class]) { if( [item isKindOfClass:KPKGroup.class]) {
KPKGroup *group = (KPKGroup *)item; KPKGroup *group = (KPKGroup *)item;
MPDocument *document = [NSDocumentController sharedDocumentController].currentDocument; MPDocument *document = NSDocumentController.sharedDocumentController.currentDocument;
if(group && document.root == group ) { if(group && document.root == group ) {
} }

View File

@@ -20,7 +20,7 @@
<string>alle Zeichen ausgewählt</string> <string>alle Zeichen ausgewählt</string>
</dict> </dict>
</dict> </dict>
<key>DUPLICATE_ENTRIES_%ld</key> <key>DUPLICATE_ENTRIES_ACTION_NAME</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
<string>%#@entries@</string> <string>%#@entries@</string>

View File

@@ -304,7 +304,7 @@
"DRAG_GROUP" = "Drag Group"; "DRAG_GROUP" = "Drag Group";
/* Action name for duplicating entries */ /* Action name for duplicating entries */
"DUPLICATE_ENTRIES_%ld" = "Duplicate Entries %ld"; "DUPLICATE_ENTRIES_ACTION_NAME" = "Duplicate Entries";
/* Menu item to directly diplicate an entry */ /* Menu item to directly diplicate an entry */
"DUPLICATE_ENTRY" = "Duplicate Entry"; "DUPLICATE_ENTRY" = "Duplicate Entry";
@@ -312,6 +312,12 @@
/* Menu item to duplicate an entry with options how to duplicate. Will present a dialog. */ /* Menu item to duplicate an entry with options how to duplicate. Will present a dialog. */
"DUPLICATE_ENTRY_WITH_OPTIONS" = "Duplicate Entry…"; "DUPLICATE_ENTRY_WITH_OPTIONS" = "Duplicate Entry…";
/* Menu item to directly diplicate a group */
"DUPLICATE_GROUP" = "Duplicate Group";
/* Action name for duplicating groups */
"DUPLICATE_GROUPS_ACTION_NAME" = "Duplicate Group";
/* Menu item in the database outline context menu to change the template group /* Menu item in the database outline context menu to change the template group
Menu item on the add entry context menu to edit template groups */ Menu item on the add entry context menu to edit template groups */
"EDIT_TEMPLATE_GROUP" = "Edit Entry Template Group"; "EDIT_TEMPLATE_GROUP" = "Edit Entry Template Group";

View File

@@ -2,6 +2,22 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>DUPLICATE_GROUPS_ACTION_NAME</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@groups@</string>
<key>groups</key>
<dict>
<key>NSStringFormatValueTypeKey</key>
<string>ld</string>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>one</key>
<string>Duplicate Group</string>
<key>other</key>
<string>Duplicate Groups</string>
</dict>
</dict>
<key>%ld_CHARACTERS_TO_PICK_REMAINING</key> <key>%ld_CHARACTERS_TO_PICK_REMAINING</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
@@ -20,7 +36,7 @@
<string>All characters picked</string> <string>All characters picked</string>
</dict> </dict>
</dict> </dict>
<key>DUPLICATE_ENTRIES_%ld</key> <key>DUPLICATE_ENTRIES_ACTION_NAME</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
<string>%#@entries@</string> <string>%#@entries@</string>

View File

@@ -20,7 +20,7 @@
<string>Todos los caracteres seleccionados</string> <string>Todos los caracteres seleccionados</string>
</dict> </dict>
</dict> </dict>
<key>DUPLICATE_ENTRIES_%ld</key> <key>DUPLICATE_ENTRIES_ACTION_NAME</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
<string>%#@entries@</string> <string>%#@entries@</string>

View File

@@ -20,7 +20,7 @@
<string>Tous les caractères ont été choisis</string> <string>Tous les caractères ont été choisis</string>
</dict> </dict>
</dict> </dict>
<key>DUPLICATE_ENTRIES_%ld</key> <key>DUPLICATE_ENTRIES_ACTION_NAME</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
<string>%#@entries@</string> <string>%#@entries@</string>
@@ -31,7 +31,7 @@
<key>NSStringFormatValueTypeKey</key> <key>NSStringFormatValueTypeKey</key>
<string>ld</string> <string>ld</string>
<key>one</key> <key>one</key>
<string>Dupliquer l'entrée</string> <string>Dupliquer l&apos;entrée</string>
<key>other</key> <key>other</key>
<string>Dupliquer les entrées</string> <string>Dupliquer les entrées</string>
<key>zero</key> <key>zero</key>

View File

@@ -20,7 +20,7 @@
<string>Alle tekens gekozen</string> <string>Alle tekens gekozen</string>
</dict> </dict>
</dict> </dict>
<key>DUPLICATE_ENTRIES_%ld</key> <key>DUPLICATE_ENTRIES_ACTION_NAME</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
<string>%#@entries@</string> <string>%#@entries@</string>

View File

@@ -24,7 +24,7 @@
<string>Wybrano wszystkie znaki</string> <string>Wybrano wszystkie znaki</string>
</dict> </dict>
</dict> </dict>
<key>DUPLICATE_ENTRIES_%ld</key> <key>DUPLICATE_ENTRIES_ACTION_NAME</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
<string>%#@wpisów@</string> <string>%#@wpisów@</string>

View File

@@ -24,7 +24,7 @@
<string>Выбраны все символы</string> <string>Выбраны все символы</string>
</dict> </dict>
</dict> </dict>
<key>DUPLICATE_ENTRIES_%ld</key> <key>DUPLICATE_ENTRIES_ACTION_NAME</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
<string>%#@entries@</string> <string>%#@entries@</string>

View File

@@ -20,7 +20,7 @@
<string>Alla tecken valda</string> <string>Alla tecken valda</string>
</dict> </dict>
</dict> </dict>
<key>DUPLICATE_ENTRIES_%ld</key> <key>DUPLICATE_ENTRIES_ACTION_NAME</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>
<string>%#@entries@</string> <string>%#@entries@</string>