[OpenLayers-Commits] r12090 - in sandbox/tschaub/editing: examples lib/OpenLayers/Control

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Jun 16 11:41:44 EDT 2011


Author: tschaub
Date: 2011-06-16 08:41:43 -0700 (Thu, 16 Jun 2011)
New Revision: 12090

Modified:
   sandbox/tschaub/editing/examples/draw-undo-redo.html
   sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js
Log:
Limit undo/redo to current sketch for now.

Modified: sandbox/tschaub/editing/examples/draw-undo-redo.html
===================================================================
--- sandbox/tschaub/editing/examples/draw-undo-redo.html	2011-06-16 15:22:30 UTC (rev 12089)
+++ sandbox/tschaub/editing/examples/draw-undo-redo.html	2011-06-16 15:41:43 UTC (rev 12090)
@@ -18,18 +18,15 @@
 
         <div id="docs">
             <p>
-                Use <code>Ctrl-Z</code> or<code> ⌘-Z</code> to undo while drawing.  
-                Use <code>Ctrl-Y</code> or<code> ⌘-Y</code> to redo what you have 
+                Use <code>Ctrl-Z</code> or <code>⌘-Z</code> to undo while drawing.  
+                Use <code>Ctrl-Y</code> or <code>⌘-Y</code> to redo what you have 
                 undone.  Use <code>Esc</code> to cancel the current sketch.
             <p>
-                The <code>control.undo</code> method works first on any current
-                sketch, removing the most recently added point.  To fully erase
-                a sketch, cancel drawing.  After removing all but two points
-                from the current sketch (in the case of a line) the undo method
-                will begin removing previously drawn features.
-            </p><p>
+                The <code>control.undo</code> method works on the current
+                sketch, removing the most recently added point.  
                 The <code>control.redo</code> method adds back items that were
-                removed from an undo.
+                removed from an undo.  To fully erase a sketch, call the 
+                <code>control.cancel</code> method.
             </p><p>
                 View the <a href="draw-undo-redo.js" target="_blank">draw-undo-redo.js</a>
                 source to see how this is done.

Modified: sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js	2011-06-16 15:22:30 UTC (rev 12089)
+++ sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js	2011-06-16 15:41:43 UTC (rev 12090)
@@ -82,7 +82,6 @@
                     this.layer.events.triggerEvent(
                         "sketchmodified", {vertex: vertex, feature: feature}
                     );
-                    delete this.redoStack;
                 },
                 create: function(vertex, feature) {
                     this.layer.events.triggerEvent(
@@ -120,13 +119,6 @@
             this.layer.addFeatures([feature]);
             this.featureAdded(feature);
             this.events.triggerEvent("featureadded",{feature : feature});
-            if (!this.undoStack) {
-                this.undoStack = [];
-            }
-            this.undoStack.push(this.layer.features.length-1);
-            if (!this._redoing) {
-                delete this.redoStack;
-            }
         }
     },
     
@@ -189,31 +181,18 @@
     },
     
     /**
-     * Method: undo
-     * Remove the most recently added point in the sketch geometry.
+     * APIMethod: undo
+     * Remove the most recently added point in the current sketch geometry.
      *
      * Returns: 
      * {Boolean} An edit was undone.
      */
     undo: function() {
-        var undone = this.handler.undo && this.handler.undo();
-        if (!undone) {
-            var index = this.undoStack && this.undoStack.pop();
-            if (index != null) {
-                var feature = this.layer.features[index];
-                this.layer.removeFeatures([feature]);
-                if (!this.redoStack) {
-                    this.redoStack = [];
-                }
-                this.redoStack.push(feature.geometry);
-                undone = true;
-            }
-        }
-        return !!undone;
+        return this.handler.undo && this.handler.undo();
     },
     
     /**
-     * Method: redo
+     * APIMethod: redo
      * Reinsert the most recently removed point resulting from an <undo> call.
      *     The undo stack is deleted whenever a point is added by other means.
      *
@@ -221,17 +200,7 @@
      * {Boolean} An edit was redone.
      */
     redo: function() {
-        var redone = false;
-        var geometry = this.redoStack && this.redoStack.pop();
-        if (geometry) {
-            this._redoing = true;
-            this.drawFeature(geometry);
-            delete this._redoing;
-            redone = true;
-        } else {
-            redone = this.handler.redo && this.handler.redo();
-        }
-        return !!redone;
+        return this.handler.redo && this.handler.redo();
     },
     
     /**
@@ -253,22 +222,5 @@
         this.handler.cancel();
     },
 
-    /**
-     * APIMethod: deactivate
-     * Deactivates a control and it's associated handler.
-     * 
-     * Returns:
-     * {Boolean} True if the control was effectively deactivated or false
-     *           if the control was already inactive.
-     */
-    deactivate: function () {
-        var deactivated = OpenLayers.Control.prototype.deactivate.apply(this, arguments);
-        if (deactivated) {
-            delete this.undoStack;
-            delete this.redoStack;
-        }
-        return deactivated;
-    },
-
     CLASS_NAME: "OpenLayers.Control.DrawFeature"
 });



More information about the Commits mailing list