From 42ecde3f0263ff29b97657b7518ebd40114aa2a9 Mon Sep 17 00:00:00 2001
From: Guillem <guillembartrina@gmail.com>
Date: Sat, 22 Aug 2020 11:13:13 +0200
Subject: [PATCH] improve frontend dirty markings for UX

---
 pd/nw/css/default.css |  8 ++++++++
 pd/nw/pd_canvas.html  |  3 +++
 pd/nw/pdgui.js        | 24 +++++++++---------------
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/pd/nw/css/default.css b/pd/nw/css/default.css
index 5abd5f15e..396a40fad 100644
--- a/pd/nw/css/default.css
+++ b/pd/nw/css/default.css
@@ -401,6 +401,14 @@ text {
     stroke: #ccc;
 }
 
+.obj .border.dirty {
+    stroke: #ff0000;
+}
+
+.obj .border.subdirty {
+    stroke: #ff8800;
+}
+
 .comment .border {
     fill: none;
 }
diff --git a/pd/nw/pd_canvas.html b/pd/nw/pd_canvas.html
index cd95e3655..7a104941a 100644
--- a/pd/nw/pd_canvas.html
+++ b/pd/nw/pd_canvas.html
@@ -78,6 +78,9 @@
         </button>
       </div>
     </dialog>
+  <div id="dirtywarning" style="position: fixed; right: 2%; top: 2%; display: none;">
+      <strong style="color: rgb(255, 0, 0); font-size: medium; -webkit-user-select: none;">[MULTIPLE DIRTY INSTANCES]</strong>
+  </div>
 	<div id="hscroll" style="background-color: rgba(0, 0, 0, 0.267); position: fixed; left: 2px; bottom: 2px; border-radius: 0px; width: 10px; height: 5px; visibility: hidden;"></div>
 	<div id="vscroll" style="background-color: rgba(0, 0, 0, 0.267); position: fixed; right: 2px; top: 2px; border-radius: 0px; width: 5px; height: 10px; visibility: hidden;"></div>
     <script type="text/javascript" src="./pd_canvas.js"></script>
diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index 6f524ba49..b9ab05f3e 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -2660,25 +2660,19 @@ function gui_gobj_deselect(cid, tag) {
 }
 
 function gui_gobj_dirty(cid, tag, state) {
-    var color;
-    switch (state) {
-        case 1:
-            color = "crimson";
-            break;
-        case 2:
-            color = "coral";
-            break;
-        default:
-            color = "none";
-            break;
-    }
-    gui(cid).get_elem(tag + "text", function(e) {
-        e.setAttribute("stroke", color);
+    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_multipledirty(cid, state) {
-    post("gui_canvas_multipledirty " + state + ": CALLED");
+    var warning = patchwin[cid].window.document.getElementById("dirtywarning");
+    if (state !== 0) warning.style.setProperty("display", "inline");
+    else warning.style.setProperty("display", "none");
 }
 
 function gui_canvas_emphasize(cid) {
-- 
GitLab