Changeset c8ef50b for perl


Ignore:
Timestamp:
Sep 21, 2011, 4:21:51 PM (13 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
c162fd6
Parents:
8ad3964
git-author:
Jason Gross <jgross@mit.edu> (06/23/11 23:58:21)
git-committer:
Jason Gross <jgross@mit.edu> (09/21/11 16:21:51)
Message:
editwin callback for canceling the editwin

The code for editwin callbacks (called when the editwin is created) has
been extended so that callbacks are called when the editwin is canceled.
The old (perl) editwin callbacks still exist and have the same
functionality that they always have.  They are now deprecated.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl.pm

    r8ad3964 rc8ef50b  
    150150
    151151A Perl subroutine that is called when the user closes the edit_win.
     152C<CALLBACK> gets called with two parameters: the text the user entered,
     153and a C<SUCCESS> boolean parameter which is false if the user canceled
     154the edit_win and true otherwise.
    152155
    153156=back
     
    159162=head2 start_edit_win PROMPT CALLBACK
    160163
    161 Equivalent to C<start_edit> called with the appropriate parameters.
     164Roughly equivalent to C<start_edit> called with the appropriate parameters.
     165C<CALLBACK> is only called on success.
     166
     167These are deprecated wrappers around L<BarnOwl::start_edit>, and should not
     168be uesd in new code.
    162169
    163170=cut
     
    170177sub start_question {
    171178    my ($prompt, $callback) = @_;
    172     BarnOwl::start_edit(type => 'question', prompt => $prompt, callback => $callback);
     179    BarnOwl::start_edit(type => 'question', prompt => $prompt, callback => sub {
     180            my ($text, $success) = @_;
     181            $callback->($text) if $success;
     182        });
    173183}
    174184
    175185sub start_password {
    176186    my ($prompt, $callback) = @_;
    177     BarnOwl::start_edit(type => 'password', prompt => $prompt, callback => $callback);
     187    BarnOwl::start_edit(type => 'password', prompt => $prompt, callback => sub {
     188            my ($text, $success) = @_;
     189            $callback->($text) if $success;
     190        });
    178191}
    179192
    180193sub start_edit_win {
    181194    my ($prompt, $callback) = @_;
    182     BarnOwl::start_edit(type => 'edit_win', prompt => $prompt, callback => $callback);
     195    BarnOwl::start_edit(type => 'edit_win', prompt => $prompt, callback => sub {
     196            my ($text, $success) = @_;
     197            $callback->($text) if $success;
     198        });
    183199}
    184200
Note: See TracChangeset for help on using the changeset viewer.