forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSidebar.Settings.History.js
146 lines (81 loc) · 2.91 KB
/
Sidebar.Settings.History.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { UIButton, UIPanel, UIBreak, UIText } from './libs/ui.js';
import { UIBoolean, UIOutliner } from './libs/ui.three.js';
function SidebarSettingsHistory( editor ) {
const strings = editor.strings;
const signals = editor.signals;
const config = editor.config;
const history = editor.history;
const container = new UIPanel();
container.add( new UIText( strings.getKey( 'sidebar/history' ).toUpperCase() ) );
//
const persistent = new UIBoolean( config.getKey( 'settings/history' ), strings.getKey( 'sidebar/history/persistent' ) );
persistent.setPosition( 'absolute' ).setRight( '8px' );
persistent.onChange( function () {
const 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.' );
const lastUndoCmd = history.undos[ history.undos.length - 1 ];
const lastUndoId = ( lastUndoCmd !== undefined ) ? lastUndoCmd.id : 0;
editor.history.enableSerialization( lastUndoId );
} else {
signals.historyChanged.dispatch();
}
} );
container.add( persistent );
container.add( new UIBreak(), new UIBreak() );
let ignoreObjectSelectedSignal = false;
const outliner = new UIOutliner( editor );
outliner.onChange( function () {
ignoreObjectSelectedSignal = true;
editor.history.goToState( parseInt( outliner.getValue() ) );
ignoreObjectSelectedSignal = false;
} );
container.add( outliner );
container.add( new UIBreak() );
// Clear History
const option = new UIButton( strings.getKey( 'sidebar/history/clear' ) );
option.onClick( function () {
if ( confirm( 'The Undo/Redo History will be cleared. Are you sure?' ) ) {
editor.history.clear();
}
} );
container.add( option );
//
const refreshUI = function () {
const options = [];
function buildOption( object ) {
const option = document.createElement( 'div' );
option.value = object.id;
return option;
}
( function addObjects( objects ) {
for ( let i = 0, l = objects.length; i < l; i ++ ) {
const object = objects[ i ];
const option = buildOption( object );
option.innerHTML = ' ' + object.name;
options.push( option );
}
} )( history.undos );
( function addObjects( objects ) {
for ( let i = objects.length - 1; i >= 0; i -- ) {
const object = objects[ i ];
const 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 };