I have my browser's plumbing working, but I found myself doing some
peculiar things.  I'm hoping that one of you can tell me wazzup.

The new() method (in MyWindowController.pm) sets up Browser_F (an
NSBrowser) and TextField_F (an NSTextField):

    # Set up TextField_F's notification jazz.

    # Found. > Classes > NSNotificationCenter > Class Methods >
    # + defaultCenter
    #
    $dnc = NSNotificationCenter->defaultCenter();

    # Found. > Classes > NSNotificationCenter > Instance Methods >
    # - addObserver:selector:name:object:
    #
    $dnc->addObserver_selector_name_object(
        $self,
        'controlTextDidEndEditing:',
        'NSControlTextDidEndEditingNotification',
        undef);

    # Set the initial path into TextField_F and Browser_F.

    # AppKit > Classes > NSCell > Instance Methods >
    # setStringValue:
    #
    $self->{'TextField_F'}->setStringValue($curr_path);

    # AppKit > Classes > NSBrowser > Instance Methods >
    # setPath:
    #
    $self->{'Browser_F'}->setPath($curr_path);

    # Set up a method to accept single-click events from Browser_F.

    # AppKit > Classes > NSControl > Instance Methods >
    # setTarget:
    #
    $self->{'Browser_F'}->setTarget($self);

    # AppKit > Classes > NSControl > Instance Methods >
    # setAction:
    #
    $self->{'Browser_F'}->setAction('browserFSgl:');


When a single click is detected by Browser_F, browserFSgl() picks up
the path from Browser_F, sets the value of TextField_F, and posts a
notification that TextField_F has finished editing:

# browserFSgl - handle single-click event in browser

$OBJC_EXPORT{'browserFSgl:'} = {
    'args'   => '@',
    'return' => 'v'
};

sub browserFSgl {

    my ($self, $browser) = @_;

    my ($path);

    # AppKit > Classes > NSBrowser > Instance Methods >
    # path
    #
    $path = $browser->path();
    $path = '/' if ($path eq '');

    # AppKit > Classes > NSCell > Instance Methods >
    # setStringValue:
    #
    $self->{'TextField_F'}->setStringValue($path);

    # Found. > Classes > NSNotificationCenter > Instance Methods >
    # postNotificationName:object:
    #
    $dnc->postNotificationName_object(
        'NSControlTextDidEndEditingNotification',
        $self->{'TextField_F'});

    return($self);
}


When the notification arrives, controlTextDidEndEditing() picks up
the new_path and compares it with the curr_path.  It does this because
it's getting called into action when I click on an item in Browser_F
(before browserFSgl() gets called!).  If the path is truly new, it
updates other parts of the window, then sets the path for Browser_F
(this event _could_ have come from TextField_F, after all :-).

sub controlTextDidEndEditing {

    my ($self, $aNotification) = @_;

    my ($name, $new_path, $tableView);

    # AppKit > Classes > NSCell > Instance Methods >
    # stringValue
    #
    $new_path =  $aNotification->object()->stringValue();

    # KLUDGE - why are we being called when nothing has changed?

    $new_path =~ s|^.*\n||;
    if ($new_path eq $curr_path) {
        return($self);
    }
    $curr_path = $new_path;

    ...

    # AppKit > Classes > NSBrowser > Instance Methods >
    # setPath:
    #
    $self->{'Browser_F'}->setPath($curr_path);

    return($self);
}

--
email: [EMAIL PROTECTED]; phone: +1 650-873-7841
http://www.cfcl.com/rdm    - my home page, resume, etc.
http://www.cfcl.com/Meta   - The FreeBSD Browser, Meta Project, etc.
http://www.ptf.com/dossier - Prime Time Freeware's DOSSIER series
http://www.ptf.com/tdc     - Prime Time Freeware's Darwin Collection

Reply via email to