2013년 11월 1일 금요일

File Association



파인더에서 파일을 더블클릭했을때 어플에서 처리하려면 아래와 같이 한다.

1. 파일의 속성을 선택하고 어플을 지정하여 열도록 한다.

2. application:openFile을 app delegate에 추가한다.
   openFile은 아래 순서로 호출된다.


   applicationWillFinishLaunching
   openFile
   applicationDidFinishLaunching

- (void)applicationWillFinishLaunching:(NSNotification *)notification
{
    isLaunched = FALSE;
}

- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
    if(isLaunched){  // 어플이 이미 떠 있을때

        // 윈도우가 close 되어 있으면 다시 띄운다.
        [[[self getMainViewwindow]makeKeyAndOrderFront:[[self getMainView ] window]];

        // 파일을 처리한다.
        [[self getMainViewopenFile:filename];
    }
    else{  // 어플이 최초로 실행될때
        // 파일을 처리한다.
        [self setStartPath:filename];

        // 아래 코드를 넣지 않으면 5초 있다가 뜬다.
        NSApplication * myapp = [NSApplication sharedApplication];
        [myapp activateIgnoringOtherApps:YES];
        [[self window] makeKeyAndOrderFront:[self window]];

        // 키보드 이벤트를 받을 윈도우에 포커스를 준다. 
        [dicomImage.window makeFirstResponder:dicomImage];
    }
        
    return YES;

}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    ...    
    isLaunched = TRUE;
}

- (BOOL)getIsLaunched
{
    return isLaunched;
}


2013년 9월 26일 목요일

대화상자 띄우기


1. Xib 만들기
File - New - File - User Interface - Application
"Sample.xib"를 생성

2. File's owner 변경
Sample.xib를 클릭
File's owner 클릭
Identity Ispector 클릭
Custom Class의 Class를 대화상자를 호출할 클래스로 변경

3. 
@interface MyController : NSObject
{
}

@property (assign) IBOutlet NSWindow * calibration;

4.
@implementation MyController
@synthesize calibration = _calibration;


- (IBAction)onButtonCalibration:(id)sender;
{
    // Show Dialog Box
    if(!_calibration)
        [NSBundle loadNibNamed:@"calibration" owner:self];
    
    [NSApp beginSheet:self.calibration
       modalForWindow:[[NSApp delegate] window]
        modalDelegate:self
       didEndSelector:NULL
          contextInfo:NULL];
    
}