Skip to content

Commit

Permalink
Reworked dashboard item provider to simplify the process of adding ne…
Browse files Browse the repository at this point in the history
…w runnable options to it
  • Loading branch information
SpontanCombust committed Aug 4, 2024
1 parent a5caf76 commit 527e500
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 156 deletions.
79 changes: 16 additions & 63 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,58 +161,56 @@
{
"command": "witcherscript-ide.game.launchDx12",
"title": "Launch the game (DX12)",
"category": "WitcherScript-IDE",
"icon": "$(run)"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.game.launchDx12Debug",
"title": "Launch the game for debugging (DX12)",
"category": "WitcherScript-IDE",
"icon": "$(debug-alt)"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.game.launchDx11",
"title": "Launch the game (DX11)",
"category": "WitcherScript-IDE",
"icon": "$(run)"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.game.launchDx11Debug",
"title": "Launch the game for debugging (DX11)",
"category": "WitcherScript-IDE",
"icon": "$(debug-alt)"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.game.recompileScripts",
"title": "Recompile game scripts",
"category": "WitcherScript-IDE",
"icon": "$(run)"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.game.execConsoleCommand",
"title": "Execute console command",
"category": "WitcherScript-IDE",
"icon": "$(run)"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.misc.openLogs",
"title": "Open extension logs",
"category": "WitcherScript-IDE",
"enablement": "witcherscript-ide.languageServerActive",
"icon": "$(run)"
"enablement": "witcherscript-ide.languageServerActive"
},
{
"command": "witcherscript-ide.misc.openSettings",
"title": "Open extension settings",
"category": "WitcherScript-IDE",
"icon": "$(run)"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.misc.openGameHostSettings",
"title": "Open extension settings for the game host",
"category": "WitcherScript-IDE",
"icon": "$(gear)"
},
{
"command": "witcherscript-ide.misc.runDashboardOption",
"title": "Run the option",
"category": "WitcherScript-IDE",
"icon": "$(run)"
},
{
"command": "witcherscript-ide.debug.showScriptAst",
"title": "Show script AST",
Expand Down Expand Up @@ -376,59 +374,14 @@
"when": "view == witcherscript-ide.vanillaFilesView && viewItem == script",
"group": "inline"
},
{
"command": "witcherscript-ide.game.launchDx12",
"when": "view == witcherscript-ide.dashboardView && viewItem == launchGameDx12",
"group": "inline"
},
{
"command": "witcherscript-ide.game.launchDx12Debug",
"when": "view == witcherscript-ide.dashboardView && viewItem == launchGameDx12Debug",
"group": "inline"
},
{
"command": "witcherscript-ide.game.launchDx11",
"when": "view == witcherscript-ide.dashboardView && viewItem == launchGameDx11",
"group": "inline"
},
{
"command": "witcherscript-ide.game.launchDx11Debug",
"when": "view == witcherscript-ide.dashboardView && viewItem == launchGameDx11Debug",
"group": "inline"
},
{
"command": "witcherscript-ide.projects.init",
"when": "view == witcherscript-ide.dashboardView && viewItem == initWideProject",
"group": "inline"
},
{
"command": "witcherscript-ide.projects.create",
"when": "view == witcherscript-ide.dashboardView && viewItem == createWideProject",
"group": "inline"
},
{
"command": "witcherscript-ide.misc.openGameHostSettings",
"when": "view == witcherscript-ide.dashboardView && viewItem == gameHostInfo",
"group": "inline"
},
{
"command": "witcherscript-ide.game.recompileScripts",
"when": "view == witcherscript-ide.dashboardView && viewItem == recompileScripts",
"group": "inline"
},
{
"command": "witcherscript-ide.game.execConsoleCommand",
"when": "view == witcherscript-ide.dashboardView && viewItem == execConsoleCommand",
"group": "inline"
},
{
"command": "witcherscript-ide.misc.openSettings",
"when": "view == witcherscript-ide.dashboardView && viewItem == openSettings",
"group": "inline"
},
{
"command": "witcherscript-ide.misc.openLogs",
"when": "view == witcherscript-ide.dashboardView && viewItem == openLspLogs",
"command": "witcherscript-ide.misc.runDashboardOption",
"when": "view == witcherscript-ide.dashboardView && viewItem == dashboardCommandOption",
"group": "inline"
}
],
Expand Down
1 change: 1 addition & 0 deletions editors/vscode/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function registerCommands(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("witcherscript-ide.misc.openSettings", misc.commandOpenSettings()),
vscode.commands.registerCommand("witcherscript-ide.misc.openGameHostSettings", misc.commandOpenGameHostSettings()),
vscode.commands.registerCommand("witcherscript-ide.misc.openFileReadOnly", misc.commandOpenFileReadOnly()),
vscode.commands.registerCommand("witcherscript-ide.misc.runDashboardOption", misc.commandRunDashboardOption()),
);

const cfg = getConfiguration();
Expand Down
7 changes: 7 additions & 0 deletions editors/vscode/src/commands/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from 'vscode';
import { Cmd } from './index'
import { getLanguageClient } from '../lsp/lang_client';
import * as tdcp from '../providers/text_document_content_providers'
import { DashboardCommandOptionItem } from '../providers/dashboard_provider';


export function commandShowCommandsInPalette(): Cmd {
Expand Down Expand Up @@ -41,4 +42,10 @@ export function commandOpenFileReadOnly(): Cmd {
tdcp.ReadOnlyContentProvider.getInstance().eventEmitter.fire(uri);
vscode.window.showTextDocument(uri);
}
}

export function commandRunDashboardOption(): Cmd {
return (item: DashboardCommandOptionItem) => {
vscode.commands.executeCommand(item.btnCommand)
}
}
151 changes: 58 additions & 93 deletions editors/vscode/src/providers/dashboard_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,155 +65,120 @@ export class DashboardProvider implements vscode.TreeDataProvider<Item> {
}


export type Item =
GameLaunchOptionsHeaderItem |
GameLaunchOptionItem |
ProjectSystemOptionsHeaderItem |
ProjectSystemOptionItem |
RemoteCommandsHeaderItem |
RemoteCommandsHostInfoItem |
RemoteCommandItem;


class GameLaunchOptionsHeaderItem extends vscode.TreeItem {
abstract class DashboardOptionsHeaderItem extends vscode.TreeItem {
readonly parent = undefined;

constructor() {
super("Game launch options", vscode.TreeItemCollapsibleState.Expanded);
constructor(
override readonly label: string
) {
super(label, vscode.TreeItemCollapsibleState.Expanded);
}

getChildren(): Item[] {
return [
new GameLaunchOptionItem(this, "Launch the game (DX12)", "launchGameDx12"),
new GameLaunchOptionItem(this, "Launch the game for debugging (DX12)", "launchGameDx12Debug"),
new GameLaunchOptionItem(this, "Launch the game (DX11)", "launchGameDx11"),
new GameLaunchOptionItem(this, "Launch the game for debugging (DX11)", "launchGameDx11Debug"),
];
}
abstract getChildren(): DashboardOptionItem[];
}

class GameLaunchOptionItem extends vscode.TreeItem {
abstract class DashboardOptionItem extends vscode.TreeItem {
constructor(
readonly parent: GameLaunchOptionsHeaderItem,
readonly parent: DashboardOptionsHeaderItem,
override readonly label: string,
override readonly contextValue: string
iconId: string | undefined
) {
super(label, vscode.TreeItemCollapsibleState.None);
this.iconPath = new vscode.ThemeIcon("circle-filled");
if (iconId) {
this.iconPath = new vscode.ThemeIcon(iconId);
}
}

getChildren(): Item[] {
getChildren() {
return [];
}
}

export class DashboardCommandOptionItem extends DashboardOptionItem {
constructor(
readonly parent: DashboardOptionsHeaderItem,
override readonly label: string,
iconId: string | undefined,
readonly btnCommand: string
) {
super(parent, label, iconId);
this.contextValue = "dashboardCommandOption";
}
}

export type Item =
DashboardOptionsHeaderItem |
DashboardOptionItem;


class ProjectSystemOptionsHeaderItem extends vscode.TreeItem {
readonly parent = undefined;


class GameLaunchOptionsHeaderItem extends DashboardOptionsHeaderItem {
constructor() {
super("Project system", vscode.TreeItemCollapsibleState.Expanded);
super("Game launch options");
}

getChildren(): Item[] {
getChildren(): DashboardOptionItem[] {
return [
new ProjectSystemOptionItem(this, "Initialize a WitcherScript project in existing directory", "initWideProject"),
new ProjectSystemOptionItem(this, "Create a new WitcherScript project", "createWideProject"),
new DashboardCommandOptionItem(this, "Launch the game (DX12)", "run", "witcherscript-ide.game.launchDx12"),
new DashboardCommandOptionItem(this, "Launch the game for debugging (DX12)", "debug-alt", "witcherscript-ide.game.launchDx12Debug"),
new DashboardCommandOptionItem(this, "Launch the game (DX11)", "run", "witcherscript-ide.game.launchDx11"),
new DashboardCommandOptionItem(this, "Launch the game for debugging (DX11)", "debug-alt", "witcherscript-ide.game.launchDx11Debug"),
];
}
}

class ProjectSystemOptionItem extends vscode.TreeItem {
constructor(
readonly parent: ProjectSystemOptionsHeaderItem,
override readonly label: string,
override readonly contextValue: string
) {
super(label, vscode.TreeItemCollapsibleState.None);
this.iconPath = new vscode.ThemeIcon("package");

class ProjectSystemOptionsHeaderItem extends DashboardOptionsHeaderItem {
constructor() {
super("Project system");
}

getChildren(): Item[] {
return [];
getChildren(): DashboardOptionItem[] {
return [
new DashboardCommandOptionItem(this, "Initialize a WitcherScript project in existing directory", "package", "witcherscript-ide.projects.init"),
new DashboardCommandOptionItem(this, "Create a new WitcherScript project", "package", "witcherscript-ide.projects.create"),
];
}
}


class RemoteCommandsHeaderItem extends vscode.TreeItem {
readonly parent = undefined;

class RemoteCommandsHeaderItem extends DashboardOptionsHeaderItem {
constructor() {
super("Remote commands", vscode.TreeItemCollapsibleState.Expanded);
super("Remote commands");
}

getChildren(): Item[] {
getChildren(): DashboardOptionItem[] {
return [
new RemoteCommandsHostInfoItem(this),
new RemoteCommandItem(this, "Recompile scripts", "recompileScripts"),
new RemoteCommandItem(this, "Execute console command", "execConsoleCommand"),
new DashboardCommandOptionItem(this, "Recompile scripts", "remote", "witcherscript-ide.game.recompileScripts"),
new DashboardCommandOptionItem(this, "Execute console command", "remote", "witcherscript-ide.game.execConsoleCommand"),
];
}
}

class RemoteCommandsHostInfoItem extends vscode.TreeItem {
class RemoteCommandsHostInfoItem extends DashboardOptionItem {
constructor(
readonly parent: RemoteCommandsHeaderItem,
) {
const cfg = getConfiguration();
const label = `Game host: ${cfg.gameHostType.toString()}, address: ${cfg.gameHostIpAddress}`;

super(label, vscode.TreeItemCollapsibleState.None);
super(parent, label, undefined);
this.contextValue = "gameHostInfo";
}

getChildren(): Item[] {
return [];
}
}

class RemoteCommandItem extends vscode.TreeItem {
constructor(
readonly parent: RemoteCommandsHeaderItem,
override readonly label: string,
override readonly contextValue: string
) {
super(label, vscode.TreeItemCollapsibleState.None);
this.iconPath = new vscode.ThemeIcon("remote");
}

getChildren(): Item[] {
return [];
}
}



class MiscOptionsHeaderItem extends vscode.TreeItem {
readonly parent = undefined;

class MiscOptionsHeaderItem extends DashboardOptionsHeaderItem {
constructor() {
super("Miscellaneous", vscode.TreeItemCollapsibleState.Expanded);
super("Miscellaneous");
}

getChildren(): Item[] {
getChildren(): DashboardOptionItem[] {
return [
new MiscOptionItem(this, "Open settings", "openSettings"),
new MiscOptionItem(this, "Open language server logs", "openLspLogs")
new DashboardCommandOptionItem(this, "Open settings", "circle-filled", "witcherscript-ide.misc.openSettings"),
new DashboardCommandOptionItem(this, "Open language server logs", "circle-filled", "witcherscript-ide.misc.openLogs")
];
}
}

class MiscOptionItem extends vscode.TreeItem {
constructor(
readonly parent: MiscOptionsHeaderItem,
override readonly label: string,
override readonly contextValue: string
) {
super(label, vscode.TreeItemCollapsibleState.None);
this.iconPath = new vscode.ThemeIcon("circle-filled");
}

getChildren(): Item[] {
return [];
}
}

0 comments on commit 527e500

Please sign in to comment.