Add tab coloring by server group (#383)

This commit is contained in:
Matt Irvine
2017-12-20 18:21:48 -08:00
committed by GitHub
parent 3ffafbe5bc
commit b1b3a92717
14 changed files with 152 additions and 8 deletions

View File

@@ -220,6 +220,8 @@ export interface IConnectionManagementService {
canChangeConnectionConfig(profile: ConnectionProfile, newGroupID: string): boolean;
getTabColorForUri(uri: string): string;
/**
* Sends a notification that the language flavor for a given URI has changed.
* For SQL, this would be the specific SQL implementation being used.

View File

@@ -148,6 +148,11 @@ export class ConnectionManagementService implements IConnectionManagementService
this.disposables.push(this._onAddConnectionProfile);
this.disposables.push(this._onDeleteConnectionProfile);
// Refresh editor titles when connections start/end/change to ensure tabs are colored correctly
this.onConnectionChanged(() => this.refreshEditorTitles());
this.onConnect(() => this.refreshEditorTitles());
this.onDisconnect(() => this.refreshEditorTitles());
}
// Event Emitters
@@ -1219,6 +1224,7 @@ export class ConnectionManagementService implements IConnectionManagementService
public editGroup(group: ConnectionProfileGroup): Promise<any> {
return new Promise<string>((resolve, reject) => {
this._connectionStore.editGroup(group).then(groupId => {
this.refreshEditorTitles();
this._onAddConnectionProfile.fire();
resolve(null);
}).catch(err => {
@@ -1323,4 +1329,25 @@ export class ConnectionManagementService implements IConnectionManagementService
}
return Promise.reject('The given URI is not currently connected');
}
public getTabColorForUri(uri: string): string {
if (!WorkbenchUtils.getSqlConfigValue<string>(this._workspaceConfigurationService, 'enableTabColors')) {
return undefined;
}
let connectionProfile = this.getConnectionProfile(uri);
if (!connectionProfile) {
return undefined;
}
let matchingGroup = this._connectionStore.getGroupFromId(connectionProfile.groupId);
if (!matchingGroup) {
return undefined;
}
return matchingGroup.color;
}
private refreshEditorTitles(): void {
if (this._editorGroupService instanceof EditorPart) {
this._editorGroupService.refreshEditorTitles();
}
}
}

View File

@@ -19,7 +19,6 @@ import { ConfigurationEditingService } from 'vs/workbench/services/configuration
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import * as data from 'data';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
const MAX_CONNECTIONS_DEFAULT = 25;
@@ -490,6 +489,11 @@ export class ConnectionStore {
return result;
}
public getGroupFromId(groupId: string): IConnectionProfileGroup {
let groups = this._connectionConfig.getAllGroups();
return groups.find(group => group.id === groupId);
}
private getMaxRecentConnectionsCount(): number {
let config = this._workspaceConfigurationService.getConfiguration(Constants.sqlConfigSectionName);

View File

@@ -167,4 +167,8 @@ export class DashboardInput extends EditorInput {
&& profile1.authenticationType === profile2.authenticationType
&& profile1.groupFullName === profile2.groupFullName;
}
public get tabColor(): string {
return this._connectionService.getTabColorForUri(this.uri);
}
}

View File

@@ -180,4 +180,8 @@ export class EditDataInput extends EditorInput implements IConnectableInput {
super.close();
});
}
public get tabColor(): string {
return this._connectionManagementService.getTabColorForUri(this.uri);
}
}

View File

@@ -240,6 +240,11 @@ let registryProperties = {
'description': localize('sql.showBatchTime', '[Optional] Should execution time be shown for individual batches'),
'default': false
},
'sql.enableTabColors': {
'type': 'boolean',
'description': localize('sql.enableTabColors', 'True to color tabs based on the server group of their active connection, false otherwise'),
'default': true
},
'mssql.intelliSense.enableIntelliSense': {
'type': 'boolean',
'default': true,

View File

@@ -252,4 +252,11 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
this._currentEventCallbacks = dispose(this._currentEventCallbacks);
this._currentEventCallbacks = callbacks;
}
/**
* Get the color that should be displayed
*/
public get tabColor(): string {
return this._connectionManagementService.getTabColorForUri(this.uri);
}
}