浏览代码

added optionalName attribute to history.execute

- a command-name can now be set by providing an additional attribute in
the history.execute() function. This name is then displayed as the
description in Sidebar.History .
Daniel 9 年之前
父节点
当前提交
e0f1c0657c

+ 3 - 2
editor/docs/Implementing additional commands for undo-redo.md

@@ -28,9 +28,10 @@ Every command needs a constructor. In the constructor
 	
 CmdXXX = function () {
 
-	Cmd.call( this );	// Call default constructor
+	Cmd.call( this );					// Call default constructor
 
-	this.type = 'CmdXXX';	// has to match the object-name!
+	this.type = 'CmdXXX';				// has to match the object-name!
+	this.name = 'Set/Do/Update XXX'; 	// description of the command, used in Sidebar.History
 
 	// TODO: store all the relevant information needed to 
 	// restore the old and the new state

+ 2 - 2
editor/js/Editor.js

@@ -492,9 +492,9 @@ Editor.prototype = {
 
 	},
 
-	execute: function ( command ) {
+	execute: function ( cmd, optionalName ) {
 
-		this.history.execute( command );
+		this.history.execute( cmd, optionalName );
 
 	},
 

+ 2 - 1
editor/js/History.js

@@ -33,7 +33,7 @@ History = function ( editor ) {
 
 History.prototype = {
 
-	execute: function ( cmd ) {
+	execute: function ( cmd, optionalName ) {
 
 		var lastCmd = this.undos[ this.undos.length - 1 ];
 		var timeDifference = new Date().getTime() - this.lastCmdTime.getTime();
@@ -67,6 +67,7 @@ History.prototype = {
 			cmd.id = ++this.idCounter;
 
 		}
+		cmd.name = optionalName !== undefined ? optionalName : cmd.name;
 		cmd.execute();
 
 		this.lastCmdTime = new Date();

+ 1 - 4
editor/js/Menubar.Edit.js

@@ -188,10 +188,7 @@ Menubar.Edit = function ( editor ) {
 			}
 
 		} );
-		var minifyCmd = new CmdMultiCmds( cmds );
-		minifyCmd.name = 'Minify Shaders';
-		editor.execute( minifyCmd );
-
+		editor.execute( new CmdMultiCmds( cmds ), 'Minify Shaders' );
 
 		window.alert( nMaterialsChanged +
 				" material(s) were changed.\n" + errors.join( "\n" ) );

+ 1 - 3
editor/js/Sidebar.Geometry.js

@@ -79,9 +79,7 @@ Sidebar.Geometry = function ( editor ) {
 					new CmdSetRotation( object, new THREE.Euler( 0, 0, 0 ) ),
 					new CmdSetScale( object, new THREE.Vector3( 1, 1, 1 ) ) ];
 
-				var flattenCmd = new CmdMultiCmds( cmds );
-				flattenCmd.name = 'Flatten Geometry';
-				editor.execute( flattenCmd );
+				editor.execute( new CmdMultiCmds( cmds ), 'Flatten Geometry' );
 
 				editor.signals.geometryChanged.dispatch( object );
 				editor.signals.objectChanged.dispatch( object );