Added custom DocumentController to manipulate open panel

This commit is contained in:
Michael Starke
2014-11-01 15:20:58 +01:00
parent 3714b332f9
commit 6eefee2cd0
4 changed files with 131 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
//
// MPDocumentController.h
// MacPass
//
// Created by Michael Starke on 31.10.14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface MPDocumentController : NSDocumentController <NSOpenSavePanelDelegate>
- (IBAction)toggleAllowAllFilesButton:(id)sender;
@end

View File

@@ -0,0 +1,57 @@
//
// MPDocumentController.m
// MacPass
//
// Created by Michael Starke on 31.10.14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import "MPDocumentController.h"
#import "HNHCommon.h"
@interface MPDocumentController ()
@property (strong) IBOutlet NSView *accessoryView;
@property (weak) NSOpenPanel *openPanel;
@property (assign) BOOL allowAllFiles;
@end
@implementation MPDocumentController
- (instancetype)init {
self = [super init];
if(self) {
_allowAllFiles = NO;
}
return self;
}
- (void)beginOpenPanel:(NSOpenPanel *)openPanel forTypes:(NSArray *)inTypes completionHandler:(void (^)(NSInteger))completionHandler {
self.openPanel = openPanel;
if(!self.accessoryView) {
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
NSArray *topLevelObjects;
[myBundle loadNibNamed:@"OpenPanelAccessoryView" owner:self topLevelObjects:&topLevelObjects];
}
self.openPanel.accessoryView = self.accessoryView;
//self.openPanel.delegate = self;
[super beginOpenPanel:openPanel forTypes:inTypes completionHandler:completionHandler];
}
- (IBAction)toggleAllowAllFilesButton:(id)sender {
NSButton *button = (NSButton *)sender;
self.openPanel.allowsOtherFileTypes = HNHBoolForState(button.state);
self.allowAllFiles = HNHBoolForState(button.state);
}
#pragma mark NSOpenSavePanelDelegate
- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url {
if(self.allowAllFiles) {
return YES;
}
return NO;
}
@end

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPDocumentController">
<connections>
<outlet property="accessoryView" destination="c22-O7-iKe" id="WVB-Jm-Rfh"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe">
<rect key="frame" x="0.0" y="0.0" width="398" height="54"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button translatesAutoresizingMaskIntoConstraints="NO" id="I5Q-M2-Ha7">
<rect key="frame" x="149" y="18" width="102" height="18"/>
<buttonCell key="cell" type="check" title="Allow all files" bezelStyle="regularSquare" imagePosition="left" inset="2" id="tvV-1s-Be3">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleAllowAllFilesButton:" target="-2" id="V8B-PV-RQJ"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="I5Q-M2-Ha7" secondAttribute="bottom" constant="20" symbolic="YES" id="1Jj-lS-aRK"/>
<constraint firstItem="I5Q-M2-Ha7" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="c22-O7-iKe" secondAttribute="leading" constant="20" symbolic="YES" id="9S1-Io-6xU"/>
<constraint firstItem="I5Q-M2-Ha7" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" constant="20" symbolic="YES" id="9kk-7T-IXe"/>
<constraint firstAttribute="centerX" secondItem="I5Q-M2-Ha7" secondAttribute="centerX" constant="-0.5" id="Ob5-Dl-HCy"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="I5Q-M2-Ha7" secondAttribute="trailing" constant="20" symbolic="YES" id="wmQ-mj-8Pr"/>
</constraints>
<point key="canvasLocation" x="412" y="319"/>
</customView>
</objects>
</document>