Skip to content
Snippets Groups Projects
Commit 0b12a4fa authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: refactored CameraSnapshotManager

parent ae9a706a
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ class PluginState { ...@@ -22,7 +22,7 @@ class PluginState {
readonly dataState: State; readonly dataState: State;
readonly behaviorState: State; readonly behaviorState: State;
readonly animation: PluginAnimationManager; readonly animation: PluginAnimationManager;
readonly cameraSnapshots = new CameraSnapshotManager(); readonly cameraSnapshots: CameraSnapshotManager;
readonly snapshots = new PluginStateSnapshotManager(); readonly snapshots = new PluginStateSnapshotManager();
...@@ -89,6 +89,7 @@ class PluginState { ...@@ -89,6 +89,7 @@ class PluginState {
this.behavior.currentObject.next(this.dataState.behaviors.currentObject.value); this.behavior.currentObject.next(this.dataState.behaviors.currentObject.value);
this.cameraSnapshots = new CameraSnapshotManager(plugin);
this.animation = new PluginAnimationManager(plugin); this.animation = new PluginAnimationManager(plugin);
} }
} }
......
...@@ -7,57 +7,54 @@ ...@@ -7,57 +7,54 @@
import { Camera } from 'mol-canvas3d/camera'; import { Camera } from 'mol-canvas3d/camera';
import { OrderedMap } from 'immutable'; import { OrderedMap } from 'immutable';
import { UUID } from 'mol-util'; import { UUID } from 'mol-util';
import { RxEventHelper } from 'mol-util/rx-event-helper'; import { PluginComponent } from 'mol-plugin/component';
import { PluginContext } from 'mol-plugin/context';
export { CameraSnapshotManager } export { CameraSnapshotManager }
class CameraSnapshotManager { class CameraSnapshotManager extends PluginComponent<{ entries: OrderedMap<string, CameraSnapshotManager.Entry> }> {
private ev = RxEventHelper.create();
private _entries = OrderedMap<string, CameraSnapshotManager.Entry>().asMutable();
readonly events = { readonly events = {
changed: this.ev() changed: this.ev()
}; };
get entries() { return this._entries; }
getEntry(id: string) { getEntry(id: string) {
return this._entries.get(id); return this.state.entries.get(id);
} }
remove(id: string) { remove(id: string) {
if (!this._entries.has(id)) return; if (!this.state.entries.has(id)) return;
this._entries.delete(id); this.updateState({ entries: this.state.entries.delete(id) });
this.events.changed.next(); this.events.changed.next();
} }
add(e: CameraSnapshotManager.Entry) { add(e: CameraSnapshotManager.Entry) {
this._entries.set(e.id, e); this.updateState({ entries: this.state.entries.set(e.id, e) });
this.events.changed.next(); this.events.changed.next();
} }
clear() { clear() {
if (this._entries.size === 0) return; if (this.state.entries.size === 0) return;
this._entries = OrderedMap<string, CameraSnapshotManager.Entry>().asMutable(); this.updateState({ entries: OrderedMap<string, CameraSnapshotManager.Entry>() });
this.events.changed.next(); this.events.changed.next();
} }
getStateSnapshot(): CameraSnapshotManager.StateSnapshot { getStateSnapshot(): CameraSnapshotManager.StateSnapshot {
const entries: CameraSnapshotManager.Entry[] = []; const entries: CameraSnapshotManager.Entry[] = [];
this._entries.forEach(e => entries.push(e!)); this.state.entries.forEach(e => entries.push(e!));
return { entries }; return { entries };
} }
setStateSnapshot(state: CameraSnapshotManager.StateSnapshot ) { setStateSnapshot(state: CameraSnapshotManager.StateSnapshot ) {
this._entries = OrderedMap<string, CameraSnapshotManager.Entry>().asMutable(); const entries = OrderedMap<string, CameraSnapshotManager.Entry>().asMutable();
for (const e of state.entries) { for (const e of state.entries) {
this._entries.set(e.id, e); entries.set(e.id, e);
} }
this.updateState({ entries: entries.asImmutable() });
this.events.changed.next(); this.events.changed.next();
} }
dispose() { constructor(ctx: PluginContext) {
this.ev.dispose(); super(ctx, { entries: OrderedMap<string, CameraSnapshotManager.Entry>() });
} }
} }
......
...@@ -65,7 +65,7 @@ class CameraSnapshotList extends PluginUIComponent<{ }, { }> { ...@@ -65,7 +65,7 @@ class CameraSnapshotList extends PluginUIComponent<{ }, { }> {
render() { render() {
return <ul style={{ listStyle: 'none' }} className='msp-state-list'> return <ul style={{ listStyle: 'none' }} className='msp-state-list'>
{this.plugin.state.cameraSnapshots.entries.valueSeq().map(e =><li key={e!.id}> {this.plugin.state.cameraSnapshots.state.entries.valueSeq().map(e =><li key={e!.id}>
<button className='msp-btn msp-btn-block msp-form-control' onClick={this.apply(e!.id)}>{e!.name || e!.timestamp} <small>{e!.description}</small></button> <button className='msp-btn msp-btn-block msp-form-control' onClick={this.apply(e!.id)}>{e!.name || e!.timestamp} <small>{e!.description}</small></button>
<button onClick={this.remove(e!.id)} className='msp-btn msp-btn-link msp-state-list-remove-button'> <button onClick={this.remove(e!.id)} className='msp-btn msp-btn-link msp-state-list-remove-button'>
<span className='msp-icon msp-icon-remove' /> <span className='msp-icon msp-icon-remove' />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment