version 1.41, 2006/07/25 08:22:32 |
version 1.42, 2006/11/17 08:45:31 |
|
|
*/ |
*/ |
static LIST_HEAD(, undo_rec) undo_free; |
static LIST_HEAD(, undo_rec) undo_free; |
static int undo_free_num; |
static int undo_free_num; |
static int nobound; |
static int boundary_flag = TRUE; |
|
static int undo_enable_flag = TRUE; |
|
|
/* |
/* |
* Global variables |
|
*/ |
|
/* |
|
* undo_disable_flag: Stop doing undo (useful when we know are |
|
* going to deal with huge deletion/insertions |
|
* that we don't plan to undo) |
|
*/ |
|
int undo_disable_flag; |
|
|
|
/* |
|
* Local functions |
* Local functions |
*/ |
*/ |
static int find_dot(struct line *, int); |
static int find_dot(struct line *, int); |
|
|
} |
} |
|
|
/* |
/* |
|
* Returns TRUE if undo is enabled, FALSE otherwise. |
|
*/ |
|
int |
|
undo_enabled(void) |
|
{ |
|
return (undo_enable_flag); |
|
} |
|
|
|
/* |
* undo_enable(TRUE/FALSE) will enable / disable the undo mechanism. |
* undo_enable(TRUE/FALSE) will enable / disable the undo mechanism. |
* Returns TRUE if previously enabled, FALSE otherwise. |
* Returns TRUE if previously enabled, FALSE otherwise. |
*/ |
*/ |
int |
int |
undo_enable(int on) |
undo_enable(int on) |
{ |
{ |
int pon = undo_disable_flag; |
int pon = undo_enable_flag; |
|
|
undo_disable_flag = (on == TRUE) ? 0 : 1; |
undo_enable_flag = on; |
return ((pon == TRUE) ? FALSE : TRUE); |
return (pon); |
} |
} |
|
|
/* |
/* |
* If undo is enabled, then: |
* If undo is enabled, then: |
* undo_no_boundary(TRUE) stops recording undo boundaries between actions. |
* undo_boundary_enable(FALS) stops recording undo boundaries between actions. |
* undo_no_boundary(FALSE) enables undo boundaries. |
* undo_boundary_enable(TRUE) enables undo boundaries. |
* If undo is disabled, this function has no effect. |
* If undo is disabled, this function has no effect. |
*/ |
*/ |
|
|
void |
void |
undo_no_boundary(int flag) |
undo_boundary_enable(int flag) |
{ |
{ |
if (undo_disable_flag == FALSE) |
if (undo_enable_flag == TRUE) |
nobound = flag; |
boundary_flag = flag; |
} |
} |
|
|
/* |
/* |
* Record an undo boundary, unless 'nobound' is set via undo_no_boundary. |
* Record an undo boundary, unless boundary_flag == FALSE. |
* Does nothing if previous undo entry is already a boundary or 'modified' flag. |
* Does nothing if previous undo entry is already a boundary or 'modified' flag. |
*/ |
*/ |
void |
void |
|
|
struct undo_rec *rec; |
struct undo_rec *rec; |
int last; |
int last; |
|
|
if (nobound) |
if (boundary_flag == FALSE) |
return; |
return; |
|
|
last = lastrectype(); |
last = lastrectype(); |
|
|
struct undo_rec *rec; |
struct undo_rec *rec; |
int pos; |
int pos; |
|
|
if (undo_disable_flag) |
if (undo_enable_flag == FALSE) |
return (TRUE); |
return (TRUE); |
reg.r_linep = lp; |
reg.r_linep = lp; |
reg.r_offset = offset; |
reg.r_offset = offset; |
|
|
struct undo_rec *rec; |
struct undo_rec *rec; |
int pos; |
int pos; |
|
|
if (undo_disable_flag) |
if (undo_enable_flag == FALSE) |
return (TRUE); |
return (TRUE); |
|
|
reg.r_linep = lp; |
reg.r_linep = lp; |
|
|
int |
int |
undo_add_change(struct line *lp, int offset, int size) |
undo_add_change(struct line *lp, int offset, int size) |
{ |
{ |
if (undo_disable_flag) |
if (undo_enable_flag == FALSE) |
return (TRUE); |
return (TRUE); |
undo_add_boundary(); |
undo_add_boundary(); |
nobound = TRUE; |
boundary_flag = FALSE; |
undo_add_delete(lp, offset, size); |
undo_add_delete(lp, offset, size); |
undo_add_insert(lp, offset, size); |
undo_add_insert(lp, offset, size); |
nobound = FALSE; |
boundary_flag = TRUE; |
undo_add_boundary(); |
undo_add_boundary(); |
|
|
return (TRUE); |
return (TRUE); |
|
|
|
|
undo_add_boundary(); |
undo_add_boundary(); |
|
|
save = nobound; |
save = boundary_flag; |
nobound = TRUE; |
boundary_flag = FALSE; |
|
|
done = 0; |
done = 0; |
do { |
do { |
|
|
ptr = LIST_NEXT(ptr, next); |
ptr = LIST_NEXT(ptr, next); |
} while (ptr != NULL && !done); |
} while (ptr != NULL && !done); |
|
|
nobound = save; |
boundary_flag = save; |
undo_add_boundary(); |
undo_add_boundary(); |
|
|
ewprintf("Undo!"); |
ewprintf("Undo!"); |