Changeset 59cf91c


Ignore:
Timestamp:
Aug 17, 2002, 1:21:17 PM (22 years ago)
Author:
Erik Nygren <nygren@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
67103d4
Parents:
37c27cf
Message:
	Attempts to stay near the current message when switching views.
	     When switching from an empty view to one we've previously
	     been in, the new current message position will attempt
	     to be close to the current position from the last
	     time we visited that view.
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r1fd0b25 r59cf91c  
    88        renamed owl_fmtext_ztext_stylestrip to owl_function_ztext_styletsrip
    99             and put it in functions.c
    10 
     10        Attempts to stay near the current message when switching views.
     11             When switching from an empty view to one we've previously
     12             been in, the new current message position will attempt
     13             to be close to the current position from the last
     14             time we visited that view.
     15       
    11161.2.1
    1217        New framework for command handling.
  • filter.c

    r1aee7d9 r59cf91c  
    2121  f->polarity=0;
    2222  f->color=OWL_COLOR_DEFAULT;
     23  f->cachedmsgid=-1;
    2324  owl_list_create(&(f->fes));
    2425
     
    9596int owl_filter_get_color(owl_filter *f) {
    9697  return(f->color);
     98}
     99
     100void owl_filter_set_cachedmsgid(owl_filter *f, int cachedmsgid) {
     101  f->cachedmsgid=cachedmsgid;
     102}
     103
     104int owl_filter_get_cachedmsgid(owl_filter *f) {
     105  return(f->cachedmsgid);
    97106}
    98107
  • functions.c

    r37c27cf r59cf91c  
    16671667  owl_view *v;
    16681668  owl_filter *f;
     1669  int curid=-1, newpos;
     1670  owl_message *curm;
    16691671
    16701672  v=owl_global_get_current_view(&g);
     1673  curm=owl_view_get_element(v, owl_global_get_curmsg(&g));
     1674  if (curm) {
     1675    curid = owl_message_get_id(curm);
     1676    owl_view_save_curmsgid(v, curid);
     1677  }
     1678
    16711679  f=owl_global_get_filter(&g, filtname);
    16721680  if (!f) {
     
    16781686  owl_view_create(v, f);
    16791687
    1680   owl_global_set_curmsg(&g, 0);
     1688  /* Figure out where to set the current message to.
     1689   * - If the previous view had messages in it, go to the closest message
     1690   *   to the last message in that view.
     1691   * - If the previous view was empty, attempts to restore the position
     1692   *   from the last time we were in that view.  */
     1693  if (curm) {
     1694    newpos = owl_view_get_nearest_to_msgid(v, curid);
     1695  } else {
     1696    newpos = owl_view_get_nearest_to_saved(v);
     1697  }
     1698
     1699  owl_global_set_curmsg(&g, newpos);
     1700
    16811701  owl_global_set_curmsg_vert_offset(&g, 0);
    16821702  owl_global_set_direction_downwards(&g);
  • owl.h

    r1fd0b25 r59cf91c  
    289289  owl_list fes; /* filterelements */
    290290  int color;
     291  int cachedmsgid;  /* cached msgid: should move into view eventually */
    291292} owl_filter;
    292293
  • view.c

    r1aee7d9 r59cf91c  
    5656}
    5757
     58/* Returns the position in the view with a message closest
     59 * to the passed msgid. */
     60int owl_view_get_nearest_to_msgid(owl_view *v, int targetid) {
     61  int i, bestdist=-1, bestpos=0, curid, curdist;
     62
     63  for (i=0; i<owl_view_get_size(v); i++) {
     64    curid = owl_message_get_id(owl_view_get_element(v, i));
     65    curdist = abs(targetid-curid);
     66    if (bestdist<0 || curdist<bestdist) {
     67      bestdist = curdist;
     68      bestpos = i;
     69    }
     70  }
     71  return bestpos;
     72}
     73
     74int owl_view_get_nearest_to_saved(owl_view *v) {
     75  int cachedid = owl_filter_get_cachedmsgid(v->filter);
     76  if (cachedid<0) return(0);
     77  return owl_view_get_nearest_to_msgid(v, cachedid);
     78}
     79
     80/* saves the current message position in the filter so it can
     81 * be restored later if we switch back to this filter. */
     82void owl_view_save_curmsgid(owl_view *v, int curid) {
     83  owl_filter_set_cachedmsgid(v->filter, curid);
     84}
     85
    5886char *owl_view_get_filtname(owl_view *v) {
    5987  return(owl_filter_get_name(v->filter));
Note: See TracChangeset for help on using the changeset viewer.