aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-03-17 23:04:18 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-03-17 23:04:18 -0400
commita6ca5db7f43ee31965169ff8d6d0aaffa86dc74e (patch)
tree39e234e20df85c7b85d3ae4928fd596a025bcf09
parenta39945779d1f81444bc9639604594b03821a3be5 (diff)
tweaked drop code
-rw-r--r--src/client/documents/Documents.ts39
-rw-r--r--src/client/util/DragManager.ts2
-rw-r--r--src/client/views/collections/CollectionFreeFormView.tsx19
-rw-r--r--src/client/views/collections/CollectionViewBase.tsx34
-rw-r--r--src/client/views/nodes/DocumentView.tsx8
5 files changed, 43 insertions, 59 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 20cbcdcb4..3aa575dbb 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -1,30 +1,27 @@
+import { AudioField } from "../../fields/AudioField";
import { Document } from "../../fields/Document";
-import { Server } from "../Server";
+import { Field } from "../../fields/Field";
+import { HtmlField } from "../../fields/HtmlField";
+import { ImageField } from "../../fields/ImageField";
+import { InkField, StrokeData } from "../../fields/InkField";
+import { Key } from "../../fields/Key";
import { KeyStore } from "../../fields/KeyStore";
-import { TextField } from "../../fields/TextField";
-import { NumberField } from "../../fields/NumberField";
import { ListField } from "../../fields/ListField";
-import { FormattedTextBox } from "../views/nodes/FormattedTextBox";
-import { ImageField } from "../../fields/ImageField";
-import { ImageBox } from "../views/nodes/ImageBox";
+import { PDFField } from "../../fields/PDFField";
+import { TextField } from "../../fields/TextField";
+import { VideoField } from "../../fields/VideoField";
import { WebField } from "../../fields/WebField";
-import { WebBox } from "../views/nodes/WebBox";
+import { Server } from "../Server";
+import { CollectionPDFView } from "../views/collections/CollectionPDFView";
+import { CollectionVideoView } from "../views/collections/CollectionVideoView";
import { CollectionView, CollectionViewType } from "../views/collections/CollectionView";
-import { HtmlField } from "../../fields/HtmlField";
-import { Key } from "../../fields/Key"
-import { Field } from "../../fields/Field";
-import { KeyValueBox } from "../views/nodes/KeyValueBox"
-import { KVPField } from "../../fields/KVPField";
-import { VideoField } from "../../fields/VideoField"
-import { VideoBox } from "../views/nodes/VideoBox";
-import { AudioField } from "../../fields/AudioField";
import { AudioBox } from "../views/nodes/AudioBox";
-import { PDFField } from "../../fields/PDFField";
+import { FormattedTextBox } from "../views/nodes/FormattedTextBox";
+import { ImageBox } from "../views/nodes/ImageBox";
+import { KeyValueBox } from "../views/nodes/KeyValueBox";
import { PDFBox } from "../views/nodes/PDFBox";
-import { CollectionPDFView } from "../views/collections/CollectionPDFView";
-import { RichTextField } from "../../fields/RichTextField";
-import { CollectionVideoView } from "../views/collections/CollectionVideoView";
-import { StrokeData, InkField } from "../../fields/InkField";
+import { VideoBox } from "../views/nodes/VideoBox";
+import { WebBox } from "../views/nodes/WebBox";
export interface DocumentOptions {
x?: number;
@@ -137,7 +134,7 @@ export namespace Documents {
{ x: 0, y: 0, width: 300, height: 300, layoutKeys: [KeyStore.Data] });
}
function GetCollectionPrototype(): Document {
- return collProto ? collProto.MakeDelegate() :
+ return collProto ? collProto :
collProto = setupPrototypeOptions(collProtoId, "COLLECTION_PROTO", CollectionView.LayoutString("DataKey"),
{ panx: 0, pany: 0, scale: 1, width: 500, height: 500, layoutKeys: [KeyStore.Data] });
}
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 4a61220a5..c0abec407 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -123,7 +123,7 @@ export namespace DragManager {
// however, PDF's have a thumbnail field that contains an image of their canvas.
// So we replace the pdf's canvas with the image thumbnail
const docView: DocumentView = dragData["documentView"];
- const doc: Document = docView ? docView.props.Document : dragData["document"];
+ const doc: Document = dragData["document"];
if (doc) {
var pdfBox = dragElement.getElementsByClassName("pdfBox-cont")[0] as HTMLElement;
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index cf9bf9b92..808a22a5d 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -79,20 +79,11 @@ export class CollectionFreeFormView extends CollectionViewBase {
let screenX = de.x - (de.data["xOffset"] as number || 0);
let screenY = de.y - (de.data["yOffset"] as number || 0);
const [x, y] = this.getTransform().transformPoint(screenX, screenY);
- if (!de.data["alias"]) {
- const docView: DocumentView = de.data["documentView"];
- let doc: Document = docView ? docView.props.Document : de.data["document"];
- if (doc) {
- doc.SetNumber(KeyStore.X, x);
- doc.SetNumber(KeyStore.Y, y);
- this.bringToFront(doc);
- }
- }
- else {
- let newDoc: Document = de.data["newDoc"]
- newDoc.SetNumber(KeyStore.X, x)
- newDoc.SetNumber(KeyStore.Y, y)
- this.bringToFront(newDoc)
+ let doc: Document = de.data["document"];
+ if (doc) {
+ doc.SetNumber(KeyStore.X, x);
+ doc.SetNumber(KeyStore.Y, y);
+ this.bringToFront(doc);
}
}
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 6725fc2d1..304c44788 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -46,34 +46,30 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
@undoBatch
@action
protected drop(e: Event, de: DragManager.DropEvent) {
- const docView: DocumentView = de.data["documentView"]
- const doc: Document = de.data["document"]
- if (de.data["alias"]) {
- let newDoc = docView ? docView.props.Document.CreateAlias() : doc.CreateAlias()
- de.data["newDoc"] = newDoc
- let oldDoc = docView ? docView.props.Document : doc
+ let dropDoc: Document = de.data["document"];
+ if (de.data["alias"] && dropDoc) {
+ let oldDoc = dropDoc;
+ de.data["document"] = dropDoc = oldDoc.CreateAlias();
oldDoc.GetTAsync(KeyStore.Width, NumberField, (f: Opt<NumberField>) => {
if (f) {
- newDoc.SetNumber(KeyStore.Width, f.Data)
+ dropDoc.SetNumber(KeyStore.Width, f.Data)
}
})
oldDoc.GetTAsync(KeyStore.Height, NumberField, (f: Opt<NumberField>) => {
if (f) {
- newDoc.SetNumber(KeyStore.Height, f.Data)
+ dropDoc.SetNumber(KeyStore.Height, f.Data)
}
})
- }
-
- if (docView && docView.props.ContainingCollectionView && docView.props.ContainingCollectionView !== this.props.CollectionView) {
- if (docView.props.RemoveDocument && !de.data["alias"]) {
- docView.props.RemoveDocument(docView.props.Document)
+ } else {
+ const docView: DocumentView = de.data["documentView"];
+ if (docView && docView.props.RemoveDocument && docView.props.ContainingCollectionView !== this.props.CollectionView) {
+ docView.props.RemoveDocument(dropDoc);
+ } else if (dropDoc) {
+ this.props.removeDocument(dropDoc);
}
- this.props.addDocument(de.data["alias"] ? de.data["newDoc"] : docView.props.Document)
- } else if (doc) {
- if (!de.data["alias"]) {
- this.props.removeDocument(doc)
- }
- this.props.addDocument(de.data["alias"] ? de.data["newDoc"] : doc)
+ }
+ if (dropDoc) {
+ this.props.addDocument(dropDoc);
}
e.stopPropagation();
}
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index ec9db765a..981cabe71 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -160,20 +160,20 @@ export class DocumentView extends React.Component<DocumentViewProps> {
}
}
- startDragging(x: number, y: number, ctrlPressed: boolean) {
+ startDragging(x: number, y: number, dropAliasOfDraggedDoc: boolean) {
if (this._mainCont.current) {
const [left, top] = this.props.ScreenToLocalTransform().inverse().transformPoint(0, 0);
let dragData: { [id: string]: any } = {};
dragData["documentView"] = this;
- dragData["document"] = this.props.Document
+ dragData["document"] = this.props.Document;
dragData["xOffset"] = x - left;
dragData["yOffset"] = y - top;
- dragData["alias"] = ctrlPressed
+ dragData["alias"] = dropAliasOfDraggedDoc;
DragManager.StartDrag(this._mainCont.current, dragData, {
handlers: {
dragComplete: action(() => { }),
},
- hideSource: !ctrlPressed
+ hideSource: !dropAliasOfDraggedDoc
})
}
}