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

@@ -168,6 +168,8 @@
4C68456D17BC227B00FCDBFC /* KPKWindowAssociation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C68456C17BC227B00FCDBFC /* KPKWindowAssociation.m */; };
4C68456F17BC2A0700FCDBFC /* WelcomeWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C68456E17BC2A0700FCDBFC /* WelcomeWindow.xib */; };
4C69A73A16D589DF00EC1B1A /* HNHGradientView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C69A73916D589DF00EC1B1A /* HNHGradientView.m */; };
4C6AEEF91A043E2B00CA2420 /* MPDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */; };
4C6AEF031A04400E00CA2420 /* OpenPanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C6AEF021A04400E00CA2420 /* OpenPanelAccessoryView.xib */; };
4C6B7C7D18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */; };
4C6C72C417C01E4200768849 /* NSMutableData+KeePassKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6C72C317C01E4200768849 /* NSMutableData+KeePassKit.m */; };
4C6D1D25178579570014C5A5 /* 48_FolderTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C6D1D24178579570014C5A5 /* 48_FolderTemplate.pdf */; };
@@ -675,6 +677,9 @@
4C68456E17BC2A0700FCDBFC /* WelcomeWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WelcomeWindow.xib; sourceTree = "<group>"; };
4C69A73816D589DF00EC1B1A /* HNHGradientView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHGradientView.h; sourceTree = "<group>"; };
4C69A73916D589DF00EC1B1A /* HNHGradientView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHGradientView.m; sourceTree = "<group>"; };
4C6AEEF71A043E2B00CA2420 /* MPDocumentController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDocumentController.h; sourceTree = "<group>"; };
4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDocumentController.m; sourceTree = "<group>"; };
4C6AEF021A04400E00CA2420 /* OpenPanelAccessoryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OpenPanelAccessoryView.xib; sourceTree = "<group>"; };
4C6B7C7B18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MPDocument+HistoryBrowsing.h"; sourceTree = "<group>"; };
4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+HistoryBrowsing.m"; sourceTree = "<group>"; };
4C6C72C217C01E4200768849 /* NSMutableData+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableData+KeePassKit.h"; sourceTree = "<group>"; };
@@ -1055,6 +1060,7 @@
4C06398C15B980480004DE27 /* Views */ = {
isa = PBXGroup;
children = (
4C6AEF041A0441F800CA2420 /* AccessoryViews */,
4CF78060176E75180032EE71 /* Settings */,
4C25D58616CF0FAA00F6806C /* EntryView.xib */,
4C3FFD9D16DAF60600DF9186 /* ContextBar.xib */,
@@ -1065,7 +1071,6 @@
4CE39AC016ECE359000FE29D /* IconSelection.xib */,
4C2C8B331787500E009649F3 /* UnprotectedWarningView.xib */,
6021FE7918E15FF300C3BC51 /* DatePickingView.xib */,
4C0728BE17B68ED0005A7DD9 /* SavePanelAccessoryView.xib */,
4C26C34A18D8D5A300CF1A1C /* PreviewView.xib */,
4C74DD05177BD1640034A9DB /* MPCustomFieldView.h */,
4C74DD06177BD1640034A9DB /* MPCustomFieldView.m */,
@@ -1519,6 +1524,15 @@
name = Categories;
sourceTree = "<group>";
};
4C6AEF041A0441F800CA2420 /* AccessoryViews */ = {
isa = PBXGroup;
children = (
4C0728BE17B68ED0005A7DD9 /* SavePanelAccessoryView.xib */,
4C6AEF021A04400E00CA2420 /* OpenPanelAccessoryView.xib */,
);
name = AccessoryViews;
sourceTree = "<group>";
};
4C77E35715B84A240093A587 = {
isa = PBXGroup;
children = (
@@ -1969,6 +1983,8 @@
children = (
4C431BCB16E2A82700700A81 /* MPPasteBoardController.h */,
4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */,
4C6AEEF71A043E2B00CA2420 /* MPDocumentController.h */,
4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */,
);
name = "Data Controller";
sourceTree = "<group>";
@@ -2199,6 +2215,7 @@
4CD78AC016D155FF00768A1D /* 11_CameraTemplate.pdf in Resources */,
4C61EA0516D2FFE200AC519E /* OutlineView.xib in Resources */,
4CB9339916D3A0DD00A13B5D /* Credits.rtf in Resources */,
4C6AEF031A04400E00CA2420 /* OpenPanelAccessoryView.xib in Resources */,
4C3FFD9E16DAF60600DF9186 /* ContextBar.xib in Resources */,
4C431BCF16E2BAB000700A81 /* OverlayWindow.xib in Resources */,
4C17F105184E630200E85625 /* 14_BatteryTemplate.pdf in Resources */,
@@ -2318,6 +2335,7 @@
4C69A73A16D589DF00EC1B1A /* HNHGradientView.m in Sources */,
4C65C79C16DD283900E32CFF /* MPToolbarButton.m in Sources */,
4C431BCD16E2A82800700A81 /* MPPasteBoardController.m in Sources */,
4C6AEEF91A043E2B00CA2420 /* MPDocumentController.m in Sources */,
4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */,
4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */,
4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */,

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>