Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76f5fd8

Browse filesBrowse files
author
Eric Snow
authored
Add an icon for the "Run Python File in Terminal" command. (#6498)
Note that I called the experiment "ShowPlayIcon".
1 parent cac8024 commit 76f5fd8
Copy full SHA for 76f5fd8

14 files changed

+288-10Lines changed: 288 additions & 10 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎experiments.json‎

Copy file name to clipboardExpand all lines: experiments.json
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,23 @@
1010
"salt": "AlwaysDisplayTestExplorer",
1111
"min": 0,
1212
"max": 20
13+
},
14+
{
15+
"name": "ShowPlayIcon - start",
16+
"salt": "ShowPlayIcon",
17+
"max": 100,
18+
"min": 80
19+
},
20+
{
21+
"name": "ShowPlayIcon - runFile",
22+
"salt": "ShowPlayIcon",
23+
"max": 80,
24+
"min": 60
25+
},
26+
{
27+
"name": "ShowPlayIcon - control",
28+
"salt": "ShowPlayIcon",
29+
"min": 0,
30+
"max": 20
1331
}
1432
]
Collapse file

‎news/1 Enhancements/5321.md‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add an icon for the "Run Python File in Terminal" command.'
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@
184184
"title": "%python.command.python.execInTerminal.title%",
185185
"category": "Python"
186186
},
187+
{
188+
"command": "python.execInTerminal-icon1",
189+
"title": "%python.command.python.execInTerminal.title%",
190+
"category": "Python",
191+
"icon": {
192+
"light": "resources/light/start.svg",
193+
"dark": "resources/dark/start.svg"
194+
}
195+
},
196+
{
197+
"command": "python.execInTerminal-icon2",
198+
"title": "%python.command.python.execInTerminal.title%",
199+
"category": "Python",
200+
"icon": {
201+
"light": "resources/light/run-file.svg",
202+
"dark": "resources/dark/run-file.svg"
203+
}
204+
},
187205
{
188206
"command": "python.setInterpreter",
189207
"title": "%python.command.python.setInterpreter.title%",
@@ -566,6 +584,20 @@
566584
"group": "Python3@3"
567585
}
568586
],
587+
"editor/title": [
588+
{
589+
"command": "python.execInTerminal-icon1",
590+
"title": "%python.command.python.execInTerminal.title%",
591+
"group": "navigation",
592+
"when": "resourceLangId == python && python.showPlayIcon1"
593+
},
594+
{
595+
"command": "python.execInTerminal-icon2",
596+
"title": "%python.command.python.execInTerminal.title%",
597+
"group": "navigation",
598+
"when": "resourceLangId == python && python.showPlayIcon2"
599+
}
600+
],
569601
"explorer/context": [
570602
{
571603
"when": "resourceLangId == python && !busyTests",
Collapse file

‎resources/dark/run-file.svg‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎resources/light/run-file.svg‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎src/client/common/application/commands.ts‎

Copy file name to clipboardExpand all lines: src/client/common/application/commands.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
7272
[Commands.Build_Workspace_Symbols]: [boolean, CancellationToken];
7373
[Commands.Sort_Imports]: [undefined, Uri];
7474
[Commands.Exec_In_Terminal]: [undefined, Uri];
75+
[Commands.Exec_In_Terminal_Icon_1]: [undefined, Uri];
76+
[Commands.Exec_In_Terminal_Icon_2]: [undefined, Uri];
7577
[Commands.Tests_ViewOutput]: [undefined, CommandSource];
7678
[Commands.Tests_Select_And_Run_File]: [undefined, CommandSource];
7779
[Commands.Tests_Run_Current_File]: [undefined, CommandSource];
Collapse file

‎src/client/common/constants.ts‎

Copy file name to clipboardExpand all lines: src/client/common/constants.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export namespace Commands {
1515
export const Set_Interpreter = 'python.setInterpreter';
1616
export const Set_ShebangInterpreter = 'python.setShebangInterpreter';
1717
export const Exec_In_Terminal = 'python.execInTerminal';
18+
export const Exec_In_Terminal_Icon_1 = 'python.execInTerminal-icon1';
19+
export const Exec_In_Terminal_Icon_2 = 'python.execInTerminal-icon2';
1820
export const Exec_Selection_In_Terminal = 'python.execSelectionInTerminal';
1921
export const Exec_Selection_In_Django_Shell = 'python.execSelectionInDjangoShell';
2022
export const Tests_View_UI = 'python.viewTestUI';
Collapse file

‎src/client/common/experimentGroups.ts‎

Copy file name to clipboardExpand all lines: src/client/common/experimentGroups.ts
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ export enum AlwaysDisplayTestExplorerGroups {
66
control = 'AlwaysDisplayTestExplorer - control',
77
experiment = 'AlwaysDisplayTestExplorer - experiment'
88
}
9+
10+
// Experiment to check whether to show the "Run Python File in Terminal" icon.
11+
export enum ShowPlayIcon {
12+
control = 'ShowPlayIcon - control',
13+
icon1 = 'ShowPlayIcon - start',
14+
icon2 = 'ShowPlayIcon - runFile'
15+
}
Collapse file

‎src/client/terminals/activation.ts‎

Copy file name to clipboardExpand all lines: src/client/terminals/activation.ts
+34-2Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,43 @@
55

66
import { inject, injectable } from 'inversify';
77
import { Terminal } from 'vscode';
8-
import { ITerminalManager, IWorkspaceService } from '../common/application/types';
8+
import { IExtensionActivationService } from '../activation/types';
9+
import {
10+
ICommandManager, ITerminalManager, IWorkspaceService
11+
} from '../common/application/types';
12+
import { ShowPlayIcon } from '../common/experimentGroups';
913
import { ITerminalActivator } from '../common/terminal/types';
10-
import { IDisposable, IDisposableRegistry } from '../common/types';
14+
import {
15+
IDisposable, IDisposableRegistry, IExperimentsManager, Resource
16+
} from '../common/types';
17+
import { noop } from '../common/utils/misc';
1118
import { ITerminalAutoActivation } from './types';
1219

20+
@injectable()
21+
export class ExtensionActivationForTerminalActivation implements IExtensionActivationService {
22+
constructor(
23+
@inject(IExperimentsManager) private experiments: IExperimentsManager,
24+
@inject(ICommandManager) private commands: ICommandManager
25+
) { }
26+
public async activate(_resource: Resource): Promise<void> {
27+
this.checkExperiments();
28+
}
29+
30+
// Nothing after this point is part of the IExtensionActivationService interface.
31+
32+
public checkExperiments() {
33+
if (this.experiments.inExperiment(ShowPlayIcon.icon1)) {
34+
this.commands.executeCommand('setContext', 'python.showPlayIcon1', true)
35+
.then(noop, noop);
36+
} else if (this.experiments.inExperiment(ShowPlayIcon.icon2)) {
37+
this.commands.executeCommand('setContext', 'python.showPlayIcon2', true)
38+
.then(noop, noop);
39+
} else {
40+
this.experiments.sendTelemetryIfInExperiment(ShowPlayIcon.control);
41+
}
42+
}
43+
}
44+
1345
@injectable()
1446
export class TerminalAutoActivation implements ITerminalAutoActivation {
1547
private handler?: IDisposable;
Collapse file

‎src/client/terminals/codeExecution/codeExecutionManager.ts‎

Copy file name to clipboardExpand all lines: src/client/terminals/codeExecution/codeExecutionManager.ts
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@ export class CodeExecutionManager implements ICodeExecutionManager {
3434
}
3535

3636
public registerCommands() {
37-
this.disposableRegistry.push(this.commandManager.registerCommand(Commands.Exec_In_Terminal, this.executeFileInTerminal.bind(this)));
37+
[
38+
Commands.Exec_In_Terminal,
39+
Commands.Exec_In_Terminal_Icon_1,
40+
Commands.Exec_In_Terminal_Icon_2
41+
].forEach(cmd => {
42+
this.disposableRegistry.push(
43+
this.commandManager.registerCommand(
44+
// tslint:disable-next-line:no-any
45+
cmd as any,
46+
this.executeFileInTerminal.bind(this)
47+
)
48+
);
49+
});
3850
this.disposableRegistry.push(this.commandManager.registerCommand(Commands.Exec_Selection_In_Terminal, this.executeSelectionInTerminal.bind(this)));
3951
this.disposableRegistry.push(this.commandManager.registerCommand(Commands.Exec_Selection_In_Django_Shell, this.executeSelectionInDjangoShell.bind(this)));
4052
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.