From e455cdf73a12aadc8b984e32c47736ad68ed211a Mon Sep 17 00:00:00 2001 From: Zdenek Dolezal Date: Fri, 16 Sep 2022 14:42:22 +0200 Subject: [PATCH] New command 'blender.startDefault' Launches blender executable without prompting user to select version based on 'isDefault' settings value. Prompts user only for first time to select the default executable. --- package.json | 11 +++++++++++ src/blender_executable.ts | 29 +++++++++++++++++++++++++++++ src/extension.ts | 5 +++++ 3 files changed, 45 insertions(+) diff --git a/package.json b/package.json index ba0e7b7..dba7856 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ ], "activationEvents": [ "onCommand:blender.start", + "onCommand:blender.startDefault", "onCommand:blender.stop", "onCommand:blender.build", "onCommand:blender.buildAndStart", @@ -41,6 +42,11 @@ "title": "Start", "category": "Blender" }, + { + "command": "blender.startDefault", + "title": "Start Default", + "category": "Blender" + }, { "command": "blender.stop", "title": "Stop", @@ -126,6 +132,11 @@ "type": "boolean", "description": "Is this executable a debug build.", "default": false + }, + "isDefault": { + "type": "boolean", + "description": "Mark this executable as default for the Start Default command", + "default": false } } } diff --git a/src/blender_executable.ts b/src/blender_executable.ts index b1c62fe..5d3d148 100644 --- a/src/blender_executable.ts +++ b/src/blender_executable.ts @@ -38,10 +38,37 @@ export class BlenderExecutable { return new BlenderExecutable(data); } + public static async GetDefault() { + let allBlenderPaths = getConfig().get('executables'); + let data = allBlenderPaths.find(item => item.isDefault === true) + // Prompt user to select default Blender if none is found and update the settings + if (data === undefined) + { + data = await getFilteredBlenderPath({ + label: 'Default Blender Executable', + selectNewLabel: 'Choose a default Blender executable...', + predicate: () => true, + setSettings: item => { item.isDefault = true; } + }); + + // Mark the selected Blender as default, update config + let item = allBlenderPaths.find(item => item.path === data?.path); + if (item !== undefined) { + item.isDefault = true + getConfig().update('executables', allBlenderPaths, vscode.ConfigurationTarget.Workspace); + } + } + return new BlenderExecutable(data); + } + public static async LaunchAny() { await (await this.GetAny()).launch(); } + public static async LaunchDefault() { + await (await this.GetDefault()).launch(); + } + public static async LaunchDebug(folder: BlenderWorkspaceFolder) { await (await this.GetDebug()).launchDebug(folder); } @@ -89,6 +116,7 @@ interface BlenderPathData { path: string; name: string; isDebug: boolean; + isDefault: boolean; } interface BlenderType { @@ -131,6 +159,7 @@ async function askUser_FilteredBlenderPath(type: BlenderType): Promise Promise][] = [ ['blender.start', COMMAND_start], + ['blender.startDefault', COMMAND_startDefault], ['blender.stop', COMMAND_stop], ['blender.build', COMMAND_build], ['blender.buildAndStart', COMMAND_buildAndStart], @@ -75,6 +76,10 @@ async function COMMAND_start() { } } +async function COMMAND_startDefault() { + await BlenderExecutable.LaunchDefault() +} + async function COMMAND_stop() { RunningBlenders.sendToAll({ type: 'stop' }); }