Implement Session support through the extension host (#3228)

Full plumb through of Session support. Also fixed some test issues

- Load session and get necessary information in kernels list
- Run Cell button now works as expected
- Added a ToggleAction base class which can be used for anything that switches icons. I'd still prefer to have this be dynamic and as clean as the extension classes
- Fixed account test unhandled promise rejections (caused by incorrect / invalid tests) that made it hard to see all the test run output.
This commit is contained in:
Kevin Cunnane
2018-11-16 10:35:03 -08:00
committed by GitHub
parent f3525cc555
commit 90dc788893
23 changed files with 939 additions and 212 deletions

View File

@@ -43,41 +43,82 @@ export class AddCellAction extends Action {
}
}
export class TrustedAction extends Action {
export interface IToggleableState {
baseClass?: string;
shouldToggleTooltip?: boolean;
toggleOnClass: string;
toggleOnLabel: string;
toggleOffLabel: string;
toggleOffClass: string;
isOn: boolean;
}
export abstract class ToggleableAction extends Action {
constructor(id: string, protected state: IToggleableState) {
super(id, '');
this.updateLabelAndIcon();
}
private updateLabelAndIcon() {
if (this.state.shouldToggleTooltip) {
this.tooltip = this.state.isOn ? this.state.toggleOnLabel : this.state.toggleOffLabel;
} else {
this.label = this.state.isOn ? this.state.toggleOnLabel : this.state.toggleOffLabel;
}
let classes = this.state.baseClass ? `${this.state.baseClass} ` : '';
classes += this.state.isOn ? this.state.toggleOnClass : this.state.toggleOffClass;
this.class = classes;
}
protected toggle(isOn: boolean): void {
this.state.isOn = isOn;
this.updateLabelAndIcon();
}
}
export class TrustedAction extends ToggleableAction {
// Constants
private static readonly trustLabel = localize('trustLabel', 'Trusted');
private static readonly notTrustLabel = localize('untrustLabel', 'Not Trusted');
private static readonly trustedLabel = localize('trustLabel', 'Trusted');
private static readonly notTrustedLabel = localize('untrustLabel', 'Not Trusted');
private static readonly alreadyTrustedMsg = localize('alreadyTrustedMsg', 'Notebook is already trusted.');
private static readonly trustedCssClass = 'notebook-button icon-trusted';
private static readonly notTrustedCssClass = 'notebook-button icon-notTrusted';
private static readonly baseClass = 'notebook-button';
private static readonly trustedCssClass = 'icon-trusted';
private static readonly notTrustedCssClass = 'icon-notTrusted';
// Properties
private _isTrusted: boolean = false;
public get trusted(): boolean {
return this._isTrusted;
}
public set trusted(value: boolean) {
this._isTrusted = value;
this._setClass(value ? TrustedAction.trustedCssClass : TrustedAction.notTrustedCssClass);
this._setLabel(value ? TrustedAction.trustLabel : TrustedAction.notTrustLabel);
}
constructor(
id: string,
@INotificationService private _notificationService: INotificationService
) {
super(id, TrustedAction.notTrustLabel, TrustedAction.notTrustedCssClass);
super(id, {
baseClass: TrustedAction.baseClass,
toggleOnLabel: TrustedAction.trustedLabel,
toggleOnClass: TrustedAction.trustedCssClass,
toggleOffLabel: TrustedAction.notTrustedLabel,
toggleOffClass: TrustedAction.notTrustedCssClass,
isOn: false
});
}
public get trusted(): boolean {
return this.state.isOn;
}
public set trusted(value: boolean) {
this.toggle(value);
}
public run(context: NotebookComponent): TPromise<boolean> {
let self = this;
return new TPromise<boolean>((resolve, reject) => {
try {
if (self._isTrusted) {
if (self.trusted) {
const actions: INotificationActions = { primary: [] };
self._notificationService.notify({ severity: Severity.Info, message: TrustedAction.alreadyTrustedMsg, actions });
}
else {
self.trusted = !self._isTrusted;
self.trusted = !self.trusted;
context.updateModelTrustDetails(self.trusted);
}
resolve(true);