Skip to content

Commit

Permalink
Merge pull request #24 from srl-labs/fix-21
Browse files Browse the repository at this point in the history
Fix Selected lab status turn grey on selection
  • Loading branch information
FloSch62 authored Jan 26, 2025
2 parents 914a3a6 + 6c97dcc commit ccfae7e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
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

0 comments on commit ccfae7e

Please sign in to comment.