source: releases/F-Script Anywhere/1.1.5/Source/FSAController.m@ 543

Last change on this file since 543 was 14, checked in by Nicholas Riley, 22 years ago

F-Script Anywhere 1.1.2

File size: 7.3 KB
Line 
1//
2// FSAController.m
3// F-Script Anywhere
4//
5// Created by Nicholas Riley on Fri Feb 01 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9/*
10
11 F-Script Anywhere is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 F-Script Anywhere is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with F-Script Anywhere; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25*/
26
27#import "FSAController.h"
28#import "FSAViewAssociationController.h"
29#import "FSAnywhere.h"
30#import <FScript/FSInterpreter.h>
31
32@class ShellView;
33
34// XXX workaround for lack of focus on FSInterpreterView
35@interface CLIView : NSView
36- (ShellView *)shellView;
37@end
38
39@interface FSInterpreterView (FSAWorkaround)
40- (CLIView *)cliView;
41@end
42
43@implementation FSAController
44
45// derived from TETextWatcher.m in Mike Ferris's TextExtras
46+ (void)installMenu;
47{
48 static BOOL alreadyInstalled = NO;
49 NSMenu *mainMenu = nil;
50
51 if (!alreadyInstalled && ((mainMenu = [NSApp mainMenu]) != nil)) {
52 NSMenu *insertIntoMenu = nil;
53 NSMenuItem *item;
54 unsigned insertLoc = NSNotFound;
55 NSBundle *bundle = [NSBundle bundleForClass:self];
56 NSMenu * beforeSubmenu = [NSApp windowsMenu];
57 // Succeed or fail, we do not try again.
58 alreadyInstalled = YES;
59
60 // Add it to the main menu. We try to put it right before the Windows menu if there is one, or right before the Services menu if there is one, and if there's neither we put it right before the the last submenu item (ie above Quit and Hide on Mach, at the end on Windows.)
61
62 if (!beforeSubmenu) {
63 beforeSubmenu = [NSApp servicesMenu];
64 }
65
66 insertIntoMenu = mainMenu;
67
68 if (beforeSubmenu) {
69 NSArray *itemArray = [insertIntoMenu itemArray];
70 unsigned i, c = [itemArray count];
71
72 // Default to end of menu
73 insertLoc = c;
74
75 for (i=0; i<c; i++) {
76 if ([[itemArray objectAtIndex:i] target] == beforeSubmenu) {
77 insertLoc = i;
78 break;
79 }
80 }
81 } else {
82 NSArray *itemArray = [insertIntoMenu itemArray];
83 unsigned i = [itemArray count];
84
85 // Default to end of menu
86 insertLoc = i;
87
88 while (i-- > 0) {
89 if ([[itemArray objectAtIndex:i] hasSubmenu]) {
90 insertLoc = i+1;
91 break;
92 }
93 }
94 }
95 if (insertIntoMenu) {
96 NSMenu *fsaMenu = [[NSMenu allocWithZone: [NSMenu menuZone]] initWithTitle:NSLocalizedStringFromTableInBundle(@"FSA", @"FSA", bundle, @"Title of F-Script Anywhere menu")];
97
98 item = [insertIntoMenu insertItemWithTitle: NSLocalizedStringFromTableInBundle(@"FSA", @"FSA", bundle, @"Title of F-Script Anywhere menu") action:NULL keyEquivalent:@"" atIndex:insertLoc];
99 [insertIntoMenu setSubmenu:fsaMenu forItem:item];
100 [fsaMenu release];
101
102 // Add the items for the commands.
103 item = [fsaMenu addItemWithTitle: NSLocalizedStringFromTableInBundle(@"New F-Script Workspace", @"FSA", bundle, @"Title of F-Script Workspace menu item") action:@selector(createInterpreterWindow:) keyEquivalent: @""];
104 [item setTarget: self];
105 [fsaMenu addItemWithTitle: NSLocalizedStringFromTableInBundle(@"Associate With Interface", @"FSA", bundle, @"Title of Associate with Interface menu item") action: @selector(FSA_associateWithInterface:) keyEquivalent: @""];
106 [fsaMenu addItem: [NSMenuItem separatorItem]];
107 item = [fsaMenu addItemWithTitle: NSLocalizedStringFromTableInBundle(@"About F-Script AnywhereÉ", @"FSA", bundle, @"Title of Info Panel menu item") action:@selector(showInfo:) keyEquivalent: @""];
108 [item setTarget: self];
109 }
110 }
111
112}
113
114+ (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
115{
116 SEL sel;
117 NSAssert([menuItem target] == self, @"menu item does not target FSAController!");
118 sel = [menuItem action];
119 if (sel == @selector(showInfo:) || sel == @selector(createInterpreterWindow:)) return YES;
120 FSALog(@"-[FSAController validateMenuItem:] unknown menu item for validation: %@", menuItem);
121 return NO;
122}
123
124+ (void)createInterpreterWindow:(id)sender;
125{
126 [[self alloc] init];
127}
128
129+ (void)showInfo:(id)sender;
130{
131 int result = NSRunInformationalAlertPanel(@"About F-Script Anywhere", @"F-Script Anywhere lets you embed a F-Script interpreter in a Cocoa application while it is running.\n\nF-Script Anywhere is currently installed in this application. To remove it, quit this application.\n\nFor more information about F-Script, please visit its Web site %@.", @"OK", @"Visit Web Site", nil, FSA_FScriptURL);
132 if (result == NSAlertAlternateReturn) {
133 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: FSA_FScriptURL]];
134 }
135}
136
137+ (void)load;
138{
139 [self installMenu];
140}
141
142- (id)init {
143 self = [super initWithWindowNibName: @"FSAInterpreterPanel"];
144
145 if (self != nil) {
146 NSString *appName = nil;
147 NSWindow *window = [self window];
148
149 NSAssert(window != nil, @"Can't get interpreter window!");
150 NS_DURING
151 appName = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleName"];
152 NS_HANDLER
153 FSALog(@"Exception occurred while trying to obtain application name: %@", localException);
154 NS_ENDHANDLER
155 if (appName != nil) {
156 [window setTitle: [NSString stringWithFormat: @"%@: %@", [window title], appName]];
157 }
158
159 [window setLevel: NSNormalWindowLevel]; // XXX if set floating, it is globally floating!
160 [self showWindow: self];
161 [window makeKeyAndOrderFront: self];
162#warning this should go away when F-Script properly accepts firstResponder on the InterpreterView
163 [window makeFirstResponder: (NSView *)[[[self interpreterView] cliView] shellView]];
164 system = [[[self interpreterView] interpreter] objectForIdentifier: @"sys" found: NULL];
165 [system retain];
166 NSAssert1([system isKindOfClass: [System class]], @"Initial value bound to identifier 'sys' is not a System object, but %@", system);
167 }
168
169 return self;
170}
171
172- (void)dealloc;
173{
174 [system release];
175 [super dealloc];
176}
177
178- (FSInterpreterView *)interpreterView;
179{
180 return interpreterView;
181}
182
183- (System *)system;
184{
185 return system;
186}
187
188- (IBAction)setFloating:(id)sender;
189{
190 [[self window] setLevel: [sender state] == NSOnState ? NSFloatingWindowLevel : NSNormalWindowLevel];
191}
192
193- (IBAction)FSA_associateWithInterface:(id)sender;
194{
195 NS_DURING
196 if (viewAssociationController == nil) {
197 viewAssociationController = [[FSAViewAssociationController alloc] initWithFSAController: self];
198 }
199 [viewAssociationController showWindow: self];
200 NS_HANDLER
201 FSALog(@"%@", localException);
202 NS_ENDHANDLER
203}
204
205@end
Note: See TracBrowser for help on using the repository browser.