mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-22 15:19:27 +00:00
drafting simple plugin system
This commit is contained in:
28
MacPass/MPGenericPlugin.h
Normal file
28
MacPass/MPGenericPlugin.h
Normal 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
22
MacPass/MPPluginManager.h
Normal 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
56
MacPass/MPPluginManager.m
Normal 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
|
||||
Reference in New Issue
Block a user