2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #import "DebuggerApplication.h"
30 #import "DebuggerDocument.h"
31 #import <WebKit/WebCoreStatistics.h>
33 @implementation DebuggerApplication
36 NSTableColumn *column = [attachTable tableColumnWithIdentifier:@"name"];
37 NSBrowserCell *cell = [[NSBrowserCell alloc] init];
39 [column setDataCell:cell];
43 - (void)applicationDidFinishLaunching:(NSNotification *)notification
45 [WebCoreStatistics setShouldPrintExceptions:YES];
47 knownServerNames = [[NSMutableDictionary alloc] init];
49 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(serverLoaded:) name:WebScriptDebugServerDidLoadNotification object:nil];
50 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(serverLoaded:) name:WebScriptDebugServerQueryReplyNotification object:nil];
51 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(serverUnloaded:) name:WebScriptDebugServerWillUnloadNotification object:nil];
52 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:WebScriptDebugServerQueryNotification object:nil];
56 #pragma mark Server Detection Callbacks
58 - (void)serverLoaded:(NSNotification *)notification
60 int processId = [[[notification userInfo] objectForKey:WebScriptDebugServerProcessIdentifierKey] intValue];
61 if (processId == [[NSProcessInfo processInfo] processIdentifier])
64 NSMutableDictionary *info = [[notification userInfo] mutableCopy];
67 [knownServerNames setObject:info forKey:[notification object]];
70 [attachTable reloadData];
73 - (void)serverUnloaded:(NSNotification *)notification
75 [knownServerNames removeObjectForKey:[notification object]];
76 [attachTable reloadData];
80 #pragma mark Attach Panel Actions
82 - (IBAction)showAttachPanel:(id)sender
84 if (![attachWindow isVisible])
85 [attachWindow center];
86 [attachTable reloadData];
87 [attachWindow makeKeyAndOrderFront:sender];
90 - (IBAction)attach:(id)sender
92 if ([[attachTable selectedRowIndexes] count] != 1)
95 [attachWindow orderOut:sender];
97 unsigned int row = [[attachTable selectedRowIndexes] firstIndex];
98 NSString *key = [[knownServerNames allKeys] objectAtIndex:row];
100 // DebuggerDocument will release on close
101 DebuggerDocument *document = [[DebuggerDocument alloc] initWithServerName:key];
102 [document showWindow:sender];
106 #pragma mark Table View Delegate
108 - (int)numberOfRowsInTableView:(NSTableView *)tableView
110 return [knownServerNames count];
113 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
118 - (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(int)row
120 NSString *key = [[knownServerNames allKeys] objectAtIndex:row];
121 NSMutableDictionary *info = [knownServerNames objectForKey:key];
122 NSString *processName = [info objectForKey:WebScriptDebugServerProcessNameKey];
123 NSImage *icon = [info objectForKey:@"icon"];
126 NSString *path = [[NSWorkspace sharedWorkspace] fullPathForApplication:processName];
127 if (path) icon = [[NSWorkspace sharedWorkspace] iconForFile:path];
128 if (!icon) icon = [[NSWorkspace sharedWorkspace] iconForFileType:@"app"];
129 if (icon) [info setObject:icon forKey:@"icon"];
130 [icon setScalesWhenResized:YES];
131 [icon setSize:NSMakeSize(32, 32)];
134 [cell setImage:icon];
135 [cell setTitle:processName];
138 - (void)tableViewSelectionDidChange:(NSNotification *)notification
140 [attachButton setEnabled:([[attachTable selectedRowIndexes] count])];