mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 01:25:36 -05:00
Added editor to table designer (#17576)
* format doc * correct class name * set content * remove mssql commands * merge classes * code refactoring and bug fixing * remove unnecessary class * handle promise Co-authored-by: Alan Ren <alanren@microsoft.com>
This commit is contained in:
@@ -27,6 +27,7 @@ export class TableDesignerEditor extends EditorPane {
|
||||
public static readonly ID: string = 'workbench.editor.tableDesigner';
|
||||
|
||||
private _designer: Designer;
|
||||
private _designerTextEditor: TableDesignerTextEditor;
|
||||
private _saveChangesAction: SaveTableChangesAction;
|
||||
|
||||
constructor(
|
||||
@@ -60,8 +61,10 @@ export class TableDesignerEditor extends EditorPane {
|
||||
this._saveChangesAction = this._instantiationService.createInstance(SaveTableChangesAction);
|
||||
this._saveChangesAction.enabled = false;
|
||||
actionbar.push(this._saveChangesAction, { icon: true, label: false });
|
||||
|
||||
this._designer = new Designer(designerContainer, (editorContainer) => {
|
||||
return this._instantiationService.createInstance(TableDesignerTextEditor, editorContainer);
|
||||
this._designerTextEditor = this._instantiationService.createInstance(TableDesignerTextEditor, editorContainer);
|
||||
return this._designerTextEditor;
|
||||
}, this._contextViewService);
|
||||
this._register(attachDesignerStyler(this._designer, this.themeService));
|
||||
this._register(registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) => {
|
||||
|
||||
@@ -5,16 +5,103 @@
|
||||
|
||||
import { DesignerTextEditor } from 'sql/base/browser/ui/designer/interfaces';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
|
||||
import { UntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel';
|
||||
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
|
||||
import * as nls from 'vs/nls';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { TextResourceEditorModel } from 'vs/workbench/common/editor/textResourceEditorModel';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfigurationService';
|
||||
import { IEditorOpenContext } from 'vs/workbench/common/editor';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
|
||||
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
// TODO: Implement the text editor
|
||||
export class TableDesignerTextEditor implements DesignerTextEditor {
|
||||
class TableDesignerCodeEditor extends CodeEditorWidget {
|
||||
}
|
||||
|
||||
export class TableDesignerTextEditor extends BaseTextEditor implements DesignerTextEditor {
|
||||
private _content: string;
|
||||
private _readonly: boolean;
|
||||
private _contentChangeEventEmitter: Emitter<string> = new Emitter<string>();
|
||||
readonly onDidContentChange: Event<string> = this._contentChangeEventEmitter.event;
|
||||
|
||||
constructor(container: HTMLElement, @IInstantiationService instantiationService: IInstantiationService) {
|
||||
private _untitledTextEditorModel: UntitledTextEditorModel;
|
||||
private _editorInput: UntitledTextEditorInput;
|
||||
private _editorModel: ITextModel;
|
||||
|
||||
public static ID = 'designer.editors.textEditor';
|
||||
constructor(
|
||||
private _container: HTMLElement,
|
||||
@IModelService private _modelService: IModelService,
|
||||
@ITelemetryService telemetryService: ITelemetryService,
|
||||
@IInstantiationService instantiationService: IInstantiationService,
|
||||
@IStorageService storageService: IStorageService,
|
||||
@ITextResourceConfigurationService configurationService: ITextResourceConfigurationService,
|
||||
@IThemeService themeService: IThemeService,
|
||||
@IEditorService editorService: IEditorService,
|
||||
@IEditorGroupsService editorGroupService: IEditorGroupsService
|
||||
|
||||
) {
|
||||
super(TableDesignerTextEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, editorService, editorGroupService);
|
||||
this.create(this._container);
|
||||
this.setVisible(true);
|
||||
this._untitledTextEditorModel = this.instantiationService.createInstance(UntitledTextEditorModel, URI.from({ scheme: Schemas.untitled }), false, undefined, 'sql', undefined);
|
||||
this._editorInput = this.instantiationService.createInstance(UntitledTextEditorInput, this._untitledTextEditorModel);
|
||||
this.setInput(this._editorInput, undefined, undefined).catch(onUnexpectedError);
|
||||
this._editorInput.resolve().then((model) => {
|
||||
this._editorModel = model.textEditorModel;
|
||||
});
|
||||
}
|
||||
|
||||
public override createEditorControl(parent: HTMLElement, configuration: IEditorOptions): editorCommon.IEditor {
|
||||
return this.instantiationService.createInstance(TableDesignerCodeEditor, parent, configuration, {});
|
||||
}
|
||||
|
||||
protected override getConfigurationOverrides(): IEditorOptions {
|
||||
const options = super.getConfigurationOverrides();
|
||||
options.readOnly = true;
|
||||
if (this.input) {
|
||||
options.inDiffEditor = false;
|
||||
options.scrollBeyondLastLine = false;
|
||||
options.folding = false;
|
||||
options.renderWhitespace = 'all';
|
||||
options.wordWrap = 'off';
|
||||
options.renderIndentGuides = false;
|
||||
options.rulers = [];
|
||||
options.glyphMargin = true;
|
||||
options.minimap = {
|
||||
enabled: true
|
||||
};
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
override async setInput(input: UntitledTextEditorInput, options: ITextEditorOptions, context: IEditorOpenContext): Promise<void> {
|
||||
await super.setInput(input, options, context, CancellationToken.None);
|
||||
const editorModel = await this.input.resolve() as TextResourceEditorModel;
|
||||
await editorModel.resolve();
|
||||
this.getControl().setModel(editorModel.textEditorModel);
|
||||
}
|
||||
|
||||
protected getAriaLabel(): string {
|
||||
return nls.localize('designer.textEditorAriaLabel', "Designer text editor.");
|
||||
}
|
||||
|
||||
public override layout(dimension: DOM.Dimension) {
|
||||
this.getControl().layout(dimension);
|
||||
}
|
||||
|
||||
get content(): string {
|
||||
@@ -23,13 +110,8 @@ export class TableDesignerTextEditor implements DesignerTextEditor {
|
||||
|
||||
set content(val: string) {
|
||||
this._content = val;
|
||||
}
|
||||
|
||||
get readonly(): boolean {
|
||||
return this._readonly;
|
||||
}
|
||||
|
||||
set readonly(val: boolean) {
|
||||
this._readonly = val;
|
||||
this._modelService.updateModel(this._editorModel, this._content);
|
||||
this._untitledTextEditorModel.setDirty(false);
|
||||
this.layout(new DOM.Dimension(this._container.clientWidth, this._container.clientHeight));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user