aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/util/DocumentManager.ts10
-rw-r--r--src/client/views/InkingControl.tsx9
-rw-r--r--src/client/views/collections/CollectionDockingView.tsx22
-rw-r--r--src/client/views/collections/collectionFreeForm/MarqueeView.tsx2
-rw-r--r--src/client/views/nodes/CollectionFreeFormDocumentView.tsx6
-rw-r--r--src/new_fields/Doc.ts12
6 files changed, 39 insertions, 22 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 9a7a94228..47bcb153f 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -5,6 +5,7 @@ import { FieldValue, Cast, NumCast, BoolCast } from '../../new_fields/Types';
import { listSpec } from '../../new_fields/Schema';
import { undoBatch } from './UndoManager';
import { CollectionDockingView } from '../views/collections/CollectionDockingView';
+import { Id } from '../../new_fields/RefField';
export class DocumentManager {
@@ -26,13 +27,13 @@ export class DocumentManager {
// this.DocumentViews = new Array<DocumentView>();
}
- public getDocumentView(toFind: Doc): DocumentView | null {
+ public getDocumentViewById(id: string): DocumentView | null {
let toReturn: DocumentView | null = null;
//gets document view that is in a freeform canvas collection
DocumentManager.Instance.DocumentViews.map(view => {
- if (view.props.Document === toFind) {
+ if (view.props.Document[Id] === id) {
toReturn = view;
return;
}
@@ -40,7 +41,7 @@ export class DocumentManager {
if (!toReturn) {
DocumentManager.Instance.DocumentViews.map(view => {
let doc = view.props.Document.proto;
- if (doc && Object.is(doc, toFind)) {
+ if (doc && doc.Id === id) {
toReturn = view;
}
});
@@ -48,6 +49,9 @@ export class DocumentManager {
return toReturn;
}
+
+ public getDocumentView(toFind: Doc): DocumentView | null { return this.getDocumentViewById(toFind[Id]); }
+
public getDocumentViews(toFind: Doc): DocumentView[] {
let toReturn: DocumentView[] = [];
diff --git a/src/client/views/InkingControl.tsx b/src/client/views/InkingControl.tsx
index 4b3dbd4e0..17d4a1e49 100644
--- a/src/client/views/InkingControl.tsx
+++ b/src/client/views/InkingControl.tsx
@@ -35,12 +35,9 @@ export class InkingControl extends React.Component {
@action
switchColor = (color: ColorResult): void => {
this._selectedColor = color.hex;
- if (SelectionManager.SelectedDocuments().length === 1) {
- var sdoc = SelectionManager.SelectedDocuments()[0];
- if (sdoc.props.ContainingCollectionView) {
- Doc.SetOnPrototype(sdoc.props.Document, "backgroundColor", color.hex);
- }
- }
+ SelectionManager.SelectedDocuments().forEach(doc =>
+ doc.props.ContainingCollectionView && Doc.SetOnPrototype(doc.props.Document, "backgroundColor", color.hex)
+ );
}
@action
diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx
index 8739a213f..0aa067972 100644
--- a/src/client/views/collections/CollectionDockingView.tsx
+++ b/src/client/views/collections/CollectionDockingView.tsx
@@ -19,6 +19,7 @@ import "./CollectionDockingView.scss";
import { SubCollectionViewProps } from "./CollectionSubView";
import React = require("react");
import { ParentDocSelector } from './ParentDocumentSelector';
+import { DocumentManager } from '../../util/DocumentManager';
@observer
export class CollectionDockingView extends React.Component<SubCollectionViewProps> {
@@ -73,26 +74,33 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp
@undoBatch
@action
- public CloseRightSplit(document: Doc) {
+ public CloseRightSplit(document: Doc): boolean {
+ let retVal = false;
if (this._goldenLayout.root.contentItems[0].isRow) {
- this._goldenLayout.root.contentItems[0].contentItems.map((child: any, i: number) => {
+ retVal = Array.from(this._goldenLayout.root.contentItems[0].contentItems).some((child: any) => {
if (child.contentItems.length === 1 && child.contentItems[0].config.component === "DocumentFrameRenderer" &&
- child.contentItems[0].config.props.documentId == document[Id]) {
+ Doc.AreProtosEqual(DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId)!.Document, document)) {
child.contentItems[0].remove();
this.layoutChanged(document);
- this.stateChanged();
+ return true;
} else
- child.contentItems.map((tab: any, j: number) => {
- if (tab.config.component === "DocumentFrameRenderer" && tab.config.props.documentId === document[Id]) {
+ Array.from(child.contentItems).filter((tab: any) => tab.config.component === "DocumentFrameRenderer").some((tab: any, j: number) => {
+ if (Doc.AreProtosEqual(DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId)!.Document, document)) {
child.contentItems[j].remove();
child.config.activeItemIndex = Math.max(child.contentItems.length - 1, 0);
let docs = Cast(this.props.Document.data, listSpec(Doc));
docs && docs.indexOf(document) !== -1 && docs.splice(docs.indexOf(document), 1);
- this.stateChanged();
+ return true;
}
+ return false;
});
+ return false;
})
}
+ if (retVal) {
+ this.stateChanged();
+ }
+ return retVal;
}
@action
diff --git a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
index 080c484f4..1c29ebaae 100644
--- a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
+++ b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
@@ -79,7 +79,7 @@ export class MarqueeView extends React.Component<MarqueeViewProps>
y += 40 * this.props.getTransform().Scale;
})
})();
- } else if (e.key === "t" && e.ctrlKey) {
+ } else if (e.key === "b" && e.ctrlKey) {
//heuristically converts pasted text into a table.
// assumes each entry is separated by a tab
// skips all rows until it gets to a row with more than one entry
diff --git a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx
index 817a23ce8..2a041bf70 100644
--- a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx
+++ b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx
@@ -189,10 +189,8 @@ export class CollectionFreeFormDocumentView extends DocComponent<CollectionFreeF
SelectionManager.DeselectAll();
expandedDocs.forEach(maxDoc => {
maxDoc.isMinimized = false;
- if (!dataDocs || dataDocs.indexOf(maxDoc) == -1) {
- CollectionDockingView.Instance.AddRightSplit(maxDoc);
- } else {
- CollectionDockingView.Instance.CloseRightSplit(maxDoc);
+ if (!CollectionDockingView.Instance.CloseRightSplit(maxDoc)) {
+ CollectionDockingView.Instance.AddRightSplit(Doc.MakeCopy(maxDoc));
}
});
}
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 625ba0d6a..a8c9d28e1 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -134,7 +134,8 @@ export namespace Doc {
return Cast(Get(doc, key, ignoreProto), ctor) as FieldResult<T>;
}
export async function SetOnPrototype(doc: Doc, key: string, value: Field) {
- const proto = doc.proto;
+ const proto = Object.getOwnPropertyNames(doc).indexOf("isProto") == -1 ? doc.proto : doc;
+
if (proto) {
proto[key] = value;
}
@@ -160,6 +161,15 @@ export namespace Doc {
return doc;
}
+ // compare whether documents or their protos match
+ export function AreProtosEqual(doc: Doc, other: Doc) {
+ let r = (doc[Id] === other[Id]);
+ let r2 = (doc.proto && doc.proto.Id === other[Id]);
+ let r3 = (other.proto && other.proto.Id === doc[Id]);
+ let r4 = (doc.proto && other.proto && doc.proto[Id] === other.proto[Id]);
+ return r || r2 || r3 || r4 ? true : false;
+ }
+
export function MakeAlias(doc: Doc) {
const alias = new Doc;