Changeset 7803326 for perl/lib


Ignore:
Timestamp:
Sep 30, 2011, 8:07:53 AM (10 years ago)
Author:
Jason Gross <jgross@mit.edu>
Branches:
master, release-1.9
Children:
0c71c58, 5f784ec, 923c3f6, a962f5c, d953ede
Parents:
e89ec48
git-author:
Jason Gross <jgross@mit.edu> (06/23/11 23:58:21)
git-committer:
Jason Gross <jgross@mit.edu> (09/30/11 08:07:53)
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

    re89ec48 r7803326  
    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, for compatibility.
     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.