diff options
-rw-r--r-- | src/Utils.ts | 6 | ||||
-rw-r--r-- | src/client/views/collections/CollectionDockingView.tsx | 7 | ||||
-rw-r--r-- | src/client/views/topbar/TopBar.tsx | 26 | ||||
-rw-r--r-- | src/fields/Doc.ts | 7 |
4 files changed, 30 insertions, 16 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index d1d400de7..38eb51529 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -399,6 +399,12 @@ export function timenow() { return now.toLocaleDateString() + ' ' + h + ':' + m + ' ' + ampm; } +export function incrementTitleCopy(title: string) { + const numstr = title.match(/.*(\{([0-9]*)\})+/); + const copyNumStr = `{${1 + (numstr ? (+numstr[2]) : 0)}}`; + return (numstr ? title.replace(numstr[1], "") : title) + copyNumStr; +} + export function formatTime(time: number) { time = Math.round(time); const hours = Math.floor(time / 60 / 60); diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx index e95371aaa..64a5f38d4 100644 --- a/src/client/views/collections/CollectionDockingView.tsx +++ b/src/client/views/collections/CollectionDockingView.tsx @@ -11,7 +11,7 @@ import { List } from '../../../fields/List'; import { listSpec } from '../../../fields/Schema'; import { Cast, NumCast, StrCast } from "../../../fields/Types"; import { inheritParentAcls } from '../../../fields/util'; -import { emptyFunction } from '../../../Utils'; +import { emptyFunction, incrementTitleCopy } from '../../../Utils'; import { DocServer } from "../../DocServer"; import { Docs } from '../../documents/Documents'; import { DocumentType } from '../../documents/DocumentTypes'; @@ -390,7 +390,6 @@ export class CollectionDockingView extends CollectionSubView() { } public static async Copy(doc: Doc, clone = false) { - clone = !Doc.UserDoc().noviceMode; let json = StrCast(doc.dockingConfig); if (clone) { const cloned = (await Doc.MakeClone(doc)); @@ -403,13 +402,13 @@ export class CollectionDockingView extends CollectionSubView() { const origtabs = origtabids.map(id => DocServer.GetCachedRefField(id)).filter(f => f).map(f => f as Doc); const newtabs = origtabs.map(origtab => { const origtabdocs = DocListCast(origtab.data); - const newtab = origtabdocs.length ? Doc.MakeCopy(origtab, true) : Doc.MakeAlias(origtab); + const newtab = origtabdocs.length ? Doc.MakeCopy(origtab, true, undefined, true) : Doc.MakeAlias(origtab); const newtabdocs = origtabdocs.map(origtabdoc => Doc.MakeAlias(origtabdoc)); newtabdocs.length && (Doc.GetProto(newtab).data = new List<Doc>(newtabdocs)); json = json.replace(origtab[Id], newtab[Id]); return newtab; }); - return Docs.Create.DockDocument(newtabs, json, { title: "Snapshot: " + doc.title }); + return Docs.Create.DockDocument(newtabs, json, { title: incrementTitleCopy(StrCast(doc.title)) }); } @action diff --git a/src/client/views/topbar/TopBar.tsx b/src/client/views/topbar/TopBar.tsx index d5254e315..0af7de6af 100644 --- a/src/client/views/topbar/TopBar.tsx +++ b/src/client/views/topbar/TopBar.tsx @@ -7,7 +7,7 @@ import { StrCast } from '../../../fields/Types'; import { Utils } from '../../../Utils'; import { CurrentUserUtils } from "../../util/CurrentUserUtils"; import { SettingsManager } from "../../util/SettingsManager"; -import { undoBatch } from "../../util/UndoManager"; +import { undoBatch, UndoManager } from "../../util/UndoManager"; import { Borders, Colors } from "../global/globalEnums"; import "./TopBar.scss"; @@ -33,30 +33,36 @@ export class TopBar extends React.Component { </div> <div className="topbar-center" > <div className="topbar-lozenge-dashboard"> - <select className="topbar-dashSelect" onChange={e => CurrentUserUtils.openDashboard(Doc.UserDoc(), myDashboards[Number(e.target.value)])} + <select className="topbar-dashSelect" onChange={undoBatch(e => CurrentUserUtils.openDashboard(Doc.UserDoc(), myDashboards[Number(e.target.value)]))} value={myDashboards.indexOf(CurrentUserUtils.ActiveDashboard)} style={{ color: Colors.WHITE }}> {myDashboards.map((dash, i) => <option key={dash[Id]} value={i}> {StrCast(dash.title)} </option>)} </select> </div> <div className="topbar-dashboards"> - <div className="topbar-icon" onClick={undoBatch(() => CurrentUserUtils.createNewDashboard(Doc.UserDoc()))} - > - {"New"}<FontAwesomeIcon icon="plus"></FontAwesomeIcon> + <div className="topbar-icon" onClick={async () => { + const batch = UndoManager.StartBatch("new dash"); + await CurrentUserUtils.createNewDashboard(Doc.UserDoc()); + batch.end(); + }}> + {"New"}<FontAwesomeIcon icon="plus" /> </div> - {Doc.UserDoc().noviceMode ? (null) : <div className="topbar-icon" onClick={undoBatch(() => CurrentUserUtils.snapshotDashboard(Doc.UserDoc()))} - > - {"Snapshot"}<FontAwesomeIcon icon="camera"></FontAwesomeIcon> + {<div className="topbar-icon" onClick={async () => { + const batch = UndoManager.StartBatch("snapshot"); + await CurrentUserUtils.snapshotDashboard(Doc.UserDoc()); + batch.end(); + }}> + {"Snapshot"}<FontAwesomeIcon icon="camera" /> </div>} </div> </div> <div className="topbar-right" > <div className="topbar-icon" onClick={() => window.open( "https://brown-dash.github.io/Dash-Documentation/", "_blank")}> - {"Help"}<FontAwesomeIcon icon="question-circle"></FontAwesomeIcon> + {"Help"}<FontAwesomeIcon icon="question-circle" /> </div> <div className="topbar-icon" onClick={() => SettingsManager.Instance.open()}> - {"Settings"}<FontAwesomeIcon icon="cog"></FontAwesomeIcon> + {"Settings"}<FontAwesomeIcon icon="cog" /> </div> </div> diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index 63af8401c..50e5fcbc4 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -11,7 +11,7 @@ import { scriptingGlobal, ScriptingGlobals } from "../client/util/ScriptingGloba import { SelectionManager } from "../client/util/SelectionManager"; import { afterDocDeserialize, autoObject, Deserializable, SerializationHelper } from "../client/util/SerializationHelper"; import { UndoManager } from "../client/util/UndoManager"; -import { DashColor, intersectRect, Utils } from "../Utils"; +import { DashColor, incrementTitleCopy, intersectRect, Utils } from "../Utils"; import { DateField } from "./DateField"; import { Copy, HandleUpdate, Id, OnUpdate, Parent, Self, SelfProxy, ToScriptString, ToString, Update } from "./FieldSymbols"; import { List } from "./List"; @@ -770,7 +770,7 @@ export namespace Doc { return overwrite; } - export function MakeCopy(doc: Doc, copyProto: boolean = false, copyProtoId?: string): Doc { + export function MakeCopy(doc: Doc, copyProto: boolean = false, copyProtoId?: string, retitle = false): Doc { const copy = new Doc(copyProtoId, true); const exclude = Cast(doc.cloneFieldFilter, listSpec("string"), []); Object.keys(doc).forEach(key => { @@ -806,6 +806,9 @@ export namespace Doc { } copy.context = undefined; Doc.UserDoc().defaultAclPrivate && (copy["acl-Public"] = "Not Shared"); + if (retitle) { + copy.title = incrementTitleCopy(StrCast(copy.title)); + } return copy; } |