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 {
readonly dataState: State;
readonly behaviorState: State;
readonly animation: PluginAnimationManager;
readonly cameraSnapshots = new CameraSnapshotManager();
readonly cameraSnapshots: CameraSnapshotManager;
readonly snapshots = new PluginStateSnapshotManager();
......@@ -89,6 +89,7 @@ class PluginState {
this.behavior.currentObject.next(this.dataState.behaviors.currentObject.value);
this.cameraSnapshots = new CameraSnapshotManager(plugin);
this.animation = new PluginAnimationManager(plugin);
}
}
......
......@@ -7,57 +7,54 @@
import { Camera } from 'mol-canvas3d/camera';
import { OrderedMap } from 'immutable';
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 }
class CameraSnapshotManager {
private ev = RxEventHelper.create();
private _entries = OrderedMap<string, CameraSnapshotManager.Entry>().asMutable();
class CameraSnapshotManager extends PluginComponent<{ entries: OrderedMap<string, CameraSnapshotManager.Entry> }> {
readonly events = {
changed: this.ev()
};
get entries() { return this._entries; }
getEntry(id: string) {
return this._entries.get(id);
return this.state.entries.get(id);
}
remove(id: string) {
if (!this._entries.has(id)) return;
this._entries.delete(id);
if (!this.state.entries.has(id)) return;
this.updateState({ entries: this.state.entries.delete(id) });
this.events.changed.next();
}
add(e: CameraSnapshotManager.Entry) {
this._entries.set(e.id, e);
this.updateState({ entries: this.state.entries.set(e.id, e) });
this.events.changed.next();
}
clear() {
if (this._entries.size === 0) return;
this._entries = OrderedMap<string, CameraSnapshotManager.Entry>().asMutable();
if (this.state.entries.size === 0) return;
this.updateState({ entries: OrderedMap<string, CameraSnapshotManager.Entry>() });
this.events.changed.next();
}
getStateSnapshot(): CameraSnapshotManager.StateSnapshot {
const entries: CameraSnapshotManager.Entry[] = [];
this._entries.forEach(e => entries.push(e!));
this.state.entries.forEach(e => entries.push(e!));
return { entries };
}
setStateSnapshot(state: CameraSnapshotManager.StateSnapshot ) {
this._entries = OrderedMap<string, CameraSnapshotManager.Entry>().asMutable();
const entries = OrderedMap<string, CameraSnapshotManager.Entry>().asMutable();
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();
}
dispose() {
this.ev.dispose();
constructor(ctx: PluginContext) {
super(ctx, { entries: OrderedMap<string, CameraSnapshotManager.Entry>() });
}
}
......
......@@ -65,7 +65,7 @@ class CameraSnapshotList extends PluginUIComponent<{ }, { }> {
render() {
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 onClick={this.remove(e!.id)} className='msp-btn msp-btn-link msp-state-list-remove-button'>
<span className='msp-icon msp-icon-remove' />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment