1 /* vifm 2 * Copyright (C) 2011 xaizek. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19 #ifndef VIFM__UNDO_H__ 20 #define VIFM__UNDO_H__ 21 22 #include "ops.h" 23 24 enum 25 { 26 COMMAND_GROUP_INFO_LEN = 320, 27 28 SKIP_UNDO_REDO_OPERATION = -8192, 29 }; 30 31 /* Error statuses for un_group_undo() and un_group_redo(). */ 32 typedef enum 33 { 34 UN_ERR_SUCCESS, /* Successful undo/redo. */ 35 UN_ERR_NONE, /* No more groups to undo/redo. */ 36 UN_ERR_FAIL, /* Try has failed with an error from perform function. */ 37 UN_ERR_BROKEN, /* FS changes made undoing/redoing group impossible. */ 38 UN_ERR_BALANCE, /* Skipped unbalanced group. */ 39 UN_ERR_NOUNDO, /* Cannot undone (e.g., permanent file deletion). */ 40 UN_ERR_SKIPPED, /* Operation skipped by the user. */ 41 UN_ERR_CANCELLED, /* Operation was cancelled by the user. */ 42 UN_ERR_ERRORS, /* Skipped entirely due to errors on previous undo/redo. */ 43 } 44 UnErrCode; 45 46 /* Operation execution handler. data is from un_group_add_op() call. Should 47 * return zero on successful execution of operation, can return 48 * SKIP_UNDO_REDO_OPERATION. */ 49 typedef int (*un_perform_func)(OPS op, void *data, const char src[], 50 const char dst[]); 51 52 /* Return value meaning: 53 * 0 - available (but undo.c need to check file existence or absence); 54 * < 0 - not available; 55 * > 0 - available always (no additional checks are performed). */ 56 typedef int (*un_op_available_func)(OPS op); 57 58 /* Callback to control execution of sets of operations. Should return non-zero 59 * in case processing should be aborted, otherwise zero is expected. */ 60 typedef int (*un_cancel_requested_func)(void); 61 62 /* Won't call un_reset(), so this function could be called multiple times. 63 * exec_func can't be NULL and should return non-zero on error. op_avail and 64 * cancel can be NULL. */ 65 void un_init(un_perform_func exec_func, un_op_available_func op_avail, 66 un_cancel_requested_func cancel, const int *max_levels); 67 68 /* Frees all allocated memory. */ 69 void un_reset(void); 70 71 /* Only stores msg pointer, so it should be valid until un_group_close() is 72 * called. */ 73 void un_group_open(const char msg[]); 74 75 /* Reopens last command group. */ 76 void un_group_reopen_last(void); 77 78 /* Replaces group message (makes its own copy of the msg). If msg equals NULL 79 * or no group is currently open, does nothing. Returns previous value. */ 80 char * un_replace_group_msg(const char msg[]); 81 82 /* Returns 0 on success. */ 83 int un_group_add_op(OPS op, void *do_data, void *undo_data, const char buf1[], 84 const char buf2[]); 85 86 /* Closes current group of commands. */ 87 void un_group_close(void); 88 89 /* Checks if the last opened group isn't empty (could still be opened). Returns 90 * non-zero if so, otherwise zero is returned. */ 91 int un_last_group_empty(void); 92 93 /* Returns UN_ERR_* codes. */ 94 UnErrCode un_group_undo(void); 95 96 /* Returns UN_ERR_* codes, except for UN_ERR_NOUNDO, it's matched by 97 * UN_ERR_BALANCE on redo. */ 98 UnErrCode un_group_redo(void); 99 100 /* When detail is not 0 show detailed information for groups. Last element of 101 * list returned is NULL. Returns NULL on error. */ 102 char ** un_get_list(int detail); 103 104 /* Returns position in the list returned by un_get_list(). */ 105 int un_get_list_pos(int detail); 106 107 /* Changes position in the undo list according to position in the list returned 108 * by un_get_list(). */ 109 void un_set_pos(int pos, int detail); 110 111 /* Removes all commands which files are in specified trash directory. The 112 * special value NULL means "all trash directories". */ 113 void un_clear_cmds_with_trash(const char trash_dir[]); 114 115 #endif /* VIFM__UNDO_H__ */ 116 117 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ 118 /* vim: set cinoptions+=t0 filetype=c : */ 119