summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormongo <mongo@iomega>2016-04-21 16:05:09 -0300
committermongo <mongo@iomega>2016-04-21 16:05:09 -0300
commit1f518090dd94f3985bb1719f6d90325871fb6deb (patch)
tree172d896670c793bc28d890988d4c109ffa2c21a9
parentbbcf31c48d67b4d768eb229626ca0cd4e93ec358 (diff)
Added UNDO/REDO of actions that change column format: auto_jus command or 'f' command
-rwxr-xr-xsrc/cmds.c15
-rwxr-xr-xsrc/cmds_normal.c9
-rwxr-xr-xsrc/undo.c61
-rwxr-xr-xsrc/undo.h16
4 files changed, 100 insertions, 1 deletions
diff --git a/src/cmds.c b/src/cmds.c
index d40c044..176968b 100755
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -1317,8 +1317,16 @@ void auto_justify(int ci, int cf, int min) {
size_t result;
const char * mbsptr;
+#ifdef UNDO
+ create_undo_action();
+#endif
+
checkbounds(&maxrow, &cf);
+
for (c = ci; c <= cf; c++) {
+#ifdef UNDO
+ add_undo_col_format(c, 'R', fwidth[c], precision[c], realfmt[c]);
+#endif
fwidth[c] = min;
for (r = 0; r <= maxrow; r++) {
if ((p = *ATBL(tbl, r, c)) != NULL) {
@@ -1339,7 +1347,14 @@ void auto_justify(int ci, int cf, int min) {
fwidth[c] = sum;
}
}
+#ifdef UNDO
+ add_undo_col_format(c, 'A', fwidth[c], precision[c], realfmt[c]);
+#endif
}
+#ifdef UNDO
+ end_undo_action();
+#endif
+
return;
}
diff --git a/src/cmds_normal.c b/src/cmds_normal.c
index 151e235..f089234 100755
--- a/src/cmds_normal.c
+++ b/src/cmds_normal.c
@@ -418,7 +418,16 @@ void do_normalmode(struct block * buf) {
// format col
case L'f':
if (bs != 2) return;
+#ifdef UNDO
+
+ create_undo_action();
+ add_undo_col_format(curcol, 'R', fwidth[curcol], precision[curcol], realfmt[curcol]);
+#endif
formatcol(buf->pnext->value);
+#ifdef UNDO
+ add_undo_col_format(curcol, 'A', fwidth[curcol], precision[curcol], realfmt[curcol]);
+ end_undo_action();
+#endif
break;
// mark cell or range
diff --git a/src/undo.c b/src/undo.c
index cb96e8e..13a0b24 100755
--- a/src/undo.c
+++ b/src/undo.c
@@ -13,6 +13,7 @@ Which contains:
col_hidded: integers list (int *) hidden columns on screen
col_showed: integers list (int *) visible columns on screen
NOTE: the first position of the lists contains (number of elements - 1) in the list
+ struct undo_cols_format * cols_format: list of 'undo_col_info' elements used for undoing / redoing changes in columns format
p_sig: pointer to 'undo' struct, If NULL, this node is the last change in
the session.
@@ -57,9 +58,11 @@ Implemented actions for UNDO/REDO:
13. '-' and '+' commands in normal mode
14. Lock and unlock of cells
15. datefmt command
+16. Change in format of a column as a result of the 'f' command
+17. Change in format of a column as a result of auto_jus
NOT implemented:
-1. Change format of an entire column
+1. Change format of columns as a result of ic dc sh sl
2. Recover equations after redo of changes over ents that have equations on them.
----------------------------------------------------------------------------------------
@@ -95,6 +98,7 @@ void create_undo_action() {
undo_item.p_ant = NULL;
undo_item.p_sig = NULL;
undo_item.range_shift = NULL;
+ undo_item.cols_format = NULL;
undo_item.row_hidded = NULL;
undo_item.row_showed = NULL;
@@ -112,6 +116,7 @@ void end_undo_action() {
if ((undo_item.added == NULL &&
undo_item.removed == NULL && undo_item.range_shift == NULL &&
undo_item.row_hidded == NULL && undo_item.row_showed == NULL &&
+ undo_item.cols_format == NULL &&
undo_item.col_hidded == NULL && undo_item.col_showed == NULL) || loading) {
if (undo_list->p_ant != NULL) undo_list = undo_list->p_ant;
undo_list_pos--;
@@ -136,6 +141,7 @@ void add_to_undolist(struct undo u) {
ul->added = u.added;
ul->removed = u.removed;
ul->range_shift = u.range_shift;
+ ul->cols_format = u.cols_format;
ul->row_hidded = u.row_hidded;
ul->col_hidded = u.col_hidded;
ul->row_showed = u.row_showed;
@@ -184,6 +190,10 @@ void free_undo_node(struct undo * ul) {
e = ul->p_sig;
if (ul->range_shift != NULL) free(ul->range_shift); // Free undo_range_shift memory
+ if (ul->cols_format != NULL) { // Free cols_format memory
+ free(ul->cols_format->cols);
+ free(ul->cols_format);
+ }
if (ul->row_hidded != NULL) free(ul->row_hidded); // Free hidden row memory
if (ul->col_hidded != NULL) free(ul->col_hidded); // Free hidden col memory
if (ul->row_showed != NULL) free(ul->row_showed); // Free showed row memory
@@ -260,6 +270,23 @@ void copy_to_undostruct (int row_desde, int col_desde, int row_hasta, int col_ha
return;
}
+void add_undo_col_format(int col, int type, int fwidth, int precision, int realfmt) {
+ if (undo_item.cols_format == NULL) {
+ undo_item.cols_format = (struct undo_cols_format *) malloc( sizeof(struct undo_cols_format));
+ undo_item.cols_format->length = 1;
+ undo_item.cols_format->cols = (struct undo_col_info *) malloc( sizeof(struct undo_col_info));
+ } else {
+ undo_item.cols_format->length++;
+ undo_item.cols_format->cols = (struct undo_col_info *) realloc(undo_item.cols_format->cols, undo_item.cols_format->length * sizeof(struct undo_col_info));
+ }
+ undo_item.cols_format->cols[ undo_item.cols_format->length - 1].type = type;
+ undo_item.cols_format->cols[ undo_item.cols_format->length - 1].col = col;
+ undo_item.cols_format->cols[ undo_item.cols_format->length - 1].fwidth = fwidth;
+ undo_item.cols_format->cols[ undo_item.cols_format->length - 1].precision = precision;
+ undo_item.cols_format->cols[ undo_item.cols_format->length - 1].realfmt = realfmt;
+ return;
+}
+
// Takes a range, a rows and columns delta and save them in the undo struct
// Used to shift ranges when UNDO or REDO without duplicating 'ent' elements
void save_undo_range_shift(int delta_rows, int delta_cols, int tlrow, int tlcol, int brrow, int brcol) {
@@ -394,6 +421,7 @@ void do_undo() {
j = j->next;
}
+
// Show hidden cols and rows
// Hide visible cols and rows
if (ul->col_hidded != NULL) {
@@ -425,6 +453,22 @@ void do_undo() {
}
}
+ // Restore previous col format
+ if (ul->cols_format != NULL) {
+ struct undo_cols_format * uf = ul->cols_format;
+ int size = uf->length;
+ int i;
+
+ for (i=0; i < size; i++) {
+ if (uf->cols[i].type == 'R') {
+ fwidth[uf->cols[i].col] = uf->cols[i].fwidth;
+ precision[uf->cols[i].col] = uf->cols[i].precision;
+ realfmt[uf->cols[i].col] = uf->cols[i].realfmt;
+ }
+ }
+ }
+
+
// Restores cursor position
currow = ori_currow;
curcol = ori_curcol;
@@ -528,6 +572,21 @@ void do_redo() {
}
}
+ // Restore new col format
+ if (ul->cols_format != NULL) {
+ struct undo_cols_format * uf = ul->cols_format;
+ int size = uf->length;
+ int i;
+
+ for (i=0; i < size; i++) {
+ if (uf->cols[i].type == 'A') {
+ fwidth[uf->cols[i].col] = uf->cols[i].fwidth;
+ precision[uf->cols[i].col] = uf->cols[i].precision;
+ realfmt[uf->cols[i].col] = uf->cols[i].realfmt;
+ }
+ }
+ }
+
// Restores cursor position
currow = ori_currow;
curcol = ori_curcol;
diff --git a/src/undo.h b/src/undo.h
index 64709a9..dd8369e 100755
--- a/src/undo.h
+++ b/src/undo.h
@@ -3,6 +3,7 @@ struct undo {
struct ent * added;
struct ent * removed;
struct undo_range_shift * range_shift;
+ struct undo_cols_format * cols_format;
struct undo * p_sig;
int * row_hidded;
int * row_showed;
@@ -19,11 +20,26 @@ struct undo_range_shift {
int brcol;
};
+//These two structures are for undo / redo changes in column format
+struct undo_col_info {
+ char type; // a column can be 'R' (removed) or 'A' (added) because of change
+ int col;
+ int fwidth;
+ int precision;
+ int realfmt;
+};
+
+struct undo_cols_format {
+ size_t length; // keep the number of elements (cols)
+ struct undo_col_info * cols;
+};
+
void create_undo_action();
void end_undo_action();
void copy_to_undostruct (int row_desde, int col_desde, int row_hasta, int col_hasta, char type);
void save_undo_range_shift(int delta_rows, int delta_cols, int tlrow, int tlcol, int brrow, int brcol);
void undo_hide_show(int row, int col, char type, int arg);
+void add_undo_col_format(int col, int type, int fwidth, int precision, int realfmt);
void add_to_undolist(struct undo u);
void do_undo();