diff options
author | yipstanley <stanley_yip@brown.edu> | 2019-02-10 22:12:04 -0500 |
---|---|---|
committer | yipstanley <stanley_yip@brown.edu> | 2019-02-10 22:12:04 -0500 |
commit | 69f0b463a78c82aaf78ceb6a5162431424452311 (patch) | |
tree | a54c7129f36d307420422b3babfa6da4d85db67e /src/client/util/SelectionManager.ts | |
parent | 2e930b98726a09e597106d43a6763dd36d038771 (diff) | |
parent | 099c5823f05285fc5086c5a433658cf06dc4a04b (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into server_implementation
Diffstat (limited to 'src/client/util/SelectionManager.ts')
-rw-r--r-- | src/client/util/SelectionManager.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/client/util/SelectionManager.ts b/src/client/util/SelectionManager.ts new file mode 100644 index 000000000..0759ae110 --- /dev/null +++ b/src/client/util/SelectionManager.ts @@ -0,0 +1,39 @@ +import { CollectionFreeFormDocumentView } from "../views/nodes/CollectionFreeFormDocumentView"; +import { observable, action } from "mobx"; + +export namespace SelectionManager { + class Manager { + @observable + SelectedDocuments: Array<CollectionFreeFormDocumentView> = []; + + @action + SelectDoc(doc: CollectionFreeFormDocumentView, ctrlPressed: boolean): void { + // if doc is not in SelectedDocuments, add it + if (!ctrlPressed) { + manager.SelectedDocuments = []; + } + + if (manager.SelectedDocuments.indexOf(doc) === -1) { + manager.SelectedDocuments.push(doc) + } + } + } + + const manager = new Manager; + + export function SelectDoc(doc: CollectionFreeFormDocumentView, ctrlPressed: boolean): void { + manager.SelectDoc(doc, ctrlPressed) + } + + export function IsSelected(doc: CollectionFreeFormDocumentView): boolean { + return manager.SelectedDocuments.indexOf(doc) !== -1; + } + + export function DeselectAll(): void { + manager.SelectedDocuments = [] + } + + export function SelectedDocuments(): Array<CollectionFreeFormDocumentView> { + return manager.SelectedDocuments; + } +}
\ No newline at end of file |