I'm implementing basic printing functionality as a library extension to a GUI toolkit I use (Tk).. The code uses a custom Cocoa class as the delegate for the printPanelDidEnd:returnCode:contextInfo selector (when the print dialog is presented as a sheet).

The design of the code is to get the value of the returnCode (NSOKButton or NSCancelButton), assign it to a variable, printResult, then take action based on the variable (print or return). I am doing this because the printPanelDidEnd:returnCode:contextInfo selector isn't supposed to return a value. The issue I'm running into is that the selector returns immediately and apparently the value of printResult isn't updated in the global scope of my code.

 Here's the relevant code:

int printResult;

@interface PrintDelegate: NSObject

-(id) init;

- (void)printPanelDidEnd:(NSPrintPanel *)printPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo;

@end

@implementation PrintDelegate

-(id) init {
  self = [super init];
  return self;
}

- (void)printPanelDidEnd:(NSPrintPanel *)printPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo {

  printResult = NULL;

 if (returnCode == NSOKButton) {
    printResult = NSOKButton;
    NSLog(@"printResult is OK button!");
  }
  if (returnCode = NSCancelButton) {
    printResult = NSCancelButton;
    NSLog(@"printResult is Cancel button!");
  }

}

@end

And here's the logic in another function of my code:

[printPanel beginSheetWithPrintInfo:printInfo modalForWindow:windowRef delegate:printDelegate didEndSelector:@selector(printPanelDidEnd:returnCode:contextInfo:) contextInfo:printInfo];

if {printResult = NSOkButton} {
        //do print stuff here
} else {
        return

}

Based on the NSLog statements, I can tell that printResult is being correctly updated, but for some reason that value never makes it to the other function. I understand the selector method doesn't return a value; that's why I'm assigning the value to the printResult variable. I don't believe it should be an error of variable scope, as the variable printResult is defined at the global level of the code, outside any functions or class definitions.

Any thoughts about what I'm doing wrong here?

Thanks,
Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to