Changes in / [eba02ec:c162fd6]


Ignore:
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rf271129 rc8ef50b  
    27962796    owl_history_store(hist, owl_editwin_get_text(e), false);
    27972797
     2798  /* Take a reference to the editwin, so that it survives the pop
     2799   * context. TODO: We should perhaps refcount or otherwise protect
     2800   * the context so that, even if a command pops a context, the
     2801   * context itself will last until the command returns. */
     2802  owl_editwin_ref(e);
    27982803  owl_global_pop_context(&g);
     2804
     2805  owl_editwin_do_callback(e, false);
     2806  owl_editwin_unref(e);
    27992807}
    28002808
     
    28562864  owl_global_pop_context(&g);
    28572865
    2858   owl_editwin_do_callback(e);
     2866  owl_editwin_do_callback(e, true);
    28592867  owl_editwin_unref(e);
    28602868}
  • editwin.c

    rf271129 rc8ef50b  
    3333  oe_excursion *excursions;
    3434
    35   void (*callback)(struct _owl_editwin*);
     35  void (*callback)(struct _owl_editwin *e, bool success);
    3636  void (*destroy_cbdata)(void *);
    3737  void *cbdata;
     
    220220}
    221221
    222 void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin*))
     222void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin *, bool))
    223223{
    224224  e->callback = cb;
    225225}
    226226
    227 void (*owl_editwin_get_callback(owl_editwin *e))(owl_editwin*)
     227void (*owl_editwin_get_callback(owl_editwin *e))(owl_editwin *, bool)
    228228{
    229229  return e->callback;
     
    248248}
    249249
    250 void owl_editwin_do_callback(owl_editwin *e) {
    251   void (*cb)(owl_editwin*);
    252   cb=owl_editwin_get_callback(e);
    253   if(!cb) {
     250void owl_editwin_do_callback(owl_editwin *e, bool success)
     251{
     252  void (*cb)(owl_editwin *, bool);
     253  cb = owl_editwin_get_callback(e);
     254  if (!cb) {
    254255    owl_function_error("Internal error: No editwin callback!");
    255256  } else {
    256     /* owl_function_error("text: |%s|", owl_editwin_get_text(e)); */
    257     cb(e);
     257    cb(e, success);
    258258  }
    259259}
  • functions.c

    r6646fdb rc8ef50b  
    272272}
    273273
    274 void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *))
     274owl_editwin *owl_function_start_edit_win(const char *line)
    275275{
    276276  owl_editwin *e;
     
    286286  g_free(s);
    287287
    288   owl_editwin_set_cbdata(e, data, cleanup);
    289   owl_editwin_set_callback(e, callback);
    290288  ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti",
    291289                            owl_global_deactivate_editcontext, &g);
    292290  owl_global_push_context_obj(&g, ctx);
    293 
     291  return e;
    294292}
    295293
     
    309307void owl_function_zwrite_setup(owl_zwrite *z)
    310308{
     309  owl_editwin *e;
    311310  /* send a ping if necessary */
    312311  if (owl_global_is_txping(&g)) {
     
    316315
    317316  owl_function_write_setup("zephyr");
    318   owl_function_start_edit_win(z->zwriteline,
    319                               &owl_callback_zwrite,
    320                               z, (void(*)(void*))owl_zwrite_delete);
     317  e = owl_function_start_edit_win(z->zwriteline);
     318  owl_editwin_set_cbdata(e, z, (void (*)(void *))owl_zwrite_delete);
     319  owl_editwin_set_callback(e, &owl_callback_zwrite);
    321320}
    322321
    323322void owl_function_aimwrite_setup(const char *to)
    324323{
     324  owl_editwin *e;
    325325  /* TODO: We probably actually want an owl_aimwrite object like
    326326   * owl_zwrite. */
    327327  char *line = g_strdup_printf("aimwrite %s", to);
    328328  owl_function_write_setup("message");
    329   owl_function_start_edit_win(line,
    330                               &owl_callback_aimwrite,
    331                               g_strdup(to),
    332                               g_free);
     329  e = owl_function_start_edit_win(line);
     330  owl_editwin_set_cbdata(e, g_strdup(to), g_free);
     331  owl_editwin_set_callback(e, &owl_callback_aimwrite);
    333332  g_free(line);
    334333}
     
    336335void owl_function_loopwrite_setup(void)
    337336{
     337  owl_editwin *e;
    338338  owl_function_write_setup("message");
    339   owl_function_start_edit_win("loopwrite",
    340                               &owl_callback_loopwrite,
    341                               NULL, NULL);
    342 }
    343 
    344 void owl_callback_zwrite(owl_editwin *e) {
     339  e = owl_function_start_edit_win("loopwrite");
     340  owl_editwin_set_callback(e, &owl_callback_loopwrite);
     341}
     342
     343void owl_callback_zwrite(owl_editwin *e, bool success)
     344{
     345  if (!success) return;
    345346  owl_zwrite *z = owl_editwin_get_cbdata(e);
    346347  owl_function_zwrite(z, owl_editwin_get_text(e));
     
    437438}
    438439
    439 void owl_callback_aimwrite(owl_editwin *e) {
     440void owl_callback_aimwrite(owl_editwin *e, bool success)
     441{
     442  if (!success) return;
    440443  char *to = owl_editwin_get_cbdata(e);
    441444  owl_function_aimwrite(to, owl_editwin_get_text(e), true);
     
    501504}
    502505
    503 void owl_callback_loopwrite(owl_editwin *e) {
     506void owl_callback_loopwrite(owl_editwin *e, bool success)
     507{
     508  if (!success) return;
    504509  owl_function_loopwrite(owl_editwin_get_text(e));
    505510}
     
    912917}
    913918
    914 void owl_callback_aimlogin(owl_editwin *e) {
     919void owl_callback_aimlogin(owl_editwin *e, bool success)
     920{
     921  if (!success) return;
    915922  char *user = owl_editwin_get_cbdata(e);
    916923  owl_function_aimlogin(user,
     
    19341941}
    19351942
    1936 void owl_callback_command(owl_editwin *e)
    1937 {
     1943void owl_callback_command(owl_editwin *e, bool success)
     1944{
     1945  if (!success) return;
    19381946  char *rv;
    19391947  const char *line = owl_editwin_get_text(e);
     
    19461954}
    19471955
    1948 void owl_function_start_command(const char *line)
     1956owl_editwin *owl_function_start_command(const char *line)
    19491957{
    19501958  owl_editwin *tw;
     
    19611969  owl_global_push_context_obj(&g, ctx);
    19621970  owl_editwin_set_callback(tw, owl_callback_command);
    1963 }
    1964 
    1965 CALLER_OWN owl_editwin *owl_function_start_question(const char *line)
     1971  return tw;
     1972}
     1973
     1974owl_editwin *owl_function_start_question(const char *line)
    19661975{
    19671976  owl_editwin *tw;
     
    19781987}
    19791988
    1980 CALLER_OWN owl_editwin *owl_function_start_password(const char *line)
     1989owl_editwin *owl_function_start_password(const char *line)
    19811990{
    19821991  owl_editwin *tw;
  • perl/lib/BarnOwl.pm

    ra130fc5 rc8ef50b  
    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.
     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.
     155
     156=back
     157
    114158=head2 start_question PROMPT CALLBACK
    115159
    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 
    120160=head2 start_password PROMPT CALLBACK
    121161
    122 Like C<start_question>, but echoes the user's input as C<*>s when they
    123 input.
    124 
    125162=head2 start_edit_win PROMPT CALLBACK
    126163
    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.
     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.
     169
     170=cut
     171
     172sub start_edit {
     173    my %args = (@_);
     174    BarnOwl::Internal::start_edit($args{type}, $args{prompt}, $args{callback});
     175}
     176
     177sub start_question {
     178    my ($prompt, $callback) = @_;
     179    BarnOwl::start_edit(type => 'question', prompt => $prompt, callback => sub {
     180            my ($text, $success) = @_;
     181            $callback->($text) if $success;
     182        });
     183}
     184
     185sub start_password {
     186    my ($prompt, $callback) = @_;
     187    BarnOwl::start_edit(type => 'password', prompt => $prompt, callback => sub {
     188            my ($text, $success) = @_;
     189            $callback->($text) if $success;
     190        });
     191}
     192
     193sub start_edit_win {
     194    my ($prompt, $callback) = @_;
     195    BarnOwl::start_edit(type => 'edit_win', prompt => $prompt, callback => sub {
     196            my ($text, $success) = @_;
     197            $callback->($text) if $success;
     198        });
     199}
    130200
    131201=head2 get_data_dir
  • perlconfig.c

    rb9517cf rc8ef50b  
    520520}
    521521
    522 void owl_perlconfig_edit_callback(owl_editwin *e)
     522void owl_perlconfig_edit_callback(owl_editwin *e, bool success)
    523523{
    524524  SV *cb = owl_editwin_get_cbdata(e);
     
    537537  PUSHMARK(SP);
    538538  XPUSHs(sv_2mortal(text));
     539  XPUSHs(sv_2mortal(newSViv(success)));
    539540  PUTBACK;
    540541 
  • perlglue.xs

    rf271129 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         CODE:
    212         {
    213                 if(!SV_IS_CODEREF(callback))
    214                         croak("Callback must be a subref");
    215 
    216                 owl_function_start_edit_win(line,
    217                                             owl_perlconfig_edit_callback,
    218                                             newSVsv(callback),
    219                                             owl_perlconfig_dec_refcnt);
    220         }
    221 
    222169
    223170const char *
     
    496443                                      ival);
    497444
     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
    498470MODULE = BarnOwl                PACKAGE = BarnOwl::Editwin
    499471
  • viewwin.c

    rf271129 rc8ef50b  
    158158} owl_viewwin_search_data;
    159159
    160 static void owl_viewwin_callback_search(owl_editwin *e)
    161 {
     160static void owl_viewwin_callback_search(owl_editwin *e, bool success)
     161{
     162  if (!success) return;
    162163  int consider_current = false;
    163164  const char *line = owl_editwin_get_text(e);
Note: See TracChangeset for help on using the changeset viewer.