aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-05-10 17:02:04 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-05-10 17:02:04 -0400
commit5726d19a615385b0bcdf1e3a944056d31074edbb (patch)
treecc463245bb151cace4528c02f13b32315d8ab13d
parent9ec7cdfe8ee823afbf6eb80a0e586d99457a50d1 (diff)
made opening docs on right not create aliases. made clicking on an original document trigger replacing it with an alias.
-rw-r--r--src/client/views/collections/CollectionDockingView.tsx38
-rw-r--r--src/client/views/collections/CollectionTreeView.tsx2
-rw-r--r--src/client/views/collections/CollectionView.tsx1
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx7
-rw-r--r--src/client/views/nodes/DocumentView.tsx13
5 files changed, 47 insertions, 14 deletions
diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx
index 6fdb96f0d..6e9b2386d 100644
--- a/src/client/views/collections/CollectionDockingView.tsx
+++ b/src/client/views/collections/CollectionDockingView.tsx
@@ -71,8 +71,6 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp
(window as any).ReactDOM = ReactDOM;
DragManager.StartWindowDrag = this.StartOtherDrag;
}
- hack: boolean = false;
- undohack: any = null;
public StartOtherDrag = (e: any, dragDocs: Doc[]) => {
let config: any;
if (dragDocs.length === 1) {
@@ -192,6 +190,29 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp
return retVal;
}
+ @undoBatch
+ @action
+ public static ReplaceTab(document: Doc, stack: any): Opt<Doc> {
+ if (!CollectionDockingView.Instance) return undefined;
+ const instance = CollectionDockingView.Instance;
+ const replaceTab = (doc: Doc, child: any): Opt<Doc> => {
+ for (let i = 0; i < child.contentItems.length; i++) {
+ if (child.contentItems[i].isRow || child.contentItems[i].isColumn || child.contentItems[i].isStack) {
+ const val = replaceTab(doc, child.contentItems[i]);
+ if (val) return val;
+ } else if (child.contentItems[i].config.component === "DocumentFrameRenderer" &&
+ child.contentItems[i].config.props.documentId === doc[Id]) {
+ const alias = Doc.MakeAlias(doc);
+ child.contentItems[i].config.props.documentId = alias[Id];
+ child.contentItems[i].config.title = alias.title;
+ instance.stateChanged();
+ return alias;
+ }
+ }
+ return undefined;
+ }
+ return replaceTab(document, instance._goldenLayout.root);
+ }
//
// Creates a vertical split on the right side of the docking view, and then adds the Document to the right of that split
@@ -455,12 +476,6 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp
const json = JSON.stringify(this._goldenLayout.toConfig());
this.props.Document.dockingConfig = json;
this.updateDataField(json);
-
- if (this.undohack && !this.hack) {
- this.undohack.end();
- this.undohack = undefined;
- }
- this.hack = false;
}
itemDropped = () => {
@@ -789,6 +804,13 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> {
return CollectionDockingView.AddRightSplit(doc, libraryPath);
} else if (location === "close") {
return CollectionDockingView.CloseRightSplit(doc);
+ } else if (location === "replace") {
+ const alias = CollectionDockingView.ReplaceTab(doc, this._stack);
+ if (alias) {
+ runInAction(() => this._document = alias);
+ return true;
+ }
+ return false;
} else {// if (location === "inPlace") {
return CollectionDockingView.Instance.AddTab(this._stack, doc, libraryPath);
}
diff --git a/src/client/views/collections/CollectionTreeView.tsx b/src/client/views/collections/CollectionTreeView.tsx
index 8cd34e7ed..2f332e77d 100644
--- a/src/client/views/collections/CollectionTreeView.tsx
+++ b/src/client/views/collections/CollectionTreeView.tsx
@@ -108,7 +108,7 @@ class TreeView extends React.Component<TreeViewProps> {
Doc.ComputeContentBounds(DocListCast(this.props.document[this.fieldKey]));
}
- @undoBatch openRight = () => this.props.addDocTab(this.props.dropAction === "alias" ? Doc.MakeAlias(this.props.document) : this.props.document, "onRight", this.props.libraryPath);
+ @undoBatch openRight = () => this.props.addDocTab(this.props.document, "onRight", this.props.libraryPath);
@undoBatch move = (doc: Doc | Doc[], target: Doc | undefined, addDoc: (doc: Doc | Doc[]) => boolean) => {
return this.props.document !== target && this.props.deleteDoc(doc) && addDoc(doc);
}
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 0841d9680..ac9f64d94 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -128,6 +128,7 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
const added = docs.filter(d => !docList.includes(d));
if (added.length) {
added.map(doc => doc.context = this.props.Document);
+ added.map(add => Doc.AddDocToList(Cast(Doc.UserDoc().myCatalog, Doc, null), "data", add));
targetDataDoc[this.props.fieldKey] = new List<Doc>([...docList, ...added]);
targetDataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now()));
}
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index ed3e50f45..61081618a 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -339,6 +339,13 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
}
this._hitCluster = this.props.Document.useClusters ? this.pickCluster(this.getTransform().transformPoint(e.clientX, e.clientY)) !== -1 : false;
if (e.button === 0 && (!e.shiftKey || this._hitCluster) && !e.altKey && !e.ctrlKey && this.props.active(true)) {
+
+ if (!this.props.Document.aliasOf && !this.props.ContainingCollectionView) {
+ this.props.addDocTab(this.props.Document, "replace");
+ e.stopPropagation();
+ e.preventDefault();
+ return;
+ }
document.removeEventListener("pointermove", this.onPointerMove);
document.removeEventListener("pointerup", this.onPointerUp);
document.addEventListener("pointermove", this.onPointerMove);
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index ebfc38a54..d2dabe7ec 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -305,11 +305,14 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
}, console.log);
func();
} else {
- const fullScreenAlias = Doc.MakeAlias(this.props.Document);
- if (StrCast(fullScreenAlias.layoutKey) !== "layout_fullScreen" && fullScreenAlias.layout_fullScreen) {
- fullScreenAlias.layoutKey = "layout_fullScreen";
- }
- UndoManager.RunInBatch(() => this.props.addDocTab(fullScreenAlias, "inTab"), "double tap");
+ UndoManager.RunInBatch(() => {
+ if (StrCast(this.props.Document.layoutKey) !== "layout_fullScreen" && this.props.Document.layout_fullScreen) {
+ const fullScreenAlias = Doc.MakeAlias(this.props.Document);
+ fullScreenAlias.layoutKey = "layout_fullScreen";
+ this.props.addDocTab(fullScreenAlias, "inTab");
+ this.props.addDocTab(this.props.Document, "inTab");
+ }
+ }, "double tap");
SelectionManager.DeselectAll();
Doc.UnBrushDoc(this.props.Document);
}