open directory panel

master
Jordan Orelli 8 years ago
parent cb06c436cf
commit 2a3219c370

@ -1,4 +1,4 @@
#import <Cocoa/Cocoa.h>
@interface MainViewController : NSViewController
@interface MainViewController : NSViewController <NSOpenSavePanelDelegate>
@end

@ -3,6 +3,7 @@
@interface MainViewController ()
@property (nonatomic, strong) NSOpenPanel *selectDirectoryPanel;
@property (nonatomic, strong) NSButton *selectDirectoryButton;
@end
@ -18,17 +19,24 @@
NSLog(@"[MainViewController] viewDidLoad");
[super viewDidLoad];
// set window dimensions
[self.view.widthAnchor constraintGreaterThanOrEqualToConstant:640.0].active = YES;
[self.view.heightAnchor constraintGreaterThanOrEqualToConstant:480.0].active = YES;
// create open panel
self.selectDirectoryPanel = [NSOpenPanel openPanel];
[self.selectDirectoryPanel setCanChooseFiles:NO];
[self.selectDirectoryPanel setCanChooseDirectories:YES];
[self.selectDirectoryPanel setDelegate:self];
// create select directory button
self.selectDirectoryButton = [NSButton buttonWithTitle:@"select directory"
target:self
action:@selector(fart:)];
target:self.selectDirectoryPanel
action:@selector(runModal)];
[self.selectDirectoryButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:self.selectDirectoryButton];
// setup button constraints
[self.selectDirectoryButton.rightAnchor
constraintEqualToAnchor:self.view.rightAnchor
constant:-8.0].active = YES;
@ -37,6 +45,11 @@
constant:8.0].active = YES;
}
- (void) panel:(id)sender didChangeToDirectoryURL:(NSURL *)url {
NSLog(@"[MainViewController] panel: %@ didChangeToDirectoryURL: %@", sender, url);
return [super viewWillAppear];
}
- (void) viewWillAppear {
NSLog(@"[MainViewController] viewWillAppear");
return [super viewWillAppear];
@ -67,8 +80,4 @@
return [super viewDidLayout];
}
- (void) fart {
NSLog(@"[MainViewController] fart!");
}
@end

Loading…
Cancel
Save