Changeset fe7ece2 for functions.c


Ignore:
Timestamp:
Jul 9, 2011, 4:10:45 PM (10 years ago)
Author:
GitHub Merge Button <merge-button@github.com>
Parents:
786a410 (diff), caac19d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge caac19d40ffaea75410ce13da172590b04dae2b1 into 786a4108f9184d7c73170d373bc2cf80347b6456
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    ra16d7e5 rfe7ece2  
    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. */
Note: See TracChangeset for help on using the changeset viewer.