delete vm from list

This commit is contained in:
asvitkine 2009-08-02 22:37:34 +00:00
parent b38bb12ab3
commit abbd1785b1
2 changed files with 56 additions and 3 deletions

View File

@ -34,5 +34,6 @@
- (IBAction) importVirtualMachine: (id) sender;
- (IBAction) editVirtualMachineSettings: (id) sender;
- (IBAction) launchVirtualMachine: (id) sender;
- (IBAction) deleteVirtualMachine: (id) sender;
@end

View File

@ -21,6 +21,21 @@
#import "VMListController.h"
#import "VMSettingsController.h"
/*
TODO:
Verify if VM exists
Create Disk on New VM
Keep track of VMs that are running and disallow editing settings, re-launching, etc..
Drag-drop to re-arrange order of VMs
Drag VM from Finder to import
Don't show Preferences menu in spawned SheepShaver instances - or make them
use the same nib file as this app!
Disable buttons on empty selection
*/
@implementation VMListController
+ (id) sharedInstance
@ -46,10 +61,20 @@
- (void) awakeFromNib
{
[vmList setDataSource: self];
//[vmList setDelegate: self];
[vmList setDelegate: self];
[vmList reloadData];
}
- (void) keyDown: (NSEvent *) event
{
if ([event type] == NSKeyDown && [[event characters] length] > 0) {
unichar key = [[event characters] characterAtIndex:0];
if (key == NSDeleteFunctionKey || key == NSDeleteCharacter) {
[self deleteVirtualMachine:self];
}
}
}
- (int) numberOfRowsInTableView: (NSTableView *) table
{
return [vmArray count];
@ -128,7 +153,7 @@
}
}
- (IBAction) editVirtualMachineSettings:(id)sender
- (IBAction) editVirtualMachineSettings: (id) sender
{
int selectedRow = [vmList selectedRow];
if (selectedRow >= 0) {
@ -136,7 +161,7 @@
}
}
- (IBAction) launchVirtualMachine:(id)sender
- (IBAction) launchVirtualMachine: (id) sender
{
int selectedRow = [vmList selectedRow];
if (selectedRow >= 0) {
@ -147,4 +172,31 @@
}
}
- (IBAction) deleteVirtualMachine: (id) sender
{
int selectedRow = [vmList selectedRow];
if (selectedRow >= 0) {
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"Do you wish to remove the selected virtual machine from the list?"];
[alert addButtonWithTitle:@"Remove"];
[alert addButtonWithTitle:@"Cancel"];
[alert setAlertStyle:NSWarningAlertStyle];
[alert beginSheetModalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(_deleteVirtualMachineDone: returnCode: contextInfo:)
contextInfo:nil];
}
}
- (void) _deleteVirtualMachineDone: (NSAlert *) alert returnCode: (int) returnCode contextInfo: (void *) contextInfo
{
if (returnCode == NSAlertFirstButtonReturn) {
[vmArray removeObjectAtIndex:[vmList selectedRow]];
[vmList deselectAll:self];
[vmList reloadData];
[[NSUserDefaults standardUserDefaults] setObject:vmArray forKey:@"vm_list"];
}
}
@end