Fix #3928 'Clear output' in ... for markdown cells (#3935)

- Add filtering support for actions, and use for the Clear Output action
This commit is contained in:
Kevin Cunnane
2019-02-06 15:49:20 -08:00
committed by GitHub
parent a2d6955f79
commit f9fe88898d
2 changed files with 12 additions and 2 deletions

View File

@@ -22,7 +22,7 @@ import { CellTypes, CellType } from 'sql/parts/notebook/models/contracts';
import { CellModel } from 'sql/parts/notebook/models/cell'; import { CellModel } from 'sql/parts/notebook/models/cell';
export class CellToggleMoreActions { export class CellToggleMoreActions {
private _actions: Action[] = []; private _actions: CellActionBase[] = [];
private _moreActions: ActionBar; private _moreActions: ActionBar;
constructor( constructor(
@IInstantiationService private instantiationService: IInstantiationService) { @IInstantiationService private instantiationService: IInstantiationService) {
@@ -45,7 +45,8 @@ export class CellToggleMoreActions {
} }
this._moreActions = new ActionBar(moreActionsElement, { orientation: ActionsOrientation.VERTICAL }); this._moreActions = new ActionBar(moreActionsElement, { orientation: ActionsOrientation.VERTICAL });
this._moreActions.context = { target: moreActionsElement }; this._moreActions.context = { target: moreActionsElement };
this._moreActions.push(this.instantiationService.createInstance(ToggleMoreWidgetAction, this._actions, context), { icon: showIcon, label: false }); let validActions = this._actions.filter(a => a.canRun(context));
this._moreActions.push(this.instantiationService.createInstance(ToggleMoreWidgetAction, validActions, context), { icon: showIcon, label: false });
} }
else if (moreActionsElement.childNodes.length > 0) { else if (moreActionsElement.childNodes.length > 0) {
moreActionsElement.removeChild(moreActionsElement.childNodes[0]); moreActionsElement.removeChild(moreActionsElement.childNodes[0]);
@@ -110,6 +111,11 @@ export class ClearCellOutputAction extends CellActionBase {
super(id, label, undefined, notificationService); super(id, label, undefined, notificationService);
} }
public canRun(context: CellContext): boolean {
return context.cell && context.cell.cellType === CellTypes.Code;
}
doRun(context: CellContext): Promise<void> { doRun(context: CellContext): Promise<void> {
try { try {
(context.model.activeCell as CellModel).clearOutputs(); (context.model.activeCell as CellModel).clearOutputs();

View File

@@ -46,6 +46,10 @@ export abstract class CellActionBase extends Action {
super(id, label, icon); super(id, label, icon);
} }
public canRun(context: CellContext): boolean {
return true;
}
public run(context: CellContext): TPromise<boolean> { public run(context: CellContext): TPromise<boolean> {
if (hasModelAndCell(context, this.notificationService)) { if (hasModelAndCell(context, this.notificationService)) {
return TPromise.wrap(this.doRun(context).then(() => true)); return TPromise.wrap(this.doRun(context).then(() => true));