/*
 * UndoManager.java
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * This program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */
package org.rstudio.studio.client.workbench.views.source.editors.text.ace;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;

public class UndoManager extends JavaScriptObject
{
   protected UndoManager()
   {}

   public native final JavaScriptObject peek() /*-{
      return this.peek();
   }-*/;
   
   public final String saveState()
   {
      JavaScriptObject stateObj = saveStateNative();
      return new JSONObject(stateObj).toString();
   }
   
   public final void restoreState(String state)
   {
      JSONValue stateJson = JSONParser.parseStrict(state);
      JSONObject stateObj = stateJson.isObject();
      
      JSONArray undoStack = stateObj.get("undoStack").isArray();
      setUndoStack(undoStack.getJavaScriptObject());
      
      JSONArray redoStack = stateObj.get("redoStack").isArray();
      setRedoStack(redoStack.getJavaScriptObject());
   }
   
   
   private native final JavaScriptObject saveStateNative() /*-{
      var state = new Object();
      state.undoStack = this.$undoStack; 
      state.redoStack = this.$redoStack; 
      return state;
   }-*/;
   
   private native final void setUndoStack(JavaScriptObject undoStack) /*-{
      this.$undoStack.length = 0;
      for(var i=0,len=undoStack.length; i<len; i++)
         this.$undoStack.push(undoStack[i]);
   }-*/;
   
   private native final void setRedoStack(JavaScriptObject redoStack) /*-{
       this.$redoStack.length = 0;
       for(var i=0,len=redoStack.length; i<len; i++)
         this.$redoStack.push(redoStack[i]);
   }-*/;
}   

@@ -566,1595 +566,180 @@
 ct;%0A
-import com.google.gwt.json.client.JSONArray;%0Aimport com.google.gwt.json.client.JSONObject;%0Aimport com.google.gwt.json.client.JSONParser;%0Aimport com.google.gwt.json.client.JSONValue;%0A%0Apublic class UndoManager extends JavaScriptObject%0A%7B%0A   protected UndoManager()%0A   %7B%7D%0A%0A   public native final JavaScriptObject peek() /*-%7B%0A      return this.peek();%0A   %7D-*/;%0A   %0A   public final String saveState()%0A   %7B%0A      JavaScriptObject stateObj = saveStateNative();%0A      return new JSONObject(stateObj).toString();%0A   %7D%0A   %0A   public final void restoreState(String state)%0A   %7B%0A      JSONValue stateJson = JSONParser.parseStrict(state);%0A      JSONObject stateObj = stateJson.isObject();%0A      %0A      JSONArray undoStack = stateObj.get(%22undoStack%22).isArray();%0A      setUndoStack(undoStack.getJavaScriptObject());%0A      %0A      JSONArray redoStack = stateObj.get(%22redoStack%22).isArray();%0A      setRedoStack(redoStack.getJavaScriptObject());%0A   %7D%0A   %0A   %0A   private native final JavaScriptObject saveStateNative() /*-%7B%0A      var state = new Object();%0A      state.undoStack = this.$undoStack; %0A      state.redoStack = this.$redoStack; %0A      return state;%0A   %7D-*/;%0A   %0A   private native final void setUndoStack(JavaScriptObject undoStack) /*-%7B%0A      this.$undoStack.length = 0;%0A      for(var i=0,len=undoStack.length; i%3Clen; i++)%0A         this.$undoStack.push(undoStack%5Bi%5D);%0A   %7D-*/;%0A   %0A   private native final void setRedoStack(JavaScriptObject redoStack) /*-%7B%0A       this.$redoStack.length = 0;%0A       for(var i=0,len=redoStack.length; i%3Clen; i++)%0A         this.$redoStack.push(redoStack%5Bi%5D);%0A   %7D-*/;%0A%7D   
+%0Apublic class UndoManager extends JavaScriptObject%0A%7B%0A   protected UndoManager()%0A   %7B%7D%0A%0A   public native final JavaScriptObject peek() /*-%7B%0A      return this.peek();%0A   %7D-*/;%0A%7D
 %0A

Revert "add functions to save and restore undo state"