Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New command 'blender.startDefault' #133

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"activationEvents": [
"onCommand:blender.start",
"onCommand:blender.startDefault",
"onCommand:blender.stop",
"onCommand:blender.build",
"onCommand:blender.buildAndStart",
Expand Down Expand Up @@ -41,6 +42,11 @@
"title": "Start",
"category": "Blender"
},
{
"command": "blender.startDefault",
"title": "Start Default",
"category": "Blender"
},
{
"command": "blender.stop",
"title": "Stop",
Expand Down Expand Up @@ -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
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/blender_executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,37 @@ export class BlenderExecutable {
return new BlenderExecutable(data);
}

public static async GetDefault() {
let allBlenderPaths = <BlenderPathData[]>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);
}
Expand Down Expand Up @@ -89,6 +116,7 @@ interface BlenderPathData {
path: string;
name: string;
isDebug: boolean;
isDefault: boolean;
}

interface BlenderType {
Expand Down Expand Up @@ -131,6 +159,7 @@ async function askUser_FilteredBlenderPath(type: BlenderType): Promise<BlenderPa
path: filepath,
name: '',
isDebug: false,
isDefault: false,
};
type.setSettings(pathData);
return pathData;
Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
export function activate(context: vscode.ExtensionContext) {
let commands: [string, () => Promise<void>][] = [
['blender.start', COMMAND_start],
['blender.startDefault', COMMAND_startDefault],
['blender.stop', COMMAND_stop],
['blender.build', COMMAND_build],
['blender.buildAndStart', COMMAND_buildAndStart],
Expand Down Expand Up @@ -75,6 +76,10 @@ async function COMMAND_start() {
}
}

async function COMMAND_startDefault() {
await BlenderExecutable.LaunchDefault()
}

async function COMMAND_stop() {
RunningBlenders.sendToAll({ type: 'stop' });
}
Expand Down