소스 검색

History now uses config and History.Sidebar has a checkbox

- serializationEnabled replaced with config-value
- Sidebar.History now has a checkbox to configure if the history should
be serialized or not
Daniel 9 년 전
부모
커밋
cd5d8ee661
3개의 변경된 파일24개의 추가작업 그리고 50개의 파일을 삭제
  1. 2 0
      editor/js/Config.js
  2. 3 20
      editor/js/History.js
  3. 19 30
      editor/js/Sidebar.History.js

+ 2 - 0
editor/js/Config.js

@@ -10,6 +10,7 @@ var Config = function () {
 		'autosave': true,
 		'theme': 'css/light.css',
 
+		'project/history/stored': true,
 		'project/renderer': 'WebGLRenderer',
 		'project/renderer/antialias': true,
 		'project/renderer/shadows': true,
@@ -17,6 +18,7 @@ var Config = function () {
 
 		'ui/sidebar/animation/collapsed': true,
 		'ui/sidebar/geometry/collapsed': true,
+		'ui/sidebar/history/collapsed': true,
 		'ui/sidebar/material/collapsed': true,
 		'ui/sidebar/object3d/collapsed': false,
 		'ui/sidebar/project/collapsed': true,

+ 3 - 20
editor/js/History.js

@@ -12,7 +12,7 @@ History = function ( editor ) {
 	this.idCounter = 0;
 
 	this.historyDisabled = false;
-	this.serializationEnabled = true;
+	this.config = editor.config;
 
 	//Set editor-reference in Cmd
 
@@ -75,7 +75,7 @@ History.prototype = {
 		cmd.execute();
 		cmd.inMemory = true;
 
-		if ( this.serializationEnabled ) {
+		if ( this.config.getKey( 'project/history/stored' ) ) {
 
 			cmd.json = cmd.toJSON();	// serialize the cmd immediately after execution and append the json to the cmd
 
@@ -162,11 +162,10 @@ History.prototype = {
 	toJSON: function () {
 
 		var history = {};
-		history.serializationEnabled = this.serializationEnabled;
 		history.undos = [];
 		history.redos = [];
 
-		if ( ! this.serializationEnabled ) {
+		if ( ! this.config.getKey( 'project/history/stored' ) ) {
 
 			return history;
 
@@ -204,8 +203,6 @@ History.prototype = {
 
 		if ( json === undefined ) return;
 
-		this.serializationEnabled = json.serializationEnabled;
-
 		for ( var i = 0; i < json.undos.length; i ++ ) {
 
 			var cmdJSON = json.undos[ i ];
@@ -292,8 +289,6 @@ History.prototype = {
 
 	enableSerialization: function ( id ) {
 
-		if ( this.serializationEnabled ) return;
-
 		/**
 		 * because there might be commands in this.undos and this.redos
 		 * which have not been serialized with .toJSON() we go back
@@ -321,20 +316,8 @@ History.prototype = {
 		this.editor.signals.sceneGraphChanged.active = true;
 		this.editor.signals.historyChanged.active = true;
 
-		this.serializationEnabled = true;
-
 		this.goToState( id );
 
-	},
-
-	disableSerialization: function () {
-
-		if ( ! this.serializationEnabled ) return;
-
-		this.serializationEnabled = false;
-
-		this.editor.signals.historyChanged.dispatch();
-
 	}
 
 };

+ 19 - 30
editor/js/Sidebar.History.js

@@ -6,6 +6,8 @@ Sidebar.History = function ( editor ) {
 
 	var signals = editor.signals;
 
+	var config = editor.config;
+
 	var history = editor.history;
 
 	var container = new UI.CollapsiblePanel();
@@ -18,35 +20,16 @@ Sidebar.History = function ( editor ) {
 
 	container.addStatic( new UI.Text( 'HISTORY' ) );
 
-	// Actions
-
-	var objectActions = new UI.Select().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
-	objectActions.setOptions( {
-
-		'Actions': 'Actions',
-		'Serialization': 'Serialize History?'
-
-	} );
-	objectActions.onClick( function ( event ) {
-
-		event.stopPropagation(); // Avoid panel collapsing
-
-	} );
-	objectActions.onChange( function ( event ) {
-
-		var currentValue = history.serializationEnabled ? 'yes' : 'no';
-
-		var response;
-		if ( ( response = prompt( 'Should the history be preserved across a browser refresh? (yes or no)', currentValue ) ) === null ) {
+	// Checkbox 'Save History'
+	var saveHistorySpan = new UI.Span().setPosition( 'absolute' ).setLeft( '200px' ).setFontSize( '13px' );
+	var saveHistoryCheckbox = new UI.Checkbox( config.getKey( 'project/history/stored' ) ).setLeft( '50px' ).onChange( function () {
 
-			this.setValue( 'Actions' );
-			return;
+		config.setKey( 'project/history/stored', this.getValue() );
+		var saveHistory = this.getValue();
 
-		}
+		if ( saveHistory ) {
 
-		if ( response.toLowerCase() === 'yes' ) {
-
-			alert( 'The history will be preserved across a browser refresh.' );
+			alert( 'The history will be preserved across a browser refresh.\nThis can have an impact on performance (mainly when working with textures)!' );
 
 			var lastUndoCmd = history.undos[ history.undos.length - 1 ];
 			var lastUndoId = ( lastUndoCmd !== undefined ) ? lastUndoCmd.id : 0;
@@ -54,16 +37,22 @@ Sidebar.History = function ( editor ) {
 
 		} else {
 
-			alert( 'The history will NOT be preserved across a browser refresh.' );
-			editor.history.disableSerialization();
+			signals.historyChanged.dispatch();
 
 		}
 
-		this.setValue( 'Actions' );
+	} );
+
+	saveHistorySpan.add( saveHistoryCheckbox );
+	saveHistorySpan.add( new UI.Text( 'Save History' ).setPosition( 'relative' ).setLeft( '5px' ) );
+
+	saveHistorySpan.onClick( function ( event ) {
+
+		event.stopPropagation(); // Avoid panel collapsing
 
 	} );
-	container.addStatic( objectActions );
 
+	container.addStatic( saveHistorySpan );
 
 	container.add( new UI.Break() );