From f5331e3d697afec583f5aa9ae1a796bdc035d549 Mon Sep 17 00:00:00 2001 From: rajeshka Date: Mon, 11 Oct 2021 09:47:25 -0700 Subject: [PATCH] Added code to enable disable split cell icon (#17331) * Added code to enable diable split cell icon * adding back the deleted code * refactored * minimized lines * simplified code * minor change * minor change * Addressed PR * Addressed PR * removing unused enum value --- .../contrib/notebook/browser/cellToolbarActions.ts | 7 ++++++- .../notebook/browser/cellViews/cellToolbar.component.ts | 2 ++ src/sql/workbench/services/notebook/browser/models/cell.ts | 7 +++++++ .../services/notebook/browser/models/modelInterfaces.ts | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/sql/workbench/contrib/notebook/browser/cellToolbarActions.ts b/src/sql/workbench/contrib/notebook/browser/cellToolbarActions.ts index 5247ebeadc..29c42ec2c8 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellToolbarActions.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellToolbarActions.ts @@ -17,7 +17,7 @@ import Severity from 'vs/base/common/severity'; import { INotebookService } from 'sql/workbench/services/notebook/browser/notebookService'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; -import { MoveDirection } from 'sql/workbench/services/notebook/browser/models/modelInterfaces'; +import { CellEditModes, MoveDirection } from 'sql/workbench/services/notebook/browser/models/modelInterfaces'; const moreActionsLabel = localize('moreActionsLabel', "More"); export class EditCellAction extends ToggleableAction { @@ -78,6 +78,11 @@ export class SplitCellAction extends CellActionBase { context.model?.splitCell(context.cell.cellType, this.notebookService, index); return Promise.resolve(); } + public setListener(context: CellContext) { + this._register(context.cell.onCurrentEditModeChanged(currentMode => { + this.enabled = currentMode === CellEditModes.WYSIWYG ? false : true; + })); + } } export class MoveCellAction extends CellActionBase { diff --git a/src/sql/workbench/contrib/notebook/browser/cellViews/cellToolbar.component.ts b/src/sql/workbench/contrib/notebook/browser/cellViews/cellToolbar.component.ts index f6b0f6537c..7dae5bdf71 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/cellToolbar.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/cellToolbar.component.ts @@ -60,6 +60,8 @@ export class CellToolbarComponent { this._actionBar.context = context; let splitCellButton = this.instantiationService.createInstance(SplitCellAction, 'notebook.SplitCellAtCursor', this.buttonSplitCell, 'masked-icon icon-split-cell'); + splitCellButton.setListener(context); + splitCellButton.enabled = this.cellModel.cellType !== 'markdown'; let addCellsButton = this.instantiationService.createInstance(AddCellAction, 'notebook.AddCodeCell', localize('codeCellsPreview', "Add cell"), 'masked-pseudo code'); diff --git a/src/sql/workbench/services/notebook/browser/models/cell.ts b/src/sql/workbench/services/notebook/browser/models/cell.ts index 72a3415383..a33dc019d9 100644 --- a/src/sql/workbench/services/notebook/browser/models/cell.ts +++ b/src/sql/workbench/services/notebook/browser/models/cell.ts @@ -58,6 +58,7 @@ export class CellModel extends Disposable implements ICellModel { private _onTableUpdated = new Emitter(); private _onCellModeChanged = new Emitter(); private _onExecutionStateChanged = new Emitter(); + private _onCurrentEditModeChanged = new Emitter(); private _isTrusted: boolean; private _active: boolean; private _hover: boolean; @@ -382,6 +383,10 @@ export class CellModel extends Disposable implements ICellModel { return this._onExecutionStateChanged.event; } + public get onCurrentEditModeChanged(): Event { + return this._onCurrentEditModeChanged.event; + } + private fireExecutionStateChanged(): void { this._onExecutionStateChanged.fire(this.executionState); } @@ -416,6 +421,7 @@ export class CellModel extends Disposable implements ICellModel { public set showPreview(val: boolean) { this._showPreview = val; this._onCellPreviewChanged.fire(this._showPreview); + this._onCurrentEditModeChanged.fire(this.currentMode); } public get showMarkdown(): boolean { @@ -425,6 +431,7 @@ export class CellModel extends Disposable implements ICellModel { public set showMarkdown(val: boolean) { this._showMarkdown = val; this._onCellMarkdownChanged.fire(this._showMarkdown); + this._onCurrentEditModeChanged.fire(this.currentMode); } public get defaultTextEditMode(): string { diff --git a/src/sql/workbench/services/notebook/browser/models/modelInterfaces.ts b/src/sql/workbench/services/notebook/browser/models/modelInterfaces.ts index 2dba892370..979cd5d47d 100644 --- a/src/sql/workbench/services/notebook/browser/models/modelInterfaces.ts +++ b/src/sql/workbench/services/notebook/browser/models/modelInterfaces.ts @@ -540,6 +540,7 @@ export interface ICellModel { cellSourceChanged: boolean; readonly savedConnectionName: string | undefined; attachments: nb.ICellAttachments | undefined; + readonly onCurrentEditModeChanged: Event; readonly currentMode: CellEditModes; /** * Adds image as an attachment to cell metadata