Display a generic description text if the appropriate key is present in the InfoDictionary of the plugin bundle

This commit is contained in:
Michael Starke
2019-07-15 18:21:03 +02:00
parent fc21257173
commit 1baf2cd8e6
3 changed files with 28 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
@class KPKTree;
FOUNDATION_EXPORT NSString *const MPPluginUnkownVersion;
FOUNDATION_EXPORT NSString *const MPPluginDescriptionInfoDictionaryKey;
@interface MPPlugin : NSObject
@@ -37,8 +38,10 @@ FOUNDATION_EXPORT NSString *const MPPluginUnkownVersion;
@property (copy, readonly) NSString *name;
@property (nonatomic, copy, readonly, nullable) NSString *shortVersionString;
@property (nonatomic, copy, readonly) NSString *versionString;
@property (nonatomic, copy, readonly) NSString *localizedDescription;
@property (nonatomic, strong, readonly) NSBundle *bundle;
/**
If your plugin needs initalization override this method but you have to call [super initWithPluginHost:]
Otherwise your plugin might not get registered correctly

View File

@@ -28,6 +28,7 @@
#import "MPPluginVersionComparator.h"
NSString *const MPPluginUnkownVersion = @"unkown.plugin.version";
NSString *const MPPluginDescriptionInfoDictionaryKey = @"MPPluginDescription";
@implementation MPPlugin
@@ -90,6 +91,16 @@ NSString *const MPPluginUnkownVersion = @"unkown.plugin.version";
return MPPluginUnkownVersion;
}
- (NSString *)localizedDescription {
if([self.bundle.localizedInfoDictionary objectForKey:MPPluginDescriptionInfoDictionaryKey]) {
return self.bundle.localizedInfoDictionary[MPPluginDescriptionInfoDictionaryKey];
}
if([self.bundle.infoDictionary objectForKey:MPPluginDescriptionInfoDictionaryKey]) {
return self.bundle.infoDictionary[MPPluginDescriptionInfoDictionaryKey];
}
return @"";
}
- (void)didLoadPlugin {

View File

@@ -124,22 +124,29 @@ typedef NS_ENUM(NSUInteger, MPPluginSegmentType) {
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:dict]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:dict]];
}
else {
[self _showInfoMessageForPlugin:plugin.localizedDescription];
}
}
else if(nil != plugin) {
[self.settingsView addSubview:self.fallbackSettingsView];
NSDictionary *dict = @{ @"view" : self.fallbackSettingsView,
@"table" : self.pluginTableView.enclosingScrollView };
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:dict]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:dict]];
if(plugin.errorMessage.length > 0) {
self.fallbackDescriptionTextField.stringValue = plugin.errorMessage;
[self _showInfoMessageForPlugin:plugin.errorMessage];
}
else {
self.fallbackDescriptionTextField.stringValue = NSLocalizedString(@"PLUGIN_SETTINGS_GENERIC_ERROR_MESSAGE", "Generic message displayed if no details are know why a plugin was not loaded.");
[self _showInfoMessageForPlugin:NSLocalizedString(@"PLUGIN_SETTINGS_GENERIC_ERROR_MESSAGE", "Generic message displayed if no details are know why a plugin was not loaded.")];
}
}
}
- (void)_showInfoMessageForPlugin:(NSString *)message {
[self.settingsView addSubview:self.fallbackSettingsView];
NSDictionary *dict = @{ @"view" : self.fallbackSettingsView,
@"table" : self.pluginTableView.enclosingScrollView };
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:dict]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:dict]];
self.fallbackDescriptionTextField.stringValue = message.length > 0 ? message : @"";
}
- (MPPlugin *)pluginForRow:(NSInteger)row {
NSArray<MPPlugin __kindof *> *plugins = [MPPluginHost sharedHost].plugins;
if(0 > row || row >= plugins.count) {