Add scripted object name to query editor tab display (#4403)

* Add scripted object name to query editor tab display

* Update src/sql/parts/query/common/queryInput.ts

Co-Authored-By: shueybubbles <shueybubbles@hotmail.com>
This commit is contained in:
David Shiflet
2019-03-12 22:07:11 -04:00
committed by GitHub
parent dadfbd2ddb
commit 58e5125cde
4 changed files with 20 additions and 11 deletions

View File

@@ -144,6 +144,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
public showQueryResultsEditor(): void { this._showQueryResultsEditor.fire(); }
public updateSelection(selection: ISelectionData): void { this._updateSelection.fire(selection); }
public getTypeId(): string { return QueryInput.ID; }
// Description is shown beside the tab name in the combobox of open editors
public getDescription(): string { return this._description; }
public supportsSplitEditor(): boolean { return false; }
public getModeId(): string { return QueryInput.SCHEMA; }
@@ -168,26 +169,33 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
public getEncoding(): string { return this._sql.getEncoding(); }
public suggestFileName(): string { return this._sql.suggestFileName(); }
public getName(): string {
public getName(longForm?: boolean): string {
if (this._configurationService.getValue('sql.showConnectionInfoInTitle')) {
let profile = this._connectionManagementService.getConnectionProfile(this.uri);
let title = '';
if (this._description && this._description !== '') {
title = this._description + ' ';
}
if (profile) {
if (profile.userName) {
title = `${profile.serverName}.${profile.databaseName} (${profile.userName})`;
title += `${profile.serverName}.${profile.databaseName} (${profile.userName})`;
} else {
title = `${profile.serverName}.${profile.databaseName} (${profile.authenticationType})`;
title += `${profile.serverName}.${profile.databaseName} (${profile.authenticationType})`;
}
} else {
title = localize('disconnected', 'disconnected');
title += localize('disconnected', 'disconnected');
}
return this._sql.getName() + ` - ${trimTitle(title)}`;
return this._sql.getName() + (longForm ? (' - ' + title) : ` - ${trimTitle(title)}`);
} else {
return this._sql.getName();
}
}
// Called to get the tooltip of the tab
public getTitle() {
return this.getName(true);
}
public get hasAssociatedFilePath(): boolean { return this._sql.hasAssociatedFilePath; }
public setEncoding(encoding: string, mode: EncodingMode /* ignored, we only have Encode */): void {
@@ -309,4 +317,4 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
public get tabColor(): string {
return this._connectionManagementService.getTabColorForUri(this.uri);
}
}
}

View File

@@ -223,7 +223,8 @@ export function script(connectionProfile: IConnectionProfile, metadata: azdata.O
let script: string = result.script;
if (script) {
queryEditorService.newSqlEditor(script, connectionProfile.providerName).then((owner) => {
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
queryEditorService.newSqlEditor(script, connectionProfile.providerName, undefined, description).then((owner) => {
// Connect our editor to the input connection
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },

View File

@@ -74,7 +74,7 @@ export class QueryEditorService implements IQueryEditorService {
/**
* Creates new untitled document for SQL query and opens in new editor tab
*/
public newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean): Promise<IConnectableInput> {
public newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean, objectName?: string): Promise<IConnectableInput> {
return new Promise<IConnectableInput>(async (resolve, reject) => {
try {
// Create file path and file URI
@@ -92,7 +92,7 @@ export class QueryEditorService implements IQueryEditorService {
}
const queryResultsInput: QueryResultsInput = this._instantiationService.createInstance(QueryResultsInput, docUri.toString());
let queryInput: QueryInput = this._instantiationService.createInstance(QueryInput, '', fileInput, queryResultsInput, connectionProviderName);
let queryInput: QueryInput = this._instantiationService.createInstance(QueryInput, objectName, fileInput, queryResultsInput, connectionProviderName);
this._editorService.openEditor(queryInput, { pinned: true })
.then((editor) => {

View File

@@ -23,7 +23,7 @@ export interface IQueryEditorService {
_serviceBrand: any;
// Creates new untitled document for SQL queries and opens it in a new editor tab
newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean): Promise<IConnectableInput>;
newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean, objectName?:string ): Promise<IConnectableInput>;
// Creates a new query plan document
newQueryPlanEditor(xmlShowPlan: string): Promise<any>;