/* ** LibraryLocationPanel.m ** ** Copyright (c) 2004 ** ** Author: Yen-Ju Chen ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "LibraryLocationPanel.h" #include "Utilities.h" static LibraryLocationPanel *sharedInstance; @implementation LibraryLocationPanel - (NSString *) libraryLocationPath { return [locationTextField stringValue]; } - (IBAction)findLocationAction:(id)sender { int result; NSOpenPanel *openPanel = [NSOpenPanel openPanel]; [openPanel setCanChooseDirectories: YES]; [openPanel setAllowsMultipleSelection: NO]; [openPanel setResolvesAliases: YES]; result = [openPanel runModalForTypes: nil]; if (result == NSOKButton) { [locationTextField setStringValue: [[openPanel filenames] objectAtIndex: 0]]; } } - (IBAction)okAction:(id)sender { buttonResult = NSOKButton; [panel performClose: sender]; } - (IBAction)cancelAction:(id)sender { [panel performClose: sender]; } - (int) makePanelKeyAndOrderFront: (id) sender { buttonResult = NSCancelButton; [locationTextField setStringValue: MyLibraryPath(nil)]; [panel makeKeyAndOrderFront: sender]; [NSApp runModalForWindow: panel]; return buttonResult; } - (BOOL) windowShouldClose: (id) sender { [NSApp stopModal]; return YES; } - (void) awakeFromNib { } + (LibraryLocationPanel *) sharedPanel { if (sharedInstance == nil) { sharedInstance = [[LibraryLocationPanel alloc] init]; } return sharedInstance; } - (id) init { self = [super init]; BOOL result = [NSBundle loadNibNamed: @"LibraryLocationPanel" owner: self]; if (result == NO) { NSLog(@"Unable to load LibraryLocationPanel interface"); return nil; } return self; } @end