-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapSelectAppDelegate.m
More file actions
92 lines (73 loc) · 2.55 KB
/
MapSelectAppDelegate.m
File metadata and controls
92 lines (73 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// MapSelectAppDelegate.m
// MapSelect
//
// Created by Michael Klein on 2011-05-24.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "MapSelectAppDelegate.h"
#import "VolumeInfo.h"
@implementation MapSelectAppDelegate
- (void)volumeDidMount:(NSNotification*)notification
{
NSString * path = [[notification userInfo] objectForKey:@"NSDevicePath"];
VolumeInfo * volume = [VolumeInfo volumeInfoWithPath:path];
if (volume != nil)
[volumesController addObject:volume];
}
- (void)volumeDidUnmount:(NSNotification*)notification
{
NSString * path = [[notification userInfo] objectForKey:@"NSDevicePath"];
NSEnumerator * e = [[volumesController content] objectEnumerator];
VolumeInfo * volume_info;
while ((volume_info = [e nextObject]) != nil)
{
if ([[volume_info volumePath] isEqualToString:path])
{
[volumesController removeObject:volume_info];
break;
}
}
}
- (NSSortDescriptor*)mapArraySortDescriptors
{
NSSortDescriptor * sd = [[NSSortDescriptor alloc] initWithKey:@"mapName" ascending:YES];
return [NSArray arrayWithObject:sd];
}
- (void)ejectVolume:(NSString*)path
{
[[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath:path];
}
- (void)awakeFromNib
{
NSNotificationCenter * nc = [[NSWorkspace sharedWorkspace] notificationCenter];
[nc addObserver:self
selector:@selector(volumeDidMount:)
name:NSWorkspaceDidMountNotification
object:nil];
[nc addObserver:self
selector:@selector(volumeDidUnmount:)
name:NSWorkspaceDidUnmountNotification
object:nil];
NSArray * volumePaths = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];
NSEnumerator * e = [volumePaths objectEnumerator];
NSString * path;
while ((path = [e nextObject]) != nil)
{
VolumeInfo * volume = [VolumeInfo volumeInfoWithPath:path];
if (volume != nil)
[volumesController addObject:volume];
}
[volumesController addObserver:self forKeyPath:@"selection.currentMap" options:0 context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
VolumeInfo * volume = [[object valueForKey:@"selectedObjects"] objectAtIndex:0];
id map = [object valueForKeyPath:keyPath];
NSString * map_name = [map isKindOfClass:[NSString class]] ? map : nil;
[volume activateMap:map_name];
}
@end