/[gnustep]/gnustep/dev-apps/Gorm/Gorm.m
ViewVC logotype

Contents of /gnustep/dev-apps/Gorm/Gorm.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.105 - (show annotations) (download)
Wed Oct 1 23:11:01 2003 UTC (20 years, 7 months ago) by gcasa
Branch: MAIN
CVS Tags: Gorm-0_4_0
Changes since 1.104: +2 -2 lines
Changed version number and minor cleanup in GormNSMenu.m

1 /* Gorm.m
2 *
3 * Copyright (C) 1999, 2003 Free Software Foundation, Inc.
4 *
5 * Author: Richard Frith-Macdonald <richard@brainstrom.co.uk>
6 * Author: Gregory John Casamento <greg_casamento@yahoo.com>
7 * Date: 1999, 2003
8 *
9 * This file is part of GNUstep.
10 *
11 * This program 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 * This program 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 this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 #include "GormPrivate.h"
27 #include "GormPrefController.h"
28 #include "GormFontViewController.h"
29 #include "GormSetNameController.h"
30
31 // for templates...
32 #include <AppKit/NSControl.h>
33 #include <AppKit/NSButton.h>
34
35 NSDate *startDate;
36 NSString *GormToggleGuidelineNotification = @"GormToggleGuidelineNotification";
37 NSString *GormDidModifyClassNotification = @"GormDidModifyClassNotification";
38 NSString *GormDidAddClassNotification = @"GormDidAddClassNotification";
39 NSString *GormDidDeleteClassNotification = @"GormDidDeleteClassNotification";
40
41 @class InfoPanel;
42
43 // we had this include for grouping/ungrouping selectors
44 #include "GormViewWithContentViewEditor.h"
45
46 @implementation NSCell (GormAdditions)
47 /*
48 * this methods is directly coming from NSCell.m
49 * The only additions is [textObject setUsesFontPanel: NO]
50 * We do this because we want to have control over the font panel changes
51 */
52 - (NSText *)setUpFieldEditorAttributes:(NSText *)textObject
53 {
54 [textObject setUsesFontPanel: NO];
55 [textObject setTextColor: [self textColor]];
56 if (_cell.contents_is_attributed_string == NO)
57 {
58 /* TODO: Manage scrollable attribute */
59 [textObject setFont: _font];
60 [textObject setAlignment: _cell.text_align];
61 }
62 else
63 {
64 /* FIXME/TODO. What do we do if we are an attributed string.
65 Think about what happens when the user ends editing.
66 Allows editing text attributes... Formatter... TODO. */
67 }
68 [textObject setEditable: _cell.is_editable];
69 [textObject setSelectable: _cell.is_selectable || _cell.is_editable];
70 [textObject setRichText: _cell.is_rich_text];
71 [textObject setImportsGraphics: _cell.imports_graphics];
72 [textObject setSelectedRange: NSMakeRange(0, 0)];
73
74 return textObject;
75 }
76 @end
77
78 @implementation GSNibItem (GormAdditions)
79 - initWithClassName: (NSString*)className frame: (NSRect)frame
80 {
81 self = [super init];
82
83 theClass = [className copy];
84 theFrame = frame;
85
86 return self;
87 }
88 - (NSString*) className
89 {
90 return theClass;
91 }
92 @end
93
94 @implementation GormObjectProxy
95 /*
96 * Perhaps this would be better to have a dummy initProxyWithCoder
97 * in GSNibItem class, so that we are not dependent on actual coding
98 * order of the ivars ?
99 */
100 - (id) initWithCoder: (NSCoder*)aCoder
101 {
102 int version = [aCoder versionForClassName:
103 NSStringFromClass([GSNibItem class])];
104
105 if (version == NSNotFound)
106 {
107 NSLog(@"no GSNibItem");
108 version = [aCoder versionForClassName:
109 NSStringFromClass([GormObjectProxy class])];
110 }
111
112 if (version == 0)
113 {
114 // do not decode super (it would try to morph into theClass ! )
115 [aCoder decodeValueOfObjCType: @encode(id) at: &theClass];
116 theFrame = [aCoder decodeRect];
117 //NSLog(@"Decoding proxy : %@", theClass);
118 RETAIN(theClass);
119
120 return self;
121 }
122 else if (version == 1)
123 {
124 // do not decode super (it would try to morph into theClass ! )
125 [aCoder decodeValueOfObjCType: @encode(id) at: &theClass];
126 theFrame = [aCoder decodeRect];
127 [aCoder decodeValueOfObjCType: @encode(unsigned int)
128 at: &autoresizingMask];
129 //NSLog(@"Decoding proxy : %@", theClass);
130 RETAIN(theClass);
131
132 return self;
133 }
134 else
135 {
136 NSLog(@"no initWithCoder for version %d", version);
137 RELEASE(self);
138 return nil;
139 }
140 }
141
142 - (NSString*) inspectorClassName
143 {
144 return @"GormNotApplicableInspector";
145 }
146
147 - (NSString*) classInspectorClassName
148 {
149 return @"GormNotApplicableInspector";
150 }
151
152 - (void) setClassName: (NSString *)className
153 {
154 RELEASE(theClass);
155 theClass = [className copy];
156 }
157 @end
158
159 // define the class proxy...
160 @implementation GormClassProxy
161 - (id) initWithClassName: (NSString*)n
162 {
163 self = [super init];
164 if (self != nil)
165 {
166 ASSIGN(name, n);
167 }
168 return self;
169 }
170
171 - (void) dealloc
172 {
173 RELEASE(name);
174 [super dealloc];
175 }
176
177 - (NSString*) className
178 {
179 return name;
180 }
181
182 - (NSString*) inspectorClassName
183 {
184 return @"GormClassInspector";
185 }
186
187 - (NSString*) classInspectorClassName
188 {
189 return @"GormNotApplicableInspector";
190 }
191
192 - (NSString*) connectInspectorClassName
193 {
194 return @"GormNotApplicableInspector";
195 }
196
197 - (NSString*) sizeInspectorClassName
198 {
199 return @"GormNotApplicableInspector";
200 }
201 @end
202 @implementation Gorm
203
204 - (id<IBDocuments>) activeDocument
205 {
206 unsigned i = [documents count];
207
208 if (i > 0)
209 {
210 while (i-- > 0)
211 {
212 id doc = [documents objectAtIndex: i];
213
214 if ([doc isActive] == YES)
215 {
216 return doc;
217 }
218 }
219 }
220 return nil;
221 }
222
223 /*
224 NSApp
225 */
226 - (id) init
227 {
228 self = [super init];
229 if (self != nil)
230 {
231 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
232 NSBundle *bundle = [NSBundle mainBundle];
233 NSString *path;
234
235 path = [bundle pathForImageResource: @"GormLinkImage"];
236 linkImage = [[NSImage alloc] initWithContentsOfFile: path];
237 path = [bundle pathForImageResource: @"GormSourceTag"];
238 sourceImage = [[NSImage alloc] initWithContentsOfFile: path];
239 path = [bundle pathForImageResource: @"GormTargetTag"];
240 targetImage = [[NSImage alloc] initWithContentsOfFile: path];
241
242 documents = [NSMutableArray new];
243 [nc addObserver: self
244 selector: @selector(handleNotification:)
245 name: IBSelectionChangedNotification
246 object: nil];
247 [nc addObserver: self
248 selector: @selector(handleNotification:)
249 name: IBWillCloseDocumentNotification
250 object: nil];
251
252 /*
253 * Make sure the palettes manager exists, so that the editors and
254 * inspectors provided in the standard palettes are available.
255 */
256 [self palettesManager];
257
258 // load the interface...
259 if(![NSBundle loadNibNamed: @"Gorm" owner: self])
260 {
261 NSLog(@"Failed to load interface");
262 exit(-1);
263 }
264 }
265 return self;
266 }
267
268
269 - (void) dealloc
270 {
271 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
272
273 [nc removeObserver: self];
274 RELEASE(infoPanel);
275 RELEASE(inspectorsManager);
276 RELEASE(palettesManager);
277 RELEASE(documents);
278 RELEASE(classManager);
279 // [super dealloc];
280 }
281
282
283 - (void) applicationDidFinishLaunching: (NSApplication*)sender
284 {
285 if ( [[NSUserDefaults standardUserDefaults] boolForKey: @"ShowInspectors"] )
286 {
287 [[[self inspectorsManager] panel] makeKeyAndOrderFront: self];
288 }
289 if ( [[NSUserDefaults standardUserDefaults] boolForKey: @"ShowPalettes"] )
290 {
291 [[[self palettesManager] panel] makeKeyAndOrderFront: self];
292 }
293 }
294
295
296 - (void) applicationWillTerminate: (NSApplication*)sender
297 {
298 // [[NSUserDefaults standardUserDefaults]
299 // setBool: [[[self inspectorsManager] panel] isVisible]
300 // forKey: @"ShowInspectors"];
301 // [[NSUserDefaults standardUserDefaults]
302 // setBool: [[[self palettesManager] panel] isVisible]
303 // forKey: @"ShowPalettes"];
304 }
305
306 - (BOOL) applicationShouldTerminate: (NSApplication*)sender
307 {
308 id doc;
309 BOOL edited = NO;
310 NSEnumerator *enumerator = [documents objectEnumerator];
311
312
313 if (isTesting == YES)
314 {
315 [self endTesting: sender];
316 return NO;
317 }
318
319
320 while (( doc = [enumerator nextObject] ) != nil )
321 {
322 if ([[doc window] isDocumentEdited] == YES)
323 {
324 edited = YES;
325 break;
326 }
327 }
328
329 if (edited == YES)
330 {
331 int result;
332 result = NSRunAlertPanel(NULL, _(@"There are edited windows"),
333 _(@"Review Unsaved"),_( @"Quit Anyway"), _(@"Cancel"));
334 if (result == NSAlertDefaultReturn)
335 {
336 enumerator = [ documents objectEnumerator];
337 while ((doc = [enumerator nextObject]) != nil)
338 {
339 if ( [[doc window] isDocumentEdited] == YES)
340 {
341 if ( ! [doc couldCloseDocument] )
342 return NO;
343 }
344 }
345 }
346 else if (result == NSAlertOtherReturn)
347 return NO;
348 }
349 return YES;
350 }
351
352 - (GormClassManager*) classManager
353 {
354 id document = [self activeDocument];
355
356 if (document != nil) return [document classManager];
357
358 /* kept in the case one want access to the classManager without document */
359 else if (classManager == nil)
360 {
361 classManager = [GormClassManager new];
362 }
363 return classManager;
364
365 }
366
367
368 /***********************************************************************/
369 /*********************** Info Menu Actions****************************/
370 /***********************************************************************/
371
372 - (id) connectDestination
373 {
374 return connectDestination;
375 }
376
377 - (id) connectSource
378 {
379 return connectSource;
380 }
381
382
383 - (void) displayConnectionBetween: (id)source
384 and: (id)destination
385 {
386 NSWindow *window;
387 NSRect rect;
388
389
390 if (source != connectSource)
391 {
392 if (connectSource != nil)
393 {
394 window = [[self activeDocument] windowAndRect: &rect
395 forObject: connectSource];
396 if (window != nil)
397 {
398 NSView *view = [[window contentView] superview];
399
400 rect.origin.x --;
401 rect.size.width ++;
402
403 rect.size.height ++;
404
405 [window disableFlushWindow];
406 [view displayRect: rect];
407
408 [window enableFlushWindow];
409 [window flushWindow];
410 }
411 }
412 connectSource = source;
413 }
414 if (destination != connectDestination)
415 {
416 if (connectDestination != nil)
417 {
418 window = [[self activeDocument] windowAndRect: &rect
419 forObject: connectDestination];
420 if (window != nil)
421 {
422 NSView *view = [[window contentView] superview];
423
424 /*
425 * Erase image from old location.
426 */
427 rect.origin.x --;
428 rect.size.width ++;
429 rect.size.height ++;
430
431 [view lockFocus];
432 [view displayRect: rect];
433 [view unlockFocus];
434 [window flushWindow];
435 }
436 }
437 connectDestination = destination;
438 }
439 if (connectSource != nil)
440 {
441 window = [[self activeDocument] windowAndRect: &rect forObject: connectSource];
442 if (window != nil)
443 {
444 NSView *view = [[window contentView] superview];
445
446 rect.origin.x++;
447 rect.size.width--;
448 rect.size.height--;
449 [view lockFocus];
450 [[NSColor greenColor] set];
451 NSFrameRectWithWidth(rect, 2);
452
453 [sourceImage compositeToPoint: rect.origin
454 operation: NSCompositeSourceOver];
455 [view unlockFocus];
456 [window flushWindow];
457 }
458 }
459 if (connectDestination != nil && connectDestination == connectSource)
460 {
461 window = [[self activeDocument] windowAndRect: &rect
462 forObject: connectDestination];
463 if (window != nil)
464 {
465 NSView *view = [[window contentView] superview];
466
467 rect.origin.x += 3;
468 rect.origin.y += 2;
469 rect.size.width -= 5;
470 rect.size.height -= 5;
471 [view lockFocus];
472 [[NSColor purpleColor] set];
473 NSFrameRectWithWidth(rect, 2);
474
475 rect.origin.x += [targetImage size].width;
476 [targetImage compositeToPoint: rect.origin
477 operation: NSCompositeSourceOver];
478 [view unlockFocus];
479 [window flushWindow];
480 }
481 }
482 else if (connectDestination != nil)
483 {
484 window = [[self activeDocument] windowAndRect: &rect
485 forObject: connectDestination];
486 if (window != nil)
487 {
488 NSView *view = [[window contentView] superview];
489
490 rect.origin.x++;
491 rect.size.width--;
492 rect.size.height--;
493 [view lockFocus];
494 [[NSColor purpleColor] set];
495 NSFrameRectWithWidth(rect, 2);
496
497 [targetImage compositeToPoint: rect.origin
498 operation: NSCompositeSourceOver];
499 [view unlockFocus];
500 [window flushWindow];
501 }
502 }
503 }
504
505
506
507 /***********************************************************************/
508 /*********************** Info Menu Actions ****************************/
509 /***********************************************************************/
510
511 - (void) infoPanel: (id) sender
512 {
513 NSMutableDictionary *dict;
514
515 dict = [NSMutableDictionary dictionaryWithCapacity: 8];
516 [dict setObject: @"Gorm"
517 forKey: @"ApplicationName"];
518 [dict setObject: @"[GNUstep | Graphical] Object Relationship Modeller"
519 forKey: @"ApplicationDescription"];
520 [dict setObject: @"Gorm 0.4.0 (Beta)"
521 forKey: @"ApplicationRelease"];
522 [dict setObject: @"0.4.0 Oct 01 2003"
523 forKey: @"FullVersionID"];
524 [dict setObject: [NSArray arrayWithObjects: @"Gregory John Casamento <greg_casamento@yahoo.com>",
525 @"Richard Frith-Macdonald <rfm@gnu.org>",
526 @"Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>",
527 nil]
528 forKey: @"Authors"];
529 [dict setObject: @"Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc."
530 forKey: @"Copyright"];
531 [dict setObject: @"Released under the GNU General Public License 2.0"
532 forKey: @"CopyrightDescription"];
533
534 [self orderFrontStandardInfoPanelWithOptions: dict];
535 }
536
537
538 - (void) preferencesPanel: (id) sender
539 {
540 if(! preferencesController)
541 {
542 preferencesController = [[GormPrefController alloc] initWithWindowNibName:@"GormPreferences"];
543 }
544
545 [[preferencesController window] makeKeyAndOrderFront:nil];
546 }
547
548
549 /***********************************************************************/
550 /*********************** Document Menu Actions*************************/
551 /***********************************************************************/
552 - (void) open: (id) sender
553 {
554 GormDocument *doc = [GormDocument new];
555
556 [documents addObject: doc];
557 RELEASE(doc);
558 if ([doc openDocument: sender] == nil)
559 {
560 [documents removeObjectIdenticalTo: doc];
561 doc = nil;
562 }
563 else
564 {
565 [[doc window] makeKeyAndOrderFront: self];
566 }
567 }
568
569
570 //include Modules Menu
571 - (void) newGormDocument : (id) sender
572 {
573 id doc = [GormDocument new];
574 [documents addObject: doc];
575 RELEASE(doc);
576 switch ([sender tag])
577 {
578 case 0:
579 [doc setupDefaults: @"Application"];
580 break;
581 case 1:
582 [doc setupDefaults: @"Empty"];
583 break;
584 case 2:
585 [doc setupDefaults: @"Inspector"];
586 break;
587 case 3:
588 [doc setupDefaults: @"Palette"];
589 break;
590
591 default:
592 printf("unknow newGormDocument tag");
593 }
594 if (NSEqualPoints(cascadePoint, NSZeroPoint))
595 {
596 NSRect frame = [[doc window] frame];
597 cascadePoint = NSMakePoint(frame.origin.x, NSMaxY(frame));
598 }
599 cascadePoint = [[doc window] cascadeTopLeftFromPoint:cascadePoint];
600 [[doc window] makeKeyAndOrderFront: self];
601 }
602
603 - (void) save: (id)sender
604 {
605 [(GormDocument *)[self activeDocument] saveGormDocument: sender];
606 }
607
608 - (void) saveAs: (id)sender
609 {
610 [(GormDocument *)[self activeDocument] saveAsDocument: sender];
611 }
612
613
614 - (void) saveAll: (id)sender
615 {
616 NSEnumerator *enumerator = [documents objectEnumerator];
617 id doc;
618
619 while ((doc = [enumerator nextObject]) != nil)
620 {
621 if ([[doc window] isDocumentEdited] == YES)
622 {
623 if (! [doc saveGormDocument: sender] )
624 NSLog(@"can not save %@",doc);
625 }
626 }
627 }
628
629
630 - (void) revertToSaved: (id)sender
631 {
632 id doc = [(GormDocument *)[self activeDocument] revertDocument: sender];
633
634 if (doc != nil)
635 {
636 [documents addObject: doc];
637 [[doc window] makeKeyAndOrderFront: self];
638 }
639 }
640
641 - (void) close: (id)sender
642 {
643 NSWindow *window = [(GormDocument *)[self activeDocument] window];
644
645 [window setReleasedWhenClosed: YES];
646 [window performClose: self];
647 }
648
649 - (void) debug: (id) sender
650 {
651 [[self activeDocument] performSelector: @selector(printAllEditors)];
652 }
653
654 - (void) loadSound: (id) sender
655 {
656 [(GormDocument *)[self activeDocument] openSound: sender];
657 }
658
659 - (void) loadImage: (id) sender
660 {
661 [(GormDocument *)[self activeDocument] openImage: sender];
662 }
663
664 - (void) testInterface: (id)sender
665 {
666 if (isTesting == YES)
667 {
668 return;
669 }
670 else
671 {
672 NSUserDefaults *defaults;
673 NSNotificationCenter *notifCenter = [NSNotificationCenter defaultCenter];
674 GormDocument *activDoc = (GormDocument*)[self activeDocument];
675 NSData *data;
676 NSArchiver *archiver;
677
678
679 isTesting = YES; // set here, so that beginArchiving and endArchiving do not use templates.
680 archiver = [[NSArchiver alloc] init];
681 [activDoc beginArchiving];
682 [archiver encodeClassName: @"GormNSWindow"
683 intoClassName: @"NSWindow"];
684 [archiver encodeClassName: @"GormNSPanel"
685 intoClassName: @"NSPanel"];
686 [archiver encodeClassName: @"GormNSMenu"
687 intoClassName: @"NSMenu"];
688 [archiver encodeClassName: @"GormNSPopUpButton"
689 intoClassName: @"NSPopUpButton"];
690 [archiver encodeClassName: @"GormNSPopUpButtonCell"
691 intoClassName: @"NSPopUpButtonCell"];
692 [archiver encodeClassName: @"GormCustomView"
693 intoClassName: @"GormTestCustomView"];
694 [archiver encodeRootObject: activDoc];
695 data = RETAIN([archiver archiverData]);
696 [activDoc endArchiving];
697 RELEASE(archiver);
698
699 [notifCenter postNotificationName: IBWillBeginTestingInterfaceNotification
700 object: self];
701
702 if ([selectionOwner conformsToProtocol: @protocol(IBEditors)] == YES)
703 {
704 [(id<IBEditors>)selectionOwner makeSelectionVisible: NO];
705 }
706
707 defaults = [NSUserDefaults standardUserDefaults];
708 menuLocations = [[defaults objectForKey: @"NSMenuLocations"] copy];
709 [defaults removeObjectForKey: @"NSMenuLocations"];
710
711 testContainer = [NSUnarchiver unarchiveObjectWithData: data];
712 if (testContainer != nil)
713 {
714 [testContainer awakeWithContext: nil];
715 RETAIN(testContainer);
716 }
717
718 /*
719 * If the NIB didn't have a main menu, create one,
720 * otherwise, ensure that 'quit' ends testing mode.
721 */
722 if ([self mainMenu] == mainMenu)
723 {
724 NSMenu *testMenu;
725
726 testMenu = [[NSMenu alloc] initWithTitle: _(@"Test")];
727 [testMenu addItemWithTitle: _(@"Quit")
728 action: @selector(deferredEndTesting:)
729 keyEquivalent: @"q"];
730 [self setMainMenu: testMenu];
731 RELEASE(testMenu);
732 }
733 else
734 {
735 NSMenu *testMenu = [self mainMenu];
736 id item;
737
738 item = [testMenu itemWithTitle: _(@"Quit")];
739 if (item != nil)
740 {
741 [item setAction: @selector(deferredEndTesting:)];
742 }
743 else
744 {
745 [testMenu addItemWithTitle: _(@"Quit")
746 action: @selector(deferredEndTesting:)
747 keyEquivalent: @"q"];
748 }
749 }
750
751 [notifCenter postNotificationName: IBDidBeginTestingInterfaceNotification
752 object: self];
753
754 RELEASE(data);
755 }
756 }
757
758
759
760
761 /***********************************************************************/
762 /*********************** Edit Menu Actions*****************************/
763 /***********************************************************************/
764
765 - (void) copy: (id)sender
766 {
767 if ([[selectionOwner selection] count] == 0
768 || [selectionOwner respondsToSelector: @selector(copySelection)] == NO)
769 return;
770
771 [(GormGenericEditor *)selectionOwner copySelection];
772 }
773
774
775 - (void) cut: (id)sender
776 {
777 if ([[selectionOwner selection] count] == 0
778 || [selectionOwner respondsToSelector: @selector(copySelection)] == NO
779 || [selectionOwner respondsToSelector: @selector(deleteSelection)] == NO)
780 return;
781 [(GormGenericEditor *)selectionOwner copySelection];
782 [(GormGenericEditor *)selectionOwner deleteSelection];
783 }
784
785 - (void) paste: (id)sender
786 {
787 if ([selectionOwner respondsToSelector: @selector(pasteInSelection)] == NO)
788 return;
789
790 [(GormGenericEditor *)selectionOwner pasteInSelection];
791 }
792
793
794 - (void) delete: (id)sender
795 {
796 if ([[selectionOwner selection] count] == 0
797 || [selectionOwner respondsToSelector: @selector(deleteSelection)] == NO)
798 return;
799 [(GormGenericEditor *)selectionOwner deleteSelection];
800 }
801
802 - (void) selectAllItems: (id)sender
803 {
804 /* FIXME */
805 return;
806 }
807
808 - (void) setName: (id)sender
809 {
810 GormSetNameController *panel;
811 int returnPanel;
812 NSTextField *textField;
813 NSArray *selectionArray = [selectionOwner selection];
814 id obj = [selectionArray objectAtIndex: 0];
815 NSString *name;
816
817 panel = [GormSetNameController new];
818 returnPanel = [panel runAsModal];
819 textField = [panel textField];
820
821 if (returnPanel == NSAlertDefaultReturn)
822 {
823 name = [[textField stringValue] stringByTrimmingSpaces];
824 if (name != nil && [name isEqual: @""] == NO)
825 {
826 [[self activeDocument] setName: name forObject: obj];
827 }
828 }
829 RELEASE(panel);
830 }
831
832 - (void) guideline: (id) sender
833 {
834 [[NSNotificationCenter defaultCenter] postNotificationName: GormToggleGuidelineNotification
835 object:nil];
836 if ( [guideLineMenuItem tag] == 0 )
837 {
838 [guideLineMenuItem setTitle:_(@"Enable GuideLine")];
839 [guideLineMenuItem setTag:1];
840 }
841 else if ( [guideLineMenuItem tag] == 1)
842 {
843 [guideLineMenuItem setTitle:_(@"Disable GuideLine")];
844 [guideLineMenuItem setTag:0];
845 }
846 }
847
848
849 - (void) orderFrontFontPanel: (id) sender
850 {
851 NSFontPanel *fontPanel = [NSFontPanel sharedFontPanel];
852 GormFontViewController *gfvc =
853 [GormFontViewController sharedGormFontViewController];
854 [fontPanel setAccessoryView: [gfvc view]];
855 [[NSFontManager sharedFontManager] orderFrontFontPanel: self];
856 }
857
858 /***********************************************************************/
859 /*********************** Group Action *******************************/
860 /***********************************************************************/
861
862 - (void) groupSelectionInSplitView: (id)sender
863 {
864 if ([[selectionOwner selection] count] < 2
865 || [selectionOwner respondsToSelector: @selector(groupSelectionInSplitView)] == NO)
866 return;
867
868 [(GormGenericEditor *)selectionOwner groupSelectionInSplitView];
869 }
870
871 - (void) groupSelectionInBox: (id)sender
872 {
873 if ([selectionOwner respondsToSelector: @selector(groupSelectionInBox)] == NO)
874 return;
875 [(GormGenericEditor *)selectionOwner groupSelectionInBox];
876 }
877
878 - (void) groupSelectionInScrollView: (id)sender
879 {
880 if ([selectionOwner respondsToSelector: @selector(groupSelectionInScrollView)] == NO)
881 return;
882 [(GormGenericEditor *)selectionOwner groupSelectionInScrollView];
883 }
884
885 - (void) ungroup: (id)sender
886 {
887 NSLog(@"ungroup: selectionOwner %@", selectionOwner);
888 if ([selectionOwner respondsToSelector: @selector(ungroup)] == NO)
889 return;
890 [(GormGenericEditor *)selectionOwner ungroup];
891 }
892
893
894
895 /***********************************************************************/
896 /*********************** Classes Action *******************************/
897 /***********************************************************************/
898
899 - (void) createSubclass: (id)sender
900 {
901 [(GormDocument *)[self activeDocument] createSubclass: sender];
902 }
903
904
905 - (void) loadClass: (id)sender
906 {
907 // Call the current document and create the class
908 // descibed by the header
909 [(GormDocument *)[self activeDocument] loadClass: sender];
910 }
911
912 - (void) createClassFiles: (id)sender
913 {
914 [(GormDocument *)[self activeDocument] createClassFiles: sender];
915 }
916
917 - (void) instantiateClass: (id)sender
918 {
919 [(GormDocument *)[self activeDocument] instantiateClass: sender];
920 }
921
922 - (void) addAttributeToClass: (id)sender
923 {
924 [(GormDocument *)[self activeDocument] addAttributeToClass: sender];
925 }
926
927 - (void) remove: (id)sender
928 {
929 [(GormDocument *)[self activeDocument] remove: sender];
930 }
931
932 /*
933 - (id) editClass: (id)sender
934 {
935 [self inspector: self];
936 return [(id)[self activeDocument] editClass: sender];
937 }
938 */
939
940
941 /***********************************************************************/
942 /*********************** Classes Action *******************************/
943 /***********************************************************************/
944
945 - (void) inspector: (id) sender
946 {
947 [[[self inspectorsManager] panel] makeKeyAndOrderFront: self];
948 }
949
950 - (void) palettes: (id) sender
951 {
952 [[[self palettesManager] panel] makeKeyAndOrderFront: self];
953 }
954
955 - (void) loadPalette: (id) sender
956 {
957 [[self palettesManager] openPalette: sender];
958 }
959
960
961 - (void) deferredEndTesting: (id) sender
962 {
963 [[NSRunLoop currentRunLoop]
964 performSelector: @selector(endTesting:)
965 target: self
966 argument: nil
967 order: 5000
968 modes: [NSArray arrayWithObjects:
969 NSDefaultRunLoopMode,
970 NSModalPanelRunLoopMode,
971 NSEventTrackingRunLoopMode, nil]];
972 }
973
974 - (id) endTesting: (id)sender
975 {
976 if (isTesting == NO)
977 {
978 return nil;
979 }
980 else
981 {
982 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
983 NSUserDefaults *defaults;
984 NSEnumerator *e;
985 id val;
986 CREATE_AUTORELEASE_POOL(pool);
987
988 [nc postNotificationName: IBWillEndTestingInterfaceNotification
989 object: self];
990
991 /*
992 * Make sure windows will go away when the container is destroyed.
993 */
994 e = [[testContainer nameTable] objectEnumerator];
995 while ((val = [e nextObject]) != nil)
996 {
997 if ([val isKindOfClass: [NSWindow class]] == YES)
998 {
999 [val close];
1000 }
1001 }
1002
1003 // prevent saving of this, if the menuLocations have not previously been set.
1004 if(menuLocations != nil)
1005 {
1006 defaults = [NSUserDefaults standardUserDefaults];
1007 [defaults setObject: menuLocations forKey: @"NSMenuLocations"];
1008 DESTROY(menuLocations);
1009 }
1010
1011 [self setMainMenu: mainMenu];
1012
1013 isTesting = NO;
1014
1015 if ([selectionOwner conformsToProtocol: @protocol(IBEditors)] == YES)
1016 {
1017 [(id<IBEditors>)selectionOwner makeSelectionVisible: YES];
1018 }
1019 [nc postNotificationName: IBDidEndTestingInterfaceNotification
1020 object: self];
1021 RELEASE(pool);
1022 return self;
1023 }
1024 }
1025
1026 - (void) finishLaunching
1027 {
1028 NSBundle *bundle;
1029 NSString *path;
1030
1031 /*
1032 * establish registration domain defaults from file.
1033 */
1034 bundle = [NSBundle mainBundle];
1035 path = [bundle pathForResource: @"Defaults" ofType: @"plist"];
1036 if (path != nil)
1037 {
1038 NSDictionary *dict;
1039
1040 dict = [NSDictionary dictionaryWithContentsOfFile: path];
1041 if (dict != nil)
1042 {
1043 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
1044
1045 [defaults registerDefaults: dict];
1046 }
1047 }
1048
1049 [self setDelegate: self];
1050 [super finishLaunching];
1051 NSDebugLog(@"StartupTime %f", [startDate timeIntervalSinceNow]);
1052 }
1053
1054 - (void) handleNotification: (NSNotification*)notification
1055 {
1056 NSString *name = [notification name];
1057 id obj = [notification object];
1058
1059 if ([name isEqual: IBSelectionChangedNotification])
1060 {
1061 /*
1062 * If we are connecting - stop it - a change in selection must mean
1063 * that the connection process has ended.
1064 */
1065 if ([self isConnecting] == YES)
1066 {
1067 [self stopConnecting];
1068 }
1069 [selectionOwner makeSelectionVisible: NO];
1070 selectionOwner = obj;
1071 [[self inspectorsManager] updateSelection];
1072 }
1073 else if ([name isEqual: IBWillCloseDocumentNotification])
1074 {
1075 RETAIN(obj);
1076 [documents removeObjectIdenticalTo: obj];
1077 AUTORELEASE(obj);
1078 }
1079 }
1080
1081
1082
1083 - (void) awakeFromNib
1084 {
1085 // set the menu...
1086 mainMenu = (NSMenu *)gormMenu;
1087 //for cascadePoint
1088 cascadePoint = NSZeroPoint;
1089 }
1090
1091
1092 - (GormInspectorsManager*) inspectorsManager
1093 {
1094 if (inspectorsManager == nil)
1095 {
1096 inspectorsManager = [GormInspectorsManager new];
1097 }
1098 return inspectorsManager;
1099 }
1100
1101
1102 - (BOOL) isConnecting
1103 {
1104 return isConnecting;
1105 }
1106
1107 - (BOOL) isTestingInterface
1108 {
1109 return isTesting;
1110 }
1111
1112 - (NSImage*) linkImage
1113 {
1114 return linkImage;
1115 }
1116
1117
1118 - (id) miniaturize: (id)sender
1119 {
1120 NSWindow *window = [(GormDocument *)[self activeDocument] window];
1121
1122 [window miniaturize: self];
1123 return nil;
1124 }
1125
1126
1127
1128 - (BOOL)application:(NSApplication *)application openFile:(NSString *)fileName
1129 {
1130 GormDocument *doc = [GormDocument new];
1131
1132 [documents addObject: doc];
1133 RELEASE(doc);
1134 if ([doc loadDocument: fileName] == nil)
1135 {
1136 [documents removeObjectIdenticalTo: doc];
1137 doc = nil;
1138 }
1139 else
1140 {
1141 [[doc window] makeKeyAndOrderFront: self];
1142 }
1143
1144 return (doc != nil);
1145 }
1146
1147 - (GormPalettesManager*) palettesManager
1148 {
1149 if (palettesManager == nil)
1150 {
1151 palettesManager = [GormPalettesManager new];
1152 }
1153 return palettesManager;
1154 }
1155
1156
1157
1158 - (id<IBSelectionOwners>) selectionOwner
1159 {
1160 return (id<IBSelectionOwners>)selectionOwner;
1161 }
1162
1163 - (id) selectedObject
1164 {
1165 return [[selectionOwner selection] lastObject];
1166 }
1167
1168
1169 - (void) startConnecting
1170 {
1171 if (isConnecting == YES)
1172 {
1173 return;
1174 }
1175 if (connectDestination == nil || connectSource == nil)
1176 {
1177 return;
1178 }
1179 if ([[self activeDocument] containsObject: connectDestination] == NO)
1180 {
1181 NSLog(@"Oops - connectDestination not in active document");
1182 return;
1183 }
1184 if ([[self activeDocument] containsObject: connectSource] == NO)
1185 {
1186 NSLog(@"Oops - connectSource not in active document");
1187 return;
1188 }
1189 isConnecting = YES;
1190 [[self inspectorsManager] updateSelection];
1191 }
1192
1193 - (void) stopConnecting
1194 {
1195 [self displayConnectionBetween: nil and: nil];
1196 isConnecting = NO;
1197 }
1198
1199
1200 - (BOOL) validateMenuItem: (NSMenuItem*)item
1201 {
1202 GormDocument *active = (GormDocument*)[self activeDocument];
1203 SEL action = [item action];
1204
1205 if (sel_eq(action, @selector(close:))
1206 || sel_eq(action, @selector(miniaturize:))
1207 || sel_eq(action, @selector(save:))
1208 || sel_eq(action, @selector(saveAs:))
1209 || sel_eq(action, @selector(saveAll:)))
1210 {
1211 if (active == nil)
1212 return NO;
1213 }
1214
1215 if (sel_eq(action, @selector(revertToSaved:)))
1216 {
1217 if (active == nil || [active documentPath] == nil
1218 || [[active window] isDocumentEdited] == NO)
1219 return NO;
1220 }
1221
1222 if (sel_eq(action, @selector(testInterface:)))
1223 {
1224 if (active == nil)
1225 return NO;
1226 }
1227
1228 if (sel_eq(action, @selector(copy:)))
1229 {
1230 if ([[selectionOwner selection] count] == 0)
1231 return NO;
1232 return [selectionOwner respondsToSelector: @selector(copySelection)];
1233 }
1234
1235 if (sel_eq(action, @selector(cut:)))
1236 {
1237 if ([[selectionOwner selection] count] == 0)
1238 return NO;
1239 return ([selectionOwner respondsToSelector: @selector(copySelection)]
1240 && [selectionOwner respondsToSelector: @selector(deleteSelection)]);
1241 }
1242
1243 if (sel_eq(action, @selector(delete:)))
1244 {
1245 if ([[selectionOwner selection] count] == 0)
1246 return NO;
1247 return [selectionOwner respondsToSelector: @selector(deleteSelection)];
1248 }
1249
1250 if (sel_eq(action, @selector(paste:)))
1251 {
1252 return [selectionOwner respondsToSelector: @selector(pasteInSelection)];
1253 }
1254
1255 if (sel_eq(action, @selector(setName:)))
1256 {
1257 NSArray *s = [selectionOwner selection];
1258 NSString *n;
1259 id o;
1260
1261 if ([s count] == 0)
1262 {
1263 return NO;
1264 }
1265 if ([s count] > 1)
1266 {
1267 return NO;
1268 }
1269 o = [s objectAtIndex: 0];
1270 n = [active nameForObject: o];
1271
1272 if ([n isEqual: @"NSOwner"] || [n isEqual: @"NSFirst"]
1273 || [n isEqual: @"NSFont"])
1274 {
1275 return NO;
1276 }
1277 }
1278
1279 if(sel_eq(action, @selector(createSubclass:)) ||
1280 sel_eq(action, @selector(loadClass:)) ||
1281 sel_eq(action, @selector(createClassFiles:)) ||
1282 sel_eq(action, @selector(instantiateClass:)) ||
1283 sel_eq(action, @selector(addAttributeToClass:)) ||
1284 sel_eq(action, @selector(remove:)))
1285 {
1286 id document = [(id<IB>)NSApp activeDocument];
1287 if(document == nil)
1288 {
1289 return NO;
1290 }
1291
1292 if(![document isEditingClasses])
1293 {
1294 return NO;
1295 }
1296 }
1297
1298 if(sel_eq(action, @selector(loadSound:)) ||
1299 sel_eq(action, @selector(loadImage:)) ||
1300 sel_eq(action, @selector(debug:)))
1301 {
1302 id document = [(id<IB>)NSApp activeDocument];
1303 if(document == nil)
1304 {
1305 return NO;
1306 }
1307 }
1308
1309 return YES;
1310 }
1311
1312 - (NSMenu*) classMenu
1313 {
1314 return classMenu;
1315 }
1316 @end
1317
1318 // custom class additions...
1319 @interface GSClassSwapper (GormCustomClassAdditions)
1320 - (BOOL) isInInterfaceBuilder;
1321 @end
1322
1323 @implementation GSClassSwapper (GormCustomClassAdditions)
1324 - (BOOL) isInInterfaceBuilder
1325 {
1326 return YES;
1327 }
1328 @end
1329
1330 // temporary until the deprecated template is removed...
1331 @interface NSWindowTemplate (GormCustomClassAdditions)
1332 - (BOOL) isInInterfaceBuilder;
1333 @end
1334
1335 @implementation NSWindowTemplate (GormCustomClassAdditions)
1336 - (BOOL) isInInterfaceBuilder
1337 {
1338 return YES;
1339 }
1340 @end
1341
1342 // main...
1343 int
1344 main(int argc, const char **argv)
1345 {
1346 startDate = [[NSDate alloc] init];
1347 // [NSObject enableDoubleReleaseCheck: YES];
1348 NSApplicationMain(argc, argv);
1349
1350 return 0;
1351 }
1352

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26