open directory panel

master
Jordan Orelli 8 years ago
parent cb06c436cf
commit 2a3219c370

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

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

Loading…
Cancel
Save