Skip to content

Commit

Permalink
Handle case where no plugin can load file
Browse files Browse the repository at this point in the history
  • Loading branch information
griff committed Mar 29, 2018
1 parent 2ee8a48 commit b6baaed
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
1 change: 0 additions & 1 deletion Framework/src/MZDataProviderPlugin.m
Expand Up @@ -14,7 +14,6 @@ - (BOOL)isEnabled
return YES;
}


- (NSArray *)types
{
NSArray* types = [self.bundle objectForInfoDictionaryKey:@"CFBundleDocumentTypes"];
Expand Down
71 changes: 70 additions & 1 deletion Framework/src/MZPluginController.m
Expand Up @@ -49,6 +49,20 @@ - (id)initWithController:(MZPluginController *)controller

@end

@interface MZNoPluginNotification : MZReadNotification <MZDataController>
{
NSString* fileName;
}

+ (id)notifierWithController:(MZPluginController *)controller
delegate:(id<MZEditsReadDelegate>)delegate
fromFile:(NSString *)fileName;
- (id)initWithController:(MZPluginController *)controller
delegate:(id<MZEditsReadDelegate>)delegate
fromFile:(NSString *)fileName;

@end


@interface MZSearchDelegate : NSObject <MZSearchProviderDelegate>
{
Expand Down Expand Up @@ -709,8 +723,12 @@ - (MZSearchProviderPlugin *)searchProviderWithIdentifier:(NSString *)identifier
{
MZDataProviderPlugin* provider = [self dataProviderForPath:fileName];
if(!provider) {
id<MZDataReadDelegate> otherDelegate =
[MZNoPluginNotification notifierWithController:self
delegate:theDelegate
fromFile:fileName];
MZLoggerInfo(@"No plugin for file '%@'", fileName);
return nil;
return otherDelegate;
}

id<MZDataReadDelegate> otherDelegate = [MZReadNotification notifierWithController:self delegate:theDelegate];
Expand Down Expand Up @@ -897,6 +915,57 @@ - (void)dataProvider:(MZDataProviderPlugin *)provider
@end


@implementation MZNoPluginNotification

+ (id)notifierWithController:(MZPluginController *)controller
delegate:(id<MZEditsReadDelegate>)delegate
fromFile:(NSString *)fileName
{
return [[[self alloc] initWithController:controller delegate:delegate fromFile:fileName] autorelease];
}

- (id)initWithController:(MZPluginController *)theController
delegate:(id<MZEditsReadDelegate>)theDelegate
fromFile:(NSString *)theFileName
{
self = [super initWithController:theController
delegate:theDelegate];
if(self)
{
fileName = [theFileName retain];
[self performSelectorOnMainThread:@selector(noPlugin) withObject:nil waitUntilDone:NO];
}
return self;
}

- (void)dealloc
{
[fileName release];
[super dealloc];
}

- (void)noPlugin
{
NSDictionary* dict = [NSDictionary dictionaryWithObject:
NSLocalizedString(@"No plugin found for file", @"No read plugin error")
forKey:NSLocalizedDescriptionKey];
NSError* error = [NSError errorWithDomain:@"MetaZ" code:12 userInfo:dict];

[self dataProvider:nil controller:self loadedMeta:nil fromFile:fileName error:error];
}

- (BOOL)isFinished
{
return YES;
}

- (void)cancel
{
}

@end


@implementation MZSearchDelegate
@synthesize performedSearches;
@synthesize finishedSearches;
Expand Down

0 comments on commit b6baaed

Please sign in to comment.