Changeset 7803326


Ignore:
Timestamp:
Sep 30, 2011, 8:07:53 AM (13 years ago)
Author:
Jason Gross <jgross@mit.edu>
Branches:
master, release-1.10, 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.
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rf271129 r7803326  
    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 r7803326  
    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

    rc737503 r7803326  
    341341}
    342342
    343 void owl_callback_zwrite(owl_editwin *e) {
     343void owl_callback_zwrite(owl_editwin *e, bool success)
     344{
     345  if (!success) return;
    344346  owl_zwrite *z = owl_editwin_get_cbdata(e);
    345347  owl_function_zwrite(z, owl_editwin_get_text(e));
     
    436438}
    437439
    438 void owl_callback_aimwrite(owl_editwin *e) {
     440void owl_callback_aimwrite(owl_editwin *e, bool success)
     441{
     442  if (!success) return;
    439443  char *to = owl_editwin_get_cbdata(e);
    440444  owl_function_aimwrite(to, owl_editwin_get_text(e), true);
     
    500504}
    501505
    502 void owl_callback_loopwrite(owl_editwin *e) {
     506void owl_callback_loopwrite(owl_editwin *e, bool success)
     507{
     508  if (!success) return;
    503509  owl_function_loopwrite(owl_editwin_get_text(e));
    504510}
     
    911917}
    912918
    913 void owl_callback_aimlogin(owl_editwin *e) {
     919void owl_callback_aimlogin(owl_editwin *e, bool success)
     920{
     921  if (!success) return;
    914922  char *user = owl_editwin_get_cbdata(e);
    915923  owl_function_aimlogin(user,
     
    19331941}
    19341942
    1935 void owl_callback_command(owl_editwin *e)
    1936 {
     1943void owl_callback_command(owl_editwin *e, bool success)
     1944{
     1945  if (!success) return;
    19371946  char *rv;
    19381947  const char *line = owl_editwin_get_text(e);
  • 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
  • perlconfig.c

    rb9517cf r7803326  
    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 
  • viewwin.c

    rf271129 r7803326  
    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.