mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 01:25:38 -05:00
* Connection URI made to include every option available instead of basic details (#22045) * Revert "Merge remote-tracking branch 'origin' into feat/connectionUri" This reverts commit 11b2d31bf99e216daee823f732254f69a017fee1, reversing changes made to 36e4db8c0744f81565efdfd2f56a3ae3c0026896. * Revert "Revert "Merge remote-tracking branch 'origin' into feat/connectionUri"" This reverts commit f439673c2693e1144c52e04c14e82cd8566c13a6. * Added changes and fixes for feat connectionuri (#22706) * add title generation at start * added await to refreshConnectionTreeTitles
110 lines
4.3 KiB
TypeScript
110 lines
4.3 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { Disposable } from 'vs/base/common/lifecycle';
|
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
|
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
|
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
|
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
|
|
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
|
|
import { IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar';
|
|
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
|
import { localize } from 'vs/nls';
|
|
|
|
// Connection status bar showing the current global connection
|
|
export class ConnectionStatusbarItem extends Disposable implements IWorkbenchContribution {
|
|
|
|
private static readonly ID = 'status.connection.status';
|
|
|
|
private statusItem: IStatusbarEntryAccessor;
|
|
private readonly name = localize('status.connection.status', "Connection Status");
|
|
|
|
constructor(
|
|
@IStatusbarService private readonly statusbarService: IStatusbarService,
|
|
@IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService,
|
|
@IEditorService private readonly editorService: IEditorService,
|
|
@IObjectExplorerService private readonly objectExplorerService: IObjectExplorerService,
|
|
) {
|
|
super();
|
|
this.statusItem = this._register(
|
|
this.statusbarService.addEntry({
|
|
name: this.name,
|
|
text: '',
|
|
ariaLabel: ''
|
|
},
|
|
ConnectionStatusbarItem.ID,
|
|
StatusbarAlignment.RIGHT, 100)
|
|
);
|
|
|
|
this.hide();
|
|
|
|
this._register(this.connectionManagementService.onConnect(() => this._updateStatus()));
|
|
this._register(this.connectionManagementService.onConnectionChanged(() => this._updateStatus()));
|
|
this._register(this.connectionManagementService.onDisconnect(() => this._updateStatus()));
|
|
this._register(this.editorService.onDidActiveEditorChange(() => this._updateStatus()));
|
|
this._register(this.objectExplorerService.onSelectionOrFocusChange(() => this._updateStatus()));
|
|
}
|
|
|
|
private hide() {
|
|
this.statusbarService.updateEntryVisibility(ConnectionStatusbarItem.ID, false);
|
|
}
|
|
|
|
private show() {
|
|
this.statusbarService.updateEntryVisibility(ConnectionStatusbarItem.ID, true);
|
|
}
|
|
|
|
// Update the connection status shown in the bar
|
|
private _updateStatus(): void {
|
|
let activeConnection = TaskUtilities.getCurrentGlobalConnection(this.objectExplorerService, this.connectionManagementService, this.editorService);
|
|
if (activeConnection) {
|
|
this._setConnectionText(activeConnection);
|
|
this.show();
|
|
} else {
|
|
this.hide();
|
|
}
|
|
}
|
|
|
|
// Set connection info to connection status bar
|
|
private _setConnectionText(connectionProfile: IConnectionProfile): void {
|
|
let text: string = undefined;
|
|
let fullEditorText: string = this.connectionManagementService.getEditorConnectionProfileTitle(connectionProfile);
|
|
if (fullEditorText.length === 0) {
|
|
text = connectionProfile.serverName;
|
|
if (text) {
|
|
if (connectionProfile.databaseName && connectionProfile.databaseName !== '') {
|
|
text = text + ' : ' + connectionProfile.databaseName;
|
|
} else {
|
|
text = text + ' : ' + '<default>';
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
text = fullEditorText;
|
|
}
|
|
|
|
let tooltip: string = undefined;
|
|
|
|
if (!fullEditorText) {
|
|
tooltip = 'Server: ' + connectionProfile.serverName + '\r\n' +
|
|
'Database: ' + (connectionProfile.databaseName ? connectionProfile.databaseName : '<default>') + '\r\n';
|
|
|
|
if (connectionProfile.userName && connectionProfile.userName !== '') {
|
|
tooltip = tooltip + 'Login: ' + connectionProfile.userName + '\r\n';
|
|
}
|
|
}
|
|
else {
|
|
// It is difficult to have every possible option that is different displayed as above with consistent naming, therefore the tooltip will show the full string.
|
|
tooltip = fullEditorText;
|
|
}
|
|
|
|
|
|
this.statusItem.update({
|
|
name: this.name,
|
|
text: text,
|
|
ariaLabel: text, tooltip
|
|
});
|
|
}
|
|
}
|