Clear invalid taskbar actions when changing notebook providers. (#20446)

This commit is contained in:
Cory Rivera
2022-08-24 12:01:41 -07:00
committed by GitHub
parent 5f04de6f1c
commit 1a094ba6a9
2 changed files with 16 additions and 25 deletions

View File

@@ -162,4 +162,7 @@ export class Taskbar {
this.actionBar.dispose(); this.actionBar.dispose();
} }
public clear(): void {
this.actionBar.clear();
}
} }

View File

@@ -26,7 +26,7 @@ import { IConnectionManagementService } from 'sql/platform/connection/common/con
import { INotebookService, INotebookParams, INotebookEditor, INotebookSection, INavigationProvider, ICellEditorProvider, NotebookRange } from 'sql/workbench/services/notebook/browser/notebookService'; import { INotebookService, INotebookParams, INotebookEditor, INotebookSection, INavigationProvider, ICellEditorProvider, NotebookRange } from 'sql/workbench/services/notebook/browser/notebookService';
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel'; import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
import { Deferred } from 'sql/base/common/promise'; import { Deferred } from 'sql/base/common/promise';
import { Taskbar } from 'sql/base/browser/ui/taskbar/taskbar'; import { ITaskbarContent, Taskbar } from 'sql/base/browser/ui/taskbar/taskbar';
import { AddCellAction, KernelsDropdown, AttachToDropdown, TrustedAction, RunAllCellsAction, ClearAllOutputsAction, CollapseCellsAction, RunParametersAction, NotebookViewsActionProvider } from 'sql/workbench/contrib/notebook/browser/notebookActions'; import { AddCellAction, KernelsDropdown, AttachToDropdown, TrustedAction, RunAllCellsAction, ClearAllOutputsAction, CollapseCellsAction, RunParametersAction, NotebookViewsActionProvider } from 'sql/workbench/contrib/notebook/browser/notebookActions';
import { DropdownMenuActionViewItem } from 'sql/base/browser/ui/buttonMenu/buttonMenu'; import { DropdownMenuActionViewItem } from 'sql/base/browser/ui/buttonMenu/buttonMenu';
import { INotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes'; import { INotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes';
@@ -81,7 +81,6 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
private _modelReadyDeferred = new Deferred<NotebookModel>(); private _modelReadyDeferred = new Deferred<NotebookModel>();
private _trustedAction: TrustedAction; private _trustedAction: TrustedAction;
private _runAllCellsAction: RunAllCellsAction; private _runAllCellsAction: RunAllCellsAction;
private _providerRelatedActions: IAction[] = [];
private _scrollTop: number; private _scrollTop: number;
private _navProvider: INavigationProvider; private _navProvider: INavigationProvider;
private navigationResult: nb.NavigationResult; private navigationResult: nb.NavigationResult;
@@ -89,6 +88,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
private _onScroll = new Emitter<void>(); private _onScroll = new Emitter<void>();
// Don't show the right hand toolbar actions if the notebook is created in a diff editor. // Don't show the right hand toolbar actions if the notebook is created in a diff editor.
private _showToolbarActions: boolean = this._notebookParams.input.showActions; private _showToolbarActions: boolean = this._notebookParams.input.showActions;
private _initialToolbarContent: ITaskbarContent[];
constructor( constructor(
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
@@ -476,11 +476,6 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
} }
private handleProviderIdChanged(providerId: string) { private handleProviderIdChanged(providerId: string) {
// If there are any actions that were related to the previous provider,
// disable them in the actionBar
this._providerRelatedActions.forEach(action => {
action.enabled = false;
});
this.setContextKeyServiceWithProviderId(providerId); this.setContextKeyServiceWithProviderId(providerId);
this.fillInActionsForCurrentContext(); this.fillInActionsForCurrentContext();
} }
@@ -576,7 +571,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
} }
if (this._showToolbarActions) { if (this._showToolbarActions) {
this._actionBar.setContent([ this._initialToolbarContent = [
{ element: buttonDropdownContainer }, { element: buttonDropdownContainer },
{ action: this._runAllCellsAction }, { action: this._runAllCellsAction },
{ element: Taskbar.createTaskbarSeparator() }, { element: Taskbar.createTaskbarSeparator() },
@@ -588,16 +583,17 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
{ action: clearResultsButton }, { action: clearResultsButton },
{ action: this._trustedAction }, { action: this._trustedAction },
{ action: runParametersAction }, { action: runParametersAction },
]); ];
} else { } else {
this._actionBar.setContent([ this._initialToolbarContent = [
{ element: buttonDropdownContainer }, { element: buttonDropdownContainer },
{ action: this._runAllCellsAction }, { action: this._runAllCellsAction },
{ element: Taskbar.createTaskbarSeparator() }, { element: Taskbar.createTaskbarSeparator() },
{ element: kernelContainer }, { element: kernelContainer },
{ element: attachToContainer }, { element: attachToContainer },
]); ];
} }
this._actionBar.setContent(this._initialToolbarContent);
} }
protected initNavSection(): void { protected initNavSection(): void {
@@ -664,7 +660,12 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
let notebookBarMenu = this.menuService.createMenu(MenuId.NotebookToolbar, this.contextKeyService); let notebookBarMenu = this.menuService.createMenu(MenuId.NotebookToolbar, this.contextKeyService);
let groups = notebookBarMenu.getActions({ arg: null, shouldForwardArgs: true }); let groups = notebookBarMenu.getActions({ arg: null, shouldForwardArgs: true });
fillInActions(groups, { primary, secondary }, false, g => g === '', Number.MAX_SAFE_INTEGER, (action: SubmenuAction, group: string, groupSize: number) => group === undefined || group === ''); fillInActions(groups, { primary, secondary }, false, g => g === '', Number.MAX_SAFE_INTEGER, (action: SubmenuAction, group: string, groupSize: number) => group === undefined || group === '');
this.addPrimaryContributedActions(primary);
this._actionBar.clear();
this._actionBar.setContent(this._initialToolbarContent);
for (let action of primary) {
this._actionBar.addAction(action);
}
} }
} }
@@ -674,19 +675,6 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
} }
} }
private addPrimaryContributedActions(primary: IAction[]) {
for (let action of primary) {
// Need to ensure that we don't add the same action multiple times
let foundIndex = this._providerRelatedActions.findIndex(act => act.id === action.id);
if (foundIndex < 0) {
this._actionBar.addAction(action);
this._providerRelatedActions.push(action);
} else {
this._providerRelatedActions[foundIndex].enabled = true;
}
}
}
private setContextKeyServiceWithProviderId(providerId: string) { private setContextKeyServiceWithProviderId(providerId: string) {
let provider = new RawContextKey<string>('providerId', providerId); let provider = new RawContextKey<string>('providerId', providerId);
provider.bindTo(this.contextKeyService); provider.bindTo(this.contextKeyService);