Changeset 67b959c
- Timestamp:
- Jun 25, 2011, 10:01:22 AM (13 years ago)
- Children:
- caac19d
- Parents:
- b2bfe1f
- git-author:
- Jason Gross <jgross@mit.edu> (05/23/11 19:06:48)
- git-committer:
- Jason Gross <jgross@mit.edu> (06/25/11 10:01:22)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
re6d7e4e r67b959c 693 693 "current view.\n"), 694 694 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"), 695 704 696 705 OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE, … … 2331 2340 } 2332 2341 2342 char *owl_command_delete_and_expunge(int argc, const char *const *argv, const char *buff) 2343 { 2344 bool exclaim_success = true; 2345 2346 if (argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--quiet"))) { 2347 exclaim_success = false; 2348 argc--; 2349 argv++; 2350 } else if (!strcmp(argv[argc - 1], "-q") || !strcmp(argv[argc - 1], "--quiet")) { 2351 exclaim_success = false; 2352 argc--; 2353 } 2354 2355 if (argc == 1) { 2356 owl_function_delete_and_expunge_cur(exclaim_success); 2357 return NULL; 2358 } 2359 2360 if (argc == 3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) { 2361 owl_function_delete_and_expunge_by_id(atoi(argv[2]), exclaim_success); 2362 return NULL; 2363 } 2364 2365 owl_function_makemsg("Unknown arguments to delete-and-expunge command"); 2366 return NULL; 2367 } 2368 2333 2369 char *owl_command_undelete(int argc, const char *const *argv, const char *buff) 2334 2370 { -
functions.c
rb2bfe1f r67b959c 662 662 } 663 663 664 void 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 676 void 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 664 694 /* if move_after is 1, moves after the delete */ 665 695 void owl_function_deletecur(int move_after) … … 1653 1683 } 1654 1684 1685 void owl_function_delete_and_expunge_by_id(int id, bool exclaim_success) 1686 { 1687 const owl_messagelist *ml = owl_global_get_msglist(&g); 1688 int msg = owl_messagelist_get_index_by_id(ml, id); 1689 if (msg < 0) { 1690 owl_function_error("No message with id %d: unable to delete", id); 1691 } else { 1692 owl_function_delete_and_expunge_message(msg); 1693 if (exclaim_success) 1694 owl_function_makemsg("Message deleted and expunged"); 1695 } 1696 } 1697 1655 1698 /* note: this applies to global message list, not to view. 1656 1699 * If flag is 1, deletes. If flag is 0, undeletes. */ -
messagelist.c
rfc8a87a r67b959c 25 25 } 26 26 27 owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id)27 int owl_messagelist_get_index_by_id(const owl_messagelist *ml, int target_id) 28 28 { 29 /* return the message with id == 'id'. If it doesn't exist return NULL. */29 /* return the message index with id == 'id'. If it doesn't exist return -1. */ 30 30 int first, last, mid, msg_id; 31 31 owl_message *m; … … 38 38 msg_id = owl_message_get_id(m); 39 39 if (msg_id == target_id) { 40 return (m);40 return mid; 41 41 } else if (msg_id < target_id) { 42 42 first = mid + 1; … … 45 45 } 46 46 } 47 return(NULL); 47 return -1; 48 } 49 50 owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id) 51 { 52 /* return the message with id == 'id'. If it doesn't exist return NULL. */ 53 int n = owl_messagelist_get_index_by_id(ml, target_id); 54 if (n < 0) return NULL; 55 return ml->list->pdata[n]; 48 56 } 49 57 … … 66 74 owl_message_unmark_delete(ml->list->pdata[n]); 67 75 return(0); 76 } 77 78 void owl_messagelist_delete_and_expunge_element(owl_messagelist *ml, int n) 79 { 80 owl_message_delete(g_ptr_array_remove_index(ml->list, n)); 68 81 } 69 82
Note: See TracChangeset
for help on using the changeset viewer.