| | 255 | - (void)savePanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo |
|---|
| | 256 | { |
|---|
| | 257 | Q_DEBUG(@"savePanelDidEnd"); |
|---|
| | 258 | |
|---|
| | 259 | NSFileManager *fileManager; |
|---|
| | 260 | NSMutableArray *knownVMs; |
|---|
| | 261 | |
|---|
| | 262 | if (returnCode == NSOKButton) { |
|---|
| | 263 | |
|---|
| | 264 | fileManager = [NSFileManager defaultManager]; |
|---|
| | 265 | |
|---|
| | 266 | // move untitled Document to named document |
|---|
| | 267 | if ([fileManager movePath:[[[configuration objectForKey:@"Temporary"] objectForKey:@"URL"] path] toPath:[panel filename] handler:nil]) { |
|---|
| | 268 | [[configuration objectForKey:@"Temporary"] setObject:[panel URL] forKey:@"URL"]; |
|---|
| | 269 | [self setFileURL:[panel URL]]; |
|---|
| | 270 | |
|---|
| | 271 | // if outside default path, add to knownVNs |
|---|
| | 272 | if (![[[panel filename] stringByDeletingLastPathComponent] isEqual:[[qApplication userDefaults] objectForKey:@"dataPath"]]) { |
|---|
| | 273 | if (![[[qApplication userDefaults] objectForKey:@"knownVMs"] containsObject:[panel filename]]) { |
|---|
| | 274 | knownVMs = [[[[qApplication userDefaults] objectForKey:@"knownVMs"] mutableCopy] autorelease]; |
|---|
| | 275 | [knownVMs addObject:[panel filename]]; |
|---|
| | 276 | [[qApplication userDefaults] setObject:knownVMs forKey:@"knownVMs"]; |
|---|
| | 277 | } |
|---|
| | 278 | } |
|---|
| | 279 | |
|---|
| | 280 | [[NSNotificationCenter defaultCenter] postNotificationName:@"QVMStatusDidChange" object:nil]; //communicate new state |
|---|
| | 281 | } else { |
|---|
| | 282 | [self defaultAlertMessage:@"Could not save %@" informativeText:[NSString stringWithFormat:@"There was an error while saving %@", [self displayName], [self displayName]]]; |
|---|
| | 283 | } |
|---|
| | 284 | } |
|---|
| | 285 | } |
|---|
| | 286 | |
|---|
| | 287 | - (IBAction)saveDocumentAs:(id)sender |
|---|
| | 288 | { |
|---|
| | 289 | Q_DEBUG(@"saveDocumentAs"); |
|---|
| | 290 | |
|---|
| | 291 | if (VMState == QDocumentShutdown || VMState == QDocumentSaved) { |
|---|
| | 292 | NSSavePanel *savePanel = [NSSavePanel savePanel]; |
|---|
| | 293 | [savePanel setAllowedFileTypes:[NSArray arrayWithObject:@"qvm"]]; |
|---|
| | 294 | [savePanel setCanSelectHiddenExtension:YES]; |
|---|
| | 295 | [savePanel beginSheetForDirectory:[[qApplication userDefaults] objectForKey:@"dataPath"] file:[self displayName] modalForWindow:[screenView window] modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:nil]; |
|---|
| | 296 | } else { |
|---|
| | 297 | [self defaultAlertMessage:@"VM is running" informativeText:@"Please shutdown the VM before saving the VM to a new Name"]; |
|---|
| | 298 | } |
|---|
| | 299 | } |
|---|
| | 300 | |
|---|
| 257 | | // Todo: |
|---|
| 258 | | // implement saving as following: |
|---|
| 259 | | // if VM is shutdown/saved: |
|---|
| 260 | | // - save the .qvm package with the save name |
|---|
| 261 | | // - save configuration.plist |
|---|
| 262 | | // if the VM is running |
|---|
| 263 | | // - save a snapshot |
|---|
| 264 | | |
|---|
| 265 | | [distributedObject setCommand:'W' arg1:0 arg2:0 arg3:0 arg4:0]; |
|---|
| | 305 | // Todo: Document was not yet saved with a proper name, we call a savepanel and move the VM |
|---|
| | 306 | if (VMState == QDocumentShutdown || VMState == QDocumentSaved) { |
|---|
| | 307 | [self saveDocumentAs:self]; |
|---|
| | 308 | |
|---|
| | 309 | // if the VM is running, we make a snapshot |
|---|
| | 310 | } else if (VMState == QDocumentPaused || VMState == QDocumentRunning) { |
|---|
| | 311 | [self setVMState:QDocumentSaving]; |
|---|
| | 312 | [distributedObject setCommand:'W' arg1:0 arg2:0 arg3:0 arg4:0]; |
|---|
| | 313 | } |
|---|