ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/MacOSX/Launcher/VMListController.mm
Revision: 1.3
Committed: 2009-08-02T20:24:38Z (15 years, 1 month ago) by asvitkine
Branch: MAIN
Changes since 1.2: +14 -4 lines
Log Message:
New Virtual Machine button working

File Contents

# User Rev Content
1 asvitkine 1.1 /*
2     * VMListController.mm - SheepShaver VM manager in Cocoa on Mac OS X
3     *
4     * Copyright (C) 2009 Alexei Svitkine
5     *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #import "VMListController.h"
22     #import "VMSettingsController.h"
23    
24     @implementation VMListController
25    
26     + (id) sharedInstance
27     {
28     static VMListController *_sharedInstance = nil;
29     if (!_sharedInstance) {
30     _sharedInstance = [[VMListController allocWithZone:[self zone]] init];
31     }
32     return _sharedInstance;
33     }
34    
35     - (id) init
36     {
37     self = [super initWithWindowNibName:@"VMListWindow"];
38    
39     NSArray *vms = [[NSUserDefaults standardUserDefaults] stringArrayForKey:@"vm_list"];
40     vmArray = [[NSMutableArray alloc] initWithCapacity:[vms count]];
41     [vmArray addObjectsFromArray:vms];
42    
43     return self;
44     }
45    
46     - (void) awakeFromNib
47     {
48 asvitkine 1.2 [vmList setDataSource: self];
49 asvitkine 1.1 //[vmList setDelegate: self];
50 asvitkine 1.2 [vmList reloadData];
51 asvitkine 1.1 }
52    
53     - (int) numberOfRowsInTableView: (NSTableView *) table
54     {
55 asvitkine 1.2 return [vmArray count];
56 asvitkine 1.1 }
57    
58     - (id) tableView: (NSTableView *) table objectValueForTableColumn: (NSTableColumn *) c row: (int) r
59     {
60 asvitkine 1.2 return [vmArray objectAtIndex: r]; // [[vmArray objectAtIndex: r] lastPathComponent];
61 asvitkine 1.1 }
62    
63     //- (NSString *) tableView: (NSTableView *) table toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
64     // tableColumn: (NSTableColumn *) c row: (int) r mouseLocation: (NSPoint) loc
65     //{
66     // return [vmArray objectAtIndex: r];
67     //}
68    
69     - (IBAction) newVirtualMachine: (id) sender
70     {
71     NSSavePanel *save = [NSSavePanel savePanel];
72     [save setMessage: @"New SheepShaver Virtual Machine:"];
73     [save setRequiredFileType: @"sheepvm"];
74     [save setCanSelectHiddenExtension: YES];
75     [save setExtensionHidden: NO];
76     [save beginSheetForDirectory: nil
77     file: @"New.sheepvm"
78     modalForWindow: [self window]
79     modalDelegate: self
80     didEndSelector: @selector(_newVirtualMachineDone: returnCode: contextInfo:)
81     contextInfo: nil];
82     }
83    
84     - (IBAction) _newVirtualMachineDone: (NSSavePanel *) save returnCode: (int) returnCode contextInfo: (void *) contextInfo
85     {
86     if (returnCode == NSOKButton) {
87 asvitkine 1.3 NSFileManager *manager = [NSFileManager defaultManager];
88     [manager createDirectoryAtPath:[save filename] attributes:nil];
89     [manager createFileAtPath:[[save filename] stringByAppendingPathComponent:@"prefs"] contents:nil attributes:nil];
90     [vmArray addObject:[save filename]];
91     [vmList reloadData];
92     [[NSUserDefaults standardUserDefaults] setObject:vmArray forKey:@"vm_list"];
93     [vmList selectRow:([vmArray count] - 1) byExtendingSelection:NO];
94     [self editVirtualMachineSettings:self];
95     if ([[VMSettingsController sharedInstance] cancelWasClicked]) {
96     [manager removeFileAtPath:[save filename] handler:nil];
97     [vmArray removeObjectAtIndex:([vmArray count] - 1)];
98     [vmList reloadData];
99     }
100     // TODO advanced: show sub-panel in save dialog that says "Create Disk:"
101 asvitkine 1.1 }
102     }
103    
104     - (IBAction) importVirtualMachine: (id) sender
105     {
106     NSOpenPanel *open = [NSOpenPanel openPanel];
107     [open setMessage:@"Import SheepShaver Virtual Machine:"];
108     [open setResolvesAliases:YES];
109     // Curiously, bundles are treated as "files" not "directories" by NSOpenPanel.
110     [open setCanChooseDirectories:NO];
111     [open setCanChooseFiles:YES];
112     [open setAllowsMultipleSelection:NO];
113     [open beginSheetForDirectory: nil
114     file: nil
115     types: [NSArray arrayWithObject:@"sheepvm"]
116     modalForWindow: [self window]
117     modalDelegate: self
118     didEndSelector: @selector(_importVirtualMachineDone: returnCode: contextInfo:)
119     contextInfo: nil];
120     }
121    
122     - (void) _importVirtualMachineDone: (NSOpenPanel *) open returnCode: (int) returnCode contextInfo: (void *) contextInfo
123     {
124     if (returnCode == NSOKButton) {
125     [vmArray addObject:[open filename]];
126     [vmList reloadData];
127     [[NSUserDefaults standardUserDefaults] setObject:vmArray forKey:@"vm_list"];
128     }
129     }
130    
131     - (IBAction) editVirtualMachineSettings:(id)sender
132     {
133     int selectedRow = [vmList selectedRow];
134 asvitkine 1.2 if (selectedRow >= 0) {
135 asvitkine 1.1 [[VMSettingsController sharedInstance] editSettingsFor:[vmArray objectAtIndex:selectedRow] sender:sender];
136 asvitkine 1.2 }
137 asvitkine 1.1 }
138    
139 asvitkine 1.2 - (IBAction) launchVirtualMachine:(id)sender
140 asvitkine 1.1 {
141 asvitkine 1.2 int selectedRow = [vmList selectedRow];
142     if (selectedRow >= 0) {
143     NSTask *sheep = [[NSTask alloc] init];
144     [sheep setLaunchPath:[[NSBundle mainBundle] pathForAuxiliaryExecutable:@"SheepShaver"]];
145     [sheep setArguments:[NSArray arrayWithObject:[vmArray objectAtIndex:selectedRow]]];
146     [sheep launch];
147     }
148 asvitkine 1.1 }
149    
150     @end