Using preferences instead of settings name. Alert for incompaitble plugins now has a button to show preferences

This commit is contained in:
Michael Starke
2019-02-08 15:04:16 +01:00
parent d3641af1fc
commit 00362bf33c
13 changed files with 126 additions and 69 deletions

View File

@@ -33,7 +33,7 @@
#import "MPPasswordCreatorViewController.h"
#import "MPPluginHost.h"
#import "MPSettingsHelper.h"
#import "MPSettingsWindowController.h"
#import "MPPreferencesWindowController.h"
#import "MPStringLengthValueTransformer.h"
#import "MPPrettyPasswordTransformer.h"
#import "MPTemporaryFileStorageCenter.h"
@@ -59,7 +59,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
@property (strong) NSWindow *welcomeWindow;
@property (strong) IBOutlet NSWindow *passwordCreatorWindow;
@property (strong, nonatomic) MPSettingsWindowController *settingsController;
@property (strong, nonatomic) MPPreferencesWindowController *preferencesController;
@property (strong, nonatomic) MPPasswordCreatorViewController *passwordCreatorController;
@end
@@ -228,10 +228,10 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
#pragma mark -
#pragma mark Actions
- (void)showPreferences:(id)sender {
if(self.settingsController == nil) {
self.settingsController = [[MPSettingsWindowController alloc] init];
if(self.preferencesController == nil) {
self.preferencesController = [[MPPreferencesWindowController alloc] init];
}
[self.settingsController showSettings];
[self.preferencesController showPreferences];
}
- (void)showPasswordCreator:(id)sender {

View File

@@ -523,7 +523,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
}
- (NSURL *)suggestedKeyURL {
MPAppDelegate *delegate = (MPAppDelegate *)[NSApp delegate];
MPAppDelegate *delegate = (MPAppDelegate *)NSApp.delegate;
if(!delegate.isAllowedToStoreKeyFile) {
return nil;
}
@@ -630,7 +630,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
if(!metaData.enforceMasterKeyChange) {
return NO;
}
return ((24*60*60*metaData.masterKeyChangeEnforcementInterval) < -[metaData.masterKeyChanged timeIntervalSinceNow]);
return ((24*60*60*metaData.masterKeyChangeEnforcementInterval) < - metaData.masterKeyChanged.timeIntervalSinceNow);
}
- (BOOL)shouldRecommendPasswordChange {
@@ -638,7 +638,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
if(!metaData.recommendMasterKeyChange) {
return NO;
}
return ( (24*60*60*metaData.masterKeyChangeRecommendationInterval) < -[metaData.masterKeyChanged timeIntervalSinceNow]);
return ( (24*60*60*metaData.masterKeyChangeRecommendationInterval) < - metaData.masterKeyChanged.timeIntervalSinceNow);
}
#pragma mark Data manipulation

View File

@@ -22,9 +22,9 @@
#import <Cocoa/Cocoa.h>
#import "MPViewController.h"
#import "MPSettingsTab.h"
#import "MPPreferencesTab.h"
@interface MPGeneralSettingsController : MPViewController <MPSettingsTab>
@interface MPGeneralSettingsController : MPViewController <MPPreferencesTab>
@property (weak) IBOutlet NSButton *clearPasteboardOnQuitCheckButton;
@property (weak) IBOutlet NSPopUpButton *clearPasteboardTimeoutPopup;

View File

@@ -21,11 +21,11 @@
//
#import "MPViewController.h"
#import "MPSettingsTab.h"
#import "MPPreferencesTab.h"
@class DDHotKeyTextField;
@interface MPIntegrationSettingsController : MPViewController <MPSettingsTab, NSTextFieldDelegate>
@interface MPIntegrationSettingsController : MPViewController <MPPreferencesTab, NSTextFieldDelegate>
/* Autotype */
@property (strong) IBOutlet NSButton *enableGlobalAutotypeCheckBox;
@property (strong) IBOutlet DDHotKeyTextField *hotKeyTextField;

View File

@@ -31,6 +31,7 @@
#import "MPPluginVersionComparator.h"
#import "NSApplication+MPAdditions.h"
#import "MPAppDelegate.h"
#import "MPSettingsHelper.h"
#import "NSError+Messages.h"
@@ -286,7 +287,25 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun
alert.informativeText = NSLocalizedString(@"ALERT_INCOMPATIBLE_PLUGINS_ENCOUNTERED_INFORMATIVE_TEXT", "Informative text of the alert displayed when plugins where disabled due to incompatibilty");
alert.alertStyle = NSAlertStyleWarning;
alert.showsSuppressionButton = YES;
[alert runModal];
[alert addButtonWithTitle:NSLocalizedString(@"ALERT_INCOMPATIBLE_PLUGINS_ENCOUNTERED_BUTTON_OK", @"Button in dialog to leave plugin ds disabled and continiue!")];
[alert addButtonWithTitle:NSLocalizedString(@"ALERT_INCOMPATIBLE_PLUGINS_ENCOUNTERED_BUTTON_OPEN_PREFERENCES", @"Button in dialog to open plugin preferences pane!")];
NSModalResponse returnCode = [alert runModal];
//BOOL suppressWarning = (alert.suppressionButton.state == NSOnState);
//[NSUserDefaults.standardUserDefaults setBool:suppressWarning forKey:kMPSettingsKeyAutotypeHideAccessibiltyWarning];
switch(returnCode) {
case NSAlertFirstButtonReturn: {
/* ok, ignore */
break;
}
case NSAlertSecondButtonReturn:
/* open prefs */
[((MPAppDelegate *)NSApp.delegate) showPreferences:nil];
break;
default:
break;
}
}
}

View File

@@ -21,9 +21,9 @@
//
#import "MPViewController.h"
#import "MPSettingsTab.h"
#import "MPPreferencesTab.h"
@interface MPPluginSettingsController : MPViewController <MPSettingsTab>
@interface MPPluginSettingsController : MPViewController <MPPreferencesTab>
- (IBAction)addOrRemovePlugin:(id)sender;
- (IBAction)browsePlugins:(id)sender;

View File

@@ -26,7 +26,7 @@
Protrocoll to be implemented by ViewControllers that can be added to
the settings windows. Tabs are ordered as the controllers are included.
*/
@protocol MPSettingsTab <NSObject>
@protocol MPPreferencesTab <NSObject>
@required
@property (readonly, copy) NSString *identifier;

View File

@@ -22,11 +22,18 @@
#import <Cocoa/Cocoa.h>
@protocol MPSettingsTab;
@protocol MPPreferencesTab;
@interface MPSettingsWindowController : NSWindowController <NSToolbarDelegate>
typedef NS_ENUM(NSUInteger, MPPreferencesTab) {
MPPreferencesTabGeneral,
MPPreferencesTabWorkflow,
MPPreferencesTabUpdate,
MPPreferencesTabPlugins
};
- (void)showSettings;
- (void)showSettingsTabWithIdentifier:(NSString *)identifier;
@interface MPPreferencesWindowController : NSWindowController <NSToolbarDelegate>
- (void)showPreferences;
- (void)showPreferencesTab:(MPPreferencesTab)tab;
@end

View File

@@ -20,40 +20,43 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#import "MPSettingsWindowController.h"
#import "MPPreferencesWindowController.h"
#import "MPPreferencesTab.h"
#import "MPGeneralSettingsController.h"
#import "MPIntegrationSettingsController.h"
#import "MPWorkflowSettingsController.h"
#import "MPUpdateSettingsController.h"
#import "MPPluginSettingsController.h"
@interface MPSettingsWindowController () {
@interface MPPreferencesWindowController () {
NSString *lastIdentifier;
}
@property (strong, nonatomic) NSMutableDictionary *settingsController;
@property (strong, nonatomic) NSMutableDictionary *preferencesController;
@property (strong, nonatomic) NSMutableDictionary *toolbarItems;
@property (strong) NSArray *defaultToolbarItems;
@end
@implementation MPSettingsWindowController
@implementation MPPreferencesWindowController
- (NSString *)windowNibName {
return @"SettingsWindow";
return @"PreferencesWindow";
}
-(id)init {
self = [super initWithWindow:nil];
if(self) {
NSToolbar *tb = [[NSToolbar alloc] initWithIdentifier:@"SettingsToolBar"];
NSToolbar *tb = [[NSToolbar alloc] initWithIdentifier:@"PreferencesToolBar"];
tb.allowsUserCustomization = NO;
tb.displayMode = NSToolbarDisplayModeIconAndLabel;
_settingsController = [[NSMutableDictionary alloc] initWithCapacity:5];
_preferencesController = [[NSMutableDictionary alloc] initWithCapacity:5];
_toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:5];
lastIdentifier = nil;
[self _setupDefaultSettingsTabs];
[self _setupDefaultPreferencesTabs];
tb.delegate = self;
self.window.toolbar = tb;
@@ -62,17 +65,17 @@
}
- (void)showSettings {
- (void)showPreferences {
if(self.defaultToolbarItems.count > 0) {
[self showSettingsTabWithIdentifier:self.defaultToolbarItems[0]];
[self _showPreferencesTabWithIdentifier:self.defaultToolbarItems[0]];
}
}
- (void)showSettingsTabWithIdentifier:(NSString *)identifier {
- (void)_showPreferencesTabWithIdentifier:(NSString *)identifier {
if(nil == identifier) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Identifier cannot be nil" userInfo:nil];
}
id<MPSettingsTab> tab = self.settingsController[identifier];
id<MPPreferencesTab> tab = self.preferencesController[identifier];
if(tab == nil){
NSLog(@"Warning. Unknown settingscontroller for identifier: %@. Did you miss to add the controller?", identifier);
return;
@@ -111,8 +114,35 @@
[self.window makeKeyAndOrderFront:nil];
}
- (void)_addSettingsTab:(id<MPSettingsTab>)tabController {
if(NO == [tabController conformsToProtocol:@protocol(MPSettingsTab)]) {
- (void)showPreferencesTab:(MPPreferencesTab)tab {
Class tabClass;
switch(tab) {
case MPPreferencesTabPlugins:
tabClass = MPPluginSettingsController.class;
break;
case MPPreferencesTabUpdate:
tabClass = MPUpdateSettingsController.class;
break;
case MPPreferencesTabWorkflow:
tabClass = MPWorkflowSettingsController.class;
break;
case MPPreferencesTabGeneral:
default:
tabClass = MPGeneralSettingsController.class;
break;
}
NSString *identifier;
for(id<MPPreferencesTab> tab in self.preferencesController) {
if([tab isKindOfClass:tabClass]) {
identifier = tab.identifier;
break;
}
}
[self _showPreferencesTabWithIdentifier:identifier];
}
- (void)_addSettingsTab:(id<MPPreferencesTab>)tabController {
if(NO == [tabController conformsToProtocol:@protocol(MPPreferencesTab)]) {
NSException *protocollException = [NSException exceptionWithName:NSInvalidArgumentException
reason:@"Controller must conform to MPSettingsTabProtrocoll"
userInfo:nil];
@@ -125,22 +155,22 @@
@throw controllerException;
}
NSString *identifier = tabController.identifier;
if(nil != self.settingsController[identifier]) {
if(nil != self.preferencesController[identifier]) {
NSLog(@"Warning: Settingscontroller with identifier %@ already present!", identifier);
}
else {
self.settingsController[identifier] = tabController;
self.preferencesController[identifier] = tabController;
}
}
- (void)_setupDefaultSettingsTabs {
- (void)_setupDefaultPreferencesTabs {
NSArray *controllers = @[ [[MPGeneralSettingsController alloc] init],
[[MPIntegrationSettingsController alloc] init],
[[MPWorkflowSettingsController alloc] init],
[[MPUpdateSettingsController alloc] init],
[[MPPluginSettingsController alloc] init] ];
[[MPIntegrationSettingsController alloc] init],
[[MPWorkflowSettingsController alloc] init],
[[MPUpdateSettingsController alloc] init],
[[MPPluginSettingsController alloc] init] ];
NSMutableArray *identifier = [[NSMutableArray alloc] initWithCapacity:controllers.count];
for(id<MPSettingsTab> controller in controllers) {
for(id<MPPreferencesTab> controller in controllers) {
[self _addSettingsTab:controller];
[identifier addObject:controller.identifier];
}
@@ -150,14 +180,14 @@
- (void)_showSettingsTab:(id)sender {
if([sender respondsToSelector:@selector(itemIdentifier)]) {
NSString *identfier = [sender itemIdentifier];
[self showSettingsTabWithIdentifier:identfier];
[self _showPreferencesTabWithIdentifier:identfier];
}
}
#pragma mark NSToolbarDelegate
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
return self.settingsController.allKeys;
return self.preferencesController.allKeys;
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
@@ -165,7 +195,7 @@
}
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar {
return self.settingsController.allKeys;
return self.preferencesController.allKeys;
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
@@ -176,7 +206,7 @@
Setup the item to use the controllers label if one is present
and supports the appropriate @optional protocol messages
*/
id<MPSettingsTab> tab = self.settingsController[itemIdentifier];
id<MPPreferencesTab> tab = self.preferencesController[itemIdentifier];
if([tab respondsToSelector:@selector(label)]) {
item.label = [tab label];
}

View File

@@ -21,8 +21,8 @@
//
#import "MPViewController.h"
#import "MPSettingsTab.h"
#import "MPPreferencesTab.h"
@interface MPUpdateSettingsController : MPViewController <MPSettingsTab>
@interface MPUpdateSettingsController : MPViewController <MPPreferencesTab>
@end

View File

@@ -21,9 +21,9 @@
//
#import "MPViewController.h"
#import "MPSettingsTab.h"
#import "MPPreferencesTab.h"
@interface MPWorkflowSettingsController : MPViewController <MPSettingsTab>
@interface MPWorkflowSettingsController : MPViewController <MPPreferencesTab>
@property (weak) IBOutlet NSPopUpButton *browserPopup;
@property (weak) IBOutlet NSPopUpButton *doubleClickURLPopup;

View File

@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPSettingsWindowController">
<customObject id="-2" userLabel="File's Owner" customClass="MPPreferencesWindowController">
<connections>
<outlet property="window" destination="1" id="3"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<rect key="contentRect" x="196" y="240" width="400" height="300"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>