diff --git a/app/public/data/snippets/editor-samples.json b/app/public/data/snippets/editor-samples.json index 29a84580..0565c447 100644 --- a/app/public/data/snippets/editor-samples.json +++ b/app/public/data/snippets/editor-samples.json @@ -867,7 +867,7 @@ " uiSession.log.debug(`Initializing [${uiSession.extensionContext.extensionInfo.name}] extension`);", " },", " {", - " description: ''Farm Generator' Sample Extension',", + " description: 'Farm Generator Sample Extension',", " notes: 'by Molly',", " }", " );", diff --git a/app/src/UX/App.tsx b/app/src/UX/App.tsx index 20261601..b3bfd92e 100644 --- a/app/src/UX/App.tsx +++ b/app/src/UX/App.tsx @@ -18,6 +18,7 @@ import ProjectUtilities from "../app/ProjectUtilities"; import WebUtilities from "./WebUtilities"; import ProjectEditorUtilities, { ProjectEditorMode } from "./ProjectEditorUtilities"; import HttpStorage from "../storage/HttpStorage"; +import Utilities from "../core/Utilities"; export enum NewProjectTemplateType { empty, @@ -384,9 +385,11 @@ export default class App extends Component { if (firstSlash > 1) { const openToken = openQuery.substring(0, firstSlash).toLowerCase(); - const openData = openQuery.substring(firstSlash + 1, openQuery.length); + let openData = openQuery.substring(firstSlash + 1, openQuery.length); if (openToken === "gp") { + openData = Utilities.ensureNotEndsWithSlash(openData); + this._ensureProjectFromGalleryId(openData, updateContent); } } @@ -659,7 +662,7 @@ export default class App extends Component { } private async _ensureProjectFromGalleryId(galleryId: string, updateContent?: string) { - if (this.state.carto === undefined) { + if (!this.state || this.state.carto === undefined) { return; } @@ -673,22 +676,24 @@ export default class App extends Component { this._ensureProjectFromGallery(gp, updateContent); } - private async _ensureProjectFromGallery(project: IGalleryItem, updateContent?: string) { + private async _ensureProjectFromGallery(galleryItem: IGalleryItem, updateContent?: string) { if (this.state === null || this.state.carto === undefined) { return; } this._ensureProjectFromGitHubTemplate( - project.title, - project.gitHubOwner, - project.gitHubRepoName, + galleryItem.title, + galleryItem.gitHubOwner, + galleryItem.gitHubRepoName, false, - project.gitHubBranch, - project.gitHubFolder, - project.fileList, - project.id, - project.type === GalleryItemType.codeSample ? project.id : undefined, - updateContent + galleryItem.gitHubBranch, + galleryItem.gitHubFolder, + galleryItem.fileList, + galleryItem.id, + galleryItem.type !== GalleryItemType.project ? galleryItem.id : undefined, + updateContent, + undefined, + galleryItem.type ); } @@ -703,11 +708,13 @@ export default class App extends Component { projectId?: string, sampleId?: string, updateContent?: string, - description?: string + description?: string, + galleryItemType?: GalleryItemType ) { const carto = CartoApp.carto; - if (this.state === null || carto === undefined) { + // don't load if we're already actively loading something. + if (this.state === null || carto === undefined || this._loadingMessage || this.state.loadingMessage) { return; } @@ -745,6 +752,7 @@ export default class App extends Component { proj.originalGitHubRepoName === gitHubRepoName && proj.originalGitHubBranch === gitHubBranch && proj.originalGitHubFolder === gitHubFolder && + proj.originalSampleId === sampleId && updateContent === undefined ) { this._updateWindowTitle(newMode, proj); @@ -774,7 +782,11 @@ export default class App extends Component { projectId, sampleId, updateContent, - description + undefined, + undefined, + undefined, + description, + galleryItemType ); } @@ -1280,7 +1292,10 @@ export default class App extends Component { onProjectSelected={this._handleProjectSelected} /> ); - } else if (this.state.activeProject.originalSampleId) { + } else if ( + this.state.activeProject.originalSampleId && + this.state.activeProject.getItemByProjectPath("/scripts/ScriptBox.ts") + ) { // show main view (no sidebar) if it's a code sample. interior = ( = 0) { + let nextParen = content.indexOf("Extension(", registerFunction); + + if (nextParen > registerFunction) { + content = content.substring(0, registerFunction + 24) + content.substring(nextParen); + } + } + + return content; + } + static adaptSample(sampleContent: string, fileContent: string) { if (sampleContent.indexOf(" mc.") >= 0 && fileContent.indexOf(" as mc") <= 0) { sampleContent = sampleContent.replace(/mc./gi, ""); @@ -1033,6 +1045,8 @@ export default class ProjectUtilities { if (file !== undefined) { if (fullScriptBoxReplace && fileName === "ScriptBox.ts") { + snippetInjectContent = ProjectUtilities.adaptFullSample(snippetInjectContent); + file.setContent(snippetInjectContent); } else { const type = StorageUtilities.getTypeFromName(file.name); diff --git a/app/src/core/Utilities.ts b/app/src/core/Utilities.ts index 21b6d9ad..a0a1fa2c 100644 --- a/app/src/core/Utilities.ts +++ b/app/src/core/Utilities.ts @@ -894,6 +894,14 @@ export default class Utilities { return pathSegment; } + static ensureNotEndsWithSlash(pathSegment: string) { + while (pathSegment.length > 0 && pathSegment.endsWith("/")) { + pathSegment = pathSegment.substring(0, pathSegment.length - 1); + } + + return pathSegment; + } + static ensureStartsWithBackSlash(pathSegment: string) { if (!pathSegment.startsWith("\\")) { pathSegment = "\\" + pathSegment;