Sidebar.History.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Sidebar.History = function ( editor ) {
  5. var signals = editor.signals;
  6. var history = editor.history;
  7. var container = new UI.CollapsiblePanel();
  8. container.setCollapsed( editor.config.getKey( 'ui/sidebar/history/collapsed' ) );
  9. container.onCollapsedChange( function ( boolean ) {
  10. editor.config.setKey( 'ui/sidebar/history/collapsed', boolean );
  11. } );
  12. container.addStatic( new UI.Text( 'HISTORY' ) );
  13. container.add( new UI.Break() );
  14. var ignoreObjectSelectedSignal = false;
  15. var outliner = new UI.Outliner( editor );
  16. outliner.onChange( function () {
  17. ignoreObjectSelectedSignal = true;
  18. editor.history.goToState( parseInt( outliner.getValue() ) );
  19. ignoreObjectSelectedSignal = false;
  20. } );
  21. outliner.onDblClick( function () {
  22. //editor.focusById( parseInt( outliner.getValue() ) );
  23. } );
  24. container.add( outliner );
  25. //
  26. var refreshUI = function () {
  27. var options = [];
  28. var enumerator = 1;
  29. ( function addObjects( objects, pad ) {
  30. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  31. var object = objects[ i ];
  32. var html = pad + "<span style='color: #0000cc '>" + enumerator++ + ". Undo: " + object.name + "</span>";
  33. options.push( { value: object.id, html: html } );
  34. }
  35. } )( history.undos, '&nbsp;' );
  36. ( function addObjects( objects, pad ) {
  37. for ( var i = objects.length - 1; i >= 0; i -- ) {
  38. var object = objects[ i ];
  39. var html = pad + "<span style='color: #71544e'>" + enumerator++ + ". Redo: " + object.name + "</span>";
  40. options.push( { value: object.id, html: html } );
  41. }
  42. } )( history.redos, '&nbsp;' );
  43. outliner.setOptions( options );
  44. };
  45. refreshUI();
  46. // events
  47. signals.editorCleared.add( refreshUI );
  48. signals.historyChanged.add( refreshUI );
  49. signals.historyChanged.add( function ( cmd ) {
  50. outliner.setValue( cmd !== undefined ? cmd.id : null );
  51. } );
  52. return container;
  53. };