mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 01:25:37 -05:00
Table Designer - Save Changes feature and Editor related features (#17335)
* table designer add/remove row support * save changes and editor support * address comments * fix build error * including missing change * lower case request name
This commit is contained in:
@@ -9,16 +9,39 @@ import { URI } from 'vs/workbench/workbench.web.api';
|
||||
import { TableDesignerComponentInput } from 'sql/workbench/services/tableDesigner/browser/tableDesignerComponentInput';
|
||||
import { TableDesignerProvider } from 'sql/workbench/services/tableDesigner/common/interface';
|
||||
import * as azdata from 'azdata';
|
||||
import { GroupIdentifier, IEditorInput, IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
|
||||
const NewTable: string = localize('tableDesigner.newTable', "New Table");
|
||||
|
||||
export class TableDesignerInput extends EditorInput {
|
||||
public static ID: string = 'workbench.editorinputs.tableDesignerInput';
|
||||
private _designerComponentInput: TableDesignerComponentInput;
|
||||
constructor(provider: TableDesignerProvider,
|
||||
private _tableInfo: azdata.designers.TableInfo) {
|
||||
private _name: string;
|
||||
|
||||
constructor(
|
||||
private _provider: TableDesignerProvider,
|
||||
private _tableInfo: azdata.designers.TableInfo,
|
||||
@IInstantiationService private readonly _instantiationService: IInstantiationService,
|
||||
@IEditorService editorService: IEditorService) {
|
||||
super();
|
||||
this._designerComponentInput = new TableDesignerComponentInput(provider, this._tableInfo);
|
||||
this._designerComponentInput = this._instantiationService.createInstance(TableDesignerComponentInput, this._provider, this._tableInfo);
|
||||
this._register(this._designerComponentInput.onStateChange((e) => {
|
||||
this._onDidChangeDirty.fire();
|
||||
}));
|
||||
const existingNames = editorService.editors.map(editor => editor.getName());
|
||||
|
||||
if (this._tableInfo.isNewTable) {
|
||||
// Find the next available unique name for the new table designer
|
||||
let idx = 1;
|
||||
do {
|
||||
this._name = `${this._tableInfo.server}.${this._tableInfo.database} - ${NewTable} ${idx}`;
|
||||
idx++;
|
||||
} while (existingNames.indexOf(this._name) !== -1);
|
||||
} else {
|
||||
this._name = `${this._tableInfo.server}.${this._tableInfo.database} - ${this._tableInfo.schema}.${this._tableInfo.name}`;
|
||||
}
|
||||
}
|
||||
|
||||
get typeId(): string {
|
||||
@@ -34,7 +57,33 @@ export class TableDesignerInput extends EditorInput {
|
||||
}
|
||||
|
||||
override getName(): string {
|
||||
const tableName = this._tableInfo.isNewTable ? NewTable : `${this._tableInfo.schema}.${this._tableInfo.name}`;
|
||||
return `${this._tableInfo.server}.${this._tableInfo.database} - ${tableName}`;
|
||||
return this._name;
|
||||
}
|
||||
|
||||
override isDirty(): boolean {
|
||||
return this._designerComponentInput.dirty;
|
||||
}
|
||||
|
||||
override isSaving(): boolean {
|
||||
return this._designerComponentInput.saving;
|
||||
}
|
||||
|
||||
override async save(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
|
||||
await this._designerComponentInput.save();
|
||||
return this;
|
||||
}
|
||||
|
||||
override async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<void> {
|
||||
await this._designerComponentInput.revert();
|
||||
}
|
||||
|
||||
override matches(otherInput: any): boolean {
|
||||
// For existing tables, the table designer provider will give us unique id, we can use it to do the match.
|
||||
// For new tables, we can do the match using their names.
|
||||
return otherInput instanceof TableDesignerInput
|
||||
&& this._provider.providerId === otherInput._provider.providerId
|
||||
&& this._tableInfo.isNewTable === otherInput._tableInfo.isNewTable
|
||||
&& (!this._tableInfo.isNewTable || this.getName() === otherInput.getName())
|
||||
&& (this._tableInfo.isNewTable || this._tableInfo.id === otherInput._tableInfo.id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user