Changes in / [786a410:fe7ece2]


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    ra16d7e5 ra16d7e5  
    693693              "current view.\n"),
    694694  OWLCMD_ALIAS("del", "delete"),
     695
     696  OWLCMD_ARGS("delete-and-expunge", owl_command_delete_and_expunge, OWL_CTX_INTERACTIVE,
     697              "delete a message",
     698              "delete-and-expunge [-id msgid] [-q | --quiet]",
     699              "If no message id is specified the current message is deleted.\n"
     700              "Otherwise the message with the given message id is deleted.\n"
     701              "If --quiet is specified, then there is no message displayed on\n"
     702              "success.\n"),
     703  OWLCMD_ALIAS("delx", "delete-and-expunge"),
    695704
    696705  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
     
    23542363}
    23552364
     2365char *owl_command_delete_and_expunge(int argc, const char *const *argv, const char *buff)
     2366{
     2367  bool exclaim_success = true;
     2368
     2369  if (argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--quiet"))) {
     2370    exclaim_success = false;
     2371    argc--;
     2372    argv++;
     2373  } else if (!strcmp(argv[argc - 1], "-q") || !strcmp(argv[argc - 1], "--quiet")) {
     2374    exclaim_success = false;
     2375    argc--;
     2376  }
     2377
     2378  if (argc == 1) {
     2379    owl_function_delete_and_expunge_cur(exclaim_success);
     2380    return NULL;
     2381  }
     2382
     2383  if (argc == 3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
     2384    owl_function_delete_and_expunge_by_id(atoi(argv[2]), exclaim_success);
     2385    return NULL;
     2386  }
     2387
     2388  owl_function_makemsg("Unknown arguments to delete-and-expunge command");
     2389  return NULL;
     2390}
     2391
    23562392char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
    23572393{
  • functions.c

    ra16d7e5 ra16d7e5  
    662662}
    663663
     664void owl_function_delete_and_expunge_message(int n)
     665{
     666  owl_messagelist *ml = owl_global_get_msglist(&g);
     667  owl_view *v = owl_global_get_current_view(&g);
     668  int lastmsgid = owl_function_get_curmsg_id(v);
     669
     670  /* delete and expunge the message */
     671  owl_messagelist_delete_and_expunge_element(ml, n);
     672
     673  owl_function_redisplay_to_nearest(lastmsgid, v);
     674}
     675
     676void owl_function_delete_and_expunge_cur(bool exclaim_success)
     677{
     678  int curmsg;
     679  const owl_view *v = owl_global_get_current_view(&g);
     680
     681  /* bail if there's no current message */
     682  if (owl_view_get_size(v) < 1) {
     683    owl_function_error("No current message to delete");
     684    return;
     685  }
     686
     687  /* delete the current message */
     688  curmsg = owl_global_get_curmsg(&g);
     689  owl_function_delete_and_expunge_message(curmsg);
     690  if (exclaim_success)
     691    owl_function_makemsg("Message deleted and expunged");
     692}
     693
    664694/* if move_after is 1, moves after the delete */
    665695void owl_function_deletecur(int move_after)
     
    721751}
    722752
     753/* returns the current message id, if it exists.  Otherwise returns
     754 * -1 if we are past the end of the message list, and 0 otherwise. */
     755int owl_function_get_curmsg_id(const owl_view *v)
     756{
     757  int curmsg = owl_global_get_curmsg(&g);
     758  const owl_message *m = owl_view_get_element(v, curmsg);
     759  if (m)
     760    return owl_message_get_id(m);
     761  if (curmsg > 0) /* past the end of the message list (probably) */
     762    return -1;
     763  return 0;
     764}
     765
     766/* redisplays the view to the nearest message to the id given.
     767 * if msgid < 0, redisplay to past the end of the message list */
     768void owl_function_redisplay_to_nearest(int msgid, owl_view *v)
     769{
     770  int curmsg;
     771  /* update all views (we only have one right now) */
     772  owl_view_recalculate(v);
     773
     774  /* find where the new position should be */
     775  if (msgid < 0) {
     776    /* If already at the end, blank the screen and move curmsg
     777     * past the end of the messages. */
     778    curmsg = owl_view_get_size(v);
     779    owl_global_set_topmsg(&g, curmsg);
     780    owl_global_set_curmsg(&g, curmsg);
     781  } else {
     782    curmsg = owl_view_get_nearest_to_msgid(v, msgid);
     783    if (curmsg > owl_view_get_size(v) - 1)
     784      curmsg = owl_view_get_size(v) - 1;
     785    if (curmsg < 0)
     786      curmsg = 0;
     787    owl_global_set_curmsg(&g, curmsg);
     788    owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
     789  }
     790  /* if there are no messages set the direction to down in case we
     791   * delete everything upwards */
     792  owl_global_set_direction_downwards(&g);
     793
     794  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     795}
     796
    723797void owl_function_expunge(void)
    724798{
    725   int curmsg;
    726   const owl_message *m;
    727   owl_messagelist *ml;
    728   owl_view *v;
    729   int lastmsgid=0;
    730 
    731   curmsg=owl_global_get_curmsg(&g);
    732   v=owl_global_get_current_view(&g);
    733   ml=owl_global_get_msglist(&g);
    734 
    735   m=owl_view_get_element(v, curmsg);
    736   if (m) lastmsgid = owl_message_get_id(m);
     799  owl_messagelist *ml = owl_global_get_msglist(&g);
     800  owl_view *v = owl_global_get_current_view(&g);
     801  int lastmsgid = owl_function_get_curmsg_id(v);
    737802
    738803  /* expunge the message list */
    739804  owl_messagelist_expunge(ml);
    740805
    741   /* update all views (we only have one right now) */
    742   owl_view_recalculate(v);
    743 
    744   /* find where the new position should be
    745      (as close as possible to where we last where) */
    746   curmsg = owl_view_get_nearest_to_msgid(v, lastmsgid);
    747   if (curmsg>owl_view_get_size(v)-1) curmsg = owl_view_get_size(v)-1;
    748   if (curmsg<0) curmsg = 0;
    749   owl_global_set_curmsg(&g, curmsg);
    750   owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
    751   /* if there are no messages set the direction to down in case we
    752      delete everything upwards */
    753   owl_global_set_direction_downwards(&g);
     806  owl_function_redisplay_to_nearest(lastmsgid, v);
    754807 
    755808  owl_function_makemsg("Messages expunged");
    756   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    757809}
    758810
     
    16421694}
    16431695
     1696void owl_function_delete_and_expunge_by_id(int id, bool exclaim_success)
     1697{
     1698  const owl_messagelist *ml = owl_global_get_msglist(&g);
     1699  int msg = owl_messagelist_get_index_by_id(ml, id);
     1700  if (msg < 0) {
     1701    owl_function_error("No message with id %d: unable to delete", id);
     1702  } else {
     1703    owl_function_delete_and_expunge_message(msg);
     1704    if (exclaim_success)
     1705      owl_function_makemsg("Message deleted and expunged");
     1706  }
     1707}
     1708
    16441709/* note: this applies to global message list, not to view.
    16451710 * If flag is 1, deletes.  If flag is 0, undeletes. */
  • messagelist.c

    r901cee9 r901cee9  
    3030}
    3131
    32 owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id)
     32int owl_messagelist_get_index_by_id(const owl_messagelist *ml, int target_id)
    3333{
    34   /* return the message with id == 'id'.  If it doesn't exist return NULL. */
     34  /* return the message index with id == 'id'.  If it doesn't exist return -1. */
    3535  int first, last, mid, msg_id;
    3636  owl_message *m;
     
    4343    msg_id = owl_message_get_id(m);
    4444    if (msg_id == target_id) {
    45       return(m);
     45      return mid;
    4646    } else if (msg_id < target_id) {
    4747      first = mid + 1;
     
    5050    }
    5151  }
    52   return(NULL);
     52  return -1;
     53}
     54
     55owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id)
     56{
     57  /* return the message with id == 'id'.  If it doesn't exist return NULL. */
     58  int n = owl_messagelist_get_index_by_id(ml, target_id);
     59  if (n < 0) return NULL;
     60  return ml->list->pdata[n];
    5361}
    5462
     
    7179  owl_message_unmark_delete(ml->list->pdata[n]);
    7280  return(0);
     81}
     82
     83void owl_messagelist_delete_and_expunge_element(owl_messagelist *ml, int n)
     84{
     85  owl_message_delete(g_ptr_array_remove_index(ml->list, n));
    7386}
    7487
  • perl/lib/BarnOwl.pm

    r785ee77 r785ee77  
    105105Enqueue a message in the BarnOwl message list, logging it and
    106106processing it appropriately. C<MESSAGE> should be an instance of
    107 BarnOwl::Message or a subclass.
     107BarnOwl::Message or a subclass.  Returns the queued message.  This
     108is useful for, e.g., deleting a message from the message list.
    108109
    109110=head2 admin_message HEADER BODY
  • perl/lib/BarnOwl/Message.pm

    rd1ae4a4 rcaac19d  
    8181sub short_personal_context { return ""; }
    8282
     83sub delete_and_expunge {
     84    my ($m) = @_;
     85    &BarnOwl::command("delete-and-expunge --quiet --id " . $m->id);
     86}
     87
    8388sub delete {
    8489    my ($m) = @_;
  • perlglue.xs

    rce68f23 rcaac19d  
    143143                g_free(rv);
    144144
    145 void
     145SV *
    146146queue_message(msg)
    147147        SV *msg
     
    157157
    158158                owl_global_messagequeue_addmsg(&g, m);
    159         }
     159
     160                RETVAL = owl_perlconfig_message2hashref(m);
     161        }
     162        OUTPUT:
     163                RETVAL
    160164
    161165void
Note: See TracChangeset for help on using the changeset viewer.