diff options
| author | bob <bcz@cs.brown.edu> | 2019-02-04 10:44:30 -0500 |
|---|---|---|
| committer | bob <bcz@cs.brown.edu> | 2019-02-04 10:44:30 -0500 |
| commit | e79e53d78546501fc855b76a84f000289ed7433a (patch) | |
| tree | 80d3309086d31d95a139933be237842d3c3ee796 /src/views/collections/CollectionViewBase.tsx | |
| parent | 6539a76c8fae1fa816bde4d9e094eb074d1a68b8 (diff) | |
split out common code into CollectionViewBase. organized a few other things, too.
Diffstat (limited to 'src/views/collections/CollectionViewBase.tsx')
| -rw-r--r-- | src/views/collections/CollectionViewBase.tsx | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/views/collections/CollectionViewBase.tsx b/src/views/collections/CollectionViewBase.tsx new file mode 100644 index 000000000..bfded71d9 --- /dev/null +++ b/src/views/collections/CollectionViewBase.tsx @@ -0,0 +1,53 @@ +import { action, computed } from "mobx"; +import { observer } from "mobx-react"; +import { Document } from "../../fields/Document"; +import { Opt } from "../../fields/Field"; +import { Key, KeyStore } from "../../fields/Key"; +import { ListField } from "../../fields/ListField"; +import { SelectionManager } from "../../util/SelectionManager"; +import { ContextMenu } from "../ContextMenu"; +import React = require("react"); +import { DocumentView } from "../nodes/DocumentView"; +import { CollectionDockingView } from "./CollectionDockingView"; + + +export interface CollectionViewProps { + fieldKey: Key; + Document: Document; + ContainingDocumentView: Opt<DocumentView>; +} + +export const COLLECTION_BORDER_WIDTH = 2; + +@observer +export class CollectionViewBase extends React.Component<CollectionViewProps> { + + @computed + public get active(): boolean { + var isSelected = (this.props.ContainingDocumentView != undefined && SelectionManager.IsSelected(this.props.ContainingDocumentView)); + var childSelected = SelectionManager.SelectedDocuments().some(view => view.props.ContainingCollectionView == this); + var topMost = this.props.ContainingDocumentView != undefined && ( + this.props.ContainingDocumentView.props.ContainingCollectionView == undefined || + this.props.ContainingDocumentView.props.ContainingCollectionView instanceof CollectionDockingView); + return isSelected || childSelected || topMost; + } + @action + addDocument = (doc: Document): void => { + //TODO This won't create the field if it doesn't already exist + const value = this.props.Document.GetFieldValue(this.props.fieldKey, ListField, new Array<Document>()) + value.push(doc); + } + + @action + removeDocument = (doc: Document): void => { + //TODO This won't create the field if it doesn't already exist + const value = this.props.Document.GetFieldValue(this.props.fieldKey, ListField, new Array<Document>()) + if (value.indexOf(doc) !== -1) { + value.splice(value.indexOf(doc), 1) + + SelectionManager.DeselectAll() + ContextMenu.Instance.clearItems() + } + } + +}
\ No newline at end of file |
