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

mol-plugin-ui: cache focus options in StructureFocusControls

parent b24062b5
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,8 @@ import { lociLabel } from '../../mol-theme/label'; ...@@ -16,6 +16,8 @@ import { lociLabel } from '../../mol-theme/label';
import { FocusLoci } from '../../mol-plugin/behavior/dynamic/representation'; import { FocusLoci } from '../../mol-plugin/behavior/dynamic/representation';
import { StateTransform } from '../../mol-state'; import { StateTransform } from '../../mol-state';
import { Binding } from '../../mol-util/binding'; import { Binding } from '../../mol-util/binding';
import { memoizeLatest } from '../../mol-util/memoize';
import { StructureRef } from '../../mol-plugin-state/manager/structure/hierarchy-state';
interface StructureFocusControlsState { interface StructureFocusControlsState {
isBusy: boolean isBusy: boolean
...@@ -95,6 +97,8 @@ export class StructureFocusControls extends PluginUIComponent<{}, StructureFocus ...@@ -95,6 +97,8 @@ export class StructureFocusControls extends PluginUIComponent<{}, StructureFocus
componentDidMount() { componentDidMount() {
this.subscribe(this.plugin.managers.structure.focus.behaviors.current, c => { this.subscribe(this.plugin.managers.structure.focus.behaviors.current, c => {
// clear the memo cache
this.getSelectionItems([]);
this.forceUpdate(); this.forceUpdate();
}); });
...@@ -111,25 +115,8 @@ export class StructureFocusControls extends PluginUIComponent<{}, StructureFocus ...@@ -111,25 +115,8 @@ export class StructureFocusControls extends PluginUIComponent<{}, StructureFocus
return this.state.isBusy || this.actionItems.length === 0 return this.state.isBusy || this.actionItems.length === 0
} }
get actionItems() { getSelectionItems = memoizeLatest((structures: ReadonlyArray<StructureRef>) => {
const historyItems: ActionMenu.Items[] = []
const { history } = this.plugin.managers.structure.focus
if (history.length > 0) {
historyItems.push([
ActionMenu.Header('History', { description: 'Previously focused on items.' }),
...ActionMenu.createItems(history, {
label: f => f.label,
description: f => {
return f.category && f.label !== f.category
? `${f.category} | ${f.label}`
: f.label
}
})
])
}
const presetItems: ActionMenu.Items[] = [] const presetItems: ActionMenu.Items[] = []
const { structures } = this.plugin.managers.structure.hierarchy.selection;
for (const s of structures) { for (const s of structures) {
const d = s.cell.obj?.data const d = s.cell.obj?.data
if (d) { if (d) {
...@@ -146,6 +133,27 @@ export class StructureFocusControls extends PluginUIComponent<{}, StructureFocus ...@@ -146,6 +133,27 @@ export class StructureFocusControls extends PluginUIComponent<{}, StructureFocus
} }
} }
} }
return presetItems;
});
get actionItems() {
const historyItems: ActionMenu.Items[] = []
const { history } = this.plugin.managers.structure.focus
if (history.length > 0) {
historyItems.push([
ActionMenu.Header('History', { description: 'Previously focused on items.' }),
...ActionMenu.createItems(history, {
label: f => f.label,
description: f => {
return f.category && f.label !== f.category
? `${f.category} | ${f.label}`
: f.label
}
})
])
}
const presetItems: ActionMenu.Items[] = this.getSelectionItems(this.plugin.managers.structure.hierarchy.selection.structures);
if (presetItems.length === 1) { if (presetItems.length === 1) {
const item = presetItems[0] as ActionMenu.Items[] const item = presetItems[0] as ActionMenu.Items[]
const header = item[0] as ActionMenu.Header const header = item[0] as ActionMenu.Header
......
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