mirror of
https://github.com/ksherlock/ample.git
synced 2025-01-24 06:29:47 +00:00
put all recent disk image logic in the recent disk image window controller.
This commit is contained in:
parent
4ca9d2caaf
commit
0d88e3e93a
@ -50,6 +50,8 @@
|
|||||||
[self displayLaunchWindow];
|
[self displayLaunchWindow];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_diskImages = [DiskImagesWindowController new];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)displayLaunchWindow {
|
-(void)displayLaunchWindow {
|
||||||
|
@ -8,31 +8,38 @@
|
|||||||
|
|
||||||
#import "DiskImagesWindowController.h"
|
#import "DiskImagesWindowController.h"
|
||||||
#import "TableCellView.h"
|
#import "TableCellView.h"
|
||||||
|
#import "Ample.h"
|
||||||
|
|
||||||
@interface DiskImagesWindowController ()
|
@interface DiskImagesWindowController ()
|
||||||
@property (weak) IBOutlet NSTableView *tableView;
|
@property (weak) IBOutlet NSTableView *tableView;
|
||||||
@property (strong) IBOutlet NSArrayController *arrayController;
|
@property (strong) IBOutlet NSArrayController *arrayController;
|
||||||
@property NSMutableArray *content;
|
@property (strong) NSMutableArray *content;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DiskImagesWindowController {
|
@implementation DiskImagesWindowController {
|
||||||
//NSArray *_data;
|
BOOL _dirty;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-(instancetype)init {
|
||||||
|
|
||||||
|
if ((self = [super init])) {
|
||||||
|
|
||||||
|
[self loadRecentDiskImages];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
-(NSString *)windowNibName {
|
-(NSString *)windowNibName {
|
||||||
return @"DiskImages";
|
return @"DiskImages";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidLoad {
|
- (void)windowDidLoad {
|
||||||
//_data = [NSMutableArray new];
|
|
||||||
[self setContent:
|
if (!_content)
|
||||||
[NSMutableArray arrayWithObject:
|
[self setContent: [NSMutableArray new]];
|
||||||
[NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
||||||
@"/path/to/a/file.2mg", @"path",
|
|
||||||
@(12345), @"size",
|
|
||||||
nil]
|
|
||||||
]];
|
|
||||||
|
|
||||||
[super windowDidLoad];
|
[super windowDidLoad];
|
||||||
|
|
||||||
@ -41,6 +48,96 @@
|
|||||||
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)loadRecentDiskImages {
|
||||||
|
// NSError *error;
|
||||||
|
|
||||||
|
NSURL *sd = SupportDirectory();
|
||||||
|
NSURL *url = [sd URLByAppendingPathComponent: @"RecentDiskImages.plist"];
|
||||||
|
|
||||||
|
NSData *data = [NSData dataWithContentsOfURL: url];
|
||||||
|
if (data) {
|
||||||
|
_content = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListMutableContainers format:nil error: nil];
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!_content)
|
||||||
|
_content = [NSMutableArray new];
|
||||||
|
|
||||||
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||||
|
|
||||||
|
[nc addObserver: self selector: @selector(diskImageAdded:) name: @"DiskImageAdded" object: nil];
|
||||||
|
|
||||||
|
[nc addObserver: self selector: @selector(willTerminate:) name: NSApplicationWillTerminateNotification object: nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)diskImageAdded: (NSNotification *)notification {
|
||||||
|
|
||||||
|
NSURL *url = [notification object];
|
||||||
|
if (!url) return;
|
||||||
|
|
||||||
|
[self addFile: url];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)willTerminate: (NSNotification *)notification {
|
||||||
|
// if dirty, write data....
|
||||||
|
|
||||||
|
if (!_dirty) return;
|
||||||
|
|
||||||
|
NSURL *sd = SupportDirectory();
|
||||||
|
NSURL *url = [sd URLByAppendingPathComponent: @"RecentDiskImages.plist"];
|
||||||
|
|
||||||
|
if (_content && url) {
|
||||||
|
[_content writeToURL: url atomically: YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-(BOOL)addFile: (NSObject *)pathOrURL {
|
||||||
|
|
||||||
|
NSString *path = nil;
|
||||||
|
NSURL *url = nil;
|
||||||
|
if ([pathOrURL isKindOfClass: [NSString class]]) {
|
||||||
|
path = (NSString *)pathOrURL;
|
||||||
|
} else if ([pathOrURL isKindOfClass: [NSURL class]]){
|
||||||
|
url = (NSURL *)pathOrURL;
|
||||||
|
|
||||||
|
path = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding];
|
||||||
|
}
|
||||||
|
if (!path) return NO;
|
||||||
|
|
||||||
|
// todo -- check if file is in the list already...
|
||||||
|
|
||||||
|
|
||||||
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
|
NSError *error;
|
||||||
|
|
||||||
|
NSDictionary *attr = [fm attributesOfItemAtPath: path error: &error];
|
||||||
|
if (error) {
|
||||||
|
NSLog(@"%@ : %@", path, error);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NSNumber *size = [attr objectForKey: NSFileSize];
|
||||||
|
|
||||||
|
NSMutableDictionary *d = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
path, @"path",
|
||||||
|
size, @"size",
|
||||||
|
[NSDate new], @"date",
|
||||||
|
nil];
|
||||||
|
|
||||||
|
@synchronized (self) {
|
||||||
|
if (_arrayController)
|
||||||
|
[_arrayController addObject: d];
|
||||||
|
else
|
||||||
|
[_content addObject: d];
|
||||||
|
}
|
||||||
|
|
||||||
|
_dirty = YES;
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DiskImagesWindowController (TableView)
|
@implementation DiskImagesWindowController (TableView)
|
||||||
@ -91,27 +188,8 @@
|
|||||||
NSURL *url = [NSURL URLFromPasteboard: pb];
|
NSURL *url = [NSURL URLFromPasteboard: pb];
|
||||||
if (!url) return NO;
|
if (!url) return NO;
|
||||||
|
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
return [self addFile: url];
|
||||||
|
|
||||||
NSString *path = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding];
|
|
||||||
if (!path) return NO;
|
|
||||||
|
|
||||||
NSError *error = nil;
|
|
||||||
NSDictionary *attr = [fm attributesOfItemAtPath: path error: &error];
|
|
||||||
if (error) {
|
|
||||||
NSLog(@"%@ : %@", path, error);
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSNumber *size = [attr objectForKey: NSFileSize];
|
|
||||||
|
|
||||||
NSMutableDictionary *d = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
||||||
path, @"path",
|
|
||||||
size, @"size"
|
|
||||||
, nil];
|
|
||||||
|
|
||||||
[_arrayController addObject: d];
|
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -611,6 +611,14 @@ static NSString *kDragType = @"private.ample.media";
|
|||||||
|
|
||||||
- (IBAction)pathAction:(id)sender {
|
- (IBAction)pathAction:(id)sender {
|
||||||
// need to update the eject button...
|
// need to update the eject button...
|
||||||
|
|
||||||
|
NSURL *url = [(NSPathControl *)sender URL];
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||||
|
[nc postNotificationName: @"DiskImageAdded" object: url];
|
||||||
|
}
|
||||||
|
|
||||||
[self rebuildArgs];
|
[self rebuildArgs];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user