diff options
author | bobzel <zzzman@gmail.com> | 2020-08-29 11:53:43 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2020-08-29 11:53:43 -0400 |
commit | 6414d1a344c80a75c2d4fb91e3cd7126e23c4cb1 (patch) | |
tree | bf50ad57a72785a6166113f1c260583d60321386 /src | |
parent | 53e29fd0fcb09f443978b26dc31c37cf35241dae (diff) |
made isDisplayPanel a prop of the docking layout instead of a field on a Doc
Diffstat (limited to 'src')
-rw-r--r-- | src/client/documents/Documents.ts | 3 | ||||
-rw-r--r-- | src/client/views/collections/CollectionDockingView.tsx | 46 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 6 |
3 files changed, 27 insertions, 28 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 9186cea87..2ca1b95d7 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -101,7 +101,6 @@ export interface DocumentOptions { page?: number; description?: string; // added for links _viewScale?: number; - isDisplayPanel?: boolean; // whether the panel functions as GoldenLayout "stack" used to display documents forceActive?: boolean; layout?: string | Doc; // default layout string for a document childLayoutTemplate?: Doc; // template for collection to use to render its children (see PresBox or Buxton layout in tree view) @@ -848,7 +847,7 @@ export namespace Docs { { type: type, content: [ - ...configs.map(config => CollectionDockingView.makeDocumentConfig(config.doc, config.initialWidth)) + ...configs.map(config => CollectionDockingView.makeDocumentConfig(config.doc, false, config.initialWidth)) ] } ] diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx index cc3d017be..06cadcacf 100644 --- a/src/client/views/collections/CollectionDockingView.tsx +++ b/src/client/views/collections/CollectionDockingView.tsx @@ -38,7 +38,7 @@ const _global = (window /* browser */ || global /* node */) as any; @observer export class CollectionDockingView extends CollectionSubView(doc => doc) { @observable public static Instance: CollectionDockingView; - public static makeDocumentConfig(document: Doc, width?: number) { + public static makeDocumentConfig(document: Doc, isDisplayPanel?: boolean, width?: number) { return { type: 'react-component', component: 'DocumentFrameRenderer', @@ -46,6 +46,7 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { width: width, props: { documentId: document[Id], + isDisplayPanel // flag for whether a tab should be considered a placeholder that has its contents replaced with new content } }; } @@ -91,8 +92,7 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { public static CloseRightSplit(document: Opt<Doc>): boolean { const tryClose = (childItem: any) => { if (childItem.config?.component === "DocumentFrameRenderer") { - const docView = DocumentManager.Instance.getDocumentViewById(childItem.config.props.documentId); - if (docView && ((!document && docView.Document.isDisplayPanel) || (document && Doc.AreProtosEqual(docView.props.Document, document)))) { + if ((!document && childItem.config.props.isDisplayPanel) || (document && childItem.config.props.documentId === document[Id])) { childItem.remove(); return true; } @@ -115,7 +115,7 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { } const newItemStackConfig = { type: 'stack', - content: [CollectionDockingView.makeDocumentConfig(Doc.MakeAlias(doc), undefined)] + content: [CollectionDockingView.makeDocumentConfig(Doc.MakeAlias(doc))] }; const docconfig = instance._goldenLayout.root.layoutManager.createContentItem(newItemStackConfig, instance._goldenLayout); instance._goldenLayout.root.contentItems[0].addChild(docconfig); @@ -133,17 +133,15 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { const retVal = !instance._goldenLayout.root.contentItems[0].isRow ? false : Array.from(instance._goldenLayout.root.contentItems[0].contentItems).some((child: any) => { if (child.contentItems.length === 1 && child.contentItems[0].config.component === "DocumentFrameRenderer" && - DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId)?.Document.isDisplayPanel) { - const newItemStackConfig = CollectionDockingView.makeDocumentConfig(document, undefined); - runInAction(() => document.isDisplayPanel = true); + child.contentItems[0].config.isDisplayPanel) { + const newItemStackConfig = CollectionDockingView.makeDocumentConfig(document, true); child.addChild(newItemStackConfig, undefined); !addToSplit && child.contentItems[0].remove(); return true; } return Array.from(child.contentItems).filter((tab: any) => tab.config.component === "DocumentFrameRenderer").some((tab: any, j: number) => { - if (DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId)?.Document.isDisplayPanel) { - const newItemStackConfig = CollectionDockingView.makeDocumentConfig(document, undefined); - runInAction(() => document.isDisplayPanel = true); + if (tab.config.props.isDisplayPanel) { + const newItemStackConfig = CollectionDockingView.makeDocumentConfig(document, true); child.addChild(newItemStackConfig, undefined); !addToSplit && child.contentItems[j].remove(); return true; @@ -160,7 +158,7 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { // @undoBatch @action - public static AddRightSplit(document: Doc, dontSelect: boolean = false, isDisplayPanel: Opt<boolean> = undefined) { + public static AddRightSplit(document: Doc, isDisplayPanel: Opt<boolean> = undefined) { if (!CollectionDockingView.Instance) return false; const ind = Array.from(CollectionDockingView.Instance.tabMap.keys()).findIndex((tab) => tab.DashDoc === document); @@ -172,13 +170,11 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { } tab.setActive(true); } else { - document.isDisplayPanel = isDisplayPanel; - if (document._viewType === CollectionViewType.Docking) return CurrentUserUtils.openDashboard(Doc.UserDoc(), document); const instance = CollectionDockingView.Instance; const newItemStackConfig = { type: 'stack', - content: [CollectionDockingView.makeDocumentConfig(document, undefined)] + content: [CollectionDockingView.makeDocumentConfig(document, isDisplayPanel)] }; const newContentItem = instance._goldenLayout.root.layoutManager.createContentItem(newItemStackConfig, instance._goldenLayout); @@ -201,10 +197,6 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { newContentItem.callDownwards('_$init'); instance.layoutChanged(); } - if (!dontSelect) { - const view = DocumentManager.Instance.getFirstDocumentView(document); - view && SelectionManager.SelectDoc(view, false); - } return true; } @@ -275,14 +267,13 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { return true; } - // // Creates a vertical split on the right side of the docking view, and then adds the Document to that split // @undoBatch public static UseRightSplit(document: Doc, libraryPath?: Doc[], shiftKey?: boolean) { if (shiftKey || !CollectionDockingView.ReplaceRightSplit(document, libraryPath, shiftKey)) { - return CollectionDockingView.AddRightSplit(document, false, true); + return CollectionDockingView.AddRightSplit(document, true); } return false; } @@ -406,7 +397,6 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { @action onPointerDown = (e: React.PointerEvent): void => { window.addEventListener("mouseup", this.onPointerUp); - if (!(e.target as HTMLElement).closest("*.lm_content") && ((e.target as HTMLElement).closest("*.lm_tab") || (e.target as HTMLElement).closest("*.lm_stack"))) { this._flush = UndoManager.StartBatch("golden layout edit"); } @@ -463,7 +453,7 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { tab.reactComponents?.forEach((ele: any) => ReactDOM.unmountComponentAtNode(ele)); } tabCreated = (tab: any) => { - (tab.contentItem.element[0]?.firstChild?.firstChild as any)?.InitTab(tab); + (tab.contentItem.element[0]?.firstChild?.firstChild as any)?.InitTab(tab); // have to explicitly initialize tabs that reuse contents from previous abs (ie, when dragging a tab around a new tab is created for the old content) } stackCreated = (stack: any) => { @@ -515,10 +505,11 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { @observable private _panelHeight = 0; @observable private _isActive: boolean = false; @observable private _document: Doc | undefined; + @observable private _view: DocumentView | undefined; get stack(): any { return (this.props as any).glContainer.parent.parent; } get tab() { return (this.props as any).glContainer.tab; } - get view() { return this._document && DocumentManager.Instance.getDocumentView(this._document); } + get view() { return this._view; } @action init = (tab: any, doc: Opt<Doc>) => { @@ -704,7 +695,8 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { SelectionManager.DeselectAll(); if (doc._viewType === CollectionViewType.Docking) return CurrentUserUtils.openDashboard(Doc.UserDoc(), doc); switch (location) { - case "onRight": return CollectionDockingView.AddRightSplit(doc); + case "onRight": return Array.from(CollectionDockingView.Instance.tabMap.keys()).findIndex((tab) => tab.DashDoc === doc) !== -1 ? + CollectionDockingView.CloseRightSplit(doc) : CollectionDockingView.AddRightSplit(doc); case "close": return CollectionDockingView.CloseRightSplit(doc); case "replace": return CollectionDockingView.UseRightSplit(doc); case "fullScreen": return CollectionDockingView.OpenFullScreen(doc); @@ -790,12 +782,14 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { </div> </div>; } + setView = action((view: DocumentView) => this._view = view); @computed get docView() { TraceMobx(); return !this._document ? (null) : <><DocumentView key={this._document[Id]} LibraryPath={emptyPath} Document={this._document} + getView={this.setView} DataDoc={!Doc.AreProtosEqual(this._document[DataSym], this._document) ? this._document[DataSym] : undefined} bringToFront={emptyFunction} rootSelected={returnTrue} @@ -839,6 +833,6 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { </div >); } } -Scripting.addGlobal(function openOnRight(doc: any, dontSelect: boolean = false) { CollectionDockingView.AddRightSplit(doc, dontSelect); }, - "opens up the inputted document on the right side of the screen", "(doc: any, dontSelect: boolean)"); +Scripting.addGlobal(function openOnRight(doc: any) { CollectionDockingView.AddRightSplit(doc); }, + "opens up the inputted document on the right side of the screen", "(doc: any)"); Scripting.addGlobal(function useRightSplit(doc: any, shiftKey?: boolean) { CollectionDockingView.UseRightSplit(doc, undefined, shiftKey); }); diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index eb6988362..6e1357b41 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -52,6 +52,7 @@ export interface DocumentViewProps { NativeHeight: () => number; Document: Doc; DataDoc?: Doc; + getView?: (view: DocumentView) => any; LayoutTemplateString?: string; LayoutTemplate?: () => Opt<Doc>; LibraryPath: Doc[]; @@ -128,6 +129,11 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu onClickFunc = () => this.onClickHandler; onDoubleClickFunc = () => this.onDoubleClickHandler; + constructor(props: any) { + super(props); + props.getView?.(this); + } + handle1PointerHoldStart = (e: Event, me: InteractionUtils.MultiTouchEvent<React.TouchEvent>): any => { this.removeMoveListeners(); this.removeEndListeners(); |