mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-17 15:59:24 +00:00
Added rudimentary export plugin support
This commit is contained in:
@@ -151,9 +151,9 @@
|
|||||||
<action selector="mergeWithOther:" target="-1" id="OyM-CZ-TDD"/>
|
<action selector="mergeWithOther:" target="-1" id="OyM-CZ-TDD"/>
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
<menuItem title="Import" id="aTb-sW-nUd">
|
<menuItem title="Import From" id="aTb-sW-nUd">
|
||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
<menu key="submenu" title="Import" id="4q9-u1-pcm">
|
<menu key="submenu" title="Import From" id="4q9-u1-pcm">
|
||||||
<items>
|
<items>
|
||||||
<menuItem title="XML…" id="rW0-r1-QYL">
|
<menuItem title="XML…" id="rW0-r1-QYL">
|
||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
@@ -167,16 +167,20 @@
|
|||||||
</connections>
|
</connections>
|
||||||
</menu>
|
</menu>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
<menuItem title="Export" id="tz9-yK-pOf">
|
<menuItem title="Export To" id="tz9-yK-pOf">
|
||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
<menu key="submenu" title="Export" id="p8h-Fg-h1O">
|
<menu key="submenu" title="Export To" id="p8h-Fg-h1O">
|
||||||
<items>
|
<items>
|
||||||
<menuItem title="XML…" keyEquivalent="E" id="1259">
|
<menuItem title="XML…" id="1259">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="exportAsXML:" target="-1" id="NCG-gr-YI5"/>
|
<action selector="exportAsXML:" target="-1" id="NCG-gr-YI5"/>
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
</items>
|
</items>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="494" id="ALY-P3-PzW"/>
|
||||||
|
</connections>
|
||||||
</menu>
|
</menu>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
<menuItem isSeparatorItem="YES" id="74">
|
<menuItem isSeparatorItem="YES" id="74">
|
||||||
@@ -357,6 +361,7 @@ CA
|
|||||||
</menu>
|
</menu>
|
||||||
<customObject id="494" customClass="MPAppDelegate">
|
<customObject id="494" customClass="MPAppDelegate">
|
||||||
<connections>
|
<connections>
|
||||||
|
<outlet property="exportMenu" destination="p8h-Fg-h1O" id="elV-BC-ZZt"/>
|
||||||
<outlet property="fileNewMenuItem" destination="82" id="BUX-dy-HS2"/>
|
<outlet property="fileNewMenuItem" destination="82" id="BUX-dy-HS2"/>
|
||||||
<outlet property="fixAutotypeMenuItem" destination="nx7-Vf-LiD" id="5n1-bG-JxJ"/>
|
<outlet property="fixAutotypeMenuItem" destination="nx7-Vf-LiD" id="5n1-bG-JxJ"/>
|
||||||
<outlet property="importMenu" destination="4q9-u1-pcm" id="0XM-fS-Vyy"/>
|
<outlet property="importMenu" destination="4q9-u1-pcm" id="0XM-fS-Vyy"/>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ APPKIT_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
|
|||||||
@property (strong) IBOutlet NSMenuItem *fileNewMenuItem;
|
@property (strong) IBOutlet NSMenuItem *fileNewMenuItem;
|
||||||
@property (strong) IBOutlet NSMenu *itemMenu;
|
@property (strong) IBOutlet NSMenu *itemMenu;
|
||||||
@property (strong) IBOutlet NSMenu *importMenu;
|
@property (strong) IBOutlet NSMenu *importMenu;
|
||||||
|
@property (strong) IBOutlet NSMenu *exportMenu;
|
||||||
|
|
||||||
@property (strong, readonly) MPEntryContextMenuDelegate *itemActionMenuDelegate;
|
@property (strong, readonly) MPEntryContextMenuDelegate *itemActionMenuDelegate;
|
||||||
|
|
||||||
|
|||||||
@@ -240,22 +240,36 @@ typedef NS_OPTIONS(NSInteger, MPAppStartupState) {
|
|||||||
NSString *saveTitle = displayDots ? NSLocalizedString(@"SAVE_WITH_DOTS", "Save file menu item title when save will prompt for a location to save or ask for a password/key") : NSLocalizedString(@"SAVE", "Save file menu item title when save will just save the file");
|
NSString *saveTitle = displayDots ? NSLocalizedString(@"SAVE_WITH_DOTS", "Save file menu item title when save will prompt for a location to save or ask for a password/key") : NSLocalizedString(@"SAVE", "Save file menu item title when save will just save the file");
|
||||||
self.saveMenuItem.title = saveTitle;
|
self.saveMenuItem.title = saveTitle;
|
||||||
}
|
}
|
||||||
if(menu == self.fixAutotypeMenuItem.menu) {
|
else if(menu == self.fixAutotypeMenuItem.menu) {
|
||||||
self.fixAutotypeMenuItem.hidden = !(NSEvent.modifierFlags & NSAlternateKeyMask);
|
self.fixAutotypeMenuItem.hidden = !(NSEvent.modifierFlags & NSAlternateKeyMask);
|
||||||
}
|
}
|
||||||
if(menu == self.importMenu) {
|
else if(menu == self.importMenu) {
|
||||||
NSMenuItem *exportXML = menu.itemArray.firstObject;
|
NSMenuItem *exportXML = menu.itemArray.firstObject;
|
||||||
[menu removeAllItems];
|
[menu removeAllItems];
|
||||||
|
[menu addItem:exportXML];
|
||||||
for(MPPlugin<MPImportPlugin> * plugin in MPPluginHost.sharedHost.importPlugins) {
|
for(MPPlugin<MPImportPlugin> * plugin in MPPluginHost.sharedHost.importPlugins) {
|
||||||
NSMenuItem *importItem = [[NSMenuItem alloc] init];
|
NSMenuItem *importItem = [[NSMenuItem alloc] init];
|
||||||
[plugin prepareImportMenuItem:importItem];
|
[plugin prepareImportMenuItem:importItem];
|
||||||
importItem.submenu = nil; // kill any potential submenu!
|
importItem.submenu = nil; // kill any potential submenu!
|
||||||
importItem.representedObject = plugin.identifier;
|
importItem.representedObject = plugin.identifier;
|
||||||
importItem.target = nil;
|
importItem.target = nil;
|
||||||
importItem.action = @selector(importFromPlugin:);
|
importItem.action = @selector(importWithPlugin:);
|
||||||
[menu addItem:importItem];
|
[menu addItem:importItem];
|
||||||
}
|
}
|
||||||
[menu insertItem:exportXML atIndex:0];
|
}
|
||||||
|
else if(menu == self.exportMenu) {
|
||||||
|
NSMenuItem *importXML = menu.itemArray.firstObject;
|
||||||
|
[menu removeAllItems];
|
||||||
|
[menu addItem:importXML];
|
||||||
|
for(MPPlugin<MPExportPlugin> * plugin in MPPluginHost.sharedHost.exportPlugins) {
|
||||||
|
NSMenuItem *exportItem = [[NSMenuItem alloc] init];
|
||||||
|
[plugin prepareExportMenuItem:exportItem];
|
||||||
|
exportItem.submenu = nil; // kill any potential submenu!
|
||||||
|
exportItem.representedObject = plugin.identifier;
|
||||||
|
exportItem.target = nil;
|
||||||
|
exportItem.action = @selector(exportWithPlugin:);
|
||||||
|
[menu addItem:exportItem];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,8 @@
|
|||||||
- (IBAction)exportAsXML:(id)sender;
|
- (IBAction)exportAsXML:(id)sender;
|
||||||
- (IBAction)mergeWithOther:(id)sender;
|
- (IBAction)mergeWithOther:(id)sender;
|
||||||
- (IBAction)importFromXML:(id)sender;
|
- (IBAction)importFromXML:(id)sender;
|
||||||
- (IBAction)importFromPlugin:(id)sender;
|
- (IBAction)importWithPlugin:(id)sender;
|
||||||
|
- (IBAction)exportWithPlugin:(id)sender;
|
||||||
|
|
||||||
- (IBAction)lock:(id)sender;
|
- (IBAction)lock:(id)sender;
|
||||||
- (IBAction)createGroup:(id)sender;
|
- (IBAction)createGroup:(id)sender;
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)importFromPlugin:(id)sender {
|
- (void)importWithPlugin:(id)sender {
|
||||||
if(![sender isKindOfClass:NSMenuItem.class]) {
|
if(![sender isKindOfClass:NSMenuItem.class]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -304,6 +304,30 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)exportWithPlugin:(id)sender {
|
||||||
|
if(![sender isKindOfClass:NSMenuItem.class]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NSMenuItem *menuItem = sender;
|
||||||
|
if(![menuItem.representedObject isKindOfClass:NSString.class]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSWindow *sheetWindow = ((MPDocument *)self.document).windowForSheet;
|
||||||
|
if(!sheetWindow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NSString *bundleIdentifier = menuItem.representedObject;
|
||||||
|
MPPlugin<MPExportPlugin> *exportPlugin = (MPPlugin<MPExportPlugin> *)[MPPluginHost.sharedHost pluginWithBundleIdentifier:bundleIdentifier];
|
||||||
|
NSSavePanel *savePanel = NSSavePanel.savePanel;
|
||||||
|
[exportPlugin prepareSavePanel:savePanel];
|
||||||
|
[savePanel beginSheetModalForWindow:sheetWindow completionHandler:^(NSModalResponse result) {
|
||||||
|
if(result == NSModalResponseOK) {
|
||||||
|
[exportPlugin exportTree:((MPDocument *)self.document).tree forRunningSavePanel:savePanel];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)mergeWithOther:(id)sender {
|
- (void)mergeWithOther:(id)sender {
|
||||||
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
||||||
MPDocument *document = self.document;
|
MPDocument *document = self.document;
|
||||||
|
|||||||
@@ -141,9 +141,20 @@ FOUNDATION_EXPORT NSString *const MPPluginDescriptionInfoDictionaryKey;
|
|||||||
@param panel The open panel used for selecting what file(s) to import
|
@param panel The open panel used for selecting what file(s) to import
|
||||||
@return The KPKTree constructed from the selected input file(s)
|
@return The KPKTree constructed from the selected input file(s)
|
||||||
*/
|
*/
|
||||||
- (KPKTree *)treeForRunningOpenPanel:(NSOpenPanel *)panel;
|
- (nullable KPKTree *)treeForRunningOpenPanel:(NSOpenPanel *)panel;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@protocol MPExportPlugin <NSObject>
|
||||||
|
|
||||||
|
@required
|
||||||
|
|
||||||
|
- (void)prepareExportMenuItem:(NSMenuItem *)item;
|
||||||
|
- (void)prepareSavePanel:(NSSavePanel *)panel;
|
||||||
|
- (void)exportTree:(KPKTree *)tree forRunningSavePanel:(NSSavePanel *)panel;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Deprecated
|
#pragma mark Deprecated
|
||||||
|
|
||||||
@interface MPPlugin (Deprecated)
|
@interface MPPlugin (Deprecated)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ FOUNDATION_EXPORT NSString *const MPPluginHostPluginBundleIdentifiyerKey;
|
|||||||
@class MPPlugin;
|
@class MPPlugin;
|
||||||
@class KPKEntry;
|
@class KPKEntry;
|
||||||
@protocol MPImportPlugin;
|
@protocol MPImportPlugin;
|
||||||
|
@protocol MPExportPlugin;
|
||||||
@protocol MPAutotypeWindowTitleResolverPlugin;
|
@protocol MPAutotypeWindowTitleResolverPlugin;
|
||||||
|
|
||||||
@interface MPPluginHost : NSObject
|
@interface MPPluginHost : NSObject
|
||||||
@@ -53,9 +54,10 @@ FOUNDATION_EXPORT NSString *const MPPluginHostPluginBundleIdentifiyerKey;
|
|||||||
- (NSArray *)avilableMenuItemsForEntries:(NSArray <KPKEntry *>*)entries;
|
- (NSArray *)avilableMenuItemsForEntries:(NSArray <KPKEntry *>*)entries;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface MPPluginHost (MPImportPluginSupport)
|
@interface MPPluginHost (MPImportExportPluginSupport)
|
||||||
|
|
||||||
@property (readonly, copy) NSArray <MPPlugin<MPImportPlugin> __kindof*> *importPlugins;
|
@property (readonly, copy) NSArray <MPPlugin<MPImportPlugin> __kindof*> *importPlugins;
|
||||||
|
@property (readonly, copy) NSArray <MPPlugin<MPExportPlugin> __kindof*> *exportPlugins;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -459,11 +459,14 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
|
|||||||
NSString *const MPPluginBundleIdentifierKey = @"MPPluginBundleIdentifierKey";
|
NSString *const MPPluginBundleIdentifierKey = @"MPPluginBundleIdentifierKey";
|
||||||
NSString *const MPImportPluginUTIKey = @"MPImportPluginUTIKey";
|
NSString *const MPImportPluginUTIKey = @"MPImportPluginUTIKey";
|
||||||
|
|
||||||
@implementation MPPluginHost (MPImportPluginSupport)
|
@implementation MPPluginHost (MPImportExportPluginSupport)
|
||||||
|
|
||||||
- (NSArray<MPPlugin *> *)importPlugins {
|
- (NSArray<MPPlugin *> *)importPlugins {
|
||||||
return [self _pluginsConformingToProtocoll:@protocol(MPImportPlugin)];
|
return [self _pluginsConformingToProtocoll:@protocol(MPImportPlugin)];
|
||||||
}
|
}
|
||||||
|
- (NSArray<MPPlugin<MPImportPlugin> *> *)exportPlugins {
|
||||||
|
return [self _pluginsConformingToProtocoll:@protocol(MPExportPlugin)];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user