Skip to content

Commit 3374772

Browse files
committed
add select and selected feedback
1 parent b4748cc commit 3374772

5 files changed

Lines changed: 61 additions & 11 deletions

File tree

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@
193193
"category": "Python",
194194
"icon": "$(check)"
195195
},
196+
{
197+
"command": "python-envs.setEnvSelected",
198+
"title": "%python-envs.setEnvSelected.title%",
199+
"category": "Python",
200+
"icon": "$(pass-filled)"
201+
},
196202
{
197203
"command": "python-envs.remove",
198204
"title": "%python-envs.remove.title%",
@@ -333,6 +339,10 @@
333339
"command": "python-envs.setEnv",
334340
"when": "false"
335341
},
342+
{
343+
"command": "python-envs.setEnvSelected",
344+
"when": "false"
345+
},
336346
{
337347
"command": "python-envs.remove",
338348
"when": "false"
@@ -439,7 +449,12 @@
439449
{
440450
"command": "python-envs.setEnv",
441451
"group": "inline",
442-
"when": "view == env-managers && viewItem =~ /.*pythonEnvironment.*/"
452+
"when": "view == env-managers && viewItem =~ /.*pythonEnvironment.*/ && viewItem =~ /^((?!selected).)*$/"
453+
},
454+
{
455+
"command": "python-envs.setEnvSelected",
456+
"group": "inline",
457+
"when": "view == env-managers && viewItem =~ /.*pythonEnvironment.*/ && viewItem =~ /.*selected.*/"
443458
},
444459
{
445460
"command": "python-envs.createTerminal",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"python-envs.createAny.title": "Create Environment",
2929
"python-envs.set.title": "Set Project Environment",
3030
"python-envs.setEnv.title": "Set As Project Environment",
31+
"python-envs.setEnvSelected.title": "Set!",
3132
"python-envs.remove.title": "Delete Environment",
3233
"python-envs.refreshAllManagers.title": "Refresh All Environment Managers",
3334
"python-envs.refreshPackages.title": "Refresh Packages List",

src/extension.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import { ProjectView } from './features/views/projectView';
6666
import { PythonStatusBarImpl } from './features/views/pythonStatusBar';
6767
import { updateViewsAndStatus } from './features/views/revealHandler';
6868
import { TemporaryStateManager } from './features/views/temporaryStateManager';
69-
import { ProjectItem } from './features/views/treeViewItems';
69+
import { ProjectItem, PythonEnvTreeItem } from './features/views/treeViewItems';
7070
import {
7171
collectEnvironmentInfo,
7272
getEnvManagerAndPackageManagerConfigLevels,
@@ -229,6 +229,12 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
229229
}),
230230
commands.registerCommand('python-envs.setEnv', async (item) => {
231231
await setEnvironmentCommand(item, envManagers, projectManager);
232+
if (item instanceof PythonEnvTreeItem) {
233+
temporaryStateManager.setState(item.environment.envId.id, 'selected');
234+
}
235+
}),
236+
commands.registerCommand('python-envs.setEnvSelected', async () => {
237+
// No-op: This command is just for showing the feedback icon
232238
}),
233239
commands.registerCommand('python-envs.setEnvManager', async () => {
234240
await setEnvManagerCommand(envManagers, projectManager);

src/features/views/envManagersView.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from './treeViewItems';
2525

2626
const COPIED_STATE = 'copied';
27+
const SELECTED_STATE = 'selected';
2728

2829
export class EnvManagerView implements TreeDataProvider<EnvTreeItem>, Disposable {
2930
private treeView: TreeView<EnvTreeItem>;
@@ -91,14 +92,27 @@ export class EnvManagerView implements TreeDataProvider<EnvTreeItem>, Disposable
9192
getTreeItem(element: EnvTreeItem): TreeItem | Thenable<TreeItem> {
9293
if (element.kind === EnvTreeItemKind.environment && element instanceof PythonEnvTreeItem) {
9394
const itemId = element.environment.envId.id;
94-
const currentContext = element.treeItem.contextValue ?? '';
95-
if (this.stateManager?.hasState(itemId, COPIED_STATE)) {
95+
let currentContext = element.treeItem.contextValue ?? '';
96+
97+
// Handle copied state
98+
if (this.stateManager.hasState(itemId, COPIED_STATE)) {
9699
if (!currentContext.includes(COPIED_STATE)) {
97-
element.treeItem.contextValue = currentContext + COPIED_STATE + ';';
100+
currentContext = currentContext + COPIED_STATE + ';';
98101
}
99102
} else if (currentContext.includes(COPIED_STATE)) {
100-
element.treeItem.contextValue = currentContext.replace(COPIED_STATE + ';', '');
103+
currentContext = currentContext.replace(COPIED_STATE + ';', '');
101104
}
105+
106+
// Handle selected state
107+
if (this.stateManager.hasState(itemId, SELECTED_STATE)) {
108+
if (!currentContext.includes(SELECTED_STATE)) {
109+
currentContext = currentContext + SELECTED_STATE + ';';
110+
}
111+
} else if (currentContext.includes(SELECTED_STATE)) {
112+
currentContext = currentContext.replace(SELECTED_STATE + ';', '');
113+
}
114+
115+
element.treeItem.contextValue = currentContext;
102116
}
103117
return element.treeItem;
104118
}

src/features/views/projectView.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from './treeViewItems';
2828

2929
const COPIED_STATE = 'copied';
30+
const SELECTED_STATE = 'selected';
3031

3132
export class ProjectView implements TreeDataProvider<ProjectTreeItem> {
3233
private treeView: TreeView<ProjectTreeItem>;
@@ -145,7 +146,7 @@ export class ProjectView implements TreeDataProvider<ProjectTreeItem> {
145146
if (element.kind === ProjectTreeItemKind.project && element instanceof ProjectItem) {
146147
const itemId = element.project.uri.fsPath;
147148
const currentContext = element.treeItem.contextValue ?? '';
148-
if (this.stateManager?.hasState(itemId, COPIED_STATE)) {
149+
if (this.stateManager.hasState(itemId, COPIED_STATE)) {
149150
if (!currentContext.includes(COPIED_STATE)) {
150151
element.treeItem.contextValue = currentContext + ';' + COPIED_STATE;
151152
}
@@ -154,14 +155,27 @@ export class ProjectView implements TreeDataProvider<ProjectTreeItem> {
154155
}
155156
} else if (element.kind === ProjectTreeItemKind.environment && element instanceof ProjectEnvironment) {
156157
const itemId = element.environment.envId.id;
157-
const currentContext = element.treeItem.contextValue ?? '';
158-
if (this.stateManager?.hasState(itemId, COPIED_STATE)) {
158+
let currentContext = element.treeItem.contextValue ?? '';
159+
160+
// Handle copied state
161+
if (this.stateManager.hasState(itemId, COPIED_STATE)) {
159162
if (!currentContext.includes(COPIED_STATE)) {
160-
element.treeItem.contextValue = currentContext + ';' + COPIED_STATE;
163+
currentContext = currentContext + ';' + COPIED_STATE;
161164
}
162165
} else if (currentContext.includes(COPIED_STATE)) {
163-
element.treeItem.contextValue = currentContext.replace(';' + COPIED_STATE, '');
166+
currentContext = currentContext.replace(';' + COPIED_STATE, '');
164167
}
168+
169+
// Handle selected state
170+
if (this.stateManager.hasState(itemId, SELECTED_STATE)) {
171+
if (!currentContext.includes(SELECTED_STATE)) {
172+
currentContext = currentContext + ';' + SELECTED_STATE;
173+
}
174+
} else if (currentContext.includes(SELECTED_STATE)) {
175+
currentContext = currentContext.replace(';' + SELECTED_STATE, '');
176+
}
177+
178+
element.treeItem.contextValue = currentContext;
165179
}
166180
return element.treeItem;
167181
}

0 commit comments

Comments
 (0)