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

Fix Selected lab status turn grey on selection #24

Merged
merged 1 commit into from
Jan 26, 2025
Merged
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
4 changes: 4 additions & 0 deletions resources/icons/partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/icons/running.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/icons/stopped.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/icons/undeployed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 22 additions & 9 deletions src/containerlabTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ContainerlabTreeDataProvider implements vscode.TreeDataProvider<Con
private _onDidChangeTreeData = new vscode.EventEmitter<ContainerlabNode | undefined | void>();
public readonly onDidChangeTreeData = this._onDidChangeTreeData.event;

constructor() { }
constructor(private context: vscode.ExtensionContext) { }

getTreeItem(element: ContainerlabNode): vscode.TreeItem {
return element;
Expand Down Expand Up @@ -97,23 +97,23 @@ export class ContainerlabTreeDataProvider implements vscode.TreeDataProvider<Con
}

let contextVal: string;
let color: vscode.ThemeColor;
let iconFilename: string;
if (info.containers.length === 0) {
// Undeployed
contextVal = "containerlabLabUndeployed";
color = new vscode.ThemeColor('disabledForeground'); // grey
iconFilename = "undeployed.svg"; // pick your grey or other color
} else {
// Deployed
contextVal = "containerlabLabDeployed";
const states = info.containers.map(c => c.state);
const allRunning = states.every(s => s === 'running');
const noneRunning = states.every(s => s !== 'running');
if (allRunning) {
color = new vscode.ThemeColor('testing.iconPassed'); // green
iconFilename = "running.svg"; // green circle
} else if (noneRunning) {
color = new vscode.ThemeColor('testing.iconFailed'); // red
iconFilename = "stopped.svg"; // red circle
} else {
color = new vscode.ThemeColor('problemsWarningIcon.foreground'); // partial => yellow
iconFilename = "partial.svg"; // yellow circle
}
}

Expand All @@ -133,7 +133,11 @@ export class ContainerlabTreeDataProvider implements vscode.TreeDataProvider<Con
},
contextVal
);
node.iconPath = new vscode.ThemeIcon('circle-filled', color);
const iconFile = this.context.asAbsolutePath(
path.join('resources', 'icons', iconFilename)
);
const iconUri = vscode.Uri.file(iconFile);
node.iconPath = { light: iconUri, dark: iconUri };
node.description = utils.getRelLabFolderPath(labPath);
nodes.push(node);
}
Expand Down Expand Up @@ -179,8 +183,17 @@ export class ContainerlabTreeDataProvider implements vscode.TreeDataProvider<Con
);
node.tooltip = `Container: ${ctr.name}\nID: ${ctr.container_id}\nState: ${ctr.state}\nIPv4: ${v4Addr}\nIPv6: ${v6Addr}`;

if (ctr.state === 'running') {node.iconPath = new vscode.ThemeIcon('circle-filled', new vscode.ThemeColor('testing.iconPassed'));}
else {node.iconPath = new vscode.ThemeIcon('circle-filled', new vscode.ThemeColor('testing.iconFailed'));}
let iconFilename: string;
if (ctr.state === 'running') {
iconFilename = 'running.svg';
} else {
iconFilename = 'stopped.svg';
}
const iconFile = this.context.asAbsolutePath(
path.join('resources', 'icons', iconFilename)
);
const iconUri = vscode.Uri.file(iconFile);
node.iconPath = { light: iconUri, dark: iconUri };

return node;
});
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function activate(context: vscode.ExtensionContext) {
}


const provider = new ContainerlabTreeDataProvider();
const provider = new ContainerlabTreeDataProvider(context);
vscode.window.registerTreeDataProvider('containerlabExplorer', provider);

context.subscriptions.push(vscode.commands.registerCommand('containerlab.refresh', () => {
Expand Down