2 * @author dforrer / https://github.com/dforrer
3 * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
6 Sidebar.History = function ( editor ) {
8 var signals = editor.signals;
10 var config = editor.config;
12 var history = editor.history;
14 var container = new UI.Panel();
16 container.add( new UI.Text( 'HISTORY' ) );
20 var persistent = new UI.THREE.Boolean( config.getKey( 'settings/history' ), 'persistent' );
21 persistent.setPosition( 'absolute' ).setRight( '8px' );
22 persistent.onChange( function () {
24 var value = this.getValue();
26 config.setKey( 'settings/history', value );
30 alert( 'The history will be preserved across sessions.\nThis can have an impact on performance when working with textures.' );
32 var lastUndoCmd = history.undos[ history.undos.length - 1 ];
33 var lastUndoId = ( lastUndoCmd !== undefined ) ? lastUndoCmd.id : 0;
34 editor.history.enableSerialization( lastUndoId );
38 signals.historyChanged.dispatch();
43 container.add( persistent );
45 container.add( new UI.Break(), new UI.Break() );
47 var ignoreObjectSelectedSignal = false;
49 var outliner = new UI.Outliner( editor );
50 outliner.onChange( function () {
52 ignoreObjectSelectedSignal = true;
54 editor.history.goToState( parseInt( outliner.getValue() ) );
56 ignoreObjectSelectedSignal = false;
59 container.add( outliner );
63 var refreshUI = function () {
68 function buildOption( object ) {
70 var option = document.createElement( 'div' );
71 option.value = object.id;
77 ( function addObjects( objects ) {
79 for ( var i = 0, l = objects.length; i < l; i ++ ) {
81 var object = objects[ i ];
83 var option = buildOption( object );
84 option.innerHTML = ' ' + object.name;
86 options.push( option );
93 ( function addObjects( objects, pad ) {
95 for ( var i = objects.length - 1; i >= 0; i -- ) {
97 var object = objects[ i ];
99 var option = buildOption( object );
100 option.innerHTML = ' ' + object.name;
101 option.style.opacity = 0.3;
103 options.push( option );
107 } )( history.redos, ' ' );
109 outliner.setOptions( options );
117 signals.editorCleared.add( refreshUI );
119 signals.historyChanged.add( refreshUI );
120 signals.historyChanged.add( function ( cmd ) {
122 outliner.setValue( cmd !== undefined ? cmd.id : null );