forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFScriptMenuItem.m
114 lines (90 loc) · 3.45 KB
/
FScriptMenuItem.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* FScriptMenuItem.m Copyright (c) 2004-2009 Philippe Mougin. */
/* This software is open source. See the license. */
#import "FScriptMenuItem.h"
#import "FSInterpreter.h"
#import "FSInterpreterView.h"
@implementation FScriptMenuItem
+ (void)initialize
{
NSMutableDictionary *registrationDict = [NSMutableDictionary dictionary];
[registrationDict setObject:[NSNumber numberWithDouble:[[NSFont userFixedPitchFontOfSize:-1] pointSize]] forKey:@"FScriptFontSize"];
[registrationDict setObject:@"YES" forKey:@"FScriptAutomaticallyIntrospectDeclaredProperties"];
[[NSUserDefaults standardUserDefaults] registerDefaults:registrationDict];
}
+ (void)insertInMainMenu
{
[[[NSApplication sharedApplication] mainMenu] addItem:[[[self alloc] init] autorelease]];
}
- (id)init
{
//NSLog(@"FScriptMenuItem init");
return [self initWithTitle:@"F-Script" action:@selector(submenuAction:) keyEquivalent:@""];
}
/*- (id)initWithCoder:(NSCoder *)coder
{
NSLog(@"FScriptMenuItem initWithCoder:");
return [super initWithCoder:coder];
} */
- (id)initWithTitle:(NSString *)itemName action:(SEL)anAction keyEquivalent:(NSString *)charCode
{
//NSLog(@"FScriptMenuItem initWithTitle:action:keyEquivalent:");
if (self = [super initWithTitle:itemName action:anAction keyEquivalent:charCode])
{
NSMenu *submenu = [[[NSMenu alloc] initWithTitle:@"F-Script"] autorelease];
NSMenuItem *item1 = [[[NSMenuItem alloc] initWithTitle:@"Show Console" action:@selector(showConsole:) keyEquivalent:@""] autorelease];
[item1 setTarget:self];
[submenu addItem:item1];
NSMenuItem *item2 = [[[NSMenuItem alloc] initWithTitle:@"Open Object Browser" action:@selector(openObjectBrowser:) keyEquivalent:@""] autorelease];
[item2 setTarget:self];
[submenu addItem:item2];
NSMenuItem *item3 = [[[NSMenuItem alloc] initWithTitle:@"Preferences..." action:@selector(showPreferencePanel:) keyEquivalent:@""] autorelease];
[item3 setTarget:self];
[submenu addItem:item3];
[self setSubmenu:submenu];
return self;
}
return nil;
}
- (FSInterpreterView *) interpreterView
{
if (!interpreterView) [NSBundle loadNibNamed:@"FSConsole.nib" owner:self];
return interpreterView;
}
- (IBAction)openObjectBrowser:(id)sender
{
[[[self interpreterView] interpreter] browse];
}
- (IBAction)showConsole:(id)sender
{
[[[self interpreterView] window] makeKeyAndOrderFront:nil];
}
- (void)showPreferencePanel:(id)sender
{
if (!preferencePanel)
{
if (![NSBundle loadNibNamed:@"FScriptPreferences" owner:self])
{
NSLog(@"Failed to load FScriptPreferences.nib");
NSBeep();
return;
}
[preferencePanel center];
}
[fontSizeUI setDoubleValue:[[self interpreterView] fontSize]];
[automaticallyIntrospectDeclaredPropertiesUI setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptAutomaticallyIntrospectDeclaredProperties"]];
[preferencePanel makeKeyAndOrderFront:nil];
}
- (IBAction)updatePreference:(id)sender // action
{
//NSLog(@"** updatePreference");
if (sender == fontSizeUI)
{
[[NSUserDefaults standardUserDefaults] setDouble:[fontSizeUI doubleValue] forKey:@"FScriptFontSize"];
[[self interpreterView] setFontSize:[fontSizeUI doubleValue]];
}
else if (sender == automaticallyIntrospectDeclaredPropertiesUI)
{
[[NSUserDefaults standardUserDefaults] setBool:[automaticallyIntrospectDeclaredPropertiesUI state] forKey:@"FScriptAutomaticallyIntrospectDeclaredProperties"];
}
}
@end