From 4fee0210f68bad1916698740e089c18aad067a06 Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Fri, 11 Sep 2020 16:29:09 -0700 Subject: [PATCH] Notebooks: Add setting for default text cell edit behavior (#12245) * Add setting for default text cell edit behavior * string updates --- .../cellViews/markdownToolbar.component.ts | 12 +++---- .../browser/cellViews/textCell.component.ts | 6 ++-- .../notebook/browser/notebook.contribution.ts | 5 +++ .../services/notebook/browser/models/cell.ts | 36 ++++++++++++++----- .../browser/models/modelInterfaces.ts | 1 + 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts b/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts index 27223968a7..a3afe4f2dc 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts @@ -38,9 +38,9 @@ export class MarkdownToolbarComponent { public optionHeading3 = localize('optionHeading3', "Heading 3"); public optionParagraph = localize('optionParagraph', "Paragraph"); - public textViewButton = localize('textViewButton', "View as Text"); - public splitViewButton = localize('splitViewButton', "View as Split"); - public markdownButton = localize('markdownButton', "View as Markdown"); + public richTextViewButton = localize('richTextViewButton', "Rich Text View"); + public splitViewButton = localize('splitViewButton', "Split View"); + public markdownViewButton = localize('markdownViewButton', "Markdown View"); private _taskbarContent: Array; private _wysiwygTaskbarContent: Array; @@ -77,9 +77,9 @@ export class MarkdownToolbarComponent { let heading3 = this._instantiationService.createInstance(TransformMarkdownAction, 'notebook.heading3', this.optionHeading3, 'heading 3', this.optionHeading3, this.cellModel, MarkdownButtonType.HEADING3); let paragraph = this._instantiationService.createInstance(TransformMarkdownAction, 'notebook.paragraph', this.optionParagraph, 'paragraph', this.optionParagraph, this.cellModel, MarkdownButtonType.PARAGRAPH); - this._toggleTextViewAction = this._instantiationService.createInstance(ToggleViewAction, 'notebook.toggleTextView', '', 'masked-icon show-text active', this.textViewButton, true, false); - this._toggleSplitViewAction = this._instantiationService.createInstance(ToggleViewAction, 'notebook.toggleSplitView', '', 'masked-icon split-toggle-on', this.splitViewButton, true, true); - this._toggleMarkdownViewAction = this._instantiationService.createInstance(ToggleViewAction, 'notebook.toggleMarkdownView', '', 'masked-icon show-markdown', this.markdownButton, false, true); + this._toggleTextViewAction = this._instantiationService.createInstance(ToggleViewAction, 'notebook.toggleTextView', '', this.cellModel.defaultToWYSIWYG ? 'masked-icon show-text active' : 'masked-icon show-text', this.richTextViewButton, true, false); + this._toggleSplitViewAction = this._instantiationService.createInstance(ToggleViewAction, 'notebook.toggleSplitView', '', this.cellModel.defaultToWYSIWYG ? 'masked-icon split-toggle-on' : 'masked-icon split-toggle-on active', this.splitViewButton, true, true); + this._toggleMarkdownViewAction = this._instantiationService.createInstance(ToggleViewAction, 'notebook.toggleMarkdownView', '', 'masked-icon show-markdown', this.markdownViewButton, false, true); let taskbar = this.mdtoolbar.nativeElement; this._actionBar = new Taskbar(taskbar); diff --git a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts index 8568b2d169..81f374e53a 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts @@ -217,9 +217,9 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges { this._lastTrustedMode = this.cellModel.trustedMode; if ((!cellModelSourceJoined) && !this.isEditMode) { if (this.doubleClickEditEnabled) { - this._content = localize('doubleClickEdit', "Double-click to edit"); + this._content = localize('doubleClickEdit', "Double-click to edit"); } else { - this._content = localize('addContent', "Add content here..."); + this._content = localize('addContent', "Add content here..."); } } else { this._content = this.cellModel.source[0] === '' ? '

 

' : this.cellModel.source; @@ -280,6 +280,8 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges { if (!this.isEditMode) { this.cellModel.showPreview = true; this.cellModel.showMarkdown = false; + } else { + this.markdownMode = this.cellModel.showMarkdown; } this.updatePreview(); this._changeRef.detectChanges(); diff --git a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts index d8f8298380..41fdf61e72 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -225,6 +225,11 @@ configurationRegistry.registerConfiguration({ 'type': 'boolean', 'default': true, 'description': localize('notebook.enableDoubleClickEdit', "Enable double click to edit for text cells in notebooks") + }, + 'notebook.setRichTextViewByDefault': { + 'type': 'boolean', + 'default': true, + 'description': localize('notebook.setRichTextViewByDefault', "Set Rich Text View mode by default for text cells") } } }); diff --git a/src/sql/workbench/services/notebook/browser/models/cell.ts b/src/sql/workbench/services/notebook/browser/models/cell.ts index ab2058acb5..708bb8f63b 100644 --- a/src/sql/workbench/services/notebook/browser/models/cell.ts +++ b/src/sql/workbench/services/notebook/browser/models/cell.ts @@ -68,6 +68,7 @@ export class CellModel extends Disposable implements ICellModel { private _showMarkdown: boolean = false; private _cellSourceChanged: boolean = false; private _gridDataConversionComplete: Promise[] = []; + private _defaultToWYSIWYG: boolean; constructor(cellData: nb.ICellContents, private _options: ICellModelOptions, @@ -95,15 +96,7 @@ export class CellModel extends Disposable implements ICellModel { // if the fromJson() method was already called and _cellGuid was previously set, don't generate another UUID unnecessarily this._cellGuid = this._cellGuid || generateUuid(); this.createUri(); - if (this._configurationService) { - const allowADSCommandsKey = 'notebook.allowAzureDataStudioCommands'; - this._isCommandExecutionSettingEnabled = this._configurationService.getValue(allowADSCommandsKey); - this._register(this._configurationService.onDidChangeConfiguration(e => { - if (e.affectsConfiguration(allowADSCommandsKey)) { - this._isCommandExecutionSettingEnabled = this._configurationService.getValue(allowADSCommandsKey); - } - })); - } + this.populatePropertiesFromSettings(); } public equals(other: ICellModel) { @@ -167,6 +160,9 @@ export class CellModel extends Disposable implements ICellModel { public set isEditMode(isEditMode: boolean) { this._isEditMode = isEditMode; + if (this._isEditMode) { + this.showMarkdown = !this._defaultToWYSIWYG; + } this._onCellModeChanged.fire(this._isEditMode); // Note: this does not require a notebook update as it does not change overall state } @@ -326,6 +322,9 @@ export class CellModel extends Disposable implements ICellModel { this._onCellMarkdownChanged.fire(this._showMarkdown); } + public get defaultToWYSIWYG(): boolean { + return this._defaultToWYSIWYG; + } public get cellSourceChanged(): boolean { return this._cellSourceChanged; @@ -853,4 +852,23 @@ export class CellModel extends Disposable implements ICellModel { } this._future = undefined; } + + private populatePropertiesFromSettings() { + if (this._configurationService) { + const enableWYSIWYGByDefaultKey = 'notebook.setRichTextViewByDefault'; + this._defaultToWYSIWYG = this._configurationService.getValue(enableWYSIWYGByDefaultKey); + if (!this._defaultToWYSIWYG) { + this.showMarkdown = true; + } + const allowADSCommandsKey = 'notebook.allowAzureDataStudioCommands'; + this._isCommandExecutionSettingEnabled = this._configurationService.getValue(allowADSCommandsKey); + this._register(this._configurationService.onDidChangeConfiguration(e => { + if (e.affectsConfiguration(allowADSCommandsKey)) { + this._isCommandExecutionSettingEnabled = this._configurationService.getValue(allowADSCommandsKey); + } else if (e.affectsConfiguration(enableWYSIWYGByDefaultKey)) { + this._defaultToWYSIWYG = this._configurationService.getValue(enableWYSIWYGByDefaultKey); + } + })); + } + } } diff --git a/src/sql/workbench/services/notebook/browser/models/modelInterfaces.ts b/src/sql/workbench/services/notebook/browser/models/modelInterfaces.ts index cee9239c74..fa0f2af0c6 100644 --- a/src/sql/workbench/services/notebook/browser/models/modelInterfaces.ts +++ b/src/sql/workbench/services/notebook/browser/models/modelInterfaces.ts @@ -483,6 +483,7 @@ export interface ICellModel { isEditMode: boolean; showPreview: boolean; showMarkdown: boolean; + defaultToWYSIWYG: boolean; readonly onCellPreviewModeChanged: Event; readonly onCellMarkdownModeChanged: Event; sendChangeToNotebook(change: NotebookChangeType): void;