Fix toggle more actions staying visible, and clickable issues (#3949)

- Fixed so it's now invisible instead of empty when not selected.
 - This fixes clickability and issue where it stayed visible in 1 fix
- Also fixed cell output action which used active cell instead of context cell.
This commit is contained in:
Kevin Cunnane
2019-02-07 09:35:58 -08:00
committed by GitHub
parent 5a0100757f
commit 40e0d5cfbf
5 changed files with 39 additions and 26 deletions

View File

@@ -5,14 +5,12 @@
import { ElementRef } from '@angular/core';
import { nb } from 'sqlops';
import { localize } from 'vs/nls';
import { Action } from 'vs/base/common/actions';
import { ActionBar, ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar';
import { getErrorMessage } from 'vs/base/common/errors';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import * as DOM from 'vs/base/browser/dom';
import { ICellModel } from 'sql/parts/notebook/models/modelInterfaces';
import { CellContext, CellActionBase } from 'sql/parts/notebook/cellViews/codeActions';
@@ -21,9 +19,12 @@ import { ToggleMoreWidgetAction } from 'sql/parts/dashboard/common/actions';
import { CellTypes, CellType } from 'sql/parts/notebook/models/contracts';
import { CellModel } from 'sql/parts/notebook/models/cell';
export const HIDDEN_CLASS ='actionhidden';
export class CellToggleMoreActions {
private _actions: CellActionBase[] = [];
private _moreActions: ActionBar;
private _moreActionsElement: HTMLElement;
constructor(
@IInstantiationService private instantiationService: IInstantiationService) {
this._actions.push(
@@ -36,20 +37,26 @@ export class CellToggleMoreActions {
);
}
public toggle(showIcon: boolean, elementRef: ElementRef, model: NotebookModel, cellModel: ICellModel) {
public onInit(elementRef: ElementRef, model: NotebookModel, cellModel: ICellModel) {
let context = new CellContext(model,cellModel);
let moreActionsElement = <HTMLElement>elementRef.nativeElement;
if (showIcon) {
if (moreActionsElement.childNodes.length > 0) {
moreActionsElement.removeChild(moreActionsElement.childNodes[0]);
}
this._moreActions = new ActionBar(moreActionsElement, { orientation: ActionsOrientation.VERTICAL });
this._moreActions.context = { target: moreActionsElement };
let validActions = this._actions.filter(a => a.canRun(context));
this._moreActions.push(this.instantiationService.createInstance(ToggleMoreWidgetAction, validActions, context), { icon: showIcon, label: false });
this._moreActionsElement = <HTMLElement>elementRef.nativeElement;
if (this._moreActionsElement.childNodes.length > 0) {
this._moreActionsElement.removeChild(this._moreActionsElement.childNodes[0]);
}
else if (moreActionsElement.childNodes.length > 0) {
moreActionsElement.removeChild(moreActionsElement.childNodes[0]);
this._moreActions = new ActionBar(this._moreActionsElement, { orientation: ActionsOrientation.VERTICAL, isMenu: true });
this._moreActions.context = { target: this._moreActionsElement };
let validActions = this._actions.filter(a => a.canRun(context));
this._moreActions.push(this.instantiationService.createInstance(ToggleMoreWidgetAction, validActions, context), { icon: true, label: false });
}
public toggleVisible(visible: boolean): void {
if (!this._moreActionsElement) {
return;
}
if (visible) {
DOM.addClass(this._moreActionsElement, HIDDEN_CLASS);
} else {
DOM.removeClass(this._moreActionsElement, HIDDEN_CLASS);
}
}
}
@@ -118,7 +125,10 @@ export class ClearCellOutputAction extends CellActionBase {
doRun(context: CellContext): Promise<void> {
try {
(context.model.activeCell as CellModel).clearOutputs();
let cell = context.cell || context.model.activeCell;
if (cell) {
(cell as CellModel).clearOutputs();
}
} catch (error) {
let message = getErrorMessage(error);