Fixes #250. Found workaround to force a refresh by toggleing showHiddenFiles.

This commit is contained in:
michael starke
2014-11-21 21:36:23 +01:00
parent 1e4444c426
commit f57ac5a98d
3 changed files with 43 additions and 56 deletions

View File

@@ -10,6 +10,7 @@
@interface MPDocumentController : NSDocumentController
- (IBAction)toggleAllowAllFilesButton:(id)sender;
- (IBAction)toggleAllowAllFiles:(id)sender;
- (IBAction)toggleShowHiddenFiles:(id)sender;
@end

View File

@@ -18,22 +18,15 @@
@interface MPDocumentController ()
@property (strong) IBOutlet NSView *accessoryView;
@property (weak) IBOutlet NSButton *allowAllCheckBox;
@property (weak) IBOutlet NSButton *showHiddenCheckBox;
@property (weak) NSOpenPanel *openPanel;
@property (strong) id openPanelTableHack;
@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) {
@@ -41,15 +34,24 @@
NSArray *topLevelObjects;
[myBundle loadNibNamed:@"OpenPanelAccessoryView" owner:self topLevelObjects:&topLevelObjects];
}
self.openPanel.allowedFileTypes = @[MPLegacyDocumentUTI, MPXMLDocumentUTI];
self.allowAllCheckBox.state = NSOffState;
self.showHiddenCheckBox.state = NSOffState;
self.openPanel.accessoryView = self.accessoryView;
[super beginOpenPanel:openPanel forTypes:inTypes completionHandler:completionHandler];
}
- (IBAction)toggleAllowAllFilesButton:(id)sender {
- (void)toggleAllowAllFiles:(id)sender {
NSButton *button = (NSButton *)sender;
self.allowAllFiles = HNHBoolForState(button.state);
self.openPanel.allowedFileTypes = self.allowAllFiles ? nil : @[MPLegacyDocumentUTI, MPXMLDocumentUTI];
//[self _refreshOpenPanel];
BOOL allowAllFiles = HNHBoolForState(button.state);
/* Toggle hidden to force a refresh */
self.openPanel.showsHiddenFiles = !self.openPanel.showsHiddenFiles;
self.openPanel.allowedFileTypes = allowAllFiles ? nil : @[MPLegacyDocumentUTI, MPXMLDocumentUTI];
self.openPanel.showsHiddenFiles = !self.openPanel.showsHiddenFiles;
}
- (void)toggleShowHiddenFiles:(id)sender {
self.openPanel.showsHiddenFiles = !self.openPanel.showsHiddenFiles;
}
- (NSString *)typeForContentsOfURL:(NSURL *)url error:(NSError *__autoreleasing *)outError {
@@ -60,35 +62,4 @@
return [super typeForContentsOfURL:url error:outError];
}
/*
Hack is from http://stackoverflow.com/users/1564216/eidola at
http://stackoverflow.com/questions/18192986/nsopenpanel-doesnt-validatevisiblecolumns
*/
#pragma mark NSOpenPanel Refresh Hack
- (id)_openPanelFindTable:(NSArray*)subviews; {
id table;
for(id view in subviews) {
if([[view className] isEqualToString: @"FI_TListView"]) {
table = view;
break;
}
else {
table = [self _openPanelFindTable:[view subviews]];
if (table != nil) {
break;
}
}
}
return table;
}
- (void)_refreshOpenPanel {
if(self.openPanelTableHack == nil) {
self.openPanelTableHack = [self _openPanelFindTable:[[self.openPanel contentView] subviews]];
}
[_openPanelTableHack reloadData];
[_openPanel validateVisibleColumns];
}
@end

View File

@@ -1,5 +1,5 @@
<?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">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
@@ -8,33 +8,48 @@
<customObject id="-2" userLabel="File's Owner" customClass="MPDocumentController">
<connections>
<outlet property="accessoryView" destination="c22-O7-iKe" id="WVB-Jm-Rfh"/>
<outlet property="allowAllCheckBox" destination="I5Q-M2-Ha7" id="CDu-nk-a09"/>
<outlet property="allowAllFilesCheckButton" destination="I5Q-M2-Ha7" id="bjK-5w-s5K"/>
<outlet property="showHiddenCheckBox" destination="x9q-qY-Jy2" id="4Ez-TO-E5B"/>
</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"/>
<rect key="frame" x="0.0" y="0.0" width="243" height="54"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button translatesAutoresizingMaskIntoConstraints="NO" id="x9q-qY-Jy2">
<rect key="frame" x="69" y="8" width="133" height="18"/>
<buttonCell key="cell" type="check" title="Show hidden files" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="FfY-KA-8IC">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleShowHiddenFiles:" target="-2" id="YW3-e3-aeV"/>
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="I5Q-M2-Ha7">
<rect key="frame" x="149" y="18" width="102" height="18"/>
<rect key="frame" x="69" y="28" width="105" 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"/>
<action selector="toggleAllowAllFiles:" target="-2" id="0Xt-0u-zVS"/>
</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"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="I5Q-M2-Ha7" secondAttribute="trailing" constant="20" symbolic="YES" id="0he-6w-YTN"/>
<constraint firstItem="I5Q-M2-Ha7" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" constant="10" id="6h7-ms-2hq"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="x9q-qY-Jy2" secondAttribute="trailing" constant="20" symbolic="YES" id="G8o-qS-cwc"/>
<constraint firstItem="x9q-qY-Jy2" firstAttribute="top" secondItem="I5Q-M2-Ha7" secondAttribute="bottom" constant="6" id="Vtk-Vw-Y5u"/>
<constraint firstAttribute="centerX" secondItem="I5Q-M2-Ha7" secondAttribute="centerX" id="evr-ZX-930"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="x9q-qY-Jy2" secondAttribute="bottom" constant="10" id="f1c-Ha-7hR"/>
<constraint firstItem="I5Q-M2-Ha7" firstAttribute="leading" secondItem="x9q-qY-Jy2" secondAttribute="leading" id="sUu-Ol-LM0"/>
</constraints>
<point key="canvasLocation" x="412" y="319"/>
<point key="canvasLocation" x="-534.5" y="-117"/>
</customView>
</objects>
</document>