-
Notifications
You must be signed in to change notification settings - Fork 1
/
SwitchActionOptionSheetController.m
92 lines (75 loc) · 3.09 KB
/
SwitchActionOptionSheetController.m
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
//
// SwitchActionOptionSheetController.m
// rooSwitchNLPlugin
//
// Created by Brian Cooke on 3/13/07.
// Copyright 2007 roobasoft, LLC. All rights reserved.
//
#import "SwitchActionOptionSheetController.h"
@implementation SwitchActionOptionSheetController
- (void) awakeFromNib
{
[profiles removeAllItems];
[profiles setEnabled:NO];
[applications removeAllItems];
[applications addItemWithTitle:@"Choose..."];
// set the popup of applications to switch to the files present in
// their app support/rooSwitch dir
NSString *dir = [NSHomeDirectory() stringByAppendingString:@"/Library/Application Support/rooSwitch"];
NSArray *files = [[NSFileManager defaultManager] directoryContentsAtPath:dir];
NSString *file = nil;
NSEnumerator *enumerator = [files objectEnumerator];
while ((file = [enumerator nextObject]))
{
if ([[file pathExtension] isEqualToString:@"rooSwitch"])
{
NSString *title = [[file lastPathComponent] stringByDeletingPathExtension];
[applications addItemWithTitle:title];
NSMenuItem *menuItem = [applications itemWithTitle:title];
NSString *fullPath = [dir stringByAppendingPathComponent:file];
[menuItem setRepresentedObject:[fullPath retain]];
if ([[options valueForKey:@"application"] isEqualToString:fullPath])
{
[applications selectItemWithTitle:title];
[self applicationChanged:self];
}
// [menuItem setImage:[[NSImage alloc] initByReferencingFile:]
}
}
}
- (IBAction)applicationChanged:(id)sender
{
[options setValue:[[applications selectedItem] representedObject] forKey:@"application"];
NSString *rooSwitchFile = [options valueForKey:@"application"];
//NSLog(@"Now we have %@", rooSwitchFile);
[profiles removeAllItems];
[profiles setEnabled:YES];
// load up the profiles
NSXMLDocument *xmlDoc = nil;
NSError *err=nil;
NSURL *furl = [NSURL fileURLWithPath:[rooSwitchFile stringByAppendingPathComponent:@"profiles.xml"]];
if (!furl)
{
return;
}
xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:(NSXMLNodePreserveWhitespace|NSXMLNodePreserveCDATA) error:&err];
if( xmlDoc == nil )
{
xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:NSXMLDocumentTidyXML error:&err];
}
NSArray *matches = [xmlDoc nodesForXPath:@".//object[@type=\"PROFILE\"]//attribute[@name=\"name\"]" error:&err];
//NSLog(@"Matches = %@ - err = %@", matches, err);
NSEnumerator *enumerator = [matches objectEnumerator];
NSXMLNode *profile = nil;
while ((profile = [enumerator nextObject]))
{
[profiles addItemWithTitle:[profile stringValue]];
if ([[options valueForKey:@"profile"] isEqualToString:[profile stringValue]])
[profiles selectItemWithTitle:[profile stringValue]];
}
}
- (IBAction)profileChanged:(id)sender
{
[options setValue:[[profiles selectedItem] title] forKey:@"profile"];
}
@end