drafting simple plugin system

This commit is contained in:
michael starke
2015-07-16 15:06:37 +02:00
parent e4a7b81a5f
commit af27e7b265
4 changed files with 122 additions and 0 deletions

28
MacPass/MPGenericPlugin.h Normal file
View File

@@ -0,0 +1,28 @@
//
// MPGenericPlugin.h
// MacPass
//
// Created by Michael Starke on 16/07/15.
// Copyright (c) 2015 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@class MPPluginManager
@protocol MPGenericPlugin <NSObject>
@required
@property (readonly) NSString *name;
@property (readonly) NSString *version;
@property (readonly) NSInteger *versionNumber;
- (instancetype)initWithPluginManager:(MPPluginManager *)manager;
@optional
- (void)manager:(MPPluginManager *)manager willAddNode:(KPKNode *)node;
- (void)manager:(MPPluginManager *)manager didAddNode(KPKNode *)node;
- (void)manager:(MPPluginManager *)manager willRemoveNode:(KPKNode *)node;
- (void)manager:(MPPluginManager *)manager didRemoveNode:(KPKNode *)node;
@end

22
MacPass/MPPluginManager.h Normal file
View File

@@ -0,0 +1,22 @@
//
// MPPluginManager.h
// MacPass
//
// Created by Michael Starke on 16/07/15.
// Copyright (c) 2015 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@class KPKNode;
@interface MPPluginManager : NSObject
typedef BOOL (^NodeMatchBlock)(KPKNode *aNode);
+ (instancetype)sharedManager;
- (NSArray *)filteredEntriesUsingBlock:(NodeMatchBlock) matchBlock;
- (NSArray *)filteredGroupsUsingBlock:(NodeMatchBlock) matchBlock;
@end

56
MacPass/MPPluginManager.m Normal file
View File

@@ -0,0 +1,56 @@
//
// MPPluginManager.m
// MacPass
//
// Created by Michael Starke on 16/07/15.
// Copyright (c) 2015 HicknHack Software GmbH. All rights reserved.
//
#import "MPPluginManager.h"
#import "MPDocument.h"
#import "KPKTree.h"
@implementation MPPluginManager
+ (instancetype)sharedManager {
static MPPluginManager *instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[MPPluginManager alloc] _init];
});
return instance;
}
- (instancetype)init {
return nil;
}
- (instancetype)_init {
self = [super init];
return self;
}
- (NSArray *)filteredEntriesUsingBlock:(NodeMatchBlock)matchBlock {
NSArray *currentDocuments = [[NSDocumentController sharedDocumentController] documents];
NSMutableArray *entries = [[NSMutableArray alloc] initWithCapacity:200];
for(MPDocument *document in currentDocuments) {
if(document.tree) {
[entries addObjectsFromArray:document.tree.allEntries];
}
}
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { return matchBlock(evaluatedObject); }];
return [[NSArray alloc] initWithArray:[entries filteredArrayUsingPredicate:predicate] copyItems:YES];
}
- (NSArray *)filteredGroupsUsingBlock:(NodeMatchBlock)matchBlock {
return nil;
}
- (void)_loadPlugins {
}
@end