Commit 7301e935 authored by Guillem Bartrina's avatar Guillem Bartrina
Browse files

add mechanism that visually marks abstraction objects that are edited but...

add mechanism that visually marks abstraction objects that are edited but unsaved, and all their ancestors
parent bdc1b00b
......@@ -401,6 +401,14 @@ text {
stroke: #ccc;
}
.obj .border.dirty {
stroke: #ff0000;
}
.obj .border.subdirty {
stroke: #ff8800;
}
.comment .border {
fill: none;
}
......
......@@ -2659,6 +2659,16 @@ function gui_gobj_deselect(cid, tag) {
});
}
function gui_gobj_dirty(cid, tag, state) {
gui(cid).get_gobj(tag, function(e) {
var border = e.querySelector(".border");
border.classList.remove("dirty");
border.classList.remove("subdirty");
if(state === 1) border.classList.add("dirty");
else if(state === 2) border.classList.add("subdirty");
});
}
function gui_canvas_emphasize(cid) {
gui(cid).get_elem("patchsvg", function(e) {
// raise the window
......
......@@ -463,6 +463,8 @@ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv)
}
else x->gl_env = 0;
x->gl_subdirties = 0;
if (yloc < GLIST_DEFCANVASYLOC)
yloc = GLIST_DEFCANVASYLOC;
if (xloc < 0)
......@@ -757,6 +759,27 @@ void canvas_reflecttitle(t_canvas *x)
namebuf, canvas_getdir(x)->s_name, x->gl_dirty);
}
/* --------------------- */
/* climbs up to the root canvas while enabling or disabling visual markings for dirtiness
of traversed canvases */
void canvas_dirtyclimb(t_canvas *x, int n)
{
if (x->gl_owner)
{
gobj_dirty(&x->gl_gobj, x->gl_owner,
(n ? 1 : (x->gl_subdirties ? 2 : 0)));
x = x->gl_owner;
while(x->gl_owner)
{
x->gl_subdirties += ((unsigned)n ? 1 : -1);
if(!x->gl_dirty)
gobj_dirty(&x->gl_gobj, x->gl_owner, (x->gl_subdirties ? 2 : 0));
x = x->gl_owner;
}
}
}
/* mark a glist dirty or clean */
void canvas_dirty(t_canvas *x, t_floatarg n)
{
......@@ -768,6 +791,9 @@ void canvas_dirty(t_canvas *x, t_floatarg n)
x2->gl_dirty = n;
if (x2->gl_havewindow)
canvas_reflecttitle(x2);
/* set dirtiness visual markings */
canvas_dirtyclimb(x2, (unsigned)n);
}
}
......
......@@ -232,6 +232,8 @@ struct _glist
t_symbol *gl_templatesym; /* for "canvas" data type */
t_word *gl_vec; /* for "canvas" data type */
t_gpointer gl_gp; /* parent for "canvas" data type */
int gl_subdirties; /* number of descending dirty abstractions */
};
#define gl_gobj gl_obj.te_g
......@@ -436,6 +438,7 @@ EXTERN void gobj_save(t_gobj *x, t_binbuf *b);
EXTERN void gobj_properties(t_gobj *x, struct _glist *glist);
EXTERN void gobj_save(t_gobj *x, t_binbuf *b);
EXTERN int gobj_shouldvis(t_gobj *x, struct _glist *glist);
EXTERN void gobj_dirty(t_gobj *x, t_glist *g, int state);
/* -------------------- functions on glists --------------------- */
EXTERN t_glist *glist_new( void);
......
......@@ -1288,6 +1288,7 @@ void canvas_undo_paste(t_canvas *x, void *z, int action)
}
}
void canvas_dirtyclimb(t_canvas *x, int n);
int clone_match(t_pd *z, t_symbol *name, t_symbol *dir);
/* recursively check for abstractions to reload as result of a save.
......@@ -1313,6 +1314,11 @@ static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir,
canvas_isabstraction((t_canvas *)g) &&
((t_canvas *)g)->gl_name == name &&
canvas_getdir((t_canvas *)g) == dir);
/* remove dirtiness visual markings */
if(remakeit && ((t_canvas *)g)->gl_dirty)
canvas_dirtyclimb((t_canvas *)g, 0);
/* also remake it if it's a "clone" with that name */
if (pd_class(&g->g_pd) == clone_class &&
clone_match(&g->g_pd, name, dir))
......@@ -5846,6 +5852,13 @@ static void gobj_emphasize(t_glist *g, t_gobj *x)
gui_vmess("gui_gobj_emphasize", "xs", g, rtext_gettag(y));
}
/* tell the gui to mark a gobj as dirty (change border color) */
void gobj_dirty(t_gobj *x, t_glist *g, int state)
{
t_rtext *y = glist_findrtext(g, (t_text *)x);
gui_vmess("gui_gobj_dirty", "xsi", g, rtext_gettag(y), state);
}
static int glist_dofinderror(t_glist *gl, void *error_object)
{
t_gobj *g;
......
......@@ -2121,6 +2121,16 @@ static void text_vis(t_gobj *z, t_glist *glist, int vis)
text_drawborder(x, glist, rtext_gettag(y),
rtext_width(y), rtext_height(y), 1);
rtext_draw(y);
/* check whether we have to tell the gui to mark
(border color) the gobj as dirty or not */
if(pd_class(&x->te_pd) == canvas_class)
{
if (((t_canvas *)x)->gl_dirty)
gobj_dirty(x, glist, 1);
else if (((t_canvas *)x)->gl_subdirties)
gobj_dirty(x, glist, 2);
}
}
}
else
......
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