Skip to content

Commit

Permalink
Add generated name mirrored from vscode-edu (#10186)
Browse files Browse the repository at this point in the history
* Add generated name mirrored from vscode-edu

* prefill in open screen
  • Loading branch information
jwunderl authored Sep 15, 2024
1 parent a6054af commit 24d825c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions localtypings/pxteditor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ declare namespace pxt.editor {
notifyProjectCompiled?: (headerId: string, compileResult: pxtc.CompileResult) => void;
notifyProjectSaved?: (header: pxt.workspace.Header) => void;
onDownloadButtonClick?: () => Promise<void>;
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;
Expand Down
1 change: 1 addition & 0 deletions pxtlib/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> = undefined;
export let getDefaultProjectName: () => string = undefined;
}
4 changes: 2 additions & 2 deletions webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ export class ProjectView
this.hintManager.clearViewedHints();

return this.createProjectAsync({
name: "untitled",
name: lf("untitled"),
tutorial: options,
preferredEditor: editor,
dependencies
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ export class NewProjectDialog extends data.Component<ISettingsProps, NewProjectD
show = () => {
pxt.tickEvent('newprojectdialog.show', undefined, { interactiveConsent: false });
this.setState({
name: "",
name: pxt.commands.getDefaultProjectName?.() || "",
emoji: "",
visible: true,
languageRestriction: pxt.editor.LanguageRestriction.Standard
Expand Down

0 comments on commit 24d825c

Please sign in to comment.