Changeset 8ad3964


Ignore:
Timestamp:
Sep 21, 2011, 4:21:50 PM (13 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
c8ef50b
Parents:
11d55e5
git-author:
Jason Gross <jgross@mit.edu> (07/10/11 17:58:20)
git-committer:
Jason Gross <jgross@mit.edu> (09/21/11 16:21:50)
Message:
Made BarnOwl::start_* wrappers around a new BarnOwl::start_edit

A new function, BarnOwl::start_edit, was created as the preferred
interface for starting the edit_win from perl.

The perl interface to the edit_win is backwards compatible.

This is mostly preparation for the next commit, which generalizes the
syntax of starting an edit_win to allow callbacks on cancel.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl.pm

    ra130fc5 r8ad3964  
    99                    zephyr_stylestrip zephyr_smartstrip_user zephyr_getsubs
    1010                    queue_message admin_message
     11                    start_edit
    1112                    start_question start_password start_edit_win
    1213                    get_data_dir get_config_dir popless_text popless_ztext
     
    105106Enqueue a message in the BarnOwl message list, logging it and
    106107processing it appropriately. C<MESSAGE> should be an instance of
    107 BarnOwl::Message or a subclass.  Returns the queued message.  This
    108 is useful for, e.g., deleting a message from the message list.
     108BarnOwl::Message or a subclass.
    109109
    110110=head2 admin_message HEADER BODY
     
    112112Display a BarnOwl B<Admin> message, with the given header and body.
    113113
     114=head2 start_edit %ARGS
     115
     116Displays a prompt on the screen and lets the user enter text,
     117and calls a callback when the editwin is closed.
     118
     119C<%ARGS> must contain the following keys:
     120
     121=over 4
     122
     123=item prompt
     124
     125The line to display on the screen
     126
     127=item type
     128
     129One of:
     130
     131=over 4
     132
     133=item edit_win
     134
     135Displays the prompt on a line of its own and opens the edit_win.
     136
     137=item question
     138
     139Displays prompt on the screen and lets the user enter a line of
     140text.
     141
     142=item password
     143
     144Like question, but echoes the user's input as C<*>s when they
     145input.
     146
     147=back
     148
     149=item callback
     150
     151A Perl subroutine that is called when the user closes the edit_win.
     152
     153=back
     154
    114155=head2 start_question PROMPT CALLBACK
    115156
    116 Displays C<PROMPT> on the screen and lets the user enter a line of
    117 text, and calls C<CALLBACK>, which must be a perl subroutine
    118 reference, with the text the user entered
    119 
    120157=head2 start_password PROMPT CALLBACK
    121158
    122 Like C<start_question>, but echoes the user's input as C<*>s when they
    123 input.
    124 
    125159=head2 start_edit_win PROMPT CALLBACK
    126160
    127 Like C<start_question>, but displays C<PROMPT> on a line of its own
    128 and opens the editwin. If the user cancels the edit win, C<CALLBACK>
    129 is not invoked.
     161Equivalent to C<start_edit> called with the appropriate parameters.
     162
     163=cut
     164
     165sub start_edit {
     166    my %args = (@_);
     167    BarnOwl::Internal::start_edit($args{type}, $args{prompt}, $args{callback});
     168}
     169
     170sub start_question {
     171    my ($prompt, $callback) = @_;
     172    BarnOwl::start_edit(type => 'question', prompt => $prompt, callback => $callback);
     173}
     174
     175sub start_password {
     176    my ($prompt, $callback) = @_;
     177    BarnOwl::start_edit(type => 'password', prompt => $prompt, callback => $callback);
     178}
     179
     180sub start_edit_win {
     181    my ($prompt, $callback) = @_;
     182    BarnOwl::start_edit(type => 'edit_win', prompt => $prompt, callback => $callback);
     183}
    130184
    131185=head2 get_data_dir
  • perlglue.xs

    r11d55e5 r8ad3964  
    167167        }
    168168
    169 void
    170 start_question(line, callback)
    171         const char *line
    172         SV *callback
    173         PREINIT:
    174                 owl_editwin *e;
    175         CODE:
    176         {
    177                 if(!SV_IS_CODEREF(callback))
    178                         croak("Callback must be a subref");
    179 
    180                 e = owl_function_start_question(line);
    181 
    182                 owl_editwin_set_cbdata(e,
    183                                        newSVsv(callback),
    184                                        owl_perlconfig_dec_refcnt);
    185                 owl_editwin_set_callback(e, owl_perlconfig_edit_callback);
    186         }
    187 
    188 void
    189 start_password(line, callback)
    190         const char *line
    191         SV *callback
    192         PREINIT:
    193                 owl_editwin *e;
    194         CODE:
    195         {
    196                 if(!SV_IS_CODEREF(callback))
    197                         croak("Callback must be a subref");
    198 
    199                 e = owl_function_start_password(line);
    200 
    201                 owl_editwin_set_cbdata(e,
    202                                        newSVsv(callback),
    203                                        owl_perlconfig_dec_refcnt);
    204                 owl_editwin_set_callback(e, owl_perlconfig_edit_callback);
    205         }
    206 
    207 void
    208 start_edit_win(line, callback)
    209         const char *line
    210         SV *callback
    211         PREINIT:
    212                 owl_editwin *e;
    213         CODE:
    214         {
    215                 if(!SV_IS_CODEREF(callback))
    216                         croak("Callback must be a subref");
    217 
    218                 e = owl_function_start_edit_win(line);
    219                 owl_editwin_set_cbdata(e,
    220                                        newSVsv(callback),
    221                                        owl_perlconfig_dec_refcnt);
    222                 owl_editwin_set_callback(e, &owl_perlconfig_edit_callback);
    223         }
    224 
    225169
    226170const char *
     
    499443                                      ival);
    500444
     445void
     446start_edit(edit_type, line, callback)
     447        const char *edit_type
     448        const char *line
     449        SV *callback
     450        PREINIT:
     451                owl_editwin *e;
     452        CODE:
     453        {
     454                if (!SV_IS_CODEREF(callback))
     455                        croak("Callback must be a subref");
     456
     457                if (!strcmp(edit_type, "question"))
     458                        e = owl_function_start_question(line);
     459                else if (!strcmp(edit_type, "password"))
     460                        e = owl_function_start_password(line);
     461                else if (!strcmp(edit_type, "edit_win"))
     462                        e = owl_function_start_edit_win(line);
     463                else
     464                        croak("edit_type must be one of 'password', 'question', 'edit_win', not '%s'", edit_type);
     465
     466                owl_editwin_set_cbdata(e, newSVsv(callback), owl_perlconfig_dec_refcnt);
     467                owl_editwin_set_callback(e, owl_perlconfig_edit_callback);
     468        }
     469
    501470MODULE = BarnOwl                PACKAGE = BarnOwl::Editwin
    502471
Note: See TracChangeset for help on using the changeset viewer.