Changeset 3895e23 for functions.c


Ignore:
Timestamp:
Dec 25, 2003, 12:05:02 AM (17 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
280ddc6
Parents:
330bcec
Message:
The '!' key (bound to 'view -r') now creates a negative version of the
  current view and switches to it.  i.e. "show me all the messages that
  are not these"
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r40458b9 r3895e23  
    22502250}
    22512251
    2252 #if 0
    2253 void owl_function_change_view_old(char *filtname)
     2252void owl_function_change_currentview_filter(char *filtname)
    22542253{
    22552254  owl_view *v;
     
    22592258
    22602259  v=owl_global_get_current_view(&g);
     2260
    22612261  curmsg=owl_global_get_curmsg(&g);
    22622262  if (curmsg==-1) {
     
    22702270  }
    22712271
    2272   /* grab the filter */;
    22732272  f=owl_global_get_filter(&g, filtname);
    22742273  if (!f) {
     
    22772276  }
    22782277
    2279   /* free the existing view and create a new one based on the filter */
    2280   owl_view_free(v);
    2281   owl_view_create(v, f);
     2278  owl_view_new_filter(v, f);
    22822279
    22832280  /* Figure out what to set the current message to.
     
    22932290
    22942291  owl_global_set_curmsg(&g, newpos);
    2295 
    22962292  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
    22972293  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    22982294  owl_global_set_direction_downwards(&g);
    22992295}
    2300 #endif
    2301 
    2302 void owl_function_change_view(char *filtname)
    2303 {
    2304   owl_view *v;
    2305   owl_filter *f;
    2306   int curid=-1, newpos, curmsg;
    2307   owl_message *curm=NULL;
    2308 
    2309   v=owl_global_get_current_view(&g);
    2310 
    2311   curmsg=owl_global_get_curmsg(&g);
    2312   if (curmsg==-1) {
    2313     owl_function_debugmsg("Hit the curmsg==-1 case in change_view");
    2314   } else {
    2315     curm=owl_view_get_element(v, curmsg);
    2316     if (curm) {
    2317       curid=owl_message_get_id(curm);
    2318       owl_view_save_curmsgid(v, curid);
    2319     }
    2320   }
    2321 
    2322   f=owl_global_get_filter(&g, filtname);
    2323   if (!f) {
    2324     owl_function_error("Unknown filter %s", filtname);
    2325     return;
    2326   }
    2327 
    2328   owl_view_new_filter(v, f);
    2329 
    2330   /* Figure out what to set the current message to.
    2331    * - If the view we're leaving has messages in it, go to the closest message
    2332    *   to the last message pointed to in that view.
    2333    * - If the view we're leaving is empty, try to restore the position
    2334    *   from the last time we were in the new view.  */
    2335   if (curm) {
    2336     newpos = owl_view_get_nearest_to_msgid(v, curid);
    2337   } else {
    2338     newpos = owl_view_get_nearest_to_saved(v);
    2339   }
    2340 
    2341   owl_global_set_curmsg(&g, newpos);
    2342   owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
    2343   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    2344   owl_global_set_direction_downwards(&g);
    2345 }
    23462296
    23472297void owl_function_create_filter(int argc, char **argv)
     
    23552305    return;
    23562306  }
     2307
     2308  owl_function_debugmsg("owl_function_create_filter: starting to create filter named %s", argv[1]);
    23572309
    23582310  v=owl_global_get_current_view(&g);
     
    24052357  /* if it was in use by the current view then update */
    24062358  if (inuse) {
    2407     owl_function_change_view(argv[1]);
     2359    owl_function_change_currentview_filter(argv[1]);
    24082360  }
    24092361  owl_global_set_needrefresh(&g);
    24102362  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     2363}
     2364
     2365/* If 'filtername' does not start with 'not-' create a filter named
     2366 * 'not-<filtername>' defined as "not filter <filtername>".  If the
     2367 * filter 'not-<filtername>' already exists, do not overwrite it.  If
     2368 * 'filtername' begins with 'not-' and a filter 'filtername' already
     2369 * exists, then do nothing.  If the filter 'filtername' does not
     2370 * exist, create it and define it as 'not filter <filtername>'
     2371 *
     2372 * Returns the name of the negated filter, which the caller must free.
     2373 */
     2374char *owl_function_create_negative_filter(char *filtername)
     2375{
     2376  char *newname;
     2377  owl_filter *tmpfilt;
     2378  char *argv[5];
     2379
     2380  owl_function_debugmsg("owl_function_create_negative_filter");
     2381 
     2382  if (!strncmp(filtername, "not-", 4)) {
     2383    newname=owl_strdup(filtername+4);
     2384  } else {
     2385    newname=owl_sprintf("not-%s", filtername);
     2386  }
     2387
     2388  tmpfilt=owl_global_get_filter(&g, newname);
     2389  if (!tmpfilt) {
     2390    argv[0]="filter"; /* anything is fine here */
     2391    argv[1]=newname;
     2392    argv[2]="not";
     2393    argv[3]="filter";
     2394    argv[4]=filtername;
     2395    owl_function_create_filter(5, argv);
     2396  }
     2397
     2398  owl_function_debugmsg("owl_function_create_negative_filter: returning with %s", newname);
     2399  return(newname);
    24112400}
    24122401
Note: See TracChangeset for help on using the changeset viewer.