ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/MacOSX/Launcher/VMListController.mm
(Generate patch)

Comparing SheepShaver/src/MacOSX/Launcher/VMListController.mm (file contents):
Revision 1.5 by asvitkine, 2009-08-02T23:17:18Z vs.
Revision 1.6 by asvitkine, 2009-08-02T23:46:44Z

# Line 27 | Line 27 | TODO:
27  
28   Verify if VM exists
29   Create Disk on New VM
30 Keep track of VMs that are running and disallow editing settings, re-launching, etc..
30   Drag-drop to re-arrange order of VMs
31   Drag VM from Finder to import
32   Don't show Preferences menu in spawned SheepShaver instances - or make them
# Line 54 | Line 53 | use the same nib file as this app!
53          vmArray = [[NSMutableArray alloc] initWithCapacity:[vms count]];
54          [vmArray addObjectsFromArray:vms];
55  
56 +        tasks = [[NSMutableDictionary alloc] init];
57 +
58 +        [[NSNotificationCenter defaultCenter] addObserver:self
59 +                selector:@selector(onTaskTerminated:)
60 +                name:NSTaskDidTerminateNotification
61 +                object:nil];
62 +
63          return self;
64   }
65  
# Line 167 | Line 173 | use the same nib file as this app!
173   {
174          int selectedRow = [vmList selectedRow];
175          if (selectedRow >= 0) {
176 <                [[VMSettingsController sharedInstance] editSettingsFor:[vmArray objectAtIndex:selectedRow] sender:sender];
176 >                NSString *path = [vmArray objectAtIndex:selectedRow];
177 >                if ([tasks objectForKey:path]) {
178 >                        NSAlert *alert = [[[NSAlert alloc] init] autorelease];
179 >                        [alert setMessageText:@"Cannot edit virtual machine settings while it's running."];
180 >                        [alert setAlertStyle:NSWarningAlertStyle];
181 >                        [alert beginSheetModalForWindow:[self window]
182 >                                    modalDelegate:self
183 >                                   didEndSelector:nil
184 >                                      contextInfo:nil];
185 >                } else {
186 >                        [[VMSettingsController sharedInstance] editSettingsFor:path sender:sender];
187 >                }
188          }
189   }
190  
# Line 175 | Line 192 | use the same nib file as this app!
192   {
193          int selectedRow = [vmList selectedRow];
194          if (selectedRow >= 0) {
195 <                NSTask *sheep = [[NSTask alloc] init];
196 <                [sheep setLaunchPath:[[NSBundle mainBundle] pathForAuxiliaryExecutable:@"SheepShaver"]];
197 <                [sheep setArguments:[NSArray arrayWithObject:[vmArray objectAtIndex:selectedRow]]];
198 <                [sheep launch];
195 >                NSString *path = [vmArray objectAtIndex:selectedRow];
196 >                if ([tasks objectForKey:path]) {
197 >                        NSAlert *alert = [[[NSAlert alloc] init] autorelease];
198 >                        [alert setMessageText:@"The selected virtual machine is already running."];
199 >                        [alert setAlertStyle:NSWarningAlertStyle];
200 >                        [alert beginSheetModalForWindow:[self window]
201 >                                    modalDelegate:self
202 >                                   didEndSelector:nil
203 >                                      contextInfo:nil];
204 >                } else {
205 >                        NSTask *sheep = [[NSTask alloc] init];
206 >                        [sheep setLaunchPath:[[NSBundle mainBundle] pathForAuxiliaryExecutable:@"SheepShaver"]];
207 >                        [sheep setArguments:[NSArray arrayWithObject:path]];
208 >                        [sheep launch];
209 >                        [tasks setObject:sheep forKey:path];
210 >                }
211 >        }
212 > }
213 >
214 > - (void) onTaskTerminated: (NSNotification *) notification
215 > {
216 >        NSArray *paths = [tasks allKeys];
217 >        NSEnumerator *enumerator = [paths objectEnumerator];
218 >        NSString *path;
219 >        while ((path = [enumerator nextObject])) {
220 >                NSTask *task = [tasks objectForKey:path];
221 >                if (![task isRunning]) {
222 >                        [tasks removeObjectForKey:path];
223 >                        [task release];
224 >                }
225          }
226   }
227  
# Line 196 | Line 239 | use the same nib file as this app!
239                                   didEndSelector:@selector(_deleteVirtualMachineDone: returnCode: contextInfo:)
240                                      contextInfo:nil];
241  
242 <                        }
242 >        }
243   }
244  
245   - (void) _deleteVirtualMachineDone: (NSAlert *) alert returnCode: (int) returnCode contextInfo: (void *) contextInfo

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines