123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import { UIPanel, UIBreak, UIText } from './libs/ui.js';
- import { UIBoolean, UIOutliner } from './libs/ui.three.js';
- function SidebarSettingsHistory( editor ) {
- var strings = editor.strings;
- var signals = editor.signals;
- var config = editor.config;
- var history = editor.history;
- var container = new UIPanel();
- container.add( new UIText( strings.getKey( 'sidebar/history' ).toUpperCase() ) );
- //
- var persistent = new UIBoolean( config.getKey( 'settings/history' ), strings.getKey( 'sidebar/history/persistent' ) );
- persistent.setPosition( 'absolute' ).setRight( '8px' );
- persistent.onChange( function () {
- var value = this.getValue();
- config.setKey( 'settings/history', value );
- if ( value ) {
- alert( 'The history will be preserved across sessions.\nThis can have an impact on performance when working with textures.' );
- var lastUndoCmd = history.undos[ history.undos.length - 1 ];
- var lastUndoId = ( lastUndoCmd !== undefined ) ? lastUndoCmd.id : 0;
- editor.history.enableSerialization( lastUndoId );
- } else {
- signals.historyChanged.dispatch();
- }
- } );
- container.add( persistent );
- container.add( new UIBreak(), new UIBreak() );
- var ignoreObjectSelectedSignal = false;
- var outliner = new UIOutliner( editor );
- outliner.onChange( function () {
- ignoreObjectSelectedSignal = true;
- editor.history.goToState( parseInt( outliner.getValue() ) );
- ignoreObjectSelectedSignal = false;
- } );
- container.add( outliner );
- //
- var refreshUI = function () {
- var options = [];
- function buildOption( object ) {
- var option = document.createElement( 'div' );
- option.value = object.id;
- return option;
- }
- ( function addObjects( objects ) {
- for ( var i = 0, l = objects.length; i < l; i ++ ) {
- var object = objects[ i ];
- var option = buildOption( object );
- option.innerHTML = ' ' + object.name;
- options.push( option );
- }
- } )( history.undos );
- ( function addObjects( objects ) {
- for ( var i = objects.length - 1; i >= 0; i -- ) {
- var object = objects[ i ];
- var option = buildOption( object );
- option.innerHTML = ' ' + object.name;
- option.style.opacity = 0.3;
- options.push( option );
- }
- } )( history.redos );
- outliner.setOptions( options );
- };
- refreshUI();
- // events
- signals.editorCleared.add( refreshUI );
- signals.historyChanged.add( refreshUI );
- signals.historyChanged.add( function ( cmd ) {
- if ( ignoreObjectSelectedSignal === true ) return;
- outliner.setValue( cmd !== undefined ? cmd.id : null );
- } );
- return container;
- }
- export { SidebarSettingsHistory };
|