diff --git a/CHANGELOG.md b/CHANGELOG.md index c62f7185..b7ceaee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - [#709](https://github.com/estruyf/vscode-front-matter/issues/709): Take "where clause" into account on content creation - [#710](https://github.com/estruyf/vscode-front-matter/issues/710): Hide child field when parent field its "when clause" is not met, also remove the fields from the content - [#713](https://github.com/estruyf/vscode-front-matter/issues/713): Add the ability to always use quotes around string values in front matter +- [#722](https://github.com/estruyf/vscode-front-matter/issues/722): Allow to create sub-content which shows a dialog to select the parent folder ### ⚡️ Optimizations diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 90052cfb..c3805bb5 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -582,6 +582,12 @@ "helpers.contentType.setContentType.noFrontMatter.warning": "No front matter data found to set the content type.", "helpers.contentType.setContentType.quickPick.title": "Select the content type", "helpers.contentType.setContentType.quickPick.placeholder": "Which content type would you like to use?", + "helpers.contentType.create.allowSubContent.title": "Do you want to create it as sub-content?", + "helpers.contentType.create.allowSubContent.placeHolder": "Do you want to create it as sub-content?", + "helpers.contentType.create.allowSubContent.showOpenDialog.openLabel": "Select folder", + "helpers.contentType.create.allowSubContent.showOpenDialog.title": "Select folder to create the content", + "helpers.contentType.create.pageBundle.title": "Create as a page bundle?", + "helpers.contentType.create.pageBundle.placeHolder": "Do you want to create the sub-content as a page bundle?", "helpers.contentType.create.progress.title": "{0}: Creating content...", "helpers.contentType.create.success": "Your new content has been created.", "helpers.contentType.verify.warning": "The content type actions are not available in this mode.", diff --git a/package.json b/package.json index dc43ec26..169aa6bd 100644 --- a/package.json +++ b/package.json @@ -1074,7 +1074,17 @@ "clearEmpty": { "type": "boolean", "default": false, - "description": "%setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.clearEmpty.description%" + "description": "%setting.frontMatter.taxonomy.contentTypes.items.properties.clearEmpty.description%" + }, + "allowAsSubContent": { + "type": "boolean", + "default": false, + "description": "%setting.frontMatter.taxonomy.contentTypes.items.properties.allowAsSubContent.description%" + }, + "isSubContent": { + "type": "boolean", + "default": false, + "description": "%setting.frontMatter.taxonomy.contentTypes.items.properties.isSubContent.description%" }, "fields": { "$id": "#contenttypefield", diff --git a/package.nls.json b/package.nls.json index 94c0e3ef..de0ecc3a 100644 --- a/package.nls.json +++ b/package.nls.json @@ -245,8 +245,10 @@ "setting.frontMatter.taxonomy.dateField.deprecationMessage": "This setting is deprecated and will be removed in the next major version. Please use the new `isPublishDate` settings instead in your content types date fields.", "setting.frontMatter.taxonomy.modifiedField.deprecationMessage": "This setting is deprecated and will be removed in the next major version. Please use the new `isModifiedDate` settings instead in your content types date fields.", "setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.customType.description": "Specify the name of the custom field type to use.", - "setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.clearEmpty.description": "Specify if the empty values should be cleared.", + "setting.frontMatter.taxonomy.contentTypes.items.properties.clearEmpty.description": "Specify if the empty values should be cleared.", "setting.frontMatter.website.host.markdownDescription": "Specify the host URL of your website. [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.website.url)", "command.frontMatter.settings.refresh": "Refresh Front Matter Settings", - "setting.frontMatter.config.dynamicFilePath.markdownDescription": "Specify the path to the dynamic config file (ex: [[workspace]]/config.js). [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.config.dynamicfilepath)" + "setting.frontMatter.config.dynamicFilePath.markdownDescription": "Specify the path to the dynamic config file (ex: [[workspace]]/config.js). [Check in the docs](https://frontmatter.codes/docs/settings/overview#frontmatter.config.dynamicfilepath)", + "setting.frontMatter.taxonomy.contentTypes.items.properties.allowAsSubContent.description": "Specify if the content type can be used as sub content.", + "setting.frontMatter.taxonomy.contentTypes.items.properties.isSubContent.description": "Specify if the content type is sub content." } \ No newline at end of file diff --git a/src/helpers/ContentType.ts b/src/helpers/ContentType.ts index 81581822..1c8da874 100644 --- a/src/helpers/ContentType.ts +++ b/src/helpers/ContentType.ts @@ -814,6 +814,62 @@ export class ContentType { cancellable: false }, async () => { + if (contentType.isSubContent || contentType.allowAsSubContent) { + let showDialog = true; + + if (contentType.allowAsSubContent) { + const subContentAnswer = await window.showQuickPick( + [l10n.t(LocalizationKey.commonNo), l10n.t(LocalizationKey.commonYes)], + { + title: l10n.t(LocalizationKey.helpersContentTypeCreateAllowSubContentTitle), + placeHolder: l10n.t( + LocalizationKey.helpersContentTypeCreateAllowSubContentPlaceHolder + ), + ignoreFocusOut: true + } + ); + showDialog = subContentAnswer === l10n.t(LocalizationKey.commonYes); + } + + if (showDialog) { + const folderLocation = await window.showOpenDialog({ + canSelectFiles: false, + canSelectFolders: true, + canSelectMany: false, + defaultUri: Uri.file(folderPath), + openLabel: l10n.t( + LocalizationKey.helpersContentTypeCreateAllowSubContentShowOpenDialogOpenLabel + ), + title: l10n.t( + LocalizationKey.helpersContentTypeCreateAllowSubContentShowOpenDialogTitle + ) + }); + + if (!folderLocation || folderLocation.length === 0) { + return; + } + + folderPath = folderLocation[0].fsPath; + + if (contentType.pageBundle) { + const createAsPageBundle = await window.showQuickPick( + [l10n.t(LocalizationKey.commonNo), l10n.t(LocalizationKey.commonYes)], + { + title: l10n.t(LocalizationKey.helpersContentTypeCreatePageBundleTitle), + placeHolder: l10n.t( + LocalizationKey.helpersContentTypeCreatePageBundlePlaceHolder + ), + ignoreFocusOut: true + } + ); + + if (createAsPageBundle === l10n.t(LocalizationKey.commonNo)) { + contentType.pageBundle = false; + } + } + } + } + let titleValue = await Questions.ContentTitle(); if (!titleValue) { return; diff --git a/src/localization/localization.enum.ts b/src/localization/localization.enum.ts index d0f5a9b7..3b49353f 100644 --- a/src/localization/localization.enum.ts +++ b/src/localization/localization.enum.ts @@ -1896,6 +1896,30 @@ export enum LocalizationKey { * Which content type would you like to use? */ helpersContentTypeSetContentTypeQuickPickPlaceholder = 'helpers.contentType.setContentType.quickPick.placeholder', + /** + * Do you want to create it as sub-content? + */ + helpersContentTypeCreateAllowSubContentTitle = 'helpers.contentType.create.allowSubContent.title', + /** + * Do you want to create it as sub-content? + */ + helpersContentTypeCreateAllowSubContentPlaceHolder = 'helpers.contentType.create.allowSubContent.placeHolder', + /** + * Select folder + */ + helpersContentTypeCreateAllowSubContentShowOpenDialogOpenLabel = 'helpers.contentType.create.allowSubContent.showOpenDialog.openLabel', + /** + * Select folder to create the content + */ + helpersContentTypeCreateAllowSubContentShowOpenDialogTitle = 'helpers.contentType.create.allowSubContent.showOpenDialog.title', + /** + * Create as a page bundle? + */ + helpersContentTypeCreatePageBundleTitle = 'helpers.contentType.create.pageBundle.title', + /** + * Do you want to create the sub-content as a page bundle? + */ + helpersContentTypeCreatePageBundlePlaceHolder = 'helpers.contentType.create.pageBundle.placeHolder', /** * {0}: Creating content... */ diff --git a/src/models/PanelSettings.ts b/src/models/PanelSettings.ts index 4b96db01..7b6bd2c9 100644 --- a/src/models/PanelSettings.ts +++ b/src/models/PanelSettings.ts @@ -65,6 +65,8 @@ export interface ContentType { postScript?: string; filePrefix?: string; clearEmpty?: boolean; + isSubContent?: boolean; + allowAsSubContent?: boolean; } export type FieldType =