Commit 79305cc3 authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

major overhaul of existing undo actions to conform to the infinite undo...

major overhaul of existing undo actions to conform to the infinite undo format, changed how undo create functions, started undo recreate, reformatted undo index, a number of minor bug fixes, implemented undo actions index 1,2,4,5, and 9 and started working on 10.
parent 4305ecce
This diff is collapsed.
......@@ -211,7 +211,7 @@ void glist_grab(t_glist *x, t_gobj *y, t_glistmotionfn motionfn,
t_canvas *glist_getcanvas(t_glist *x)
{
//fprintf(stderr,"gobj_shouldvis\n");
//fprintf(stderr,"glist_getcanvas\n");
while (x->gl_owner && !x->gl_havewindow && x->gl_isgraph &&
gobj_shouldvis(&x->gl_gobj, x->gl_owner)) {
x = x->gl_owner;
......
......@@ -88,6 +88,7 @@ void glist_text(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
extern t_pd *newest;
void canvas_getargs(int *argcp, t_atom **argvp);
extern int we_are_undoing;
static void canvas_objtext(t_glist *gl, int xpix, int ypix, int selected,
t_binbuf *b)
......@@ -117,8 +118,9 @@ static void canvas_objtext(t_glist *gl, int xpix, int ypix, int selected,
else x = 0;
if (!x)
{
/* LATER make the color reflect this */
x = (t_text *)pd_new(text_class);
/* LATER make the color reflect this */
//fprintf(stderr,"creating blank object\n");
x = (t_text *)pd_new(text_class);
}
x->te_binbuf = b;
x->te_xpix = xpix;
......@@ -137,6 +139,15 @@ static void canvas_objtext(t_glist *gl, int xpix, int ypix, int selected,
if (pd_class(&x->ob_pd) == voutlet_class)
canvas_resortoutlets(glist_getcanvas(gl));
canvas_unsetcurrent((t_canvas *)gl);
// here we recreate data buffer inside previously created undo snapshot
//canvas_undo_create(glist_getcanvas(gl), glist_getcanvas(gl)->u_last->data, UNDO_FREE);
//glist_getcanvas(gl)->u_last->data = canvas_undo_set_create(glist_getcanvas(gl));
/*if (binbuf_getnatom(x->te_binbuf) && !we_are_undoing) {
fprintf(stderr,"canvas_objtext calls create undo\n");
//glist_select(gl, &x->te_g);
canvas_undo_add(glist_getcanvas(gl), 9, "create",
(void *)canvas_undo_set_create(glist_getcanvas(gl)));
}*/
if ( glist_isvisible( ((t_canvas *)gl) ) ) {
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", glist_getcanvas(gl));
}
......@@ -225,11 +236,22 @@ void canvas_obj(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
canvas_howputnew(gl, &connectme, &xpix, &ypix, &indx, &nobj);
pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1);
canvas_objtext(gl, xpix, ypix, 1, b);
if (connectme)
//t_undo_create *u_c = (t_undo_create *)glist_getcanvas(gl)->u_last->data;
if (connectme) {
fprintf(stderr,"canvas_obj calls canvas_connect\n");
//u_c->indx = indx;
//u_c->nobj = nobj;
canvas_connect(gl, indx, 0, nobj, 0);
else canvas_startmotion(glist_getcanvas(gl));
}
else {
fprintf(stderr,"canvas_obj calls canvas_startmotion\n");
//u_c->indx = -1;
//u_c->nobj = -1;
canvas_startmotion(glist_getcanvas(gl));
}
//canvas_setundo(glist_getcanvas(gl), canvas_undo_create, canvas_undo_set_create(gl), "create");
canvas_undo_add(glist_getcanvas(gl), 8, "create");
canvas_undo_add(glist_getcanvas(gl), 9, "create",
(void *)canvas_undo_set_create(glist_getcanvas(gl)));
}
}
......@@ -238,7 +260,7 @@ void canvas_obj(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
/* iemlib */
void canvas_iemguis(t_glist *gl, t_symbol *guiobjname)
{
fprintf(stderr,"canvas_iemguis\n");
//fprintf(stderr,"canvas_iemguis\n");
t_atom at;
t_binbuf *b = binbuf_new();
//int xpix, ypix;
......@@ -272,7 +294,8 @@ void canvas_iemguis(t_glist *gl, t_symbol *guiobjname)
//canvas_objtext(gl, xpix, ypix, 1, b);
else canvas_startmotion(glist_getcanvas(gl));
//canvas_setundo(glist_getcanvas(gl), canvas_undo_create, canvas_undo_set_create(gl), "create");
canvas_undo_add(glist_getcanvas(gl), 8, "create");
canvas_undo_add(glist_getcanvas(gl), 9, "create",
(void *)canvas_undo_set_create(glist_getcanvas(gl)));
}
void canvas_bng(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
......@@ -511,7 +534,7 @@ static void message_free(t_message *x)
void canvas_msg(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
{
fprintf(stderr,"canvas_msg\n");
//fprintf(stderr,"canvas_msg\n");
t_message *x = (t_message *)pd_new(message_class);
x->m_messresponder.mr_pd = messresponder_class;
x->m_messresponder.mr_outlet = outlet_new(&x->m_text, &s_float);
......@@ -545,7 +568,8 @@ void canvas_msg(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
canvas_connect(gl, indx, 0, nobj, 0);
else canvas_startmotion(glist_getcanvas(gl));
//canvas_setundo(glist_getcanvas(gl), canvas_undo_create, canvas_undo_set_create(gl), "create");
canvas_undo_add(glist_getcanvas(gl), 8, "create");
canvas_undo_add(glist_getcanvas(gl), 9, "create",
(void *)canvas_undo_set_create(glist_getcanvas(gl)));
}
}
......@@ -932,7 +956,7 @@ static void gatom_vis(t_gobj *z, t_glist *glist, int vis)
void canvas_atom(t_glist *gl, t_atomtype type,
t_symbol *s, int argc, t_atom *argv)
{
fprintf(stderr,"canvas_atom\n");
//fprintf(stderr,"canvas_atom\n");
t_gatom *x = (t_gatom *)pd_new(gatom_class);
t_atom at;
x->a_text.te_width = 0; /* don't know it yet. */
......@@ -1006,7 +1030,8 @@ void canvas_atom(t_glist *gl, t_atomtype type,
canvas_connect(gl, indx, 0, nobj, 0);
else canvas_startmotion(glist_getcanvas(gl));
//canvas_setundo(glist_getcanvas(gl), canvas_undo_create, canvas_undo_set_create(gl), "create");
canvas_undo_add(glist_getcanvas(gl), 8, "create");
canvas_undo_add(glist_getcanvas(gl), 9, "create",
(void *)canvas_undo_set_create(glist_getcanvas(gl)));
}
}
......@@ -1790,6 +1815,10 @@ void text_setto(t_text *x, t_glist *glist, char *buf, int bufsize)
if (newest && pd_class(newest) == canvas_class)
canvas_loadbang((t_canvas *)newest);
canvas_restoreconnections(glist_getcanvas(glist));
glist_select(
fprintf(stderr,"text_setto calls canvas_undo_add\n");
canvas_undo_add(glist_getcanvas(glist), 10, "recreate",
(void *)canvas_undo_set_recreate(glist_getcanvas(glist), &x->te_g));
}
/* if we made a new "pd" or changed a window name,
update window list */
......
......@@ -2,6 +2,12 @@
#include "g_canvas.h"
#include <stdio.h>
//used for canvas_objtext to differentiate between objects being created by user
//vs. those (re)created by the undo/redo actions
int we_are_undoing = 0;
extern const char *canvas_undo_name;
t_undo_action *canvas_undo_init(t_canvas *x)
{
t_undo_action *a = (t_undo_action *)getbytes(sizeof(*a));
......@@ -16,12 +22,12 @@ t_undo_action *canvas_undo_init(t_canvas *x)
x->u_last = a;
a->prev = NULL;
a->name = "no";
sys_vgui("pdtk_undomenu nobody no no\n");
//sys_vgui("pdtk_undomenu .x%lx no no\n", (t_int)a->x);
}
else {
if (x->u_last->next) {
//we need to rebranch first then add the new action
canvas_undo_rebranch(x->u_last);
canvas_undo_rebranch(x);
}
x->u_last->next = a;
a->prev = x->u_last;
......@@ -31,18 +37,14 @@ t_undo_action *canvas_undo_init(t_canvas *x)
return(a);
}
t_undo_action *canvas_undo_add(t_canvas *x, int type, const char *name)
t_undo_action *canvas_undo_add(t_canvas *x, int type, const char *name, void *data)
{
fprintf(stderr,"canvas_undo_add\n");
fprintf(stderr,"canvas_undo_add %d\n", type);
t_undo_action *a = canvas_undo_init(x);
//TODO: parse out type and fill accordingly
if (type == 8) { //create
t_undo_create *data = (t_undo_create *)canvas_undo_set_create(x);
a->type = 8;
a->data = (void *)data;
}
a->name = name;
a->type = type;
a->data = (void *)data;
a->name = (char *)name;
canvas_undo_name = name;
sys_vgui("pdtk_undomenu .x%lx %s no\n", x, a->name);
return(a);
}
......@@ -52,13 +54,23 @@ void canvas_undo_undo(t_canvas *x)
fprintf(stderr,"canvas_undo_undo\n");
if (x->u_queue && x->u_last != x->u_queue) {
fprintf(stderr,"do it\n");
we_are_undoing = 1;
glist_noselect(x);
if (x->u_last->type == 8) { //create
canvas_undo_create(x, x->u_last->data, UNDO_UNDO);
}
switch(x->u_last->type)
{
case 1: canvas_undo_connect(x, x->u_last->data, UNDO_UNDO); break; //connect
case 2: canvas_undo_disconnect(x, x->u_last->data, UNDO_UNDO); break; //disconnect
case 4: canvas_undo_move(x, x->u_last->data, UNDO_UNDO); break; //move
case 5: canvas_undo_paste(x, x->u_last->data, UNDO_UNDO); break; //paste
case 9: canvas_undo_create(x, x->u_last->data, UNDO_UNDO); break; //create
case 10:canvas_undo_recreate(x, x->u_last->data, UNDO_UNDO); break; //recreate
default:
error("canvas_undo_undo: unsupported undo command");
}
x->u_last = x->u_last->prev;
char *undo_action = x->u_last->name;
char *redo_action = x->u_last->next->name;
we_are_undoing = 0;
if (glist_isvisible(x) && glist_istoplevel(x)) {
sys_vgui("pdtk_undomenu .x%lx %s %s\n", x, undo_action, redo_action);
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x);
......@@ -71,13 +83,23 @@ void canvas_undo_redo(t_canvas *x)
fprintf(stderr,"canvas_undo_redo\n");
if (x->u_queue && x->u_last->next) {
fprintf(stderr,"do it\n");
we_are_undoing = 1;
x->u_last = x->u_last->next;
glist_noselect(x);
if (x->u_last->type == 8) { //create
canvas_undo_create(x, x->u_last->data, UNDO_REDO);
}
switch(x->u_last->type)
{
case 1: canvas_undo_connect(x, x->u_last->data, UNDO_REDO); break; //connect
case 2: canvas_undo_disconnect(x, x->u_last->data, UNDO_REDO); break; //disconnect
case 4: canvas_undo_move(x, x->u_last->data, UNDO_REDO); break; //move
case 5: canvas_undo_paste(x, x->u_last->data, UNDO_REDO); break; //paste
case 9: canvas_undo_create(x, x->u_last->data, UNDO_REDO); break; //create
case 10:canvas_undo_recreate(x, x->u_last->data, UNDO_REDO); break; //recreate
default:
error("canvas_undo_redo: unsupported undo command");
}
char *undo_action = x->u_last->name;
char *redo_action = (x->u_last->next ? x->u_last->next->name : "no");
we_are_undoing = 0;
if (glist_isvisible(x) && glist_istoplevel(x)) {
sys_vgui("pdtk_undomenu .x%lx %s %s\n", x, undo_action, redo_action);
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x);
......@@ -85,16 +107,24 @@ void canvas_undo_redo(t_canvas *x)
}
}
void canvas_undo_rebranch(t_undo_action *u)
void canvas_undo_rebranch(t_canvas *x)
{
fprintf(stderr,"canvas_undo_rebranch");
if (u->next) {
if (x->u_last->next) {
t_undo_action *a;
for(a = u->next; a; a = a->next) {
for(a = x->u_last->next; a; a = a->next) {
fprintf(stderr,".");
if (a->type == 8) { //create
canvas_undo_create(a->x, a->data, UNDO_FREE);
}
switch(a->type)
{
case 1: canvas_undo_connect(x, a->data, UNDO_FREE); break; //connect
case 2: canvas_undo_disconnect(x, a->data, UNDO_FREE); break; //disconnect
case 4: canvas_undo_move(x, a->data, UNDO_FREE); break; //move
case 5: canvas_undo_paste(x, a->data, UNDO_FREE); break; //paste
case 9: canvas_undo_create(x, a->data, UNDO_FREE); break; //create
case 10:canvas_undo_recreate(x, a->data, UNDO_FREE); break; //recreate
default:
error("canvas_undo_rebranch: unsupported undo command");
}
freebytes(a, sizeof(*a));
}
}
......@@ -103,12 +133,12 @@ void canvas_undo_rebranch(t_undo_action *u)
void canvas_undo_check_canvas_pointers(t_canvas *x)
{
//currently unnecessary unless we decide to implement one central undo for all patchers
}
void canvas_undo_purge_abstraction_actions(t_canvas *x)
{
//currently unnecessary unless we decide to implement one central undo for all patchers
}
void canvas_undo_free(t_canvas *x)
......@@ -118,9 +148,17 @@ void canvas_undo_free(t_canvas *x)
t_undo_action *a;
for(a = x->u_queue; a; a = a->next) {
fprintf(stderr,".");
if (a->type == 8) { //create
canvas_undo_create(a->x, a->data, UNDO_FREE);
}
switch(a->type)
{
case 1: canvas_undo_connect(x, a->data, UNDO_FREE); break; //connect
case 2: canvas_undo_disconnect(x, a->data, UNDO_FREE); break; //disconnect
case 4: canvas_undo_move(x, a->data, UNDO_FREE); break; //move
case 5: canvas_undo_paste(x, a->data, UNDO_FREE); break; //paste
case 9: canvas_undo_create(x, a->data, UNDO_FREE); break; //create
case 10:canvas_undo_recreate(x, a->data, UNDO_FREE); break; //recreate
default:
error("canvas_undo_rebranch: unsupported undo command");
}
freebytes(a, sizeof(*a));
}
}
......
......@@ -27,14 +27,15 @@ be purged since abstraction's state will now default to its original (saved) sta
Types of undo data:
0 - init data (start of the queue)
1 - connect & disconnect
2 - cut, clear & typing into objects
3 - motion, inclding "tidy up" and stretching
4 - paste & duplicate
5 - apply
6 - arrange (to front/back)
7 - canvas apply
8 - create
1 - connect
2 - disconnect
3 - cut, clear & typing into objects
4 - motion, inclding "tidy up" and stretching
5 - paste & duplicate
6 - apply
7 - arrange (to front/back)
8 - canvas apply
9 - create
*/
struct _undo_action
......@@ -52,25 +53,46 @@ struct _undo_action
#endif
EXTERN t_undo_action *canvas_undo_init(t_canvas *x);
EXTERN t_undo_action *canvas_undo_add(t_canvas *x, int type, const char *name);
EXTERN t_undo_action *canvas_undo_add(t_canvas *x,
int type, const char *name, void *data);
EXTERN void canvas_undo_undo(t_canvas *x);
EXTERN void canvas_undo_redo(t_canvas *x);
EXTERN void canvas_undo_rebranch(t_undo_action *u);
EXTERN void canvas_undo_rebranch(t_canvas *x);
EXTERN void canvas_undo_check_canvas_pointers(t_canvas *x);
EXTERN void canvas_undo_purge_abstraction_actions(t_canvas *x);
EXTERN void canvas_undo_free(t_canvas *x);
/* --------- 8. create ----------- */
/* --------- 1. connect ---------- */
typedef struct _undo_create
{
int u_index; /* index of the created object object */
t_binbuf *u_objectbuf; /* the object cleared or typed into */
t_binbuf *u_reconnectbuf; /* connections into and out of object */
} t_undo_create;
EXTERN void *canvas_undo_set_connect(t_canvas *x,
int index1, int outno, int index2, int inno);
EXTERN void canvas_undo_connect(t_canvas *x, void *z, int action);
/* --------- 2. disconnect ------- */
EXTERN void *canvas_undo_set_disconnect(t_canvas *x,
int index1, int outno, int index2, int inno);
EXTERN void canvas_undo_disconnect(t_canvas *x, void *z, int action);
/* --------- 4. move ------------- */
EXTERN void *canvas_undo_set_move(t_canvas *x, int selected);
EXTERN void canvas_undo_move(t_canvas *x, void *z, int action);
/* --------- 5. paste ------------ */
EXTERN void *canvas_undo_set_paste(t_canvas *x, int offset);
EXTERN void canvas_undo_paste(t_canvas *x, void *z, int action);
/* --------- 9. create ----------- */
EXTERN void canvas_undo_create(t_canvas *x, void *z, int action);
EXTERN void *canvas_undo_set_create(t_canvas *x);
/* --------- 10. recreate -------- */
extern void canvas_undo_create(t_canvas *x, void *z, int action);
extern void *canvas_undo_set_create(t_canvas *x);
EXTERN void canvas_undo_recreate(t_canvas *x, void *z, int action);
EXTERN void *canvas_undo_set_recreate(t_canvas *x);
/* ------------------------------- */
......
......@@ -8,6 +8,7 @@ behavior for "gobjs" appears at the end of this file. */
#include "m_pd.h"
#include "m_imp.h"
#include <stdio.h>
union inletunion
{
......@@ -466,6 +467,7 @@ void outlet_free(t_outlet *x)
t_outconnect *obj_connect(t_object *source, int outno,
t_object *sink, int inno)
{
fprintf(stderr,"obj_connect\n");
t_inlet *i;
t_outlet *o;
t_pd *to;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment