diff --git a/localtypings/pxteditor.d.ts b/localtypings/pxteditor.d.ts index 61180439aa1c..668d53b4864b 100644 --- a/localtypings/pxteditor.d.ts +++ b/localtypings/pxteditor.d.ts @@ -1138,6 +1138,7 @@ declare namespace pxt.editor { notifyProjectCompiled?: (headerId: string, compileResult: pxtc.CompileResult) => void; notifyProjectSaved?: (header: pxt.workspace.Header) => void; onDownloadButtonClick?: () => Promise; + getDefaultProjectName?: () => string; // If defined, replaces 'Untitled' as the default project name // Used with the @tutorialCompleted macro. See docs/writing-docs/tutorials.md for more info onTutorialCompleted?: () => void; diff --git a/pxtlib/cmds.ts b/pxtlib/cmds.ts index a54389dc8739..12ffa2ba13e2 100644 --- a/pxtlib/cmds.ts +++ b/pxtlib/cmds.ts @@ -44,4 +44,5 @@ namespace pxt.commands { export let notifyProjectCompiled: (headerId: string, compileResult: pxtc.CompileResult) => void = undefined; export let notifyProjectSaved: (header: pxt.workspace.Header) => void = undefined; export let onDownloadButtonClick: () => Promise = undefined; + export let getDefaultProjectName: () => string = undefined; } \ No newline at end of file diff --git a/webapp/src/app.tsx b/webapp/src/app.tsx index 37f0fbc7f4cf..d204a6e67d13 100644 --- a/webapp/src/app.tsx +++ b/webapp/src/app.tsx @@ -2476,7 +2476,7 @@ export class ProjectView this.hintManager.clearViewedHints(); return this.createProjectAsync({ - name: "untitled", + name: lf("untitled"), tutorial: options, preferredEditor: editor, dependencies @@ -2894,7 +2894,7 @@ export class ProjectView this.setSideDoc(undefined); if (!options.prj) options.prj = pxt.appTarget.blocksprj; let cfg = pxt.U.clone(options.prj.config); - cfg.name = options.name || lf("Untitled"); + cfg.name = options.name || pxt.commands.getDefaultProjectName?.() || lf("Untitled"); cfg.documentation = options.documentation; let files: pxt.workspace.ScriptText = Util.clone(options.prj.files) if (options.filesOverride) { diff --git a/webapp/src/cmds.ts b/webapp/src/cmds.ts index 3985e392d813..9e796e96457c 100644 --- a/webapp/src/cmds.ts +++ b/webapp/src/cmds.ts @@ -393,6 +393,10 @@ function applyExtensionResult() { log(`extension showProgramTooLargeErrorAsync`); pxt.commands.showProgramTooLargeErrorAsync = res.showProgramTooLargeErrorAsync; } + if (res.getDefaultProjectName) { + log(`extension getDefaultProjectName`); + pxt.commands.getDefaultProjectName = res.getDefaultProjectName; + } if (res.getDownloadMenuItems) { log(`extension getDownloadMenuItems`); pxt.commands.getDownloadMenuItems = res.getDownloadMenuItems; diff --git a/webapp/src/projects.tsx b/webapp/src/projects.tsx index 9a5cd26d7091..e651f4e34bc2 100644 --- a/webapp/src/projects.tsx +++ b/webapp/src/projects.tsx @@ -1483,7 +1483,7 @@ export class NewProjectDialog extends data.Component { pxt.tickEvent('newprojectdialog.show', undefined, { interactiveConsent: false }); this.setState({ - name: "", + name: pxt.commands.getDefaultProjectName?.() || "", emoji: "", visible: true, languageRestriction: pxt.editor.LanguageRestriction.Standard