| 264 | | - (IBAction)filterLogForSelectedFS:(id)sender |
| 265 | | { |
| 266 | | [self showLogViewer: self]; |
| 267 | | NSArray* selectedFilesystems = [self selectedFilesystems]; |
| 268 | | if ([selectedFilesystems count] == 1) |
| 269 | | { |
| 270 | | [logViewerController filterForFilesystem: |
| 271 | | [selectedFilesystems objectAtIndex: 0]]; |
| 272 | | } |
| 273 | | } |
| 274 | | |
| 275 | | # pragma mark View Construction |
| 276 | | |
| 277 | | - (NSView*)wrapViewInOKCancel:(NSView*)innerView; |
| 278 | | { |
| 279 | | NSInteger buttonWidth = 80; |
| 280 | | NSInteger buttonHeight = 25; |
| 281 | | NSInteger buttonRightPadding = 5; |
| 282 | | NSInteger buttonBottomPadding = 5; |
| 283 | | NSInteger buttonXDistance = 0; |
| 284 | | NSInteger buttonAreaHeight = 2*buttonBottomPadding + buttonHeight; |
| 285 | | |
| 286 | | NSView* outerView = [[NSView alloc] init]; |
| 287 | | |
| 288 | | [outerView setFrameSize: NSMakeSize([innerView frame].size.width, |
| 289 | | [innerView frame].size.height + buttonAreaHeight)]; |
| 290 | | |
| 291 | | [outerView addSubview: innerView]; |
| 292 | | [innerView setFrame: NSMakeRect(0, buttonAreaHeight, [innerView frame].size.width, |
| 293 | | [innerView frame].size.height)]; |
| 294 | | |
| 295 | | NSRect okButtonFrame = NSMakeRect([outerView frame].size.width-buttonRightPadding-buttonWidth, |
| 296 | | buttonBottomPadding, |
| 297 | | buttonWidth, |
| 298 | | buttonHeight); |
| 299 | | NSButton* okButton = [[NSButton alloc] initWithFrame: okButtonFrame]; |
| 300 | | [okButton setBezelStyle: NSRoundedBezelStyle]; |
| 301 | | [okButton setTitle:@"OK"]; |
| 302 | | [okButton setTarget: self]; |
| 303 | | [okButton setAction:@selector(filesystemEditOKClicked:)]; |
| 304 | | [okButton setKeyEquivalent:@"\r"]; |
| 305 | | [okButton setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin]; |
| 306 | | |
| 307 | | |
| 308 | | NSRect cancelButtonFrame = NSMakeRect(okButtonFrame.origin.x - buttonXDistance- buttonWidth, |
| 309 | | buttonBottomPadding, |
| 310 | | buttonWidth, buttonHeight); |
| 311 | | NSButton* cancelButton = [[NSButton alloc] initWithFrame: cancelButtonFrame]; |
| 312 | | [cancelButton setBezelStyle: NSRoundedBezelStyle]; |
| 313 | | [cancelButton setTitle:@"Cancel"]; |
| 314 | | [cancelButton setTarget: self]; |
| 315 | | [cancelButton setAction:@selector(filesystemEditCancelClicked:)]; |
| 316 | | [cancelButton setKeyEquivalent:@"\e"]; |
| 317 | | [cancelButton setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin]; |
| 318 | | |
| 319 | | [outerView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; |
| 320 | | [outerView addSubview:cancelButton]; |
| 321 | | [outerView addSubview: okButton]; |
| 322 | | |
| 323 | | return outerView; |
| 324 | | } |
| 325 | | |
| 326 | | # pragma mark Action Methods |
| 327 | | |
| | 269 | # pragma mark Filesystem Methods |
| 334 | | - (void)deleteFilesystem:(MFClientFS*)fs |
| 335 | | { |
| 336 | | if ([fs isUnmounted] || [fs isFailedToMount]) |
| 337 | | { |
| 338 | | NSString* messageText = [NSString stringWithFormat: @"Are you sure you want to delete the filesystem %@?", fs.name]; |
| 339 | | NSAlert* deleteConfirmation = [NSAlert new]; |
| 340 | | [deleteConfirmation setMessageText: messageText]; |
| 341 | | [deleteConfirmation addButtonWithTitle:@"OK"]; |
| 342 | | NSButton* cancelButton = [deleteConfirmation addButtonWithTitle:@"Cancel"]; |
| 343 | | [cancelButton setKeyEquivalent:@"\e"]; |
| 344 | | [deleteConfirmation setAlertStyle: NSCriticalAlertStyle]; |
| 345 | | [deleteConfirmation beginSheetModalForWindow: [filesystemTableView window] |
| 346 | | modalDelegate:self |
| 347 | | didEndSelector:@selector(deleteConfirmationAlertDidEnd:returnCode:contextInfo:) |
| 348 | | contextInfo:fs]; |
| 349 | | } |
| 350 | | else |
| 351 | | { |
| 352 | | MFLogSO(self, fs, @"Can't delete FS %@", fs); |
| 353 | | } |
| 354 | | } |
| 355 | | |
| 356 | | - (IBAction)editSelectedFS:(id)sender |
| 357 | | { |
| 358 | | NSArray* selectedFilesystems = [self selectedFilesystems]; |
| 359 | | if (!selectedFilesystems || [selectedFilesystems count] != 1) |
| 360 | | { |
| 361 | | return; |
| 362 | | } |
| 363 | | else |
| 364 | | { |
| 365 | | [self editFilesystem: [selectedFilesystems objectAtIndex: 0]]; |
| 366 | | } |
| 367 | | } |
| 368 | | |
| 369 | | - (IBAction)toggleSelectedFS:(id)sender |
| 370 | | { |
| 371 | | NSArray* selectedFilesystems = [self selectedFilesystems]; |
| 372 | | if (!selectedFilesystems || [selectedFilesystems count] != 1) |
| 373 | | { |
| 374 | | return; |
| 375 | | } |
| 376 | | else |
| 377 | | { |
| 378 | | [self toggleFilesystem: [selectedFilesystems objectAtIndex: 0]]; |
| 379 | | } |
| 380 | | } |
| 381 | | |
| 382 | | - (IBAction)revealConfigForSelectedFS:(id)sender |
| 383 | | { |
| 384 | | for(MFClientFS* fs in [self selectedFilesystems]) |
| 385 | | { |
| 386 | | [[NSWorkspace sharedWorkspace] selectFile:fs.filePath |
| 387 | | inFileViewerRootedAtPath:nil]; |
| 388 | | } |
| 389 | | } |
| 390 | | |
| 391 | | - (IBAction)revealSelectedFS:(id)sender |
| 392 | | { |
| 393 | | for(MFClientFS* fs in [self selectedFilesystems]) |
| 394 | | { |
| 395 | | if ([fs isMounted]) |
| 396 | | [[NSWorkspace sharedWorkspace] selectFile: nil |
| 397 | | inFileViewerRootedAtPath: fs.mountPath ]; |
| 398 | | } |
| 399 | | } |
| 400 | | |
| 401 | | - (IBAction)duplicateSelectedFS:(id)sender |
| 402 | | { |
| 403 | | // TODO: Implement |
| 404 | | } |
| 405 | | |
| 406 | | - (IBAction)deleteSelectedFS:(id)sender |
| 407 | | { |
| 408 | | for(MFClientFS* fs in [self selectedFilesystems]) |
| 409 | | [self deleteFilesystem: fs]; |
| 410 | | } |
| 411 | | |
| 412 | | |
| 413 | | - (void)deleteConfirmationAlertDidEnd:(NSAlert*)alert returnCode:(NSInteger)code contextInfo:(void*)context |
| 414 | | { |
| 415 | | MFClientFS* fs = (MFClientFS*)context; |
| 416 | | if (code == NSAlertSecondButtonReturn) |
| 417 | | { |
| 418 | | |
| 419 | | } |
| 420 | | else if (code == NSAlertFirstButtonReturn) |
| 421 | | { |
| 422 | | [client deleteFilesystem: fs]; |
| 423 | | } |
| 424 | | } |
| | 325 | - (void)deleteFilesystem:(MFClientFS*)fs |
| | 326 | { |
| | 327 | if ([fs isUnmounted] || [fs isFailedToMount]) |
| | 328 | { |
| | 329 | NSString* messageText = [NSString stringWithFormat: @"Are you sure you want to delete the filesystem %@?", fs.name]; |
| | 330 | NSAlert* deleteConfirmation = [NSAlert new]; |
| | 331 | [deleteConfirmation setMessageText: messageText]; |
| | 332 | [deleteConfirmation addButtonWithTitle:@"OK"]; |
| | 333 | NSButton* cancelButton = [deleteConfirmation addButtonWithTitle:@"Cancel"]; |
| | 334 | [cancelButton setKeyEquivalent:@"\e"]; |
| | 335 | [deleteConfirmation setAlertStyle: NSCriticalAlertStyle]; |
| | 336 | [deleteConfirmation beginSheetModalForWindow: [filesystemTableView window] |
| | 337 | modalDelegate:self |
| | 338 | didEndSelector:@selector(deleteConfirmationAlertDidEnd:returnCode:contextInfo:) |
| | 339 | contextInfo:fs]; |
| | 340 | } |
| | 341 | else |
| | 342 | { |
| | 343 | MFLogSO(self, fs, @"Can't delete FS %@", fs); |
| | 344 | } |
| | 345 | } |
| | 346 | |
| | 347 | |
| | 348 | |
| | 349 | # pragma mark Selected Action Methods |
| | 350 | |
| | 351 | - (IBAction)filterLogForSelectedFS:(id)sender |
| | 352 | { |
| | 353 | [self showLogViewer: self]; |
| | 354 | NSArray* selectedFilesystems = [self selectedFilesystems]; |
| | 355 | if ([selectedFilesystems count] == 1) |
| | 356 | { |
| | 357 | [logViewerController filterForFilesystem: |
| | 358 | [selectedFilesystems objectAtIndex: 0]]; |
| | 359 | } |
| | 360 | } |
| | 361 | |
| | 362 | - (IBAction)editSelectedFS:(id)sender |
| | 363 | { |
| | 364 | NSArray* selectedFilesystems = [self selectedFilesystems]; |
| | 365 | if (!selectedFilesystems || [selectedFilesystems count] != 1) |
| | 366 | { |
| | 367 | return; |
| | 368 | } |
| | 369 | else |
| | 370 | { |
| | 371 | [self editFilesystem: [selectedFilesystems objectAtIndex: 0]]; |
| | 372 | } |
| | 373 | } |
| | 374 | |
| | 375 | - (IBAction)toggleSelectedFS:(id)sender |
| | 376 | { |
| | 377 | NSArray* selectedFilesystems = [self selectedFilesystems]; |
| | 378 | if (!selectedFilesystems || [selectedFilesystems count] != 1) |
| | 379 | { |
| | 380 | return; |
| | 381 | } |
| | 382 | else |
| | 383 | { |
| | 384 | [self toggleFilesystem: [selectedFilesystems objectAtIndex: 0]]; |
| | 385 | } |
| | 386 | } |
| | 387 | |
| | 388 | - (IBAction)revealConfigForSelectedFS:(id)sender |
| | 389 | { |
| | 390 | for(MFClientFS* fs in [self selectedFilesystems]) |
| | 391 | { |
| | 392 | [[NSWorkspace sharedWorkspace] selectFile:fs.filePath |
| | 393 | inFileViewerRootedAtPath:nil]; |
| | 394 | } |
| | 395 | } |
| | 396 | |
| | 397 | - (IBAction)revealSelectedFS:(id)sender |
| | 398 | { |
| | 399 | for(MFClientFS* fs in [self selectedFilesystems]) |
| | 400 | { |
| | 401 | if ([fs isMounted]) |
| | 402 | [[NSWorkspace sharedWorkspace] selectFile: nil |
| | 403 | inFileViewerRootedAtPath: fs.mountPath ]; |
| | 404 | } |
| | 405 | } |
| | 406 | |
| | 407 | - (IBAction)duplicateSelectedFS:(id)sender |
| | 408 | { |
| | 409 | } |
| | 410 | |
| | 411 | - (IBAction)deleteSelectedFS:(id)sender |
| | 412 | { |
| | 413 | for(MFClientFS* fs in [self selectedFilesystems]) |
| | 414 | [self deleteFilesystem: fs]; |
| | 415 | } |
| | 416 | |
| | 417 | |
| | 418 | - (void)deleteConfirmationAlertDidEnd:(NSAlert*)alert returnCode:(NSInteger)code contextInfo:(void*)context |
| | 419 | { |
| | 420 | MFClientFS* fs = (MFClientFS*)context; |
| | 421 | if (code == NSAlertSecondButtonReturn) |
| | 422 | { |
| | 423 | |
| | 424 | } |
| | 425 | else if (code == NSAlertFirstButtonReturn) |
| | 426 | { |
| | 427 | [client deleteFilesystem: fs]; |
| | 428 | } |
| | 429 | } |
| | 430 | |
| | 431 | |
| | 432 | |
| | 433 | |
| | 434 | |
| | 435 | # pragma mark Notification |
| | 436 | - (void)filesystemDidChangeStatus:(MFClientFS*)fs |
| | 437 | { |
| | 438 | [filesystemTableView statusChangedForFS: fs]; |
| | 439 | if ([fs isFailedToMount]) |
| | 440 | { |
| | 441 | if ([fs error]) |
| | 442 | { |
| | 443 | [NSApp presentError:[fs error] |
| | 444 | modalForWindow:[filesystemTableView window] |
| | 445 | delegate:nil |
| | 446 | didPresentSelector:nil |
| | 447 | contextInfo:nil]; |
| | 448 | } |
| | 449 | else |
| | 450 | { |
| | 451 | MFLogSO(self, fs, @"No error for failed-to-mount fs %@", fs); |
| | 452 | } |
| | 453 | } |
| | 454 | } |
| | 455 | |
| | 456 | - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context |
| | 457 | { |
| | 458 | if (context == self) { |
| | 459 | [self resizeWindowForContent]; |
| | 460 | } |
| | 461 | else { |
| | 462 | [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; |
| | 463 | } |
| | 464 | } |
| | 465 | |
| | 466 | |
| | 467 | # pragma mark Editing Mechanics |
| | 468 | - (void)filesystemEditOKClicked:(id)sender |
| | 469 | { |
| | 470 | MFClientFS* fs = fsBeingEdited; |
| | 471 | NSError* error = [fs endEditingAndCommitChanges: YES]; |
| | 472 | if (error) |
| | 473 | { |
| | 474 | [NSApp presentError: error |
| | 475 | modalForWindow: [sender window] |
| | 476 | delegate: nil |
| | 477 | didPresentSelector: nil |
| | 478 | contextInfo: nil ]; |
| | 479 | } |
| | 480 | else |
| | 481 | { |
| | 482 | [NSApp endSheet: [sender window]]; |
| | 483 | } |
| | 484 | |
| | 485 | creatingNewFS = NO; |
| | 486 | } |
| | 487 | |
| | 488 | |
| | 489 | - (void)filesystemEditCancelClicked:(id)sender |
| | 490 | { |
| | 491 | MFClientFS* fs = fsBeingEdited; |
| | 492 | [fs endEditingAndCommitChanges: NO]; |
| | 493 | if (creatingNewFS) |
| | 494 | [client deleteFilesystem: fsBeingEdited]; |
| | 495 | creatingNewFS = NO; |
| | 496 | [NSApp endSheet: [sender window]]; |
| | 497 | |
| | 498 | } |
| | 499 | |
| | 500 | - (void)sheetDidEnd:(NSWindow*)sheet |
| | 501 | { |
| | 502 | [sheet orderOut:self]; |
| | 503 | fsBeingEdited = nil; |
| | 504 | } |
| | 505 | |
| | 506 | |
| | 507 | - (NSError *)application:(NSApplication *)application willPresentError:(NSError *)error |
| | 508 | { |
| | 509 | if ([error code] == kMFErrorCodeMountFaliure) |
| | 510 | { |
| | 511 | NSString* newDescription = [NSString stringWithFormat: @"Could not mount filesystem: %@", [error localizedDescription]]; |
| | 512 | return [MFError errorWithErrorCode:kMFErrorCodeMountFaliure description:newDescription]; |
| | 513 | } |
| | 514 | else |
| | 515 | { |
| | 516 | return error; |
| | 517 | } |
| | 518 | } |
| | 519 | |
| | 520 | - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename |
| | 521 | { |
| | 522 | NSString* fsLocation = [@"~/Library/Application Support/Macfusion/Filesystems" stringByExpandingTildeInPath]; |
| | 523 | if ([[filename stringByDeletingLastPathComponent] isEqualToString: fsLocation]) |
| | 524 | { |
| | 525 | NSString* uuid = [[filename lastPathComponent] stringByDeletingPathExtension]; |
| | 526 | [self editFilesystem: [client filesystemWithUUID: uuid]]; |
| | 527 | } |
| | 528 | else |
| | 529 | { |
| | 530 | MFLogS(self, @"Not opening file. It is in the wrong place"); |
| | 531 | } |
| | 532 | |
| | 533 | return YES; |
| | 534 | } |
| 493 | | # pragma mark Notification |
| 494 | | - (void)filesystemDidChangeStatus:(MFClientFS*)fs |
| 495 | | { |
| 496 | | [filesystemTableView statusChangedForFS: fs]; |
| 497 | | if ([fs isFailedToMount]) |
| 498 | | { |
| 499 | | if ([fs error]) |
| 500 | | { |
| 501 | | [NSApp presentError:[fs error] |
| 502 | | modalForWindow:[filesystemTableView window] |
| 503 | | delegate:nil |
| 504 | | didPresentSelector:nil |
| 505 | | contextInfo:nil]; |
| 506 | | } |
| 507 | | else |
| 508 | | { |
| 509 | | MFLogSO(self, fs, @"No error for failed-to-mount fs %@", fs); |
| 510 | | } |
| 511 | | } |
| 512 | | } |
| 513 | | |
| 514 | | - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context |
| 515 | | { |
| 516 | | if (context == self) { |
| 517 | | [self resizeWindowForContent]; |
| 518 | | } |
| 519 | | else { |
| 520 | | [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; |
| 521 | | } |
| 522 | | } |
| 523 | | |
| 524 | | |
| 525 | | # pragma mark Editing Mechanics |
| 526 | | - (void)filesystemEditOKClicked:(id)sender |
| 527 | | { |
| 528 | | MFClientFS* fs = fsBeingEdited; |
| 529 | | NSError* error = [fs endEditingAndCommitChanges: YES]; |
| 530 | | if (error) |
| 531 | | { |
| 532 | | [NSApp presentError: error |
| 533 | | modalForWindow: [sender window] |
| 534 | | delegate: nil |
| 535 | | didPresentSelector: nil |
| 536 | | contextInfo: nil ]; |
| 537 | | } |
| 538 | | else |
| 539 | | { |
| 540 | | [NSApp endSheet: [sender window]]; |
| 541 | | } |
| 542 | | |
| 543 | | creatingNewFS = NO; |
| 544 | | } |
| 545 | | |
| 546 | | |
| 547 | | - (void)filesystemEditCancelClicked:(id)sender |
| 548 | | { |
| 549 | | MFClientFS* fs = fsBeingEdited; |
| 550 | | [fs endEditingAndCommitChanges: NO]; |
| 551 | | if (creatingNewFS) |
| 552 | | [client deleteFilesystem: fsBeingEdited]; |
| 553 | | creatingNewFS = NO; |
| 554 | | [NSApp endSheet: [sender window]]; |
| 555 | | |
| 556 | | } |
| 557 | | |
| 558 | | - (void)sheetDidEnd:(NSWindow*)sheet |
| 559 | | { |
| 560 | | [sheet orderOut:self]; |
| 561 | | fsBeingEdited = nil; |
| 562 | | } |
| 563 | | |
| 564 | | |
| 565 | | - (NSError *)application:(NSApplication *)application willPresentError:(NSError *)error |
| 566 | | { |
| 567 | | if ([error code] == kMFErrorCodeMountFaliure) |
| 568 | | { |
| 569 | | NSString* newDescription = [NSString stringWithFormat: @"Could not mount filesystem: %@", [error localizedDescription]]; |
| 570 | | return [MFError errorWithErrorCode:kMFErrorCodeMountFaliure description:newDescription]; |
| 571 | | } |
| 572 | | else |
| 573 | | { |
| 574 | | return error; |
| 575 | | } |
| 576 | | } |
| 577 | | |
| 578 | | - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename |
| 579 | | { |
| 580 | | NSString* fsLocation = [@"~/Library/Application Support/Macfusion/Filesystems" stringByExpandingTildeInPath]; |
| 581 | | if ([[filename stringByDeletingLastPathComponent] isEqualToString: fsLocation]) |
| 582 | | { |
| 583 | | NSString* uuid = [[filename lastPathComponent] stringByDeletingPathExtension]; |
| 584 | | [self editFilesystem: [client filesystemWithUUID: uuid]]; |
| 585 | | } |
| 586 | | else |
| 587 | | { |
| 588 | | MFLogS(self, @"Not opening file. It is in the wrong place"); |
| 589 | | } |
| 590 | | |
| 591 | | return YES; |
| | 554 | # pragma mark View Construction |
| | 555 | |
| | 556 | - (NSView*)wrapViewInOKCancel:(NSView*)innerView |
| | 557 | { |
| | 558 | NSInteger buttonWidth = 80; |
| | 559 | NSInteger buttonHeight = 25; |
| | 560 | NSInteger buttonRightPadding = 5; |
| | 561 | NSInteger buttonBottomPadding = 5; |
| | 562 | NSInteger buttonXDistance = 0; |
| | 563 | NSInteger buttonAreaHeight = 2*buttonBottomPadding + buttonHeight; |
| | 564 | |
| | 565 | NSView* outerView = [[NSView alloc] init]; |
| | 566 | |
| | 567 | [outerView setFrameSize: NSMakeSize([innerView frame].size.width, |
| | 568 | [innerView frame].size.height + buttonAreaHeight)]; |
| | 569 | |
| | 570 | [outerView addSubview: innerView]; |
| | 571 | [innerView setFrame: NSMakeRect(0, buttonAreaHeight, [innerView frame].size.width, |
| | 572 | [innerView frame].size.height)]; |
| | 573 | |
| | 574 | NSRect okButtonFrame = NSMakeRect([outerView frame].size.width-buttonRightPadding-buttonWidth, |
| | 575 | buttonBottomPadding, |
| | 576 | buttonWidth, |
| | 577 | buttonHeight); |
| | 578 | NSButton* okButton = [[NSButton alloc] initWithFrame: okButtonFrame]; |
| | 579 | [okButton setBezelStyle: NSRoundedBezelStyle]; |
| | 580 | [okButton setTitle:@"OK"]; |
| | 581 | [okButton setTarget: self]; |
| | 582 | [okButton setAction:@selector(filesystemEditOKClicked:)]; |
| | 583 | [okButton setKeyEquivalent:@"\r"]; |
| | 584 | [okButton setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin]; |
| | 585 | |
| | 586 | |
| | 587 | NSRect cancelButtonFrame = NSMakeRect(okButtonFrame.origin.x - buttonXDistance- buttonWidth, |
| | 588 | buttonBottomPadding, |
| | 589 | buttonWidth, buttonHeight); |
| | 590 | NSButton* cancelButton = [[NSButton alloc] initWithFrame: cancelButtonFrame]; |
| | 591 | [cancelButton setBezelStyle: NSRoundedBezelStyle]; |
| | 592 | [cancelButton setTitle:@"Cancel"]; |
| | 593 | [cancelButton setTarget: self]; |
| | 594 | [cancelButton setAction:@selector(filesystemEditCancelClicked:)]; |
| | 595 | [cancelButton setKeyEquivalent:@"\e"]; |
| | 596 | [cancelButton setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin]; |
| | 597 | |
| | 598 | [outerView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; |
| | 599 | [outerView addSubview:cancelButton]; |
| | 600 | [outerView addSubview: okButton]; |
| | 601 | |
| | 602 | return outerView; |