Skip to content

Instantly share code, notes, and snippets.

@lattejed
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save lattejed/87e39688a864b6c94401 to your computer and use it in GitHub Desktop.

Select an option

Save lattejed/87e39688a864b6c94401 to your computer and use it in GitHub Desktop.
//
// Controller.m
//
// Created by Matthew Smith on 4/21/14.
// Copyright (c) 2014 LatteJed. All rights reserved.
//
#import "Controller.h"
#import "Model.h"
@interface Controller ()
@property (nonatomic, weak) IBOutlet NSButton* openFileButton;
@property (nonatomic, weak) IBOutlet FileView* fileView;
@property (nonatomic, strong) Model* model;
@end
@implementation Controller
- (void)awakeFromNib;
{
[self.openFileButton setActionBlock:^{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel beginSheetModalForWindow:[[self view] window]
completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton)
{
self.model = [Model new];
self.model.url = [[panel URLs] firstObject];
}
}];
}];
[[NSNotificationCenter defaultCenter]
addObserverForName:kNotificationURLDidUpdate
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
if ([self.model url])
{
[self.fileView setFileWithURL:self.model.url];
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment