提交 2bf0d0b6 编写于 作者: M Mr.doob

Editor: Added rudimentary undo/redo system.

上级 1d904463
......@@ -83,6 +83,7 @@
<script src="js/Editor.js"></script>
<script src="js/Config.js"></script>
<script src="js/History.js"></script>
<script src="js/Loader.js"></script>
<script src="js/Menubar.js"></script>
<script src="js/Menubar.File.js"></script>
......
......@@ -70,6 +70,7 @@ var Editor = function () {
};
this.config = new Config();
this.history = new History( this );
this.storage = new Storage();
this.loader = new Loader( this );
......@@ -411,6 +412,8 @@ Editor.prototype = {
clear: function () {
this.history.clear();
this.camera.position.set( 500, 250, 500 );
this.camera.lookAt( new THREE.Vector3() );
......
/**
* @author mrdoob / http://mrdoob.com/
*/
var History = function ( editor ) {
this.array = [];
this.arrayLength = -1;
this.current = -1;
this.isRecording = true;
//
var scope = this;
var signals = editor.signals;
signals.objectAdded.add( function ( object ) {
if ( scope.isRecording === false ) return;
scope.add(
function () {
editor.removeObject( object );
editor.select( null );
},
function () {
editor.addObject( object );
editor.select( object );
}
);
} );
};
History.prototype = {
add: function ( undo, redo ) {
this.current ++;
this.array[ this.current ] = { undo: undo, redo: redo };
this.arrayLength = this.current;
},
undo: function () {
if ( this.current < 0 ) return;
this.isRecording = false;
this.array[ this.current ].undo();
this.current --;
this.isRecording = true;
},
redo: function () {
if ( this.current === this.arrayLength ) return;
this.isRecording = false;
this.current ++;
this.array[ this.current ].redo();
this.isRecording = true;
},
clear: function () {
this.array = [];
this.arrayLength = -1;
this.current = -1;
}
};
......@@ -16,6 +16,34 @@ Menubar.Edit = function ( editor ) {
options.setClass( 'options' );
container.add( options );
// Undo
var option = new UI.Panel();
option.setClass( 'option' );
option.setTextContent( 'Undo' );
option.onClick( function () {
editor.history.undo();
} );
options.add( option );
// Redo
var option = new UI.Panel();
option.setClass( 'option' );
option.setTextContent( 'Redo' );
option.onClick( function () {
editor.history.redo();
} );
options.add( option );
// ---
options.add( new UI.HorizontalRule() );
// Clone
var option = new UI.Panel();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册