Skip to content

Commit

Permalink
PORT - variable context (#4770)
Browse files Browse the repository at this point in the history
* Add new editor context for just if native notebook is active (#4762)

* update news

Co-authored-by: Ian Huff <ianhuff@LICHYOGAIOT.northamerica.corp.microsoft.com>
  • Loading branch information
IanMatthewHuff and Ian Huff authored Feb 11, 2021
1 parent ed32da6 commit 26bde57
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
([#4664](https://github.com/Microsoft/vscode-jupyter/issues/4664))
1. Add notebook codicon for Juypter viewContainer.
([#4538](https://github.com/Microsoft/vscode-jupyter/issues/4538))
1. Allow options to show native variable view only when looking at native notebooks.
([#4761](https://github.com/Microsoft/vscode-jupyter/issues/4761))

### Code Health

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
"dark": "resources/dark/variable_explorer.svg"
},
"category": "Jupyter",
"enablement": "!jupyter.variableViewVisible"
"enablement": "notebookViewType == jupyter-notebook && !jupyter.variableViewVisible"
}
],
"menus": {
Expand Down Expand Up @@ -1294,7 +1294,7 @@
"command": "jupyter.openVariableView",
"title": "%jupyter.command.jupyter.openVariableView.title%",
"category": "Jupyter",
"when": "jupyter.isnativeactive"
"when": "notebookViewType == jupyter-notebook"
},
{
"command": "jupyter.selectNativeJupyterUriFromToolBar",
Expand Down Expand Up @@ -1839,7 +1839,7 @@
"type": "webview",
"id": "jupyterViewVariables",
"name": "Variables",
"when": "jupyter.isnativeactive"
"when": "jupyter.isvscodenotebookactive"
}
]
}
Expand Down
10 changes: 10 additions & 0 deletions src/client/datascience/commands/activeEditorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class ActiveEditorContextService implements IExtensionSingleActivationSer
private isNotebookTrusted: ContextKey;
private isPythonFileActive: boolean = false;
private isPythonNotebook: ContextKey;
private isVSCodeNotebookActive: ContextKey;
constructor(
@inject(IInteractiveWindowProvider) private readonly interactiveProvider: IInteractiveWindowProvider,
@inject(INotebookEditorProvider) private readonly notebookEditorProvider: INotebookEditorProvider,
Expand Down Expand Up @@ -82,6 +83,7 @@ export class ActiveEditorContextService implements IExtensionSingleActivationSer
this.hasNativeNotebookCells = new ContextKey(EditorContexts.HaveNativeCells, this.commandManager);
this.isNotebookTrusted = new ContextKey(EditorContexts.IsNotebookTrusted, this.commandManager);
this.isPythonNotebook = new ContextKey(EditorContexts.IsPythonNotebook, this.commandManager);
this.isVSCodeNotebookActive = new ContextKey(EditorContexts.IsVSCodeNotebookActive, this.commandManager);
}
public dispose() {
this.disposables.forEach((item) => item.dispose());
Expand Down Expand Up @@ -122,6 +124,14 @@ export class ActiveEditorContextService implements IExtensionSingleActivationSer
}
private onDidChangeActiveNotebookEditor(e?: INotebookEditor) {
this.nativeContext.set(!!e).ignoreErrors();

// jupyter.isnativeactive is set above, but also set jupyter.isvscodenotebookactive
// if the active document is also a vscode document
if (e && e.type === 'native') {
this.isVSCodeNotebookActive.set(true).ignoreErrors();
} else {
this.isVSCodeNotebookActive.set(false).ignoreErrors();
}
this.isNotebookTrusted.set(e?.model?.isTrusted === true).ignoreErrors();
this.isPythonNotebook.set(isPythonNotebook(e?.model?.metadata)).ignoreErrors();
this.updateMergedContexts();
Expand Down
1 change: 1 addition & 0 deletions src/client/datascience/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export namespace EditorContexts {
export const CanRestartNotebookKernel = 'jupyter.notebookeditor.canrestartNotebookkernel';
export const CanInterruptNotebookKernel = 'jupyter.notebookeditor.canInterruptNotebookKernel';
export const IsPythonNotebook = 'jupyter.ispythonnotebook';
export const IsVSCodeNotebookActive = 'jupyter.isvscodenotebookactive';
}

export namespace RegExpValues {
Expand Down

0 comments on commit 26bde57

Please sign in to comment.