File: PluginController.m

package info (click to toggle)
pcsxr 1.9.94-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,500 kB
  • ctags: 16,110
  • sloc: ansic: 117,276; objc: 8,159; cpp: 1,140; makefile: 316; asm: 145; pascal: 30; sh: 20
file content (83 lines) | stat: -rw-r--r-- 2,135 bytes parent folder | download | duplicates (2)
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
#import "PluginController.h"
#import "PcsxrPlugin.h"
#import "PcsxrController.h"

@interface PluginController ()
@property (strong) NSArray *plugins;
@property (strong) NSString *defaultKey;
@property int pluginType;
@end

@implementation PluginController
@synthesize aboutButton;
@synthesize configureButton;
@synthesize pluginMenu;

- (IBAction)doAbout:(id)sender
{
	 PcsxrPlugin *plugin = (self.plugins)[[pluginMenu indexOfSelectedItem]];
	 [plugin aboutAs:self.pluginType];
}

- (IBAction)doConfigure:(id)sender
{
	 PcsxrPlugin *plugin = (self.plugins)[[pluginMenu indexOfSelectedItem]];
	 [plugin configureAs:self.pluginType];
}

- (IBAction)selectPlugin:(id)sender
{
	if (sender == pluginMenu) {
		NSInteger index = [pluginMenu indexOfSelectedItem];
		if (index != -1) {
			PcsxrPlugin *plugin = (self.plugins)[index];

			if (![[PluginList list] setActivePlugin:plugin forType:self.pluginType]) {
				/* plugin won't initialize */
			}

			// write selection to defaults
			[[NSUserDefaults standardUserDefaults] setObject:[plugin path] forKey:self.defaultKey];

			// set button states
			[aboutButton setEnabled:[plugin hasAboutAs:self.pluginType]];
			[configureButton setEnabled:[plugin hasConfigureAs:self.pluginType]];
		} else {
			// set button states
			[aboutButton setEnabled:NO];
			[configureButton setEnabled:NO];
		}
	}
}

// must be called before anything else
- (void)setPluginsTo:(NSArray *)list withType:(int)type
{
	NSString *sel;

	// remember the list
	self.pluginType = type;
	self.plugins = list;
	self.defaultKey = [PcsxrPlugin defaultKeyForType:self.pluginType];

	// clear the previous menu items
	[pluginMenu removeAllItems];

	// load the currently selected plugin
	sel = [[NSUserDefaults standardUserDefaults] stringForKey:self.defaultKey];

	// add the menu entries
	for (PcsxrPlugin *plug in self.plugins) {
		NSString *description = [plug description];
		[pluginMenu addItemWithTitle:description];
		
		// make sure the currently selected is set as such
		if ([sel isEqualToString:[plug path]]) {
			[pluginMenu selectItemWithTitle:description];
		}
	}

	[self selectPlugin:pluginMenu];
}

@end