- Timestamp:
- 10/20/02 04:41:17 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/F-Script Anywhere/Source/FSAViewAssociationController.m
r7 r14 26 26 27 27 #import "FSAViewAssociationController.h" 28 #import "FSAController.h" 29 #import "FSAnywhere.h" 30 #import <FScript/FSInterpreter.h> 31 #import <FScript/System.h> 32 33 // XXX workaround for lack of identifier validation; should go away when F-Script adds (promised) direct support for this 34 @interface Compiler 35 + (BOOL)isValidIndentifier:(NSString *)str; 36 @end 28 37 29 38 @implementation FSAViewAssociationController 30 39 31 - (id)initWith Interpreter:(FSInterpreter *)anInterpreter;40 - (id)initWithFSAController:(FSAController *)fsa; 32 41 { 33 42 self = [super initWithWindowNibName: @"FSAViewAssociationPanel"]; 34 43 35 44 if (self != nil) { 36 interpreter = [anInterpreter retain]; 45 interpreter = [[[fsa interpreterView] interpreter] retain]; 46 system = [fsa system]; 37 47 [self window]; 38 48 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(controlTextDidChange:) name: NSControlTextDidChangeNotification object: variableNameField]; 49 [[captureButton cell] setShowsStateBy: NSContentsCellMask | NSChangeGrayCellMask]; 39 50 [self update: nil]; 40 51 } … … 53 64 - (IBAction)update:(id)sender; 54 65 { 55 [associateButton setEnabled: selectedView != nil && [[variableNameField stringValue] length] != 0]; 66 NSString *variableName = [variableNameField stringValue]; 67 BOOL canAssignToVariable = NO; 68 [browseButton setEnabled: selectedView != nil]; 69 [statusField setStringValue: @""]; 70 if ([variableName length] != 0) { 71 if (![Compiler isValidIndentifier: variableName]) { 72 [statusField setStringValue: @"Invalid name: contains spaces, punctuation or non-ASCII characters"]; 73 } else if (selectedView != nil) { 74 [statusField setStringValue: @"Click ÒAssociateÓ to assign to this variable"]; 75 canAssignToVariable = YES; 76 } 77 } 78 [associateButton setEnabled: canAssignToVariable]; 56 79 [variableNameField setEnabled: [captureButton state] == NSOffState]; 57 80 } … … 59 82 - (void)stopCapturing; 60 83 { 84 FSALog(@"stopping capture"); 61 85 [captureButton setState: NSOffState]; 62 86 [statusField setStringValue: @""]; 63 87 [self update: nil]; 64 88 [variableNameField becomeFirstResponder]; 89 } 90 91 - (void)_addElementToMenu:(id)element; 92 { 93 NSMenuItem *item; 94 if (element == nil) return; 95 item = [viewHierarchyMenu addItemWithTitle: [@" " 96 stringByAppendingString: NSStringFromClass([element class])] 97 action: @selector(elementSelected:) 98 keyEquivalent: @""]; 99 [item setTarget: self]; 100 [item setRepresentedObject: element]; 65 101 } 66 102 … … 70 106 NSView *view, *superView = nil, *contentView; 71 107 NSWindow *eventWindow; 72 NSMenuItem *item; 108 109 FSALog(@"capturing one"); 110 [captureButton setState: NSOnState]; 73 111 74 112 event = [NSApp nextEventMatchingMask: NSLeftMouseDownMask | NSRightMouseDownMask | NSKeyUpMask … … 90 128 NS_VOIDRETURN; 91 129 } 130 [viewHierarchyMenu addItemWithTitle: @"View" action: nil keyEquivalent: @""]; 131 [self _addElementToMenu: view]; 132 superView = view; 92 133 do { 93 if (superView == nil) superView = view; 94 else superView = [superView superview]; 134 superView = [superView superview]; 95 135 if (superView == nil) break; 96 item = [viewHierarchyMenu addItemWithTitle: NSStringFromClass([superView class]) 97 action: @selector(viewSelected:) 98 keyEquivalent: @""]; 99 [item setTarget: self]; 100 [item setRepresentedObject: superView]; 136 [self _addElementToMenu: superView]; 101 137 } while (superView != contentView); 102 138 [viewHierarchyMenu addItem: [NSMenuItem separatorItem]]; 103 item = [viewHierarchyMenu addItemWithTitle: NSStringFromClass([eventWindow class]) 104 action: @selector(viewSelected:) 105 keyEquivalent: @""]; 106 [item setTarget: self]; 107 [item setRepresentedObject: eventWindow]; 139 [viewHierarchyMenu addItemWithTitle: @"Window" action: nil keyEquivalent: @""]; 140 [self _addElementToMenu: eventWindow]; 108 141 NS_HANDLER 109 142 [descriptionField setStringValue: … … 111 144 NS_ENDHANDLER 112 145 [NSMenu popUpContextMenu: viewHierarchyMenu withEvent: event forView: view]; 146 if ([captureButton state] == NSOnState) 147 [self captureOneView]; 113 148 } 114 149 115 150 - (IBAction)captureView:(id)sender 116 151 { 117 [statusField setStringValue: @"Click to select; press any key to cancel."];152 [statusField setStringValue: @"Click inside one of this applicationÕs windows to select."]; 118 153 [selectedView release]; selectedView = nil; 119 154 [self update: nil]; … … 121 156 } 122 157 123 - (void) viewSelected:(NSMenuItem *)sender;158 - (void)elementSelected:(NSMenuItem *)sender; 124 159 { 125 NSView *view = [sender representedObject]; 160 NSView *element = [sender representedObject]; 161 FSALog(@"element selected: %@", sender); 126 162 NS_DURING 127 [descriptionField setStringValue: [ viewdescription]];163 [descriptionField setStringValue: [element description]]; 128 164 [selectedView release]; 129 selectedView = [ viewretain];165 selectedView = [element retain]; 130 166 NS_HANDLER 131 167 [descriptionField setStringValue: … … 136 172 } 137 173 138 - (IBAction)defineVariable:(id)sender 174 - (IBAction)defineVariable:(id)sender; 139 175 { 140 [statusField setStringValue: @"AssociatingÉ"]; 176 #warning this should change when F-Script supports a public API for identifier validation 141 177 NS_DURING 142 178 NSString *variableName = [variableNameField stringValue]; 179 [statusField setStringValue: @"AssociatingÉ"]; 143 180 [interpreter setObject: selectedView forIdentifier: variableName]; 144 181 [statusField setStringValue: [NSString stringWithFormat: @"Assigned variable Ò%@Ó", variableName]]; … … 146 183 [statusField setStringValue: [NSString stringWithFormat: @"Assocation failed: %@", localException]]; 147 184 NS_ENDHANDLER 185 } 186 187 - (IBAction)viewInObjectBrowser:(id)sender; 188 { 189 FSALog(@"system: %@", system); 190 [system browse: selectedView]; 191 [statusField setStringValue: @"Opened object browser"]; 148 192 } 149 193
Note:
See TracChangeset
for help on using the changeset viewer.