Notebooks: Add setting for default text cell edit behavior (#12245)

* Add setting for default text cell edit behavior

* string updates
This commit is contained in:
Chris LaFreniere
2020-09-11 16:29:09 -07:00
committed by GitHub
parent f99adf3de4
commit 4fee0210f6
5 changed files with 43 additions and 17 deletions

View File

@@ -38,9 +38,9 @@ export class MarkdownToolbarComponent {
public optionHeading3 = localize('optionHeading3', "Heading 3"); public optionHeading3 = localize('optionHeading3', "Heading 3");
public optionParagraph = localize('optionParagraph', "Paragraph"); public optionParagraph = localize('optionParagraph', "Paragraph");
public textViewButton = localize('textViewButton', "View as Text"); public richTextViewButton = localize('richTextViewButton', "Rich Text View");
public splitViewButton = localize('splitViewButton', "View as Split"); public splitViewButton = localize('splitViewButton', "Split View");
public markdownButton = localize('markdownButton', "View as Markdown"); public markdownViewButton = localize('markdownViewButton', "Markdown View");
private _taskbarContent: Array<ITaskbarContent>; private _taskbarContent: Array<ITaskbarContent>;
private _wysiwygTaskbarContent: Array<ITaskbarContent>; private _wysiwygTaskbarContent: Array<ITaskbarContent>;
@@ -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 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); 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._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', '', 'masked-icon split-toggle-on', this.splitViewButton, true, true); 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.markdownButton, false, true); this._toggleMarkdownViewAction = this._instantiationService.createInstance(ToggleViewAction, 'notebook.toggleMarkdownView', '', 'masked-icon show-markdown', this.markdownViewButton, false, true);
let taskbar = <HTMLElement>this.mdtoolbar.nativeElement; let taskbar = <HTMLElement>this.mdtoolbar.nativeElement;
this._actionBar = new Taskbar(taskbar); this._actionBar = new Taskbar(taskbar);

View File

@@ -217,9 +217,9 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
this._lastTrustedMode = this.cellModel.trustedMode; this._lastTrustedMode = this.cellModel.trustedMode;
if ((!cellModelSourceJoined) && !this.isEditMode) { if ((!cellModelSourceJoined) && !this.isEditMode) {
if (this.doubleClickEditEnabled) { if (this.doubleClickEditEnabled) {
this._content = localize('doubleClickEdit', "Double-click to edit"); this._content = localize('doubleClickEdit', "<i>Double-click to edit</i>");
} else { } else {
this._content = localize('addContent', "Add content here..."); this._content = localize('addContent', "<i>Add content here...</i>");
} }
} else { } else {
this._content = this.cellModel.source[0] === '' ? '<p>&nbsp;</p>' : this.cellModel.source; this._content = this.cellModel.source[0] === '' ? '<p>&nbsp;</p>' : this.cellModel.source;
@@ -280,6 +280,8 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
if (!this.isEditMode) { if (!this.isEditMode) {
this.cellModel.showPreview = true; this.cellModel.showPreview = true;
this.cellModel.showMarkdown = false; this.cellModel.showMarkdown = false;
} else {
this.markdownMode = this.cellModel.showMarkdown;
} }
this.updatePreview(); this.updatePreview();
this._changeRef.detectChanges(); this._changeRef.detectChanges();

View File

@@ -225,6 +225,11 @@ configurationRegistry.registerConfiguration({
'type': 'boolean', 'type': 'boolean',
'default': true, 'default': true,
'description': localize('notebook.enableDoubleClickEdit', "Enable double click to edit for text cells in notebooks") '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")
} }
} }
}); });

View File

@@ -68,6 +68,7 @@ export class CellModel extends Disposable implements ICellModel {
private _showMarkdown: boolean = false; private _showMarkdown: boolean = false;
private _cellSourceChanged: boolean = false; private _cellSourceChanged: boolean = false;
private _gridDataConversionComplete: Promise<void>[] = []; private _gridDataConversionComplete: Promise<void>[] = [];
private _defaultToWYSIWYG: boolean;
constructor(cellData: nb.ICellContents, constructor(cellData: nb.ICellContents,
private _options: ICellModelOptions, 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 // if the fromJson() method was already called and _cellGuid was previously set, don't generate another UUID unnecessarily
this._cellGuid = this._cellGuid || generateUuid(); this._cellGuid = this._cellGuid || generateUuid();
this.createUri(); this.createUri();
if (this._configurationService) { this.populatePropertiesFromSettings();
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);
}
}));
}
} }
public equals(other: ICellModel) { public equals(other: ICellModel) {
@@ -167,6 +160,9 @@ export class CellModel extends Disposable implements ICellModel {
public set isEditMode(isEditMode: boolean) { public set isEditMode(isEditMode: boolean) {
this._isEditMode = isEditMode; this._isEditMode = isEditMode;
if (this._isEditMode) {
this.showMarkdown = !this._defaultToWYSIWYG;
}
this._onCellModeChanged.fire(this._isEditMode); this._onCellModeChanged.fire(this._isEditMode);
// Note: this does not require a notebook update as it does not change overall state // 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); this._onCellMarkdownChanged.fire(this._showMarkdown);
} }
public get defaultToWYSIWYG(): boolean {
return this._defaultToWYSIWYG;
}
public get cellSourceChanged(): boolean { public get cellSourceChanged(): boolean {
return this._cellSourceChanged; return this._cellSourceChanged;
@@ -853,4 +852,23 @@ export class CellModel extends Disposable implements ICellModel {
} }
this._future = undefined; 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);
}
}));
}
}
} }

View File

@@ -483,6 +483,7 @@ export interface ICellModel {
isEditMode: boolean; isEditMode: boolean;
showPreview: boolean; showPreview: boolean;
showMarkdown: boolean; showMarkdown: boolean;
defaultToWYSIWYG: boolean;
readonly onCellPreviewModeChanged: Event<boolean>; readonly onCellPreviewModeChanged: Event<boolean>;
readonly onCellMarkdownModeChanged: Event<boolean>; readonly onCellMarkdownModeChanged: Event<boolean>;
sendChangeToNotebook(change: NotebookChangeType): void; sendChangeToNotebook(change: NotebookChangeType): void;