On Aug 6, 2004, at 11:16 PM, Sherm Pendley wrote:


It's not done in Xcode, but in Interface Builder. You create a new Nib with whatever panel(s) and such you want in it, and add that Nib to your project. (Okay, I lied - part of it is in Xcode.)


In the MainMenu Nib, connect the "AppName Preferences" to an action method in AppName.pm. In that action method, create a new controller object. Here's an example from ShuX:

sub showPreferences {
    my ($self, $sender) = @_;
    unless (defined $self->{'_preferences'}) {
        $self->{'_preferences'} = new PreferencesDelegate;
    }
    $self->{'_preferences'}->{'Window'}->makeKeyAndOrderFront(undef);
}

In the constructor for the PreferencesDelegate class, create an NSWindowController and use it to load the Nib, telling it that the current object is the Nib's "owner". Thus, action messages you've connected to the "File's Owner" in IB will be sent to this object. Here's part of the PreferencesDelegate new() method from ShuX - I've deleted some code that isn't relevant:

sub new {
    # Typical Perl constructor
    # See 'perltoot' for details
    my $proto = shift;
    my $class = ref($proto) || $proto;

    my $self = {
    };

    bless ($self, $class);

$self->{'wc'} = NSWindowController->alloc->initWithWindowNibName_owner("Preferences", $self);
$self->{'wc'}->window;


    return $self;
}

Once you call NSWindowController's initWithWindowNibName_owner() method, the outlets that you've connected in IB will be connected to the corresponding outlets declared in your Perl code, and action methods sent by the Nib will be sent to the newly-created object.

You can also use the same technique to create multiple instances of the same Nib, each owned by a different controller object - ShuX does this to manage multiple browser windows.


Well, I figured out why I was getting the disconnect message... Connecting to first responder instead of file's owner helps...


Now onto the next message...

When i try and get the preferences dialog to display, I get the following:

2004-08-10 15:42:53.587 PerlButtonTest[1001] NSWindow does not support utility styleMask 0x10
2004-08-10 15:42:53.600 PerlButtonTest[1001] Perl error: Can't call method "makeKeyAndOrderFront" on an undefined value at /Users/alan/Documents/XCode projects/PerlButtonTest.app/Contents/Resources/PerlButtonTest.pm line 45.


This might be a panel instead of window issue. Kind of wondering what "utility style mask 0x10" is...



Reply via email to