source: trunk/Cocoa/F-Script Anywhere/Source/FSAController.m@ 223

Last change on this file since 223 was 223, checked in by rchin, 18 years ago

Removing key-value browser button as per Philippe Mougin's request (key-value browser apparently now deprecated). I'm turning it into an associate with view button for now, that will automatically open up a browser with the selected object. The name function (as pointed out by Philippe) is no longer necessary, since it is part of the browser (there is a name button in the browser). However the select view button is not as powerful as FSA's associate (which lets you choose directly document, controller, etc.). This is not yet working, but I need to to the development on my intel mac so I'm checking it in now. It should be working in the next commit.

File size: 8.0 KB
RevLine 
[7]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"
[19]30#import "FSAWindowManager.h"
[14]31#import <FScript/FSInterpreter.h>
[7]32
33@class ShellView;
34
35// XXX workaround for lack of focus on FSInterpreterView
36@interface CLIView : NSView
37- (ShellView *)shellView;
38@end
39
[14]40@interface FSInterpreterView (FSAWorkaround)
[7]41- (CLIView *)cliView;
42@end
43
44@implementation FSAController
45
46// derived from TETextWatcher.m in Mike Ferris's TextExtras
47+ (void)installMenu;
48{
49 static BOOL alreadyInstalled = NO;
50 NSMenu *mainMenu = nil;
51
52 if (!alreadyInstalled && ((mainMenu = [NSApp mainMenu]) != nil)) {
53 NSMenu *insertIntoMenu = nil;
[153]54 id<NSMenuItem> item;
[7]55 unsigned insertLoc = NSNotFound;
[153]56 NSBundle *bundle = [NSBundle bundleForClass: self];
[7]57 NSMenu * beforeSubmenu = [NSApp windowsMenu];
58 // Succeed or fail, we do not try again.
59 alreadyInstalled = YES;
60
61 // 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.)
62
63 if (!beforeSubmenu) {
64 beforeSubmenu = [NSApp servicesMenu];
65 }
66
67 insertIntoMenu = mainMenu;
68
69 if (beforeSubmenu) {
70 NSArray *itemArray = [insertIntoMenu itemArray];
71 unsigned i, c = [itemArray count];
72
73 // Default to end of menu
74 insertLoc = c;
75
76 for (i=0; i<c; i++) {
77 if ([[itemArray objectAtIndex:i] target] == beforeSubmenu) {
78 insertLoc = i;
79 break;
80 }
81 }
82 } else {
83 NSArray *itemArray = [insertIntoMenu itemArray];
84 unsigned i = [itemArray count];
85
86 // Default to end of menu
87 insertLoc = i;
88
89 while (i-- > 0) {
90 if ([[itemArray objectAtIndex:i] hasSubmenu]) {
91 insertLoc = i+1;
92 break;
93 }
94 }
95 }
96 if (insertIntoMenu) {
[14]97 NSMenu *fsaMenu = [[NSMenu allocWithZone: [NSMenu menuZone]] initWithTitle:NSLocalizedStringFromTableInBundle(@"FSA", @"FSA", bundle, @"Title of F-Script Anywhere menu")];
[7]98
[14]99 item = [insertIntoMenu insertItemWithTitle: NSLocalizedStringFromTableInBundle(@"FSA", @"FSA", bundle, @"Title of F-Script Anywhere menu") action:NULL keyEquivalent:@"" atIndex:insertLoc];
[7]100 [insertIntoMenu setSubmenu:fsaMenu forItem:item];
101 [fsaMenu release];
102
103 // Add the items for the commands.
[14]104 item = [fsaMenu addItemWithTitle: NSLocalizedStringFromTableInBundle(@"New F-Script Workspace", @"FSA", bundle, @"Title of F-Script Workspace menu item") action:@selector(createInterpreterWindow:) keyEquivalent: @""];
[7]105 [item setTarget: self];
106 [fsaMenu addItem: [NSMenuItem separatorItem]];
[153]107 item = [fsaMenu addItemWithTitle: NSLocalizedStringFromTableInBundle(@"About F-Script Anywhere...", @"FSA", bundle, @"Title of Info Panel menu item") action:@selector(showInfo:) keyEquivalent: @""];
[7]108 [item setTarget: self];
[19]109 [[FSAWindowManager sharedManager] setWindowMenu: fsaMenu];
[7]110 }
111 }
112
113}
114
115+ (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
116{
117 SEL sel;
118 NSAssert([menuItem target] == self, @"menu item does not target FSAController!");
119 sel = [menuItem action];
120 if (sel == @selector(showInfo:) || sel == @selector(createInterpreterWindow:)) return YES;
[19]121 FSALog(@"+[FSAController validateMenuItem:] unknown menu item for validation: %@", menuItem);
[7]122 return NO;
123}
124
125+ (void)createInterpreterWindow:(id)sender;
126{
127 [[self alloc] init];
128}
129
130+ (void)showInfo:(id)sender;
131{
[19]132 int result = NSRunInformationalAlertPanel([NSString stringWithFormat: @"About F-Script Anywhere (version %s)", FSA_VERSION], @"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);
[7]133 if (result == NSAlertAlternateReturn) {
134 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: FSA_FScriptURL]];
135 }
136}
137
138- (id)init {
139 self = [super initWithWindowNibName: @"FSAInterpreterPanel"];
140
141 if (self != nil) {
142 NSWindow *window = [self window];
[19]143 NSString *label;
144 static unsigned numInterpWindows = 0;
[7]145
[153]146 NSAssert(window != nil, @"Can't get interpreter window!");
[19]147 if (interpreterNum == 0) interpreterNum = ++numInterpWindows;
148 if ( (label = [self interpreterLabel]) != nil) {
149 [window setTitle: [NSString stringWithFormat: @"%@: %@", [window title], label]];
[7]150 }
151
152 [window setLevel: NSNormalWindowLevel]; // XXX if set floating, it is globally floating!
153 [self showWindow: self];
154 [window makeKeyAndOrderFront: self];
155#warning this should go away when F-Script properly accepts firstResponder on the InterpreterView
156 [window makeFirstResponder: (NSView *)[[[self interpreterView] cliView] shellView]];
[19]157 [[FSAWindowManager sharedManager] registerWindow: window];
[14]158 system = [[[self interpreterView] interpreter] objectForIdentifier: @"sys" found: NULL];
159 [system retain];
160 NSAssert1([system isKindOfClass: [System class]], @"Initial value bound to identifier 'sys' is not a System object, but %@", system);
[7]161 }
162
163 return self;
164}
165
[14]166- (void)dealloc;
167{
168 [system release];
169 [super dealloc];
170}
171
[19]172- (NSString *)interpreterLabel;
173{
174 static NSString *appName = nil;
175 static BOOL retrievedAppName = NO;
176
177 if (appName == nil) {
178 if (retrievedAppName) return nil;
179 NS_DURING
180 appName = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleName"];
181 NS_HANDLER
182 FSALog(@"Exception occurred while trying to obtain application name: %@", localException);
183 NS_ENDHANDLER
184 retrievedAppName = YES;
185 }
186 if (interpreterNum == 1) return appName;
187 return [NSString stringWithFormat: @"%@ [%u]", appName, interpreterNum];
188}
189
[7]190- (FSInterpreterView *)interpreterView;
191{
192 return interpreterView;
193}
194
[14]195- (System *)system;
196{
197 return system;
198}
199
[7]200- (IBAction)setFloating:(id)sender;
201{
202 [[self window] setLevel: [sender state] == NSOnState ? NSFloatingWindowLevel : NSNormalWindowLevel];
203}
204
[223]205- (IBAction)FSA_associateAndOpenBrowser:(id)sender
206{
207}
208
[14]209- (IBAction)FSA_associateWithInterface:(id)sender;
[7]210{
211 NS_DURING
[19]212 FSAWindowManager *wm = [FSAWindowManager sharedManager];
[7]213 if (viewAssociationController == nil) {
[14]214 viewAssociationController = [[FSAViewAssociationController alloc] initWithFSAController: self];
[7]215 }
216 [viewAssociationController showWindow: self];
[19]217 if (![wm windowIsRegistered: [viewAssociationController window]]) {
218 [wm registerSubordinateWindow: [viewAssociationController window]
219 forWindow: [self window]];
220 }
[7]221 NS_HANDLER
222 FSALog(@"%@", localException);
223 NS_ENDHANDLER
224}
225
226@end
Note: See TracBrowser for help on using the repository browser.