version 1.46, 2008/06/14 07:38:53 |
version 1.47, 2008/09/15 16:13:35 |
|
|
} |
} |
|
|
/* |
/* |
* undo_enable(TRUE/FALSE) will enable / disable the undo mechanism. |
* undo_enable: toggle undo_enable. |
* Returns TRUE if previously enabled, FALSE otherwise. |
* Returns the previous value of the flag. |
*/ |
*/ |
int |
int |
undo_enable(int on) |
undo_enable(int f, int n) |
{ |
{ |
int pon = undo_enable_flag; |
int pon = undo_enable_flag; |
|
|
undo_enable_flag = on; |
if (f & (FFARG | FFRAND)) |
|
undo_enable_flag = n > 0; |
|
else |
|
undo_enable_flag = !undo_enable_flag; |
|
|
|
if (!(f & FFRAND)) |
|
ewprintf("Undo %sabled", undo_enable_flag ? "en" : "dis"); |
|
|
return (pon); |
return (pon); |
} |
} |
|
|
/* |
/* |
* If undo is enabled, then: |
* If undo is enabled, then: |
* undo_boundary_enable(FALSE) stops recording undo boundaries |
* Toggle undo boundary recording. |
* between actions. |
* If called with an argument, (n > 0) => enable. Otherwise disable. |
* undo_boundary_enable(TRUE) enables undo boundaries. |
* In either case, add an undo boundary |
* If undo is disabled, this function has no effect. |
* If undo is disabled, this function has no effect. |
*/ |
*/ |
|
int |
void |
undo_boundary_enable(int f, int n) |
undo_boundary_enable(int flag) |
|
{ |
{ |
if (undo_enable_flag == TRUE) |
int bon = boundary_flag; |
boundary_flag = flag; |
|
|
if (!undo_enable_flag) |
|
return (FALSE); |
|
|
|
undo_add_boundary(FFRAND, 1); |
|
|
|
if (f & (FFARG | FFRAND)) |
|
boundary_flag = n > 0; |
|
else |
|
boundary_flag = !boundary_flag; |
|
|
|
if (!(f & FFRAND)) |
|
ewprintf("Undo boundaries %sabled", |
|
boundary_flag ? "en" : "dis"); |
|
|
|
return (bon); |
} |
} |
|
|
/* |
/* |
* Record an undo boundary, unless boundary_flag == FALSE. |
* 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 |
int |
undo_add_boundary(void) |
undo_add_boundary(int f, int n) |
{ |
{ |
struct undo_rec *rec; |
struct undo_rec *rec; |
int last; |
int last; |
|
|
if (boundary_flag == FALSE) |
if (boundary_flag == FALSE) |
return; |
return (FALSE); |
|
|
last = lastrectype(); |
last = lastrectype(); |
if (last == BOUNDARY || last == MODIFIED) |
if (last == BOUNDARY || last == MODIFIED) |
return; |
return (TRUE); |
|
|
rec = new_undo_record(); |
rec = new_undo_record(); |
rec->type = BOUNDARY; |
rec->type = BOUNDARY; |
|
|
LIST_INSERT_HEAD(&curbp->b_undo, rec, next); |
LIST_INSERT_HEAD(&curbp->b_undo, rec, next); |
|
|
return; |
return (TRUE); |
} |
} |
|
|
/* |
/* |
|
|
struct undo_rec *rec; |
struct undo_rec *rec; |
int pos; |
int pos; |
|
|
if (undo_enable_flag == FALSE) |
if (!undo_enable_flag) |
return (TRUE); |
return (TRUE); |
reg.r_linep = lp; |
reg.r_linep = lp; |
reg.r_offset = offset; |
reg.r_offset = offset; |
|
|
memmove(&rec->region, ®, sizeof(struct region)); |
memmove(&rec->region, ®, sizeof(struct region)); |
rec->content = NULL; |
rec->content = NULL; |
|
|
undo_add_boundary(); |
undo_add_boundary(FFRAND, 1); |
|
|
LIST_INSERT_HEAD(&curbp->b_undo, rec, next); |
LIST_INSERT_HEAD(&curbp->b_undo, rec, next); |
|
|
|
|
struct undo_rec *rec; |
struct undo_rec *rec; |
int pos; |
int pos; |
|
|
if (undo_enable_flag == FALSE) |
if (!undo_enable_flag) |
return (TRUE); |
return (TRUE); |
|
|
reg.r_linep = lp; |
reg.r_linep = lp; |
|
|
pos = find_dot(lp, offset); |
pos = find_dot(lp, offset); |
|
|
if (offset == llength(lp)) /* if it's a newline... */ |
if (offset == llength(lp)) /* if it's a newline... */ |
undo_add_boundary(); |
undo_add_boundary(FFRAND, 1); |
else if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) { |
else if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) { |
/* |
/* |
* Separate this command from the previous one if we're not |
* Separate this command from the previous one if we're not |
|
|
*/ |
*/ |
if (rec->type == DELETE) { |
if (rec->type == DELETE) { |
if (rec->pos - rec->region.r_size != pos) |
if (rec->pos - rec->region.r_size != pos) |
undo_add_boundary(); |
undo_add_boundary(FFRAND, 1); |
} |
} |
} |
} |
rec = new_undo_record(); |
rec = new_undo_record(); |
|
|
region_get_data(®, rec->content, reg.r_size); |
region_get_data(®, rec->content, reg.r_size); |
|
|
if (lastrectype() != DELETE) |
if (lastrectype() != DELETE) |
undo_add_boundary(); |
undo_add_boundary(FFRAND, 1); |
|
|
LIST_INSERT_HEAD(&curbp->b_undo, rec, next); |
LIST_INSERT_HEAD(&curbp->b_undo, rec, next); |
|
|
|
|
int |
int |
undo_add_change(struct line *lp, int offset, int size) |
undo_add_change(struct line *lp, int offset, int size) |
{ |
{ |
if (undo_enable_flag == FALSE) |
if (!undo_enable_flag) |
return (TRUE); |
return (TRUE); |
undo_add_boundary(); |
undo_add_boundary(FFRAND, 1); |
boundary_flag = FALSE; |
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); |
boundary_flag = TRUE; |
boundary_flag = TRUE; |
undo_add_boundary(); |
undo_add_boundary(FFRAND, 1); |
|
|
return (TRUE); |
return (TRUE); |
} |
} |
|
|
* finished the current action... |
* finished the current action... |
*/ |
*/ |
|
|
undo_add_boundary(); |
undo_add_boundary(FFRAND, 1); |
|
|
save = boundary_flag; |
save = boundary_flag; |
boundary_flag = FALSE; |
boundary_flag = FALSE; |
|
|
} while (ptr != NULL && !done); |
} while (ptr != NULL && !done); |
|
|
boundary_flag = save; |
boundary_flag = save; |
undo_add_boundary(); |
undo_add_boundary(FFRAND, 1); |
|
|
ewprintf("Undo!"); |
ewprintf("Undo!"); |
} |
} |